From adbd90abeb0d586260e6df5a80bbe77782bfacba Mon Sep 17 00:00:00 2001 From: Alex Karle Date: Tue, 14 Apr 2020 20:54:04 -0400 Subject: [PATCH] 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. --- lib/Euchre/Dealer.pm | 13 ++++++++++++- public/debug.html | 5 ++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/lib/Euchre/Dealer.pm b/lib/Euchre/Dealer.pm index 16b1946..c72a7cf 100644 --- 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 index 89e2d82..1d956b8 100644 --- 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 @@
+ +


-- libgit2 1.1.1