Skip to content

Commit

Permalink
moving responsabilities
Browse files Browse the repository at this point in the history
  • Loading branch information
vmolero committed Mar 5, 2018
1 parent fe68a59 commit fa0ef71
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/components/BoardComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ export default class BoardComponent extends React.Component<{}, BoardStateInterf
}

public handleDealClick() {
let board: Board = new Board();
board.addPlayer(new Player());
let board: Board = this.state.board;
board.firstDeal();
this.setState(
{
Expand Down Expand Up @@ -83,6 +82,7 @@ export default class BoardComponent extends React.Component<{}, BoardStateInterf

public render() {
const board: Board = this.state.board;

return (
<div id="table">
<aside id="subheader">
Expand Down
32 changes: 28 additions & 4 deletions src/components/DealComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,41 @@ interface DealPropsInterface {
onStandClick: Function;
}

export default class DealComponent extends React.Component<DealPropsInterface, {}> {
interface DealStateInterface {
deal: Deal;
}

export default class DealComponent extends React.Component<DealPropsInterface, DealStateInterface> {
public render() {
let deal: Deal = this.props.deal;
let btnStandValue = deal.getPlayerScore() > deal.getHouseScore() ? 'Stand' : 'Surrender';
let invisibleDeal: string = deal.isDealOver() ? 'invisible' : '';
let invisibleOthers: string = deal.isDealOver() ? '' : 'invisible';
return (
<div id="gamezone">
<div id="gamebuttons">
<span id="playeramount"><span id="player">{deal.getPlayerScore()}</span> </span>
<input type="button" id="btnDealer" value="Deal !" onClick={() => this.props.onDealClick()} />
<input type="button" id="btnHit" value="Hit" onClick={() => this.props.onHitClick()} />
<input type="button" id="btnStand" value={btnStandValue} onClick={() => this.props.onStandClick()} />
<input
className={invisibleDeal}
type="button"
id="btnDealer"
value="Deal !"
onClick={() => this.props.onDealClick()}
/>
<input
className={invisibleOthers}
type="button"
id="btnHit"
value="Hit"
onClick={() => this.props.onHitClick()}
/>
<input
className={invisibleOthers}
type="button"
id="btnStand"
value={btnStandValue}
onClick={() => this.props.onStandClick()}
/>
<span id="bankamount"> <span id="bank">{deal.getHouseScore()}</span></span>
</div>
<HandComponent hand={deal.getPlayerHand()} caption="Your cards" prefix="player" />
Expand Down

0 comments on commit fa0ef71

Please sign in to comment.