World/Daemon.pm

filter: Statementstmt 55.2% 115 / 208 Branchbran 35.0% 21 / 60 Conditioncond 22.2% 4 / 18 MC/DCmcdc 0.0% 0 / 11 Subroutinesub 51.7% 15 / 29 Podpod 61.1% 11 / 18 totaltotal 48.2% 166 / 344 CC 44 SCAR 32.2
CC
44
Cov
49%
getstr
110.0
proc
25.0
drawallmaps
12.0
CRAP 25.0
« Console.pm ↑ Summary Item.pm »
1 package Games::Roguelike::World::Daemon;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 1 ▶use Games::Roguelike::Utils qw(:all);
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use Games::Roguelike::Console::ANSI;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use Games::Roguelike::Mob;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use POSIX;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 1 ▶use IO::Socket;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use IO::Select;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶use IO::File qw(); # this prevents warnings on win32
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 1 our $VERSION = '0.4.' . [qw$Revision: 253 $]->[1];
15  
16 1 ▶use Time::HiRes qw(time);
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 1 ▶use base 'Games::Roguelike::World';
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 # purpose of module:
21 #
22 # multi-user telnet daemon
23 # finite-state processor, allows for single-thread engine
24  
25 =head1 NAME
26  
27 Games::Roguelike::World::Daemon - roguelike game telnet daemon
28  
29 =head1 SYNOPSIS
30  
31 # for an extended example with move overrides, see the scripts/netgame included
32  
33 use strict;
34  
35 package myWorld; # always override
36 use base 'Games::Roguelike::World::Daemon';
37  
38 my $r = myWorld->new(w=>80,h=>50,dispw=>40,disph=>18); # create a networked world
39 $r->area(new Games::Roguelike::Area(name=>'1')); # create a new area in this world called "1"
40 $r->area->generate('cavelike'); # make a cavelike maze
41  
42 while (1) {
43 $r->proc();
44 }
45  
46 sub readinput { # called when input is available
47 my $self = shift;
48 if (my $c = $self->getch()) { # returns undef on failure
49 if ($self->{vp}->kbdmove($c, 1)) { # '1' in second param means "test only"
50 $r->queuemove($self->{vp}, $c); # if the move is good, queue it
51 }
52 }
53 }
54  
55 sub newconn { # called when someone connects
56 my $self = shift;
57 my $char = mychar->new($self->area(1), # create a new character
58 sym=>'@',
59 color=>'green',
60 pov=>7
61 );
62 $self->{vp} = $char; # viewpoint is a connection state obect
63 $self->{state} = 'MOVE'; # set state (another state object)
64 }
65  
66 package mychar;
67 use base 'Games::Roguelike::Mob';
68  
69 =head1 DESCRIPTION
70  
71 This module uses the Games::Roguelike::World object as the basis for a finite-state based
72 network game engine.
73  
74 * uses Games::Roguelike::Console::ANSI library to draw the current area
75 * currently assumes Games::Roguelike::Mob's as characters in the game
76 * currently assumes Games::Roguelike::Item's as items in the game
77  
78 The module provides th eservice of accepting connections, maintainting he association between
79 the connection and a "state" and "viewpoint" for each connection, managing "tick" times,
80 and rendering maps for each connection.
81  
82 =head2 METHODS
83  
84 =over
85  
86 =cut
87  
88 1 my $WIN32 = ($^O=~/win32/i);
89 1 my @SOCKS;
90  
91 =item new ()
92  
93 Similar to ::World new, but with arguments: host, port, and addr
94  
95 This begins listening for connections, and sets up some signal handlers for
96 graceful death.
97  
98 =cut
99  
100 1 ▶sub new {
Subroutine new: called CC=7 SCAR=20.0
Pod documented
101 1 my $pkg = shift;
102 1 my $r = $pkg->SUPER::new(@_, noconsole=>1);
103 1 bless $r, $pkg;
104  
105 1 ▶ $r->{tick} = 0.5 if !$r->{tick};
Branch: 1 branch
BranchTrueFalseTotal
unless $r->{"tick"} 1 0 1
106  
107 1 local $! = 0;
108 1 my %addrs;
109  
110 1 ▶ $addrs{LocalAddr} = $r->{addr} if $r->{addr};
Branch: 1 branch
BranchTrueFalseTotal
if $r->{"addr"} 0 1 1
111 1 ▶ $addrs{LocalHost} = $r->{host} if $r->{host};
Branch: 1 branch
BranchTrueFalseTotal
if $r->{"host"} 0 1 1
112 1 ▶ $addrs{LocalPort} = $r->{port} if $r->{port};
Branch: 1 branch
BranchTrueFalseTotal
if $r->{"port"} 0 1 1
113  
114 1 $r->{main_sock} = new IO::Socket::INET(
115 %addrs,
116 Listen => 1,
117 ReuseAddr => 1);
118  
119 1 ▶ die $! unless $r->{main_sock};
Branch: 1 branch
BranchTrueFalseTotal
unless $r->{"main_sock"} 0 1 1
120  
121 1 ▶ $r->{stdout} = *STDOUT unless $r->{stdout};
Branch: 1 branch
BranchTrueFalseTotal
unless $r->{"stdout"} 0 1 1
122  
123 1 $r->{read_set} = new IO::Select();
124 1 $r->{read_set}->add($r->{main_sock});
125 1 $r->{write_set} = new IO::Select();
126  
127 1 push @SOCKS, $r->{main_sock};
128
129 1 $SIG{__DIE__} = \&sig_die_handler;
130 1 $SIG{INT} = \&sig_int_handler;
131  
132 1 return $r;
133 }
134  
135 0 ▶sub sig_int_handler {
Subroutine sig_int_handler: not called CC=1 SCAR=6.9
Pod undocumented
136 0 sig_die_handler();
137 0 exit(0);
138 }
139  
140 0 ▶sub sig_die_handler {
Subroutine sig_die_handler: not called CC=2 SCAR=17.9
Pod undocumented
141 0 for (@SOCKS) {
142 0 close($_);
143 }
144 0 undef @SOCKS;
145 0 1;
146 }
147  
148 1 ▶sub DESTROY {
Subroutine DESTROY: called CC=2 SCAR=7.0
149 1 my $r = shift;
150 1 ▶ if ($r->{main_sock}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($r->{"main_sock"}) 1 0 1
151 1 $r->{main_sock}->close();
152 }
153 1 $r->SUPER::DESTROY();
154 }
155  
156 =item proc ()
157  
158 Look for waiting input and calls:
159  
160 newconn() - for new conneciton
161 readinput() - when input is available
162 tick() - to process per-turn moves
163 drawallmaps() - to render all the maps
164  
165 When those functions are called the class {vp} and {state} variables are
166 set to the connection's "viewpoint" (character) and "state".
167  
168 Also, the special scalar state 'QUIT' gracefully removes a connection.
169  
170 (It might be interesting to use code refs as states)
171  
172 =cut
173  
174 2 ▶sub proc {
Subroutine proc: called CC=19 SCAR=32.2
Pod documented
175 2 my $self = shift;
176  
177 # $self->log("proc " . $self->{read_set}->count());
178  
179 2 my $now = time();
180 2 ▶ $self->{ts} = $now unless $self->{ts};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"ts"} 1 1 2
181 2 my $rem = max(0.1, $self->{tick} - ($now - $self->{ts}));
182  
183 # $self->log("rem", $rem);
184  
185 2 my ($new_readable, $new_writable, $new_error) = IO::Select->select($self->{read_set}, $self->{write_set}, $self->{read_set}, $rem + .01);
186  
187 2 foreach my $sock (@$new_readable) {
188 2 ▶ if ($sock == $self->{main_sock}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($sock == $self->{'main_sock'}) { } 1 1 2
189 1 my $new_sock = $sock->accept();
190 1 $self->log("incoming connection from: " , $new_sock->peerhost());
191 # new socket may not be readable yet.
192 1 ▶ if ($new_sock) {
Branch: 1 branch
BranchTrueFalseTotal
if ($new_sock) 1 0 1
193 1 push @SOCKS, $new_sock;
194 1 ++$self->{req_count};
195 1 ▶ if ($WIN32) {
Branch: 1 branch
BranchTrueFalseTotal
if ($WIN32) { } 0 1 1
196 0 ioctl($new_sock, 0x8004667e, pack("I", 1));
197 } else {
198 1 fcntl($new_sock, F_SETFL(), O_NONBLOCK());
199 }
200 1 $new_sock->autoflush(1);
201 1 my @opts;
202 # pass through some options to console object on new connections
203 1 for (qw(usereadkey noinit)) {
204 2 ▶ push @opts, $_=>$self->{$_} if defined $self->{$_};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{$_} 1 1 2
205 }
206 1 $self->{read_set}->add($new_sock);
207 1 *$new_sock{HASH}->{con} = new Games::Roguelike::Console::ANSI (in=>$new_sock, out=>$new_sock, @opts);
208 1 *$new_sock{HASH}->{time} = time();
209 1 *$new_sock{HASH}->{errc} = 0;
210 1 $self->{con} = *$new_sock{HASH}->{con};
211 1 $self->echo_off();
212 1 $self->{state} = '';
213 1 $self->{vp} = '';
214 1 $self->newconn($new_sock);
215 1 *$new_sock{HASH}->{state} = $self->{state};
216 1 *$new_sock{HASH}->{char} = $self->{vp};
217 1 ▶ $self->{vp}->{con} = $self->{con} if $self->{vp} && !$self->{vp}->{con};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"vp"} and not $self->{"vp"}{"con"} 1 0 1
Condition33%1/3
$self->{"vp"} and not $self->{"vp"}{"con"}
!ll&&!rl&&r
001
MC/DC0%0/2
$self->{"vp"} and not $self->{"vp"}{"con"}
$self->{"vp"} not $self->{"vp"}{"con"}
Truth table33%1/3
A and not(B)
A= $self->{"vp"}B= not $self->{"vp"}{"con"}
ABresult
0X0
100
111
218 1 $self->log("state is: " , $self->{state});
219 }
220 } else {
221 1 ▶ if ($sock->eof() || !$sock->connected() || (*$sock{HASH}->{errc} > 5)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($sock->eof or not $sock->connected or *$sock{'HASH'}->{'errc'} > 5) { } 0 1 1
Condition33%2/6
$sock->eof or not $sock->connected or *$sock{"HASH"}->{"errc"} > 5
l!l&&r!l&&!r
001
$sock->eof or not $sock->connected
l!l&&r!l&&!r
001
MC/DC0%0/3
$sock->eof or not $sock->connected or *$sock{"HASH"}->{"errc"} > 5
$sock->eof not $sock->connected *$sock{"HASH"}->{"errc"} > 5
Truth table25%1/4
A or not(B) or C
A= $sock->eofB= not $sock->connectedC= *$sock{"HASH"}->{"errc"} > 5
ABCresult
1XX1
01X1
0011
0000
222 0 $self->{state} = 'QUIT';
223 } else {
224 1 $self->log("reading from: " , $sock->peerhost());
225 1 $self->log("state was: " , $self->{state});
226 1 $self->{con} = *$sock{HASH}->{con};
227 1 $self->{state} = *$sock{HASH}->{state};
228 1 $self->{vp} = *$sock{HASH}->{char};
229 1 $self->readinput($sock);
230 1 *$sock{HASH}->{state} = $self->{state};
231 1 *$sock{HASH}->{char} = $self->{vp};
232 1 ▶ $self->{vp}->{con} = $self->{con} if $self->{vp} && !$self->{vp}->{con};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"vp"} and not $self->{"vp"}{"con"} 0 1 1
Condition33%1/3
$self->{"vp"} and not $self->{"vp"}{"con"}
!ll&&!rl&&r
010
MC/DC0%0/2
$self->{"vp"} and not $self->{"vp"}{"con"}
$self->{"vp"} not $self->{"vp"}{"con"}
Truth table33%1/3
A and not(B)
A= $self->{"vp"}B= not $self->{"vp"}{"con"}
ABresult
0X0
100
111
233 1 $self->log("state is: " , $self->{state});
234 }
235  
236 1 ▶ if ($self->{state} eq 'QUIT') {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"state"} eq "QUIT") 1 0 1
237 1 eval {
238 1 ▶ *$sock{HASH}->{char}->{area}->delmob(*$sock{HASH}->{char}) if *$sock{HASH}->{char};
Branch: 1 branch
BranchTrueFalseTotal
if *$sock{"HASH"}->{"char"} 1 0 1
239 };
240 1 $self->{read_set}->remove($sock);
241 1 $sock->close();
242 }
243 }
244 }
245 2 foreach my $sock (@$new_error) {
246 0 *$sock{HASH}->{char}->{area}->delmob(*$sock{HASH}->{char});
247 0 $self->{read_set}->remove($sock);
248 0 close($sock);
249 }
250 {
251 2 my $now = time();
252 2 my $rem = $now - $self->{ts};
253  
254 2 ▶ if ($rem >= $self->{tick}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rem >= $self->{"tick"}) 0 2 2
255 #$self->log("tick");
256 0 $self->tick();
257 0 $self->drawallmaps();
258 0 $self->{ts} = $now;
259 }
260 }
261 }
262  
263 0 ▶sub drawallmaps {
Subroutine drawallmaps: not called CC=3 SCAR=24.8
Pod undocumented
264 0 my $self = shift;
265 0 foreach my $sock ($self->{read_set}->handles()) {
266 0 ▶ if (*$sock{HASH}->{char}) {
Branch: 1 branch
BranchTrueFalseTotal
if (*$sock{"HASH"}->{"char"}) 0 0 0
267 0 $self->{vp} = *$sock{HASH}->{char};
268 0 $self->{con} = *$sock{HASH}->{con};
269 0 $self->{area} = $self->{vp}->{area};
270 0 my $color = $self->{vp}->{color};
271 0 my $sym = $self->{vp}->{sym};
272 0 $self->setfocuscolor();
273 0 $self->drawmap();
274 0 $sock->flush();
275 0 $self->{vp}->{color} = $color;
276 0 $self->{vp}->{sym} = $sym;
277 }
278 }
279 }
280  
281 1 ▶sub echo_off {
Subroutine echo_off: called CC=1 SCAR=0.0
Pod undocumented
282 1 my $self = shift;
283 1 my $sock = $self->{con}->{out};
284 # i will echo if needed, you don't echo, i will suppress go ahead, you do suppress goahead
285 1 print $sock "\xff\xfb\x01\xff\xfb\x03\xff\xfd\x03";
286 }
287  
288 0 ▶sub echo_on {
Subroutine echo_on: not called CC=1 SCAR=6.9
Pod undocumented
289 0 my $self = shift;
290 0 my $sock = $self->{con}->{out};
291 # i wont echo, you do echo
292 0 print $sock "\xff\xfc\x01\xff\xfd\x01";
293 }
294  
295 =item getstr ()
296  
297 Reads a string from the active connection.
298  
299 Returns undef if the string is not ready.
300  
301 =cut
302  
303 0 ▶sub hexify {
Subroutine hexify: not called CC=3 SCAR=24.8
Pod undocumented
304 0 my ($s) = @_;
305 0 my $ret = '';
306 0 for (split(//,$s)) {
307 0 $ret .= sprintf("x%x", ord($_));
308 0 ▶ $ret .= "($_)" if $_ =~ /\w/;
Branch: 1 branch
BranchTrueFalseTotal
if $_ =~ /\w/ 0 0 0
309 }
310 0 return $ret;
311 }
312  
313 0 ▶sub getstr {
Subroutine getstr: not called CC=10 SCAR=47.0
Pod documented
314 0 my $self = shift;
315 0 my $sock = $self->{con}->{in};
316 0 my $first = 1;
317  
318 0 while (1) {
319 0 my $b = $self->getch();
320 0 ▶ if (!defined($b)) {
Branch: 3 branches
BranchTrueFalseTotal
if (not defined $b) { } 0 0 0
elsif ($b eq 'BACKSPACE') { } 0 0 0
elsif (length $b > 1 or $b eq '') { } 0 0 0
321 0 ▶ ++(*$sock{HASH}->{errc}) if $first;
Branch: 1 branch
BranchTrueFalseTotal
if $first 0 0 0
322 0 return undef;
323 } elsif($b eq 'BACKSPACE') {
324 0 $self->log("getstr read $b");
325 0 ▶ if (length(*$sock{HASH}->{sbuf}) > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (length *$sock{"HASH"}->{"sbuf"} > 0) 0 0 0
326 0 syswrite($sock, chr(8), 1);
327 0 syswrite($sock, ' ', 1);
328 0 syswrite($sock, chr(8), 1);
329 0 substr(*$sock{HASH}->{sbuf},-1,1) = '';
330 }
331 ▶ } elsif(length($b) > 1 || $b eq '') {
Condition0%0/3
length $b > 1 or $b eq ""
l!l&&r!l&&!r
000
MC/DC0%0/2
length $b > 1 or $b eq ""
length $b > 1 $b eq ""
Truth table0%0/3
A or B
A= length $b > 1B= $b eq ""
ABresult
1X1
011
000
332 0 next;
333 } else {
334 0 $self->log("getstr read " . ord($b));
335 0 syswrite($sock,$b,1); # echo on getstr
336 0 ▶ $first = 0 if $first;
Branch: 1 branch
BranchTrueFalseTotal
if $first 0 0 0
337 0 *$sock{HASH}->{errc} = 0;
338 0 *$sock{HASH}->{sbuf} .= $b;
339 }
340 0 ▶ if ($b eq "\n" || $b eq "\r") {
Branch: 1 branch
BranchTrueFalseTotal
if ($b eq "\n" or $b eq "\r") 0 0 0
Condition0%0/3
$b eq "\n" or $b eq "\r"
l!l&&r!l&&!r
000
MC/DC0%0/2
$b eq "\n" or $b eq "\r"
$b eq "\n" $b eq "\r"
Truth table0%0/3
A or B
A= $b eq "\n"B= $b eq "\r"
ABresult
1X1
011
000
341 0 my $temp = *$sock{HASH}->{sbuf};
342 0 *$sock{HASH}->{sbuf} = '';
343 0 return $temp;
344 }
345 }
346 }
347  
348 =item getch ()
349  
350 Reads a character from the active connection.
351  
352 Returns undef if no input is ready.
353  
354 =cut
355  
356 0 ▶sub getch {
Subroutine getch: not called CC=2 SCAR=17.9
Pod documented
357 0 my $self = shift;
358 0 my $c = $self->{con}->nbgetch();
359 0 ▶ if (! defined $c) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $c) 0 0 0
360 0 my $sock = $self->{con}->{in};
361 ++(*$sock{HASH}->{errc})
362 0 }
363 0 return $c;
364 }
365  
366 =item charmsg ($char)
367  
368 Calls showmsg on the console contained in $char;
369  
370 =cut
371  
372 0 ▶sub charmsg {
Subroutine charmsg: not called CC=1 SCAR=6.9
Pod documented
373 0 my $self = shift;
374 0 my ($char, $msg, $attr) = @_;
375 0 my $con = $self->{con};
376 0 $self->{con} = $char->{con};
377 0 $self->showmsg($msg,$attr);
378 0 $self->{con} = $con;
379 }
380  
381 # log and debug print are essentially the same thing
382  
383 5 ▶sub log {
Subroutine log: called CC=1 SCAR=0.0
Pod undocumented
384 5 my $self = shift;
385 5 my $out = $self->{stdout};
386 5 print $out scalar(localtime()) . "\t" . join("\t", @_) . "\n";
387 }
388  
389 0 ▶sub dprint {
Subroutine dprint: not called CC=1 SCAR=6.9
Pod documented
390 0 my $self = shift;
391 0 my $out = $self->{stdout};
392 0 print $out scalar(localtime()) . "\t" . join("\t", @_) . "\n";
393 }
394  
395 # override this for your game
396  
397 # for now, the way we report back state changes is to modify
398 #
399 # $self->{state}
400 # $self->{vp} # for creating/loading/switching to a character's viewpoint
401 #
402 # these are then linked to the socket
403 #
404 # actual action/movement by a charcter should be queued here, then processed according to a random sort and/or a sort based
405 # on the speed of the character at tick() time
406 #
407 # ie: if an ogre and a sprite move during the same tick, the sprite always goes first, even if the
408 # ogre's player has a faster internet connection
409 #
410 # use getch for a no-echo read of a character
411 # use getstr for an echoed read of a carraige return delimited string
412 #
413 # both will return undef if there's no input yet
414 # don't "wait" for anything in your functons, game is single threaded!
415 #
416  
417 =item readinput ()
418  
419 Must override and call getch() or getstr().
420  
421 The {vp}, {state}, and {con} vars are set on this call, can be
422 changed, and will be preserved.
423  
424 Actual action/movement by a charcter should be queued here, then processed according to
425 a random sort and/or a sort based on the speed of the character.
426  
427 For example: If a tank and a motorcycle move during the same tick, the motorcycle would always go first, even if the tank's player has a faster internet connection. Queueing the moves allows you to do this.
428  
429 Remember never to do something that blocks or waits for input, game is single-threaded.
430  
431 =cut
432  
433 0 ▶sub readinput {
Subroutine readinput: not called CC=1 SCAR=6.9
Pod documented
434 0 die "need to overide this, see netgame example";
435 }
436  
437 # override this for intro screen, please enter yor name, etc.
438 # use $self->{con} for the the Games::Roguelike::Console object (remember, chars are not actually written until flushed, which you can do here if you want)
439  
440 =item newconn ()
441  
442 Must override and either create a character or show an intro screen, or something.
443  
444 The {vp}, {state}, and {con} vars are set on this call, can be changed, and will be preserved.
445  
446 =cut
447  
448 0 ▶sub newconn {
Subroutine newconn: not called CC=1 SCAR=6.9
Pod documented
449 0 die "need to overide this, see netgame example";
450 }
451  
452 =item setfocuscolor ()
453  
454 Change the display color/symbol of the {vp} character here in order to distinguish it from other (enemy?) characters.
455  
456 =cut
457  
458 # change the symbol/color of the character when it's "in focus"
459 0 ▶sub setfocuscolor {
Subroutine setfocuscolor: not called CC=1 SCAR=6.9
Pod documented
460 0 my $self = shift;
461 0 $self->{vp}->{color} = 'bold yellow';
462 }
463  
464 =item queuemove ($char, $move[, $msg])
465  
466 Pushes a "move" for char $char showing message $msg. By default will not queu if a move has been set. The "move" variabe is set in the "char" object to record whether a move has occured.
467  
468 =cut
469  
470 # queue a move until tick time
471 0 ▶sub queuemove {
Subroutine queuemove: not called CC=3 SCAR=24.8
Pod documented
472 0 my $self = shift;
473 0 my ($char, $move, $msg) = @_;
474 0 ▶ if ($char->{move}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($char->{'move'}) { } 0 0 0
475 # already moving, so do nothing
476 # might what to show a message here
477 } else {
478 0 ▶ $self->showmsg($msg) if $msg;
Branch: 1 branch
BranchTrueFalseTotal
if $msg 0 0 0
479 0 $self->{con}->refresh();
480 0 $char->{move} = $move;
481 0 push @{$self->{qmove}}, $char;
482 }
483 }
484  
485 # override this to sort the queue by character speed, display hit points, turn-counts or other status info, etc.
486 # override to process character and mob actions/movement map is auto-redrawn for all connections after the tick (if changed)
487 # don't try to draw here... since no character has the focus...it will fail
488  
489 =item tick ()
490  
491 Override for per-turn move processing. This is called for each game turn, which defaults to a half-second.
492 Default behavior is to sort all the queued moves and execute them.
493  
494 A good way to handle this might be to make the "moves" be code references, which get passed "char" as the argument.
495  
496 =cut
497  
498 0 ▶sub tick {
Subroutine tick: not called CC=2 SCAR=17.9
Pod documented
499 0 my $self = shift;
500 0 my @auto;
501 0 foreach my $char (randsort(@{$self->{qmove}})) {
502 0 $char->kbdmove($char->{move});
503 0 $char->{move} = '';
504 }
505 }
506  
507 =back
508  
509 =head1 BUGS
510  
511 Currently this fails on Win32
512  
513 =head1 SEE ALSO
514  
515 L<Games::Roguelike::World>
516  
517 =head1 AUTHOR
518  
519 Erik Aronesty C<earonesty@cpan.org>
520  
521 =head1 LICENSE
522  
523 This program is free software; you can redistribute it and/or
524 modify it under the same terms as Perl itself.
525  
526 See L<http://www.perl.com/perl/misc/Artistic.html> or the included LICENSE file.
527  
528 =cut
529  
530 1 1;
« Console.pm ↑ Summary Item.pm »