thought you all might like this...

R

Robin

#!/usr/bin/perl
use Tk;
$m = new MainWindow ();
my $t1 = 400;
$c = $m -> Canvas (-width=>$t1, -height=>400, -background=>"black") ->
pack ();
$l = $m -> Label (-text=>"Write sentences to invade and release good
guys at the same time") -> pack ();
$t = $m -> Scrolled ("Text") -> pack ();
$t -> bind ("<a>", \&d);
$t -> bind ("<u>", \&d);
$t -> bind ("<e>", \&d);
$t -> bind ("<i>", \&d);
$t -> bind ("<o>", \&d);








MainLoop ();

sub d () {
my $e = int rand ($t1);
my $e2 = int rand ($t1);
my $e3 = int rand ($t1);
my $e4 = int rand ($t1);
$c -> create ("rectangle", $e, $e2, $e3, $e4, -outline=>"red");
my $e = int rand ($t1);
my $e2 = int rand ($t1);
my $e3 = int rand ($t1);
my $e4 = int rand ($t1);
$c -> create ("rectangle", $e, $e2, $e3, $e4, -outline=>"black");
my $e = int rand ($t1);
my $e2 = int rand ($t1);
my $e3 = int rand ($t1);
my $e4 = int rand ($t1);
$c -> create ("rectangle", $e, $e2, $e3, $e4, -outline=>"black");
if ($e == 50 or $e == 50 or $e == 301 or $e == 100) {
$z += 1;
$c -> create ("rectangle", $e, $e2, $e3, $e4, -outline=>"yellow");
$l -> configure (-text=>"Your score is $z\n");
}
if ($z == 200) {
$m -> Dialog (-text=>"You win. Now write about what the screen
looked like.") -> Show ();
exit ();
}
}
 
J

jl_post

A clever program. Thanks for sharing.

However, you have several mistakes in your code:

if ($e == 50 or $e == 50 or $e == 301 or $e == 100)

I see "if $e is 50 or if $e is 50". I'm sure that's not what you
meant.

And why aren't you using "use strict" and warnings? You may think
you don't need them, but running your script with them on points out
several more errors:

my $e = int rand ($t1);
my $e2 = int rand ($t1);
my $e3 = int rand ($t1);
my $e4 = int rand ($t1);
$c -> create ("rectangle", $e, $e2, $e3, $e4, -outline=>"red");
my $e = int rand ($t1);
my $e2 = int rand ($t1);
my $e3 = int rand ($t1);
my $e4 = int rand ($t1);

Why are you re-declaring $e, $e2, $e3, and $e4? It's either a mistake
or you don't quite understand the point of declaring variables. (I
see that most of your variables are declared, yet some aren't. Is
there a reason for that?)

The errors that "use strict" and warnings points out on your
program may be minor (and could be ignored in your program), but the
bigger your program gets, the more errors creep in, creating
exponentially more work to find and fix them. My advice is to use
"use strict;" and warnings from the start, and have them catch certain
common errors as soon as they happen.

It is a pretty cool program. Just be sure to include "use strict;"
and warnings in every Perl program you write. In that way you'll
satisfy two of Larry Wall's virtues of programming: Hubris (in that
you want your programs to be so great not even "strict" and "warnings"
can complain about them) and Laziness (in that "strict" and "warnings"
point out many common errors so rapidly that you won't spend any time
trying to find them. To fix them, yes, but to find them, no).

Also, I recommend including a short explanation of what the program
does, in the form of perldocs (or at least as comments at the top of
the script). Otherwise, people won't really know what your program
does until they run it, and for several reasons, running a program
just to find out what it does is often frowned upon.

Cheers,

-- Jean-Luc
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,263
Messages
2,571,064
Members
48,769
Latest member
Clifft

Latest Threads

Top