perl -e 'my$ani=1;if($#ARGV>=0&&$ARGV[0]eq"noani"){$ani=0}use Term::ReadKey;my($xm,$ym)=GetTerminalSize;print"\e[?25l";ReadMode(2);ReadMode(4);use worm;my@scr=();sub scr{$scr[$_[1]]->[$_[0]]=$_[2]}my@allwalls=([[0,0,1,0],[1,0,1,1],[1,1,0,1],[0,1,0,0]],[],[[1/3,1/2,2/3,1/2]],[[1/3,1/3,1/3,2/3],[2/3,1/3,2/3,2/3]]);sub wall{my$w=$_[0];init_worm("+");set_worm_delay(0.001);foreach my$walls($allwalls[$w]){foreach my$wall(@{$walls}){my($x1,$y1,$x2,$y2)=(int($wall->[0]*$xm),int($wall->[1]*$ym),int($wall->[2]*$xm),int($wall->[3]*$ym));if($x1==0){$x1=1}if($y1==0){$y1=1}if($x2==0){$x2=1}if($y2==0){$y2=1}for(my$y=$y1;$y1<=$y2?$y<=$y2:$y>=$y2;$y1<=$y2?$y++:$y--){for(my$x=$x1;$x1<=$x2?$x<=$x2:$x>=$x2;$x1<=$x2?$x++:$x--){creep_worm($x,$y);scr($x,$y,2)}}}}}if($ani){clrscr;wall(0);init_worm("::[ j :: left  ]::::] thgir :: l [::::[ i :: top   ]::::]  nwod :: k [::::[ x :: exit  ]::                  .:[ press enter]:. ");for(my$y=$ym-1;$y>=int($ym*2/3);$y-=2){for(my$x=int($xm/2)-9;$x!=int($xm/2)+9;$x++){creep_worm($x,$y)}for(my$x=int($xm/2)+8;$x!=int($xm/2)-10;$x--){creep_worm($x,$y-1)}};init_worm("::] ed.ccc.revonnah\@rgm / ten.xmg\@ffalzter.m [::.:[ tiny gpl\47d nibble clone written in perl  ]:. ");my$y=int($ym/3);for(my$x=$xm-1;$x!=int($xm/2)-24;$x--){creep_worm($x,$y)}$y++;for(my$x=int($xm/2)-23;$x!=int($xm/2)+25;$x++){creep_worm($x,$y)}init_worm("");init_worm("\@.OOOOOOooooooo...... ");for(my$x=int($xm/5),my$y=$ym-1;$y>=int($ym/2);$y--){creep_worm($x,$y)}for(my$y=int($ym/2),my$x=int($xm/5);$x!=int($xm/2)+11;$x++){creep_worm($x,$y)}}if($ani){<STDIN>}my$nl=1;my$l=1;while($nl==1){$nl=0;my($x,$y,$k)=(2,2,"l");gotoxy($x,$y);clrscr;wall(0);sub msg{my$s=$_[0];my$x=int($xm/2-(length($s)+8)/2);my$y=int($ym/2);gotoxy($x,$y);print"::[ $s ]::";if(!defined($_[1])){<STDIN>;gotoxy($x,$y);print" "x(length($s)+8)}}msg("level $l");if(defined($allwalls[$l])){wall($l)}init_worm("\@.OOOOOOooooooo...... ");set_worm_delay(0.07);my$fc=0;for(my$i=1;$i<=int($xm*$ym*5/1000);$i++){my($x,$y)=(int(rand($xm)+1),int(rand($ym)+1));if(defined($scr[$y]->[$x])){$i--}else{$scr[$y]->[$x]=1;gotoxy($x,$y);print"x";$fc++}}while($k ne"x"&&$nl==0){my$kt=ReadKey(-1);if(defined($kt)&&$kt=~/[jklix]/){$k=$kt}if($k eq"j"&&$x>0){$x--}elsif($k eq"l"&&$x<$xm){$x++}elsif($k eq"i"&&$y>0){$y--}elsif($k eq"k"&&$y<$ym){$y++}if($k ne"x"){if(defined(my$f=$scr[$y]->[$x])){if($f==1){grow_worm(undef,".","o");scr($x,$y,undef);creep_worm($x,$y);$fc--;if($fc<=0){$l++;$nl=1}}elsif($f==2){msg("luser",1);$k="x"}}else{creep_worm($x,$y)}}}}gotoxy(1,$ym-1);print"\e[J";ReadMode(0);ReadMode(1);print"\e[?25h"'
