| 1 | 2 | ▶ | use 5.20.0; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 2 | 2 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | package Games::Nintendo::Mario::NSMB 0.209; | ||||||||||
| 4 | # ABSTRACT: a class for stylus-enabled Italian plumbers | ||||||||||
| 5 | |||||||||||
| 6 | 2 | ▶ | use parent qw(Games::Nintendo::Mario); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | |||||||||||
| 8 | 2 | ▶ | use Carp (); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | |||||||||||
| 10 | #pod =head1 SYNOPSIS | ||||||||||
| 11 | #pod | ||||||||||
| 12 | #pod use Games::Nintendo::Mario::NSMB; | ||||||||||
| 13 | #pod | ||||||||||
| 14 | #pod my $hero = Games::Nintendo::Mario::SMB->new( | ||||||||||
| 15 | #pod name => 'Luigi', | ||||||||||
| 16 | #pod state => 'normal', | ||||||||||
| 17 | #pod ); | ||||||||||
| 18 | #pod | ||||||||||
| 19 | #pod $hero->powerup('mushroom'); # doop doop doop! | ||||||||||
| 20 | #pod $hero->powerup('flower'); # change clothes | ||||||||||
| 21 | #pod | ||||||||||
| 22 | #pod $hero->damage for (1 .. 2); # cue the Mario Death Music | ||||||||||
| 23 | #pod | ||||||||||
| 24 | #pod =head1 DESCRIPTION | ||||||||||
| 25 | #pod | ||||||||||
| 26 | #pod This class subclasses Games::Nintendo::Mario, providing a model of the behavior | ||||||||||
| 27 | #pod of the Mario Brothers in New Super Mario Brothers. All of the methods | ||||||||||
| 28 | #pod described in the Mario interface exist as documented. | ||||||||||
| 29 | #pod | ||||||||||
| 30 | #pod =head2 NAMES | ||||||||||
| 31 | #pod | ||||||||||
| 32 | #pod The plumber may be named Mario or Luigi. | ||||||||||
| 33 | #pod | ||||||||||
| 34 | #pod =head2 STATES | ||||||||||
| 35 | #pod | ||||||||||
| 36 | #pod The plumber's state may be any of: normal super fire shell mini mega | ||||||||||
| 37 | #pod | ||||||||||
| 38 | #pod =head2 POWERUPS | ||||||||||
| 39 | #pod | ||||||||||
| 40 | #pod Valid powerups are: mushroom flower shell mega_mushroom mini_mushroom | ||||||||||
| 41 | #pod | ||||||||||
| 42 | #pod =method games | ||||||||||
| 43 | #pod | ||||||||||
| 44 | #pod This ruleset reflects Mario in New Super Mario Bros., the first SMB game for | ||||||||||
| 45 | #pod Nintendo DS. | ||||||||||
| 46 | #pod | ||||||||||
| 47 | #pod =cut | ||||||||||
| 48 | |||||||||||
| 49 | 10 | ▶ | sub _names { qw[Mario Luigi] } | ||||||||
|
Subroutine
_names: called CC=1 SCAR=0.0
| |||||||||||
| 50 | 10 | ▶ | sub _states { qw[normal super fire shell mini mega] } | ||||||||
|
Subroutine
_states: called CC=1 SCAR=0.0
| |||||||||||
| 51 | 0 | ▶ | sub _items { qw[mushroom flower shell mega_mushroom mini_mushroom] } | ||||||||
|
Subroutine
_items: not called CC=1 SCAR=6.9
| |||||||||||
| 52 | |||||||||||
| 53 | 2 | my %__default_behavior = ( | |||||||||
| 54 | damage => 'dead', | ||||||||||
| 55 | mushroom => 'super', | ||||||||||
| 56 | flower => 'fire', | ||||||||||
| 57 | shell => 'shell', | ||||||||||
| 58 | mega_mushroom => 'mega', | ||||||||||
| 59 | mini_mushroom => 'mini', | ||||||||||
| 60 | ); | ||||||||||
| 61 | |||||||||||
| 62 | my %state = ( | ||||||||||
| 63 | normal => { %__default_behavior }, | ||||||||||
| 64 | super => { | ||||||||||
| 65 | %__default_behavior, | ||||||||||
| 66 | damage => 'normal', | ||||||||||
| 67 | mushroom => 'save', | ||||||||||
| 68 | }, | ||||||||||
| 69 | fire => { | ||||||||||
| 70 | %__default_behavior, | ||||||||||
| 71 | damage => 'normal', | ||||||||||
| 72 | flower => 'save', | ||||||||||
| 73 | mushroom => 'save', | ||||||||||
| 74 | }, | ||||||||||
| 75 | shell => { | ||||||||||
| 76 | %__default_behavior, | ||||||||||
| 77 | damage => 'super', | ||||||||||
| 78 | mushroom => 'save', | ||||||||||
| 79 | flower => 'save', | ||||||||||
| 80 | }, | ||||||||||
| 81 | 2 | mega => { map { $_ => 'ignore' } keys %__default_behavior }, | |||||||||
| 82 | mini => { %__default_behavior, mini => 'save' }, | ||||||||||
| 83 | ); | ||||||||||
| 84 | |||||||||||
| 85 | 0 | ▶ | sub games { | ||||||||
|
Subroutine
games: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 86 | 0 | return ('New Super Mario Bros.'); | |||||||||
| 87 | } | ||||||||||
| 88 | |||||||||||
| 89 | 20 | ▶ | sub _set_state { | ||||||||
|
Subroutine
_set_state: called CC=2 SCAR=6.9
| |||||||||||
| 90 | 20 | my ($self, $state, $item) = @_; | |||||||||
| 91 | |||||||||||
| 92 | 20 | ▶ | if ($state eq 'save') { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 93 | 6 | $self->{saved_item} = $item; | |||||||||
| 94 | } else { | ||||||||||
| 95 | 14 | $self->{state} = $state; | |||||||||
| 96 | } | ||||||||||
| 97 | 20 | return $self; | |||||||||
| 98 | } | ||||||||||
| 99 | |||||||||||
| 100 | 20 | ▶ | sub powerup { | ||||||||
|
Subroutine
powerup: called CC=3 SCAR=11.3
Pod
documented
| |||||||||||
| 101 | 20 | my ($self, $item) = @_; | |||||||||
| 102 | |||||||||||
| 103 | 20 | my $state = $self->state; | |||||||||
| 104 | Carp::confess "current state unknown" | ||||||||||
| 105 | 20 | ▶ | unless my $state_info = $state{ $state }; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 106 | |||||||||||
| 107 | Carp::confess "behavior for $item in $state unknown" | ||||||||||
| 108 | 20 | ▶ | unless my $new_state = $state_info->{$item}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 109 | 20 | $self->_set_state($new_state, $item); | |||||||||
| 110 | } | ||||||||||
| 111 | |||||||||||
| 112 | 6 | ▶ | sub damage { | ||||||||
|
Subroutine
damage: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 113 | 6 | my ($self) = @_; | |||||||||
| 114 | 6 | $self->powerup('damage'); | |||||||||
| 115 | } | ||||||||||
| 116 | |||||||||||
| 117 | 2 | "Go Wigi!"; | |||||||||
| 118 | |||||||||||
| 119 | __END__ | ||||||||||