line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Games::Messages; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
98549
|
use 5.006; |
|
2
|
|
|
|
|
8
|
|
|
2
|
|
|
|
|
88
|
|
4
|
2
|
|
|
2
|
|
13
|
use strict; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
79
|
|
5
|
2
|
|
|
2
|
|
11
|
use warnings; |
|
2
|
|
|
|
|
8
|
|
|
2
|
|
|
|
|
715
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
require Exporter; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our @ISA = qw(Exporter); |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our %EXPORT_TAGS = ( 'all' => [ qw( |
12
|
|
|
|
|
|
|
player_wins player_loses |
13
|
|
|
|
|
|
|
computer_beats_computer computer_beats_player |
14
|
|
|
|
|
|
|
player_beats_computer player_beats_player |
15
|
|
|
|
|
|
|
player_is_idle player_exagerates |
16
|
|
|
|
|
|
|
) ] ); |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } ); |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
our @EXPORT = qw( |
21
|
|
|
|
|
|
|
); |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
our $VERSION = '0.05'; |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
=head1 NAME |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
Games::Messages - Random messages for common situations in games |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
=head1 SYNOPSIS |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
use Games::Messages qw/:all/; |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
print player_wins($player); |
34
|
|
|
|
|
|
|
# prints something like "$player wins." or "Hurray for $player!" |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
print player_loses($player); |
37
|
|
|
|
|
|
|
# prints something like "$player is gone with the wind." |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
print computer_beats_computer(); |
40
|
|
|
|
|
|
|
# prints something like "The winner: Computer!! The loser: |
41
|
|
|
|
|
|
|
# Computer!! Hurray...' |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
print computer_beats_player($player); |
44
|
|
|
|
|
|
|
# prints something like 'Maybe you should leave the game to me and |
45
|
|
|
|
|
|
|
# go do something else.' |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
print player_beats_computer($player); |
48
|
|
|
|
|
|
|
# prints something like "Next time my AI will be better, you'll see" |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
print player_beats_player($winner, $loser); |
51
|
|
|
|
|
|
|
# prints something like '$winner wipes the floor with $loser.' |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
print player_is_idle($player); |
54
|
|
|
|
|
|
|
# prints something like 'I hope you have a good reason for leaving |
55
|
|
|
|
|
|
|
# me here alone.' |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
print player_exagerates($player); |
58
|
|
|
|
|
|
|
# prints something like 'Enough is enough, you know?' |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
=head1 DESCRIPTION |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
Games::Messages returns random messages for common situations in |
63
|
|
|
|
|
|
|
games. |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
=cut |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
my %messages; |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
BEGIN { |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
=head1 FUNCTIONS |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
There are eight functions available, suitable for different |
74
|
|
|
|
|
|
|
situations. |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
There are functions for situations where a computer interacts with a |
77
|
|
|
|
|
|
|
human player. However, if your computer player has a name, you might |
78
|
|
|
|
|
|
|
consider using instead the function I, passing as |
79
|
|
|
|
|
|
|
parameters the name of the winning player (which might be human or |
80
|
|
|
|
|
|
|
not) and the defeated player (likewise). |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
Messages returned are meant as direct speech directed to the human |
83
|
|
|
|
|
|
|
player (that is, the person with the keyboard; yes, you). They might |
84
|
|
|
|
|
|
|
not be suitable for anything else apart than showing them to that |
85
|
|
|
|
|
|
|
person. |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=cut |
88
|
|
|
|
|
|
|
|
89
|
2
|
|
|
2
|
|
992
|
%messages = ( |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
# player_wins |
92
|
|
|
|
|
|
|
p_wins => [ ['PLAYER'], |
93
|
|
|
|
|
|
|
'And the winner is... !', |
94
|
|
|
|
|
|
|
'Hurray for !', |
95
|
|
|
|
|
|
|
' amazingly wins.', |
96
|
|
|
|
|
|
|
' really knows how to handle the game.', |
97
|
|
|
|
|
|
|
' wins.', |
98
|
|
|
|
|
|
|
], |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
# player_loses |
101
|
|
|
|
|
|
|
p_lose => [ ['PLAYER'], |
102
|
|
|
|
|
|
|
'No more .', |
103
|
|
|
|
|
|
|
' is gone with the wind.', |
104
|
|
|
|
|
|
|
' is no more.', |
105
|
|
|
|
|
|
|
' loses.', |
106
|
|
|
|
|
|
|
' sucks.', |
107
|
|
|
|
|
|
|
], |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
# computer beats computer |
110
|
|
|
|
|
|
|
c_b_c => [ [], |
111
|
|
|
|
|
|
|
'Computers playing against each other... talk about wars...', |
112
|
|
|
|
|
|
|
'Oh yeah... I just love playing against myself...', |
113
|
|
|
|
|
|
|
'The winner: Computer!! The loser: Computer!! Hurray...', |
114
|
|
|
|
|
|
|
], |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
# computer beats player |
117
|
|
|
|
|
|
|
c_b_p => [ ['PLAYER'], |
118
|
|
|
|
|
|
|
'How do I tell you this? , you suck.', |
119
|
|
|
|
|
|
|
'I tell you... artificial intelligence rulez!', |
120
|
|
|
|
|
|
|
'Maybe you should leave the game to me and go do something else.', |
121
|
|
|
|
|
|
|
'Muahahahahahah!!', |
122
|
|
|
|
|
|
|
'Next time, learn how to play before messing with me.', |
123
|
|
|
|
|
|
|
'Oh yeah, baby...', |
124
|
|
|
|
|
|
|
':-P', |
125
|
|
|
|
|
|
|
'Sucka...', |
126
|
|
|
|
|
|
|
'Wait a minute while I e-mail my cousin telling him about your defeat :-P', |
127
|
|
|
|
|
|
|
], |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
# player beats computer |
130
|
|
|
|
|
|
|
p_b_c => [ ['PLAYER'], |
131
|
|
|
|
|
|
|
'I dare you doing that again.', |
132
|
|
|
|
|
|
|
'Next time my AI will be better, you\'ll see.', |
133
|
|
|
|
|
|
|
'Yeah, yeah, so you won, big deal.', |
134
|
|
|
|
|
|
|
' rulez.', |
135
|
|
|
|
|
|
|
':-|', |
136
|
|
|
|
|
|
|
], |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
# player beats another player |
139
|
|
|
|
|
|
|
p_b_p => [ ['WINNER', 'LOSER'], |
140
|
|
|
|
|
|
|
' loses again.', |
141
|
|
|
|
|
|
|
' really sucks...', |
142
|
|
|
|
|
|
|
' should know better...', |
143
|
|
|
|
|
|
|
' beats the hell out of .', |
144
|
|
|
|
|
|
|
' beats the hell out of .', |
145
|
|
|
|
|
|
|
' kicks \'s ass.', |
146
|
|
|
|
|
|
|
' rulez...', |
147
|
|
|
|
|
|
|
' takes control.', |
148
|
|
|
|
|
|
|
' wins again.', |
149
|
|
|
|
|
|
|
' wipes the floor with .', |
150
|
|
|
|
|
|
|
], |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
# player is idle |
153
|
|
|
|
|
|
|
p_idle => [ ['PLAYER'], |
154
|
|
|
|
|
|
|
'Don\'t you like me anymore?', |
155
|
|
|
|
|
|
|
'Gone to the bathroom, uh?', |
156
|
|
|
|
|
|
|
'Hey, ! Yeah, you! Come back here!', |
157
|
|
|
|
|
|
|
'I hope you have a good reason for leaving me here alone.', |
158
|
|
|
|
|
|
|
'I wonder what you\'re doing...', |
159
|
|
|
|
|
|
|
'I wonder where you are...', |
160
|
|
|
|
|
|
|
'Oh no... It seems that I am all by myself...', |
161
|
|
|
|
|
|
|
'Oh no... It seems that I am alone...', |
162
|
|
|
|
|
|
|
], |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
# player exagerates |
165
|
|
|
|
|
|
|
p_exag => [ ['PLAYER'], |
166
|
|
|
|
|
|
|
'Don\'t you ever go away?', |
167
|
|
|
|
|
|
|
'Don\'t you have something better to do?', |
168
|
|
|
|
|
|
|
'Don\'t you think it\'s about time you turn me off?', |
169
|
|
|
|
|
|
|
'Enough is enough, you know?', |
170
|
|
|
|
|
|
|
'Ring... Ring... Hello? Yes, He\'s right here. It\'s for you, ; they say you have should go.', |
171
|
|
|
|
|
|
|
'Shouldn\'t you, like... go away?', |
172
|
|
|
|
|
|
|
'Why don\'t you go fishing instead?', |
173
|
|
|
|
|
|
|
'Why don\'t you go read a book instead?', |
174
|
|
|
|
|
|
|
'You know, I\'m getting sick of your face...', |
175
|
|
|
|
|
|
|
'You know there are other stuff you can do, right?', |
176
|
|
|
|
|
|
|
], |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
); |
179
|
|
|
|
|
|
|
} |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
sub _random_message { |
182
|
|
|
|
|
|
|
# check the type of messages we want |
183
|
44
|
|
50
|
44
|
|
126
|
my $type = shift || return undef; |
184
|
|
|
|
|
|
|
# get a random message |
185
|
44
|
|
|
|
|
65
|
for (${$messages{$type}}[ 1 + int(rand(@{$messages{$type}} - 1)) ]) { |
|
44
|
|
|
|
|
208
|
|
|
44
|
|
|
|
|
85
|
|
186
|
|
|
|
|
|
|
# substitute where appropriate |
187
|
44
|
|
|
|
|
56
|
for my $name (@{${$messages{$type}}[0]}) { |
|
44
|
|
|
|
|
54
|
|
|
44
|
|
|
|
|
102
|
|
188
|
44
|
|
100
|
|
|
144
|
my $temp = shift || return undef; |
189
|
34
|
|
|
|
|
352
|
s/<$name>/$temp/g; |
190
|
|
|
|
|
|
|
} |
191
|
34
|
|
|
|
|
781
|
return $_; |
192
|
|
|
|
|
|
|
} |
193
|
|
|
|
|
|
|
} |
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
=head2 player_wins |
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
Returns a message suitable for a player who has won a game. |
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
print player_wins($player_name); |
200
|
|
|
|
|
|
|
# that prints something like "$player_name wins." |
201
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
=cut |
203
|
|
|
|
|
|
|
|
204
|
5
|
|
|
5
|
1
|
20
|
sub player_wins { _random_message('p_wins',@_); } |
205
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
=head2 player_loses |
207
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
Returns a message suitable for a player who has lost a game. |
209
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
print player_loses($player_name); |
211
|
|
|
|
|
|
|
# that prints something like "No more $player_name." |
212
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
=cut |
214
|
|
|
|
|
|
|
|
215
|
5
|
|
|
5
|
1
|
13
|
sub player_loses { _random_message('p_lose',@_); } |
216
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
=head2 computer_beats_computer |
218
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
Returns a message suitable for a situation where a computer player as |
220
|
|
|
|
|
|
|
defeated another computer player. |
221
|
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
print computer_beats_computer(); |
223
|
|
|
|
|
|
|
# that prints something like 'Oh yeah... I just love playing against |
224
|
|
|
|
|
|
|
# myself...' |
225
|
|
|
|
|
|
|
|
226
|
|
|
|
|
|
|
=cut |
227
|
|
|
|
|
|
|
|
228
|
6
|
|
|
6
|
1
|
17
|
sub computer_beats_computer { _random_message('c_b_c' ,@_); } |
229
|
|
|
|
|
|
|
|
230
|
|
|
|
|
|
|
=head2 computer_beats_player |
231
|
|
|
|
|
|
|
|
232
|
|
|
|
|
|
|
Returns a message suitable for a situation where a computer has |
233
|
|
|
|
|
|
|
defeated a human player. |
234
|
|
|
|
|
|
|
|
235
|
|
|
|
|
|
|
print computer_beats_player($player_name); |
236
|
|
|
|
|
|
|
# that prints something like "I tell you... artificial intelligence |
237
|
|
|
|
|
|
|
# rulez!" |
238
|
|
|
|
|
|
|
|
239
|
|
|
|
|
|
|
=cut |
240
|
|
|
|
|
|
|
|
241
|
5
|
|
|
5
|
1
|
16
|
sub computer_beats_player { _random_message('c_b_p' ,@_); } |
242
|
|
|
|
|
|
|
|
243
|
|
|
|
|
|
|
=head2 player_beats_computer |
244
|
|
|
|
|
|
|
|
245
|
|
|
|
|
|
|
Returns a message suitable for a situation where a human player has |
246
|
|
|
|
|
|
|
defeated a computer player. |
247
|
|
|
|
|
|
|
|
248
|
|
|
|
|
|
|
print player_beats_computer($player_name); |
249
|
|
|
|
|
|
|
# that prints something like "$player_name rulez." |
250
|
|
|
|
|
|
|
|
251
|
|
|
|
|
|
|
=cut |
252
|
|
|
|
|
|
|
|
253
|
5
|
|
|
5
|
1
|
17
|
sub player_beats_computer { _random_message('p_b_c' ,@_); } |
254
|
|
|
|
|
|
|
|
255
|
|
|
|
|
|
|
=head2 player_beats_player |
256
|
|
|
|
|
|
|
|
257
|
|
|
|
|
|
|
Returns a message suitable for a situation where a human player has |
258
|
|
|
|
|
|
|
beaten another human player. |
259
|
|
|
|
|
|
|
|
260
|
|
|
|
|
|
|
print player_beats_player($winner_name, $loser_name); |
261
|
|
|
|
|
|
|
# that prints something like "$winner_name beats the hell out of |
262
|
|
|
|
|
|
|
# $loser_name." |
263
|
|
|
|
|
|
|
|
264
|
|
|
|
|
|
|
=cut |
265
|
|
|
|
|
|
|
|
266
|
8
|
|
|
8
|
1
|
23
|
sub player_beats_player { _random_message('p_b_p' ,@_); } |
267
|
|
|
|
|
|
|
|
268
|
|
|
|
|
|
|
=head2 player_is_idle |
269
|
|
|
|
|
|
|
|
270
|
|
|
|
|
|
|
Returns a message suitable to be shown to an idle user. |
271
|
|
|
|
|
|
|
|
272
|
|
|
|
|
|
|
print player_is_idle($player_name); |
273
|
|
|
|
|
|
|
# that prints something like 'Gone to the bathroom, uh?' |
274
|
|
|
|
|
|
|
|
275
|
|
|
|
|
|
|
=cut |
276
|
|
|
|
|
|
|
|
277
|
5
|
|
|
5
|
1
|
15
|
sub player_is_idle { _random_message('p_idle',@_); } |
278
|
|
|
|
|
|
|
|
279
|
|
|
|
|
|
|
=head2 player_exagerates |
280
|
|
|
|
|
|
|
|
281
|
|
|
|
|
|
|
Returns a message suitable to be shown to a player who is exagerating |
282
|
|
|
|
|
|
|
and should leave the game. |
283
|
|
|
|
|
|
|
|
284
|
|
|
|
|
|
|
print player_exagerates($player_name); |
285
|
|
|
|
|
|
|
# that prints something like "Don't you think it's about time you |
286
|
|
|
|
|
|
|
# turn me off?" |
287
|
|
|
|
|
|
|
|
288
|
|
|
|
|
|
|
=cut |
289
|
|
|
|
|
|
|
|
290
|
5
|
|
|
5
|
1
|
15
|
sub player_exagerates { _random_message('p_exag',@_); } |
291
|
|
|
|
|
|
|
|
292
|
|
|
|
|
|
|
1; |
293
|
|
|
|
|
|
|
__END__ |