perl -e '$ani=1;if($#ARGV>=0&&$ARGV[0]eq"noani"){$ani=0}use Term::ReadKey;($xm,$ym)=GetTerminalSize;print"\e[?25l";ReadMode(2);ReadMode(4);use worm;@scr=();sub scr{$scr[$_[1]]->[$_[0]]=$_[2]}@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]],[[1/5,1/4,4/5,1/4],[1/5,2/4,4/5,2/4],[1/5,3/4,4/5,3/4]],[[1/3,0,1/3,1/2],[1,1/3,1/2,1/3],[2/3,1,2/3,1/2],[0,2/3,1/2,2/3]],[[1/2,1/5,1/2,4/5],[1/5,1/2,4/5,1/2]]);sub wall{$w=$_[0];init_worm("+");set_worm_delay(0.001);foreach$walls($allwalls[$w]){foreach$wall(@{$walls}){($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($y=$y1;$y1<=$y2?$y<=$y2:$y>=$y2;$y1<=$y2?$y++:$y--){for($x=$x1;$x1<=$x2?$x<=$x2:$x>=$x2;$x1<=$x2?$x++:$x--){if(defined($_[1])){scr($x,$y,undef)}else{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($y=$ym-1;$y>=int($ym*2/3);$y-=2){for($x=int($xm/2)-9;$x!=int($xm/2)+9;$x++){creep_worm($x,$y)}for($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  ]:. ");$y=int($ym/3);for($x=$xm-1;$x!=int($xm/2)-24;$x--){creep_worm($x,$y)}$y++;for($x=int($xm/2)-23;$x!=int($xm/2)+25;$x++){creep_worm($x,$y)}init_worm("");init_worm("\@.OOOOOOooooooo...... ");for($x=int($xm/5),$y=$ym-1;$y>=int($ym/2);$y--){creep_worm($x,$y)}for($y=int($ym/2),$x=int($xm/5);$x!=int($xm/2)+11;$x++){creep_worm($x,$y)}}if($ani){<STDIN>}$nl=1;$l=1;while($nl==1){$nl=0;gotoxy($x,$y);clrscr;wall(0);sub msg{my$s=$_[0];$x=int($xm/2-(length($s)+8)/2);$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);$fc=0;for($i=1;$i<=int($xm*$ym*5/1000);$i++){($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++}}($x,$y,$k)=(2,2,"l");while($k ne"x"&&$nl==0){$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($f=$scr[$y]->[$x])){if($f==1){grow_worm(undef,".","o");scr($x,$y,undef);creep_worm($x,$y);$fc--;if($fc<=0){wall($l,1);$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"'
