This could be more obscure but I think its at least non-obvious the way it is. Will work on a standard size terminal window. *Should* work on Windows but I don't have a box in which to test that theory. Needs Time::HiRes. I did it at first without but it just wasn't as cool. Anyway, here it is:
#!/usr/bin/perl use Time::HiRes qw(usleep); $@='Just Another Perl Hacker';$@=length($@); $|=abs(2-$@);goto f;z:if(int(rand(10))>5){($- ,$.)=($",$;);}else{($-,$.)=($",$;);}@b =();$b [0] = $-;if($- ==$;){$b[1]=1;}else{$b[1]=7 + 50 + 10 + (5 * 2);}$,='l';$,='r'if$-==$";$vd ='u';$vd='d'if int(rand(10))<5;while($|){my $s="";foreach $%(0 .. 22){foreach$=(0 .. 78) {if($===39){$s.="|";}if($%==$;&& $===0){$s.= "]";}elsif($===$b[1]&& $%==$b[0]){$s.= "*";} elsif($===78&& $%==$"){$s.="[\n";}elsif($=== 78){$s.=" \n";}else{$s.=" ";}}}print $s;#### $b[1]==1 and$,='r';$b[1]==77 and$,='l';$b[0] == 23 and$vd='u';$b[0]==0 and$vd='d';if($,eq 'r'){$b[1]++;$mp=\$";}if($, eq'l'){$b[1]--;# $mp=\$;;}if($vd eq'u'){$b[0]--;$$mp-- unless $$mp==0;}if($vd eq'd'){$b[0]++;$$mp++ unless $$mp == 22;}usleep(50_000);system($^);}f:$^= 'clear';$"=int(rand(22));$;=int(rand(22));$^ ='cls'if$^O=~m|win|i;goto z;################
Suggestions welcome!
Update: Took out the need for Time::HiRes as suggested by BrowserUk
#!/usr/bin/perl $@='Just Another Perl Hacker';$@=length($@); $|=abs(2-$@);goto f;z:if(int(rand(10))>5){($- ,$.)=($",$;);}else{($-,$.)=($",$;);}@b =();$b [0] = $-;if($- ==$;){$b[1]=1;}else{$b[1]=7 + 50 + 10 + (5 * 2);}$,='l';$,='r'if$-==$";$vd ='u';$vd='d'if int(rand(10))<5;while($|){my $s="";foreach $%(0 .. 22){foreach$=(0 .. 78) {if($===39){$s.="|";}if($%==$;&& $===0){$s.= "]";}elsif($===$b[1]&& $%==$b[0]){$s.= "*";} elsif($===78&& $%==$"){$s.="[\n";}elsif($=== 78){$s.=" \n";}else{$s.=" ";}}}print $s;#### $b[1]==1 and$,='r';$b[1]==77 and$,='l';$b[0] == 23 and$vd='u';$b[0]==0 and$vd='d';if($,eq 'r'){$b[1]++;$mp=\$";}if($, eq'l'){$b[1]--;# $mp=\$;;}if($vd eq'u'){$b[0]--;$$mp-- unless $$mp==0;}if($vd eq'd'){$b[0]++;$$mp++ unless $$mp == 22;}select $`,$`,$`,.05;system($^);} f:$^='clear';$"=int(rand(22));$;=int(rand(22 ));$^='cls'if$^O=~m|win|i;goto z;###########
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Perl plays Pong!
by BrowserUk (Patriarch) on Jan 24, 2004 at 09:43 UTC | |
|
Re: Perl plays Pong!
by jbware (Chaplain) on Jan 25, 2004 at 01:20 UTC | |
|
Re: Perl plays Pong!
by duff (Parson) on Jan 24, 2004 at 08:07 UTC | |
|
Re: Perl plays Pong!
by CountZero (Bishop) on Jan 24, 2004 at 22:33 UTC | |
by cfreak (Chaplain) on Jan 25, 2004 at 02:51 UTC | |
|
Re: Perl plays Pong!
by ysth (Canon) on Jan 25, 2004 at 06:30 UTC | |
by cfreak (Chaplain) on Jan 25, 2004 at 07:20 UTC | |
by ysth (Canon) on Jan 25, 2004 at 07:41 UTC | |
by Mr. Muskrat (Canon) on Jan 26, 2004 at 04:05 UTC |