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 e3256f83c6e111c63c099c39445b393fd49fd7b3 (patch)
parent 2d61fe7af70d5fa039017b12efbdf8ce22e01a7c
Author: Alex Karle <alex@karle.co>
Date:   Tue, 31 Mar 2020 23:52:08 -0400

Euchre::Dealer: start_game now deals hands!

With a new debug.html section to prove it ;)

Diffstat:
Mlib/Euchre/Dealer.pm | 29+++++++++++++++++++++++++++++
Mpublic/debug.html | 6++++++
2 files changed, 35 insertions(+), 0 deletions(-)

diff --git a/lib/Euchre/Dealer.pm b/lib/Euchre/Dealer.pm @@ -198,6 +198,7 @@ sub start_game { # TODO: deal! broadcast_gamestate($game); } + start_new_round($game); } sub num_players { @@ -205,6 +206,34 @@ sub num_players { return scalar grep { defined } @{$GAMES{$gid}->{players}} } +sub start_new_round { + my ($game) = @_; + + deal_players_hands($game); + + # TODO: vote trump + # TODO: start accepting play_card's +} + +# Hands need to be sent as private messages. For now, we don't +# keep them in the game state to simplify server logic +sub deal_players_hands { + my ($game) = @_; + + my ($handsA, $kiddeyA) = deal(); + my $nominee = cid_to_name(shift @$kiddeyA); + for my $p (@{$game->{players}}) { + my @hand = map { cid_to_name($_) } @{shift @$handsA}; + $p->{ws}->send({ json => + encode_json({ + msg_type => 'deal', + hand => \@hand, + trump_nominee => $nominee, + }) + }); + } +} + # XXX: The most simplest (bulkiest) message we can send is to just # broadcast the gamestate to all clients. This will be our temporary # debugging method / MVP. We can trim down the communication later diff --git a/public/debug.html b/public/debug.html @@ -20,6 +20,9 @@ document.getElementById('game').innerHTML = gameState } else if (msg.msg_type === 'error') { document.getElementById('error').innerHTML += msg.msg + '<br>' + } else if (msg.msg_type === 'deal') { + document.getElementById('hand').innerHTML = 'HAND: ' + msg.hand + '<br>' + document.getElementById('nominee').innerHTML = 'Trump Nominee: ' + msg.trump_nominee + '<br>' } }; @@ -59,6 +62,9 @@ <br><br> <div id="game">Not in a game</div> <br><br> + <div id="hand">No cards in hand</div> + <div id="nominee"></div> + <br><br> <div id="error" style="color:red"> </div> </body> </html>