File: | blib/lib/Language/Homespring/Snowmelt.pm |
Coverage: | 100.0% |
line | stmt | bran | cond | sub | time | code |
---|---|---|---|---|---|---|
1 | package Language::Homespring::Snowmelt; | |||||
2 | ||||||
3 | $VERSION = 0.01; | |||||
4 | ||||||
5 | 4 4 4 | 19 9 17 | use warnings; | |||
6 | 4 4 4 | 26 8 19 | use strict; | |||
7 | ||||||
8 | sub new { | |||||
9 | 31 | 74 | my $class = shift; | |||
10 | 31 | 104 | my $self = bless {}, $class; | |||
11 | ||||||
12 | 31 | 75 | my $options = shift; | |||
13 | 31 | 103 | $self->{interp} = $options->{interp}; | |||
14 | 31 | 77 | $self->{time_at_node} = 0; | |||
15 | 31 | 100 | $self->{location} = $options->{location}; | |||
16 | ||||||
17 | 31 | 92 | return $self; | |||
18 | } | |||||
19 | ||||||
20 | sub move { | |||||
21 | 114 | 294 | my ($self) = @_; | |||
22 | ||||||
23 | 114 | 253 | $self->{time_at_node}++; | |||
24 | ||||||
25 | # see if we can leave the current node | |||||
26 | ||||||
27 | 114 | 830 | return if (($self->{location}->{node_name} eq 'marshy') && ($self->{time_at_node} == 1)); | |||
28 | ||||||
29 | # see if we can enter the next one | |||||
30 | ||||||
31 | 86 | 263 | my $dest = $self->{location}->{parent_node}; | |||
32 | ||||||
33 | 86 | 209 | if (defined($dest)){ | |||
34 | 81 | 197 | $self->{location} = $dest; | |||
35 | 81 | 192 | $self->{time_at_node} = 0; | |||
36 | 81 | 204 | $self->smash(); | |||
37 | }else{ | |||||
38 | # if there's nowhere to go, | |||||
39 | 5 | 12 | $self->kill(); | |||
40 | } | |||||
41 | ||||||
42 | } | |||||
43 | ||||||
44 | sub kill { | |||||
45 | 5 | 16 | my ($self) = @_; | |||
46 | 5 32 | 51 138 | @{$self->{interp}->{snowmelt}} = grep{ | |||
47 | 5 | 25 | $_ ne $self | |||
48 | 5 | 6 | }@{$self->{interp}->{snowmelt}}; | |||
49 | } | |||||
50 | ||||||
51 | sub smash { | |||||
52 | 81 | 196 | my ($self) = @_; | |||
53 | ||||||
54 | # smash stuff at the current node | |||||
55 | 81 | 248 | my $node_name = $self->{location}->{node_name}; | |||
56 | ||||||
57 | #print "Smashing up a $node_name...\n"; | |||||
58 | ||||||
59 | 81 | 238 | $self->{location}->{destroyed} = 1; | |||
60 | ||||||
61 | 81 | 431 | if ($node_name eq 'universe'){ | |||
62 | 2 | 13 | $self->{interp}->{universe_ok} = 0; | |||
63 | } | |||||
64 | ||||||
65 | } | |||||
66 | ||||||
67 | 1; | |||||
68 |