commit 657f2a815616006414e602a90290c74f30031ab4 (patch)
parent 940ffc20b8332f19f3974bf258018306afdbd421
Author: Alex Karle <alex@karle.co>
Date: Fri, 3 Apr 2020 23:16:38 -0400
Euchre::Dealer: Change game's 'in_progress' -> 'phase'
Instead of a boolean of whether we're playing, this commit updates the
game state to have a phase which will be used to simplify when actions
can and cannot be done.
Diffstat:
2 files changed, 6 insertions(+), 7 deletions(-)
diff --git a/lib/Euchre/Dealer.pm b/lib/Euchre/Dealer.pm
@@ -35,7 +35,7 @@ our @EXPORT = qw(
# caller => 0-3,
# table => [ c1, c2, c3, c4 ], # up to 4 cards
# score => [X, Y],
-# in_progress => 0/1,
+# phase => 'lobby', 'play', 'vote', 'end'
# trump_nominee => 0-23,
# }
#
@@ -128,13 +128,13 @@ sub join_game {
table => [],
callers => -1,
score => [0, 0],
- in_progress => 0,
+ phase => 'lobby',
};
}
# Handle full game case
- if ($GAMES{$id}->{in_progress}) {
- send_error($p, 'Already 4 players');
+ if ($GAMES{$id}->{phase} ne 'lobby') {
+ send_error($p, 'Game already in progress');
} else {
# Add player object to Game
# All players start as spectators and have to take a seat explicitly
@@ -198,10 +198,8 @@ sub start_game {
if (num_players($game->{id}) < 4) {
send_error($p, "Can't start with empty seats!");
} else {
- $game->{in_progress} = 1;
# TODO: kick spectators out?
# TODO: deal!
- broadcast_gamestate($game);
}
start_new_round($game);
}
@@ -220,6 +218,7 @@ sub start_new_round {
# Signal vote of player next to dealer...
$game->{turn} = ($game->{dealer} + 1 % 4);
+ $game->{phase} = 'vote';
broadcast_gamestate($game); # includes trump_nominee
}
diff --git a/public/debug.html b/public/debug.html
@@ -16,7 +16,7 @@
gameState = '<br>Game: ' + msg.game.id + '<br>' +
'Players: ' + msg.game.players + '<br>' +
'Spectators: ' + msg.game.spectators + '<br>' +
- 'In Progress?: ' + msg.game.in_progress + '<br>' +
+ 'Game Phase: ' + msg.game.phase + '<br>' +
'Trump Nominee: ' + msg.game.trump_nominee + '<br>'
document.getElementById('game').innerHTML = gameState
} else if (msg.msg_type === 'error') {