diff options
author | doy <doy@tozt.net> | 2009-04-26 02:14:30 -0500 |
---|---|---|
committer | doy <doy@tozt.net> | 2009-04-26 02:14:30 -0500 |
commit | a0c8d4239bf3b2c1bd1950652af958799cd94e10 (patch) | |
tree | 32a5996ae9c8bb33e42a57f7b484c4f29e533f0b | |
parent | fd70eb77e3d8ef6f907eccdf0d9735a4280eef75 (diff) | |
download | bot-games-a0c8d4239bf3b2c1bd1950652af958799cd94e10.tar.gz bot-games-a0c8d4239bf3b2c1bd1950652af958799cd94e10.zip |
rewrite challenging again, i think i might have it this time
-rw-r--r-- | lib/Bot/Games/Game/Ghost.pm | 29 |
1 files changed, 19 insertions, 10 deletions
diff --git a/lib/Bot/Games/Game/Ghost.pm b/lib/Bot/Games/Game/Ghost.pm index 29d75e9..4f5baf6 100644 --- a/lib/Bot/Games/Game/Ghost.pm +++ b/lib/Bot/Games/Game/Ghost.pm @@ -85,22 +85,31 @@ command challenge => sub { my $player = $args->{player}; return "It's " . $self->current_player . "'s turn!" if $player ne $self->current_player; - my $prev = $self->previous_player; - my $challenger = $self->has_challenger ? $self->challenger : $player; + if ($word) { - if (!$self->valid_word_from_state($word)) { - return "$word is not valid for state " . $self->state . "!"; - } - elsif ($self->valid_word($word)) { - $self->is_over(1); - return "$word is a word! $challenger loses!"; + return "$word is not valid for state " . $self->state . "!" + unless $self->valid_word_from_state($word); + + $self->is_over(1); + # if there is a challenger, then this is a response by the current + # player, so if it's valid, the challenger loses, otherwise the current + # player loses. if there isn't a challenger, then this is asserting + # that the word exists, so if the word does exist, then the previous + # player loses, otherwise the current player loses. + if ($self->valid_word($word)) { + return "$word is a word! " + . $self->has_challenger ? $self->challenger + : $self->previous_player + . " loses!"; } else { - $self->is_over(1); - return "$word is not a word. $challenger wins!"; + return "$word is not a word! " + . $self->current_player + . " loses!"; } } else { + my $prev = $self->previous_player; $self->challenger($player); $self->current_player($prev); return "$player is challenging $prev!"; |