This is my first perl program. It is a skiing program. I wrote it in basic decades ago. Thought it would be a fun way to get aquainted with perl and introduce my son to programing.
The first part randomly fills the screen with Ts that represent trees. Then it goes into a loop that puts a V on the screen that represents the skier.
This is where I am having a problem. When the j key is pressed I want the V to move to the left. When the k key is pressed I want the V to move to the right. Instead it breaks out of the loop and the text stops scrolling.
How can I fix this so the V moves and the scrolling continues. Code below.
#!/usr/bin/perl use Win32::Console::ANSI; use Term::ANSIScreen qw/:color :cursor :screen/; use Term::ReadKey; ReadMode('noecho'); cls; #fill the screen with Ts $y = 1; while ($y < 100) { $col = int(rand(80)); printf ("%${col}s\n", T); $y = $y + 1; } $wait = 1; $skierx = 40; $skiery = 0; $y = $y + 5; while (1 < 2) { while (not defined ($key = ReadKey(-1))) { # No key pressed $col = int(rand(79)); $y = $y + 1; locate $y,$col; print "T\n"; $skiery = $y - 50; locate $skiery,$skierx; print "V"; #locate $y,1; print "$skiery $skierx $key"; select(undef, undef, undef, $wait); #pauses here $wait = $wait - .003; } # here when key pressed if ($key == "j") {$skierx = $skierx - 1;} if ($key == "k") {$skierx = $skierx + 1;} if ($key == "x") {exit;} }
In reply to newbie learning perl by mkesling
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |