From e3256f83c6e111c63c099c39445b393fd49fd7b3 Mon Sep 17 00:00:00 2001 From: Alex Karle Date: Tue, 31 Mar 2020 23:52:08 -0400 Subject: [PATCH] Euchre::Dealer: start_game now deals hands! With a new debug.html section to prove it ;) --- lib/Euchre/Dealer.pm | 29 +++++++++++++++++++++++++++++ public/debug.html | 6 ++++++ 2 files changed, 35 insertions(+) diff --git a/lib/Euchre/Dealer.pm b/lib/Euchre/Dealer.pm index 23fd05d..e7d742b 100644 --- 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 index 9cab5c0..892d90c 100644 --- 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 + '
' + } else if (msg.msg_type === 'deal') { + document.getElementById('hand').innerHTML = 'HAND: ' + msg.hand + '
' + document.getElementById('nominee').innerHTML = 'Trump Nominee: ' + msg.trump_nominee + '
' } }; @@ -59,6 +62,9 @@

Not in a game


+
No cards in hand
+
+

-- libgit2 1.1.1