euchre-live

Euchre web-app for the socially distant family
git clone git://git.alexkarle.com/euchre-live.git
Log | Files | Refs | README | LICENSE

commit 8ba04a3fd139bde77079b2befa31706e4e6f1644 (patch)
parent 73d4f687bfe9d52cd602cfdec9743ea715e9dc95
Author: Chris Karle <chriskarle@hotmail.com>
Date:   Sat, 25 Apr 2020 17:40:51 -0400

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.

Diffstat:
Massets/components/CardTable.js | 38+++++++++++++++++++++++++++++---------
Mlib/Euchre/Dealer.pm | 5++++-
2 files changed, 33 insertions(+), 10 deletions(-)

diff --git 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 && ( <Row className="table__header"> <Column className="hd__left" sm={3}> - <h3>{welcomeMsg}</h3> + <h3>{bannerMsg}</h3> </Column> <Column className="hd__right" sm={1}> <div className="exit__row"> @@ -456,7 +476,7 @@ export default class CardTable extends React.Component { </div>)} </Column> <Column className="tt__right" sm={1}> - {!showSeatPicker && ( + {(phase != 'lobby') && ( <div className="score__holder"> <div className="us__score">Us: {score[0]}</div> <div className="them__score">Them: {score[1]}</div> diff --git 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, };