commit adbd90abeb0d586260e6df5a80bbe77782bfacba (patch)
parent e3313de15530996571b76c49b130d5e5e99f27b7
Author: Alex Karle <alex@karle.co>
Date: Tue, 14 Apr 2020 20:54:04 -0400
Euchre::Dealer: Add start_seat option to start_game
Random is a common option for most games, but having the option is
important for follow up games where you want to choose who to start.
Diffstat:
2 files changed, 16 insertions(+), 2 deletions(-)
diff --git a/lib/Euchre/Dealer.pm b/lib/Euchre/Dealer.pm
@@ -229,8 +229,9 @@ sub stand_up {
}
+# start_seat: -1 - 3
sub start_game {
- my ($p) = @_;
+ my ($p, $msg) = @_;
my $game = $p->{game};
if (num_players($game->{id}) < 4) {
@@ -238,6 +239,16 @@ sub start_game {
return;
}
+ if (!defined $msg->{start_seat} || $msg->{start_seat} < 0) {
+ $game->{dealer} = int(rand(4));
+ } elsif ($msg->{start_seat} < 3) {
+ # One less since start_new_round will rotate
+ $game->{dealer} = ($msg->{start_seat} - 1);
+ } else {
+ send_error($p, "Bad seat number");
+ return;
+ }
+
# TODO: kick spectators out?
# TODO: deal!
start_new_round($game);
diff --git a/public/debug.html b/public/debug.html
@@ -73,7 +73,8 @@
ws.send(JSON.stringify({action:'stand_up'}))
}
function start_game() {
- ws.send(JSON.stringify({action:'start_game'}))
+ seat = document.getElementById('start_seat').value;
+ ws.send(JSON.stringify({action:'start_game', start_seat: seat}))
}
function vote(a) {
ws.send(JSON.stringify({action:'order', vote: order_suit, loner: a}))
@@ -101,6 +102,8 @@
<button onclick="stand()">Stand</button>
<br>
<button onclick="start_game()">Start Game</button>
+ <label for="start_seat">Start Seat:</label>
+ <input type="number" id="start_seat">
<br>
<br><br>