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 f99bf33f7a23824ae17a2453732648380ff594ec (patch)
parent 2302beb243bae272bf5701c9fb5713ac194a42cb
Author: Alex Karle <alex@karle.co>
Date:   Mon, 20 Apr 2020 18:18:15 -0400

Euchre::Dealer: Add prev_table to game state for clients

When the last card of the trick is played, the game keeps chugging,
sending each player an empty table, meaning NO ONE knows what that
person actually played! (are they cheating? was that an Ace? Who counts
trump anyways?).

The easiest solution here, short of adding an async pause to the server,
is to include the previous table in the game state. Clients can choose
to always display it (cough: my lazy debug page), or they can choose to
detect that the table is empty and temporarily display the previous
table for a few seconds before allowing users to vote/play cards.

In the process, I removed the clearing of table in start_new_round; it
was redundant (set in play_card or join_game).

Diffstat:
Mlib/Euchre/Dealer.pm | 4+++-
Mpublic/debug.html | 15+++++++++++++++
2 files changed, 18 insertions(+), 1 deletion(-)

diff --git a/lib/Euchre/Dealer.pm b/lib/Euchre/Dealer.pm @@ -34,6 +34,7 @@ our @EXPORT = qw( # led => suit, # caller => 0-3, # table => [ c1, c2, c3, c4 ], # exactly 4, undef if not played +# prev_table => [ c1, c2, c3, c4 ], # Last trick (for client-viewing) # score => [X, Y], # phase => 'lobby', 'play', 'vote', 'end' # trump_nominee => card, @@ -151,6 +152,7 @@ sub join_game { trump => undef, tricks => [0, 0, 0, 0], table => [undef, undef, undef, undef], + prev_table => [undef, undef, undef, undef], caller => -1, score => [0, 0], phase => 'lobby', @@ -271,7 +273,6 @@ sub start_new_round { # Shift dealer and deal $game->{dealer} = ($game->{dealer} + 1) % 4; - $game->{table} = [undef, undef, undef, undef]; $game->{trump} = undef; $game->{tricks} = [0,0,0,0]; $game->{out_player} = -1; @@ -423,6 +424,7 @@ sub play_card { $game->{tricks}->[$winner_id]++; $game->{turn} = $winner_id; + $game->{prev_table} = $game->{table}; $game->{table} = [undef, undef, undef, undef]; $game->{led} = undef; diff --git a/public/debug.html b/public/debug.html @@ -7,6 +7,9 @@ img.card { width: 100px; } + img.prev_card { + width: 20px; + } </style> </head> <body> @@ -53,6 +56,16 @@ } else { document.getElementById('table').innerHTML = 'No cards on table' } + if (msg.game.prev_table.length) { + document.getElementById('prev_table').innerHTML = 'Last Trick: ' + for (var i = 0; i < msg.game.prev_table.length; i++) { + var c = msg.game.prev_table[i] + if (c === null) { + c = '2B' // show back + } + document.getElementById('prev_table').innerHTML += '<img class="prev_card" src="cards/' + c + '.svg">' + } + } document.getElementById('game').innerHTML = gameState } else if (msg.msg_type === 'error') { document.getElementById('error').innerHTML += msg.msg + '<br>' @@ -120,6 +133,8 @@ <br><br> <div id="table">No cards on table</div> <br> <br> + <div id="prev_table"></div> + <br> <br> <div id="hand">No cards in hand</div> <br> <button onclick="vote(0)">Order</button>