in reply to Re^3: newbie learning perl
in thread newbie learning perl
I added use strict and use warnings. Yikes, lots of errors. I tried to clean them all up. Down to one I cant figure out. Global symbol "@xloc" requires explicit package name The array xloc is used in 2 locations so generates this warning twice. Each item in the array represents the x location of a T and the location in the array represents the y location. The line: if ($skierx eq $xloc$skiery) {print "CRASH!!!"; exit;} is how I detect that the skier has hit a tree. A different warning said I should use $ instead of @ infront of xloc. I dont get it. I seek the wisdom of the monks.
#!/usr/bin/perl use strict; use warnings; use Win32::Console::ANSI; use Term::ANSIScreen qw/:color :cursor :screen/; use Term::ReadKey; ReadMode('noecho'); cls; my $col = 0; my $skierx = 40; my $skiery = 0; my $score = 0; my $key = 0; my $wait = .3; my $y = 1; #fill the screen with Ts while ($y < 100) { $col = int(rand(80)); printf ("%${col}s\n", "T"); $y = $y + 1; } $wait = 1; $skierx = 40; $skiery = 0; $y = $y + 5; locate $y,1; print " ------------------------- Ready Set GO! --------------- +----------"; while (1 < 2) { while (not defined ($key = ReadKey(-1))) { # here when no key pressed # place a T and save X location in array, position in array = Y $col = int(rand(80)); $y = $y + 1; $xloc[$y] = $col; locate $y,$col; print "T\n"; # place V $skiery = $y - 50; locate $skiery,$skierx; print "V"; #crash??? if ($skierx eq $xloc[$skiery]) {print "CRASH!!!"; exit;} #score if ($skiery < 105) {locate $skiery,1; print "PRACTICE";} if ($skiery > 105) {$score = $score + 1;locate $skiery,1; print +"$score";} # keep speeding up, reducing pause time select(undef, undef, undef, $wait); #pauses here #$wait = $wait - .005; if ($score eq 50) {$wait = .25;} if ($score eq 100) {$wait = .2;} if ($score eq 150) {$wait = .15;} if ($score eq 200) {$wait = .1;} } # here when key pressed if ($key eq ",") {$skierx = $skierx - 1;} if ($key eq ".") {$skierx = $skierx + 1;} if ($key eq "x") {exit;} } END{ ReadMode('restore'); }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^5: newbie learning perl
by GrandFather (Saint) on Feb 20, 2015 at 22:44 UTC | |
|
Re^5: newbie learning perl
by RonW (Parson) on Feb 20, 2015 at 20:58 UTC | |
|
Re^5: newbie learning perl
by mkesling (Initiate) on Feb 20, 2015 at 20:30 UTC |