| 1 | package Bot::Cobalt::Plugin::Games::RockPaperScissors; | ||
| 2 | $Bot::Cobalt::Plugin::Games::RockPaperScissors::VERSION = '0.021003'; | ||
| 3 | use v5.10; | ||
| 4 | use strict; use warnings; | ||
| 5 | |||
| 6 | sub new { bless [], shift } | ||
| 7 | |||
| 8 | sub execute { | ||
| 9 | my ($self, $msg, $rps) = @_; | ||
| 10 | my $nick = $msg->src_nick // ''; | ||
| 11 | $rps = lc($rps // ''); | ||
| 12 | |||
| 13 | state $beats = +{ | ||
| 14 | scissors => 'paper', | ||
| 15 | paper => 'rock', | ||
| 16 | rock => 'scissors', | ||
| 17 | }; | ||
| 18 | |||
| 19 | if (! $rps) { | ||
| 20 | return "What did you want to throw, ${nick}?" | ||
| 21 | } elsif (! exists $beats->{$rps}) { | ||
| 22 | return "${nick}: You gotta throw rock, paper, or scissors!" | ||
| 23 | } | ||
| 24 | |||
| 25 | my $throw = (keys %$beats)[rand(keys %$beats)]; | ||
| 26 | |||
| 27 | $throw eq $rps ? "$nick threw $rps, I threw $throw -- it's a tie!" | ||
| 28 | : $beats->{$throw} eq $rps ? "$nick threw $rps, I threw $throw -- I win!" | ||
| 29 | : "$nick threw $rps, I threw $throw -- you win :(" | ||
| 30 | } | ||
| 31 | |||
| 32 | 1; | ||
| 33 | __END__ |