diff options
author | doy <doy@tozt.net> | 2009-04-24 23:52:36 -0500 |
---|---|---|
committer | doy <doy@tozt.net> | 2009-04-24 23:52:36 -0500 |
commit | 362d635f2c565ab45ed570e16c6cae14c6c37704 (patch) | |
tree | ec5bbb7c4bf384b68eb23616261561e95037d199 /lib | |
parent | c635cf5996f9ec6439b8eaee284681014451583d (diff) | |
download | bot-games-362d635f2c565ab45ed570e16c6cae14c6c37704.tar.gz bot-games-362d635f2c565ab45ed570e16c6cae14c6c37704.zip |
use the allow_new_player interface in ghostlikes
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Bot/Games/Game/Ghost.pm | 26 |
1 files changed, 14 insertions, 12 deletions
diff --git a/lib/Bot/Games/Game/Ghost.pm b/lib/Bot/Games/Game/Ghost.pm index 093b013..480def0 100644 --- a/lib/Bot/Games/Game/Ghost.pm +++ b/lib/Bot/Games/Game/Ghost.pm @@ -15,13 +15,6 @@ has current_player => ( command => 1, ); -has players_fixed => ( - is => 'rw', - isa => 'Bool', - default => 0, - command => 1, -); - has state => ( is => 'rw', isa => 'Str', @@ -59,11 +52,10 @@ augment turn => sub { my $self = shift; my ($player, $state) = @_; - if ($self->current_player_index == 0 - && !$self->players_fixed - && !grep { $player eq $_ } $self->players) { - $self->add_player($player); - $self->current_player($player); + if (!grep { $player eq $_ } $self->players) { + if ($self->add_player($player)) { + $self->current_player($player); + } } return "It's " . $self->current_player . "'s turn!" @@ -77,6 +69,16 @@ augment turn => sub { return $self->state($state); }; +sub allow_new_player { + my $self = shift; + + if ($self->current_player_index != 0 && $self->num_players > 1) { + $self->say("No more players can join the current game"); + return; + } + return 1; +} + command challenge => sub { my $self = shift; my ($word, $args) = @_; |