commit 5b80f02b53cc54efb609a956a15151ffd48381e3 (patch)
parent fd103786440507650c83614c24a3326e3d843a34
Author: Alex Karle <alex@karle.co>
Date: Fri, 3 Apr 2020 23:05:20 -0400
Euchre::Dealer: Add trump_nominee to game state
After discussion with ~ckarle, we decided that it would be easier to
handle the "voting round" if the trump_nominee was a persistent part of
the game state rather than a single time value on the deal.
This will make it easier for clients to know what can and cannot be
nominated trump.
Diffstat:
2 files changed, 13 insertions(+), 6 deletions(-)
diff --git a/lib/Euchre/Dealer.pm b/lib/Euchre/Dealer.pm
@@ -36,6 +36,7 @@ our @EXPORT = qw(
# table => [ c1, c2, c3, c4 ], # up to 4 cards
# score => [X, Y],
# in_progress => 0/1,
+# trump_nominee => 0-23,
# }
#
# We decided the players would keep track of their own hands
@@ -208,10 +209,13 @@ sub num_players {
sub start_new_round {
my ($game) = @_;
+ # Shift dealer and deal
+ $game->{dealer} = ($game->{dealer} + 1 % 4);
deal_players_hands($game);
- # TODO: vote trump
- # TODO: start accepting play_card's
+ # Signal vote of player next to dealer...
+ $game->{turn} = ($game->{dealer} + 1 % 4);
+ broadcast_gamestate($game); # includes trump_nominee
}
# Hands need to be sent as private messages. For now, we don't
@@ -220,14 +224,13 @@ sub deal_players_hands {
my ($game) = @_;
my ($handsA, $kiddeyA) = deal();
- my $nominee = cid_to_name(shift @$kiddeyA);
+ $game->{trump_nominee} = shift @$kiddeyA;
for my $p (@{$game->{players}}) {
my @hand = map { cid_to_name($_) } @{shift @$handsA};
$p->{ws}->send({ json =>
{
msg_type => 'deal',
hand => \@hand,
- trump_nominee => $nominee,
}
});
}
@@ -253,6 +256,10 @@ sub broadcast_gamestate {
spectators => \@snames,
};
+ if (exists $game->{trump_nominee}) {
+ $msg->{trump_nominee} = cid_to_name($game->{trump_nominee});
+ }
+
my $json = { msg_type => 'game_state', game => $msg };
for my $ws (@all_ws) {
$ws->send({ json => $json});
diff --git a/public/debug.html b/public/debug.html
@@ -16,13 +16,13 @@
gameState = '<br>Game: ' + msg.game.id + '<br>' +
'Players: ' + msg.game.players + '<br>' +
'Spectators: ' + msg.game.spectators + '<br>' +
- 'In Progress?: ' + msg.game.in_progress + '<br>'
+ 'In Progress?: ' + msg.game.in_progress + '<br>' +
+ 'Trump Nominee: ' + msg.game.trump_nominee + '<br>'
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>'
}
};