From 657f2a815616006414e602a90290c74f30031ab4 Mon Sep 17 00:00:00 2001 From: Alex Karle Date: Fri, 3 Apr 2020 23:16:38 -0400 Subject: [PATCH] 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. --- lib/Euchre/Dealer.pm | 11 +++++------ public/debug.html | 2 +- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/lib/Euchre/Dealer.pm b/lib/Euchre/Dealer.pm index ce78a02..9d35924 100644 --- 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 index d49903d..2c227c8 100644 --- a/public/debug.html +++ b/public/debug.html @@ -16,7 +16,7 @@ gameState = '
Game: ' + msg.game.id + '
' + 'Players: ' + msg.game.players + '
' + 'Spectators: ' + msg.game.spectators + '
' + - 'In Progress?: ' + msg.game.in_progress + '
' + + 'Game Phase: ' + msg.game.phase + '
' + 'Trump Nominee: ' + msg.game.trump_nominee + '
' document.getElementById('game').innerHTML = gameState } else if (msg.msg_type === 'error') { -- libgit2 1.1.1