From 1e78fe74ac5e27528d8eea75b9ad759e80113a3f Mon Sep 17 00:00:00 2001 From: Chris Odegard Date: Tue, 4 Jul 2017 00:32:57 -0400 Subject: [PATCH] Implement Betting mechanism per player #8 --- .vscode/launch.json | 4 +--- src/ControlPanel.js | 6 +++--- src/DeckContainer.js | 16 ++++++++-------- src/Table.js | 41 ++++++++++++++++++++++++++++++++++++----- 4 files changed, 48 insertions(+), 19 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index 40efaf9..986c33b 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -17,8 +17,6 @@ "name": "Attach to Chrome", "port": 9222, "webRoot": "${workspaceRoot}" - }, - - + } ] } \ No newline at end of file diff --git a/src/ControlPanel.js b/src/ControlPanel.js index fc8d57d..7b34f33 100644 --- a/src/ControlPanel.js +++ b/src/ControlPanel.js @@ -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 diff --git a/src/DeckContainer.js b/src/DeckContainer.js index 9629501..99fd33b 100644 --- a/src/DeckContainer.js +++ b/src/DeckContainer.js @@ -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} + {" "} + this._statusCalloutTarget = calloutTarget} + /> ; return (
-

+

{titleBar} - {this.props.gameStatus > 0 && - this._statusCalloutTarget = calloutTarget} - />} {" "} {toggleIcon}

diff --git a/src/Table.js b/src/Table.js index 9e914e3..0baec99 100644 --- a/src/Table.js +++ b/src/Table.js @@ -20,6 +20,7 @@ export class Table extends Component { players: [], currentPlayer: 0, turnCount: 0, + round: 0, pot: 0, minimumBet: 25, messageBarDefinition: { @@ -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); @@ -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 }); } @@ -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) ); } @@ -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); @@ -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() {