| 1 | 1 | ▶ | use 5.20.0; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 2 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | package Games::Nintendo::Mario::SMB2 0.209; | ||||||||||||||||||||||||||||
| 4 | # ABSTRACT: a class for vegetable-throwing Italian plumbers (and friends) | ||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use parent qw(Games::Nintendo::Mario::Hearts); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | #pod =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 9 | #pod | ||||||||||||||||||||||||||||
| 10 | #pod use Games::Nintendo::Mario::SMB2; | ||||||||||||||||||||||||||||
| 11 | #pod | ||||||||||||||||||||||||||||
| 12 | #pod my $liege = Games::Nintendo::Mario::SMB2->new(name => 'Peach'); | ||||||||||||||||||||||||||||
| 13 | #pod | ||||||||||||||||||||||||||||
| 14 | #pod # below outputs "Peach: 1/3" | ||||||||||||||||||||||||||||
| 15 | #pod say $liege->name . ": " . $liege->hearts . "/" . $liege->max_hearts; | ||||||||||||||||||||||||||||
| 16 | #pod | ||||||||||||||||||||||||||||
| 17 | #pod $liege->powerup('heart'); # 2/3 | ||||||||||||||||||||||||||||
| 18 | #pod $liege->damage; # 1/3 | ||||||||||||||||||||||||||||
| 19 | #pod $liege->powerup('mushroom'); # 1/4 | ||||||||||||||||||||||||||||
| 20 | #pod $liege->powerup('heart'); # 2/4 | ||||||||||||||||||||||||||||
| 21 | #pod $liege->powerup('mushroom'); # 2/5 | ||||||||||||||||||||||||||||
| 22 | #pod $liege->powerup('heart'); # 3/5 | ||||||||||||||||||||||||||||
| 23 | #pod | ||||||||||||||||||||||||||||
| 24 | #pod say "I'm feeling ", $liege->state, "!"; # She's feeling super. | ||||||||||||||||||||||||||||
| 25 | #pod | ||||||||||||||||||||||||||||
| 26 | #pod $liege->powerup('mushroom'); # Nothing happens. | ||||||||||||||||||||||||||||
| 27 | #pod | ||||||||||||||||||||||||||||
| 28 | #pod $liege->damage for (1 .. 3); # cue the Mario Death Music | ||||||||||||||||||||||||||||
| 29 | #pod | ||||||||||||||||||||||||||||
| 30 | #pod =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 31 | #pod | ||||||||||||||||||||||||||||
| 32 | #pod This class subclasses Games::Nintendo::Mario (and G::N::M::Hearts), providing a | ||||||||||||||||||||||||||||
| 33 | #pod model of the behavior of the Mario Brothers in Super Mario Brothers 2. All of | ||||||||||||||||||||||||||||
| 34 | #pod the methods described in the Mario interface exist as documented. | ||||||||||||||||||||||||||||
| 35 | #pod | ||||||||||||||||||||||||||||
| 36 | #pod =head2 NAMES | ||||||||||||||||||||||||||||
| 37 | #pod | ||||||||||||||||||||||||||||
| 38 | #pod The plumber may be named Mario or Luigi, or a non-plumbing character named | ||||||||||||||||||||||||||||
| 39 | #pod Peach or Toad may be created. | ||||||||||||||||||||||||||||
| 40 | #pod | ||||||||||||||||||||||||||||
| 41 | #pod =head2 STATES | ||||||||||||||||||||||||||||
| 42 | #pod | ||||||||||||||||||||||||||||
| 43 | #pod C<< $hero->state >> will return 'dead' if he has no hearts, 'normal' if he has | ||||||||||||||||||||||||||||
| 44 | #pod one heart, and 'super' if he has more than one heart. State may not be set | ||||||||||||||||||||||||||||
| 45 | #pod during construction; set hearts instead. | ||||||||||||||||||||||||||||
| 46 | #pod | ||||||||||||||||||||||||||||
| 47 | #pod =head2 POWERUPS | ||||||||||||||||||||||||||||
| 48 | #pod | ||||||||||||||||||||||||||||
| 49 | #pod Valid powerups are: C<mushroom> or C<heart> | ||||||||||||||||||||||||||||
| 50 | #pod | ||||||||||||||||||||||||||||
| 51 | #pod =method state | ||||||||||||||||||||||||||||
| 52 | #pod | ||||||||||||||||||||||||||||
| 53 | #pod =method name | ||||||||||||||||||||||||||||
| 54 | #pod | ||||||||||||||||||||||||||||
| 55 | #pod =method powerup | ||||||||||||||||||||||||||||
| 56 | #pod | ||||||||||||||||||||||||||||
| 57 | #pod These methods are implemented as per Games::Nintendo::Mario | ||||||||||||||||||||||||||||
| 58 | #pod | ||||||||||||||||||||||||||||
| 59 | #pod =method power | ||||||||||||||||||||||||||||
| 60 | #pod | ||||||||||||||||||||||||||||
| 61 | #pod =method speed | ||||||||||||||||||||||||||||
| 62 | #pod | ||||||||||||||||||||||||||||
| 63 | #pod =method jump | ||||||||||||||||||||||||||||
| 64 | #pod | ||||||||||||||||||||||||||||
| 65 | #pod These methods return the requested attribute for the current character. | ||||||||||||||||||||||||||||
| 66 | #pod | ||||||||||||||||||||||||||||
| 67 | #pod =method games | ||||||||||||||||||||||||||||
| 68 | #pod | ||||||||||||||||||||||||||||
| 69 | #pod The rules reflected in this module were only present in Super Mario Bros. 2 | ||||||||||||||||||||||||||||
| 70 | #pod (and its re-releases). | ||||||||||||||||||||||||||||
| 71 | #pod | ||||||||||||||||||||||||||||
| 72 | #pod =cut | ||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | 2 | ▶ | sub _names { qw[Mario Luigi Peach Toad] } | ||||||||||||||||||||||||||
|
Subroutine
_names: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 75 | 2 | ▶ | sub _states { qw[normal] } # super isn't listed to prevent creation-as-super | ||||||||||||||||||||||||||
|
Subroutine
_states: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 76 | 4 | ▶ | sub _items { qw[mushroom heart] } | ||||||||||||||||||||||||||
|
Subroutine
_items: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | 6 | ▶ | sub _goto_hash { {} } | ||||||||||||||||||||||||||
|
Subroutine
_goto_hash: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | 0 | ▶ | sub _char_attr { | ||||||||||||||||||||||||||
|
Subroutine
_char_attr: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 81 | { | ||||||||||||||||||||||||||||
| 82 | 0 | Mario => { | |||||||||||||||||||||||||||
| 83 | power => 4, | ||||||||||||||||||||||||||||
| 84 | speed => 4, | ||||||||||||||||||||||||||||
| 85 | jump => 4 | ||||||||||||||||||||||||||||
| 86 | }, | ||||||||||||||||||||||||||||
| 87 | Luigi => { | ||||||||||||||||||||||||||||
| 88 | power => 3, | ||||||||||||||||||||||||||||
| 89 | speed => 3, | ||||||||||||||||||||||||||||
| 90 | jump => 5 | ||||||||||||||||||||||||||||
| 91 | }, | ||||||||||||||||||||||||||||
| 92 | Peach => { | ||||||||||||||||||||||||||||
| 93 | power => 2, | ||||||||||||||||||||||||||||
| 94 | speed => 2, | ||||||||||||||||||||||||||||
| 95 | jump => 3 | ||||||||||||||||||||||||||||
| 96 | }, | ||||||||||||||||||||||||||||
| 97 | Toad => { | ||||||||||||||||||||||||||||
| 98 | power => 5, | ||||||||||||||||||||||||||||
| 99 | speed => 5, | ||||||||||||||||||||||||||||
| 100 | jump => 2 | ||||||||||||||||||||||||||||
| 101 | } } | ||||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | 13 | ▶ | sub state { ## no critic Homonym | ||||||||||||||||||||||||||
|
Subroutine
state: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 105 | 13 | my $hero = shift; | |||||||||||||||||||||||||||
| 106 | 13 | ▶ | if ($hero->hearts < 1) { return "dead" } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 107 | 11 | ▶ | if ($hero->hearts > 1) { return "super" } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 108 | 8 | else { return "normal" } | |||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||
| 111 | 1 | ▶ | sub name { $_[0]->{name} } | ||||||||||||||||||||||||||
|
Subroutine
name: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||
| 113 | 4 | ▶ | sub powerup { | ||||||||||||||||||||||||||
|
Subroutine
powerup: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 114 | 4 | my $hero = shift; | |||||||||||||||||||||||||||
| 115 | 4 | my $item = shift; | |||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||
| 117 | 4 | ▶ | if (($item eq 'mushroom') and ($hero->max_hearts < 5)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$item eq "mushroom" and $hero->max_hearts < 5
MC/DC100%2/2
$item eq "mushroom" and $hero->max_hearts < 5
$item eq "mushroom"
$hero->max_hearts < 5
Truth table100%3/3
A and B
A= $item eq "mushroom"B= $hero->max_hearts < 5
| |||||||||||||||||||||||||||||
| 118 | 2 | $hero->{max_hearts}++; | |||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||
| 120 | 4 | $hero->SUPER::powerup($item); | |||||||||||||||||||||||||||
| 121 | } | ||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||
| 123 | 0 | ▶ | sub power { $_[0]->_char_attr->{$_[0]->name}->{power} } | ||||||||||||||||||||||||||
|
Subroutine
power: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 124 | 0 | ▶ | sub speed { $_[0]->_char_attr->{$_[0]->name}->{speed} } | ||||||||||||||||||||||||||
|
Subroutine
speed: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 125 | 0 | ▶ | sub jump { $_[0]->_char_attr->{$_[0]->name}->{jump} } | ||||||||||||||||||||||||||
|
Subroutine
jump: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||
| 127 | 0 | ▶ | sub games { | ||||||||||||||||||||||||||
|
Subroutine
games: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 128 | 0 | return ('Super Mario Bros. 2'); | |||||||||||||||||||||||||||
| 129 | } | ||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||
| 131 | 1 | "It's-a me! Mario!"; | |||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||
| 133 | __END__ | ||||||||||||||||||||||||||||