diff options
author | doy <doy@tozt.net> | 2009-04-26 02:31:51 -0500 |
---|---|---|
committer | doy <doy@tozt.net> | 2009-04-26 02:31:51 -0500 |
commit | 2adae6f33332e3a86cdbc435530622c9bea308aa (patch) | |
tree | 36461c18386e73b62e70d1c6519ceed776dad96b | |
parent | a80d5722742519fef9c43172369d081ac0210953 (diff) | |
download | bot-games-2adae6f33332e3a86cdbc435530622c9bea308aa.tar.gz bot-games-2adae6f33332e3a86cdbc435530622c9bea308aa.zip |
make -challenge also attempt to add a new player if possible
-rw-r--r-- | lib/Bot/Games/Game/Ghost.pm | 23 |
1 files changed, 16 insertions, 7 deletions
diff --git a/lib/Bot/Games/Game/Ghost.pm b/lib/Bot/Games/Game/Ghost.pm index b468010..3927dc2 100644 --- a/lib/Bot/Games/Game/Ghost.pm +++ b/lib/Bot/Games/Game/Ghost.pm @@ -51,15 +51,10 @@ around state => sub { augment turn => sub { my $self = shift; my ($player, $state) = @_; - - if (!$self->has_challenger && !grep { $player eq $_ } $self->players) { - if ($self->add_player($player)) { - $self->current_player($player); - } - } - + $self->maybe_add_player($player); return "It's " . $self->current_player . "'s turn!" if $player ne $self->current_player; + return "You must respond to " . $self->challenger . "'s challenge!" if $self->has_challenger; return "$state isn't a valid move!" @@ -83,6 +78,7 @@ command challenge => sub { my $self = shift; my ($word, $args) = @_; my $player = $args->{player}; + $self->maybe_add_player($player); return "It's " . $self->current_player . "'s turn!" if $player ne $self->current_player; @@ -116,6 +112,9 @@ command challenge => sub { } }; +before qw/turn challenge/ => sub { +}; + command previous_player => sub { my $self = shift; return unless $self->has_current_player; @@ -149,6 +148,16 @@ sub current_player_index { return 0; } +sub maybe_add_player { + my $self = shift; + my ($player) = @_; + if (!$self->has_challenger && !grep { $player eq $_ } $self->players) { + if ($self->add_player($player)) { + $self->current_player($player); + } + } +} + __PACKAGE__->meta->make_immutable; no Bot::Games::OO; |