commit d9f1528631e35f64f9cb490472a73b9d0c86fde9 (patch)
parent 474d0eda557d8d68904a01c8a27b5017676d08ad
Author: Alex Karle <alex@karle.co>
Date: Sat, 2 May 2020 18:12:00 -0400
refactor: Move next_turn/reset_turn to Game methods
Diffstat:
2 files changed, 22 insertions(+), 23 deletions(-)
diff --git a/lib/Euchre/Dealer.pm b/lib/Euchre/Dealer.pm
@@ -298,7 +298,7 @@ sub start_new_round {
deal_players_hands($game);
# Signal vote of player next to dealer...
- reset_turn($game);
+ $game->reset_turn();
$game->phase('vote');
$game->pass_count(0);
broadcast_gamestate($game); # includes trump_nominee
@@ -325,7 +325,7 @@ sub order {
my $game = $p->game;
if ($msg->{vote} eq 'pass') {
- next_turn($game);
+ $game->next_turn();
$game->pass_count($game->pass_count + 1);
if ($game->pass_count >= 8) {
# Throw em in
@@ -365,7 +365,7 @@ sub order {
} else {
# Get right to it!
$game->phase('play');
- reset_turn($game);
+ $game->reset_turn();
}
sort_hands($game);
@@ -418,7 +418,7 @@ sub play_card {
# Update the table and current player
$game->table->[$seat] = $msg->{card};
- next_turn($game);
+ $game->next_turn();
my $played_cards = scalar grep { defined } @{$game->table};
@@ -506,7 +506,7 @@ sub dealer_swap {
# Start the game
$game->phase('play');
- reset_turn($game);
+ $game->reset_turn();
broadcast_gamestate($game);
}
@@ -544,24 +544,6 @@ sub broadcast_gamestate {
}
}
-
-sub next_turn {
- my ($game) = @_;
-
- my $turn = ($game->turn + 1) % 4;
- if ($turn == $game->out_player) {
- # It's a loner! Only gonna be one of these...
- $turn = ($turn + 1) % 4;
- }
- $game->turn($turn);
-}
-
-sub reset_turn {
- my ($game) = @_;
- $game->turn($game->dealer);
- next_turn($game);
-}
-
# We only need this when trump suit voted, not every broadcast
sub sort_hands {
my ($game) = @_;
diff --git a/lib/Euchre/Game.pm b/lib/Euchre/Game.pm
@@ -14,4 +14,21 @@ use Class::Tiny qw(id trump out_player turn dealer caller password pass_count le
start_time => sub { time },
};
+sub next_turn {
+ my ($self) = @_;
+
+ my $turn = ($self->turn + 1) % 4;
+ if ($turn == $self->out_player) {
+ # It's a loner! Only gonna be one of these...
+ $turn = ($turn + 1) % 4;
+ }
+ $self->turn($turn);
+}
+
+sub reset_turn {
+ my ($self) = @_;
+ $self->turn($self->dealer);
+ $self->next_turn();
+}
+
1;