From 8ba04a3fd139bde77079b2befa31706e4e6f1644 Mon Sep 17 00:00:00 2001 From: Chris Karle Date: Sat, 25 Apr 2020 17:40:51 -0400 Subject: [PATCH] Dealer: add END_DEBUG; CardTable fixes for end of game Dealer: add END_DEBUG environment option which starts the game at [9, 9] so that game end & rollover can be debugged. CardTable: Add a game win announcement, fix handling 'end' phase including update score, display seatPicker and Exit at end of game to allow changing of seats/players. --- assets/components/CardTable.js | 38 +++++++++++++++++++++++++++++--------- lib/Euchre/Dealer.pm | 5 ++++- 2 files changed, 33 insertions(+), 10 deletions(-) diff --git a/assets/components/CardTable.js b/assets/components/CardTable.js index 02e88eb..4b360f9 100644 --- a/assets/components/CardTable.js +++ b/assets/components/CardTable.js @@ -48,13 +48,18 @@ export default class CardTable extends React.Component { handLengths: [], score: [0, 0], trickWinner:'', - tricks:[] + tricks:[], + bannerMsg: '' }; }; componentDidMount () { - const websoc = this.props.client; - websoc.onmessage = (event) => this.processResponse(event); + const {name, tableName, client} = this.props; + client.onmessage = (event) => this.processResponse(event); + const welcomeMsg = 'Welcome to the ' + tableName + ' table, ' + name + '!'; + this.setState({ + bannerMsg: welcomeMsg + }); }; processResponse = (event) => { @@ -80,6 +85,9 @@ export default class CardTable extends React.Component { case 'pause': this.processPause(msg); break; + case 'end': + this.processEnd(msg); + break; default: break; } @@ -201,6 +209,20 @@ export default class CardTable extends React.Component { }) } + processEnd = msg => { + const {playerNames, mySeat, leftSeat, partnerSeat, rightSeat} = this.state; + // arrangeScore[0] us, [1] them + const finalScore = this.arrangeScore(msg.game.score); + const winMsg = finalScore[0] > finalScore[1] ? + 'You and ' + playerNames[partnerSeat] + ' win the game!!' : + playerNames[leftSeat] + ' and ' + playerNames[rightSeat] + ' win this one...'; + this.setState({ + phase: 'end', + score: finalScore, + bannerMsg: winMsg + }); + } + handStartSetup = msg => { const {leftSeat, rightSeat, partnerSeat, mySeat, dealSeat} = this.state; let handInfo = ['', '', '', '']; @@ -409,14 +431,12 @@ export default class CardTable extends React.Component { const { playerNames, mySeat, phase, myCards, myHandInfo, myTurnInfo, partnerName, partnerHandInfo, partnerTurnInfo, partnerSeat, leftName, leftTurnInfo, leftHandInfo, leftSeat, rightName, rightHandInfo, rightTurnInfo, rightSeat, trumpPlace, trumpNom, turnSeat, - dealSeat, trump, handLengths, score, trickWinner } = this.state; - const {name, tableName} = this.props; - const showSeatPicker = phase == 'lobby'; + dealSeat, trump, handLengths, score, trickWinner, bannerMsg } = this.state; + const showSeatPicker = phase == 'lobby' || phase == 'end'; const showTrump = (phase == 'vote') || (phase == 'vote2') || (phase == 'swap'); const showTrumpPicker = showTrump && (turnSeat == mySeat); const showSwap = (phase == 'swap') && (dealSeat == mySeat); const showInfo = !showSeatPicker && !showTrumpPicker && !showSwap; - const welcomeMsg = 'Welcome to the ' + tableName + ' table, ' + name + '!'; const tcp = "trump__holder " + trumpPlace; const trumpImage = (phase != 'vote2') ? 'cards/' + trumpNom + '.svg' : 'cards/1B.svg'; const trumpMsg = phase == 'play' ? suit[trump] + ' are trump' : ''; @@ -427,7 +447,7 @@ export default class CardTable extends React.Component { {showSeatPicker && ( -

{welcomeMsg}

+

{bannerMsg}

@@ -456,7 +476,7 @@ export default class CardTable extends React.Component {
)}
- {!showSeatPicker && ( + {(phase != 'lobby') && (
Us: {score[0]}
Them: {score[1]}
diff --git a/lib/Euchre/Dealer.pm b/lib/Euchre/Dealer.pm index 5b12215..2bceb72 100644 --- a/lib/Euchre/Dealer.pm +++ b/lib/Euchre/Dealer.pm @@ -172,6 +172,9 @@ sub join_game { my $id = $msg->{game_id}; + # ckDebug: if env END_DEBUG make score 9-9 + # as in line ~102 above: my $timeout = $ENV{DEBUG} ? 1 : (60 * 30); # 30 mins + # init game if needed if (!exists $GAMES{$id}) { $GAMES{$id} = { @@ -184,7 +187,7 @@ sub join_game { tricks => [0, 0, 0, 0], table => [undef, undef, undef, undef], caller => -1, - score => [0, 0], + score => $ENV{END_DEBUG} ? [9,9] :[0, 0], phase => 'lobby', start_time => time, }; -- libgit2 1.1.1