Skip to content

Commit

Permalink
Implement Betting mechanism per player #8
Browse files Browse the repository at this point in the history
  • Loading branch information
codegard1 committed Jul 4, 2017
1 parent 9f4f2a6 commit 1e78fe7
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 19 deletions.
4 changes: 1 addition & 3 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
"name": "Attach to Chrome",
"port": 9222,
"webRoot": "${workspaceRoot}"
},


}
]
}
6 changes: 3 additions & 3 deletions src/ControlPanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,9 @@ export class ControlPanel extends Component {
onClick: this.props.stay
},
{
key: "reset-game",
name: "Reset Game",
ariaLabel: "Reset Game",
key: "new-round",
name: "New Round",
ariaLabel: "New Round",
iconProps: { iconName: "Refresh" },
disabled: false,
onClick: this.props.resetGame
Expand Down
16 changes: 8 additions & 8 deletions src/DeckContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,19 +83,19 @@ export class DeckContainer extends Component {
{` ($${this.props.player.bank}) `}{" "}
Hand Value: {this.props.handValue.aceAsOne}
{this.props.handValue.aceAsOne !== this.props.handValue.aceAsEleven &&
" / " + this.props.handValue.aceAsEleven}{" "}
" / " + this.props.handValue.aceAsEleven}
{" "}
<i
className="ms-Icon ms-Icon--Info"
onClick={this._toggleStatusCallout}
ref={calloutTarget => this._statusCalloutTarget = calloutTarget}
/>
</span>;

return (
<div className={style}>
<h3 className="ms-font-xl">
<h3 className="ms-font-s">
{titleBar}
{this.props.gameStatus > 0 &&
<i
className="ms-Icon ms-Icon--Info"
onClick={this._toggleStatusCallout}
ref={calloutTarget => this._statusCalloutTarget = calloutTarget}
/>}
{" "}
{toggleIcon}
</h3>
Expand Down
41 changes: 36 additions & 5 deletions src/Table.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export class Table extends Component {
players: [],
currentPlayer: 0,
turnCount: 0,
round: 0,
pot: 0,
minimumBet: 25,
messageBarDefinition: {
Expand All @@ -45,6 +46,7 @@ export class Table extends Component {
this._deal = this._deal.bind(this);
this._hit = this._hit.bind(this);
this._bet = this._bet.bind(this);
this._ante = this._ante.bind(this);
this._stay = this._stay.bind(this);
this._draw = this._draw.bind(this);
this._reset = this._reset.bind(this);
Expand Down Expand Up @@ -133,6 +135,7 @@ export class Table extends Component {
players[index].hand = [];
players[index].handValue = { aceAsOne: 0, aceAsEleven: 0 };
players[index].status = "ok";
players[index].turn = false;
this.setState({ players });
}

Expand All @@ -153,9 +156,11 @@ export class Table extends Component {
selected: [],
gameStatus: 0,
turnCount: 0,
currentPlayer: 0
currentPlayer: 0,
round: this.state.round + 1,
pot: 0
},
this._showMessageBar("Game reset", MessageBarType.info)
this._showMessageBar("New Round", MessageBarType.info)
);
}

Expand Down Expand Up @@ -380,9 +385,14 @@ export class Table extends Component {
this._showMessageBar("Hello", MessageBarType.info);
break;

case 1: // New Game
case 1: // Game in progress
this._showMessageBar("Game in progress", MessageBarType.info);

// all players bet the minimum to start
if (this.state.turnCount === 0) {
this._ante();
}

// evaluate hands
players.forEach(player => {
player.handValue = this._evaluateHand(player.hand);
Expand Down Expand Up @@ -470,9 +480,30 @@ export class Table extends Component {
}
}

_bet(ev, target, amount = this.state.minimumBet) {
_bet(
ev,
target,
playerIndex = this.state.currentPlayer,
amount = this.state.minimumBet
) {
let players = this.state.players;
players[playerIndex].bank -= amount;
const pot = this.state.pot + amount;
this.setState({ pot });
this.setState({ pot, players });
}

_ante(amount = this.state.minimumBet) {
let players = this.state.players;
let pot = this.state.pot;

players.forEach(player => {
player.bank -= amount;
pot += amount;
});
this.setState(
{ players, pot },
this._showMessageBar(`Ante: ${amount}`, MessageBarType.info)
);
}

render() {
Expand Down

0 comments on commit 1e78fe7

Please sign in to comment.