Skip to content

Instantly share code, notes, and snippets.

@laserbat
Created July 7, 2011 15:16
Show Gist options
  • Save laserbat/1069735 to your computer and use it in GitHub Desktop.
Save laserbat/1069735 to your computer and use it in GitHub Desktop.
#!/usr/bin/perl
use Curses;initscr;refresh;noecho;curs_set cbreak;$pd=3;$ph=10;$zd=7;$zh=40;sub z{for$x(0..$w){for$y(0..$h){if($zo[$x][$y]<=0){$z[$x][$y]=0;$zo[$x][$y]=0}for(0..20){$zxn=int(rand 3)-1;$zyn=int(rand 3)-1;if(!$l[$x+$zxn][$y+$zyn]){last}}if(!int(rand 5)and$le[$x][$y]and$x!=$yy and$y!=$yx){$z[$x][$y]=1;$zo[$x][$y]=$zh}else{$z[$x][$y]=0}if($z[$x][$y]){$z[$x+$zxn][$y+$zyn]=$z[$x][$y];$zo[$x+$zxn][$y+$zyn]=$zo[$x][$y]}if(int(rand 5)and!o($x,$y)and$zxn or$zyn){$z[$x][$y]=0;$zo[$x][$y]=0}if(o($x,$y)and$z[$x][$y]){$ph-=$zd-int(rand 3);flash;addstr(22,0,"The zombie hits!".' 'x10);refresh}}}}sub p{a: $m=getc;if($m==8){$yy2--}elsif($m==2){$yy2++}elsif($m==4){$yx2--}elsif($m==6){$yx2++}elsif($m==9){$yx2++;$yy2--}elsif($m==7){$yx2--;$yy2--}elsif($m==1){$yx2--;$yy2++}elsif($m==3){$yx2++;$yy2++}elsif($m eq'q'){endwin;exit}else{goto a}if($z[$yy2][$yx2]){$zo[$yy2][$yx2]-=$pd+int(rand 3);flash;addstr(22,0,"You hit the zombie!".' 'x10);refresh;($yy2,$yx2)=($yy,$yx);$hz=1}if($le[$yy2][$yx2]and!$z[$yy2][$yx2]){($yy,$yx)=($yy2,$yx2)}else{($yy2,$yx2)=($yy,$yx);if(!$hz){goto a}$hz=0}if($yy==10and$yx==0or$yy==11and$yx==0){endwin;exit}}sub d{@l=@_;foreach$x(0..20){foreach$y(0..70){if(o($x,$y)){addstr($x,$y,$l[$x][$y]?'.':'#');addstr($x,$y,$z[$x][$y]? 'Z':'');addstr($x,$y,$ie[$x][$y]? '*':'');$z[$x][$y] = 0 if $ie[$x][$y]}else{addstr($x,$y,' ')}}}if(o(10,0)){addstr(10,0,'+')}if(o(11,0)){addstr(11,0,'+')}$l[10][0]=1;$l[11][0]=1;addstr(21,0,"Get out from the graveard!");if($ph <= 0){endwin;exit}addstr($yy,$yx,'@');refresh}sub l{($h,$w)=(@_);foreach$x(0..$w){foreach$y(0..$h){if(!$x or!$y or$y==$h or$x==$w){$le[$x][$y]=0;}else{$le[$x][$y]=1}}}foreach(5..(int(rand 15)+20)){($gy,$gx)=((int(rand 60)+5),(int(rand 11)+5));$le[$gx][$_]=0 foreach($gy..$gy+2);$le[$gx+1][$_]=0 foreach($gy..$gy+2);foreach$x(0..$w){foreach$y(0..$h){if(!int(rand 5) and $le[$x][$y] and $x != $yy and $y != $yx){$z[$x][$y]=1;$zo[$x][$y]=$zh;}else{$z[$x][$y]=0}if(!int(rand 100)and$le[$x][$y]and$x!=$yy and$y!=$yx){$ie[$x][$y]=1}else{$ie[$x][$y]=0}}}}sub v {sort { int(rand 3)-1 <=> int(rand 3)-1 } @_}@is=('sword','shield','holy water','heling potion','potion of might');@id=(10,0,5,0,20);@ih=(0,10,5,10,20);@of=(0,1,2,3,4);@of=v@of;sub i{if ($ie[$yy][$yx]){$ax=shift(@of);$it=$is[$ax];$pd+=$id[$ax];$ph+=$ih[$ax];$sc+=15;$ic++;if($ic > 5){$it=$is[3];$id=0;$ih=10}clear;flash;addstr("You got a $it!\nPress any key.\n");refresh;getc;$ie[$yy][$yx]=0;}}return @le}sub o{($x,$y)=(@_);if($yy>=$x-1and$yx>=$y-1and$yy-1<=$x and$yx-1<=$y){return 1}}sub g{d@_;p;z;i}($yx,$yy)=(69,19);($yx2,$yy2)=(69,19);$l=@le=l(70,20);g@le while$l
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment