From 1003ff9a3c3db67c83f20a427572018b5046b21b Mon Sep 17 00:00:00 2001 From: Alex Karle Date: Sat, 25 Apr 2020 21:00:10 -0400 Subject: [PATCH] Euchre::Dealer: Add restart_game action for end game At the end of the game, players should be able to decide if they want to play again or if they want to leave. Restart game just resets the score and throws you back into the 'lobby' phase (for seat picking, etc) start_game will then work from there, dealing new hands and all that. --- lib/Euchre/Dealer.pm | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/Euchre/Dealer.pm b/lib/Euchre/Dealer.pm index 748e2f2..3d85d75 100644 --- a/lib/Euchre/Dealer.pm +++ b/lib/Euchre/Dealer.pm @@ -136,6 +136,7 @@ sub handle_msg { take_seat => [\&take_seat, 'lobby', "Can't change seats during game"], stand_up => [\&stand_up, 'lobby', "Can't change seats during game"], start_game => [\&start_game, 'lobby', "Game already started"], + restart_game => [\&restart_game, 'end', "Game hasn't ended"], # Gameplay order => [\&order, 'vote', "Not time for a vote", 1], @@ -294,11 +295,18 @@ sub start_game { return; } - # TODO: kick spectators out? - # TODO: deal! start_new_round($game); } +sub restart_game { + my ($p) = @_; + my $game = $p->{game}; + + $game->{score} = $ENV{END_DEBUG} ? [9,9] : [0,0]; + $game->{phase} = 'lobby'; + broadcast_gamestate($game); +} + sub num_players { my ($gid) = @_; return scalar grep { defined } @{$GAMES{$gid}->{players}} -- libgit2 1.1.1