array(1=>' ',2=>1,3=>''), 2=>array(1=>' ',2=>0,3=>''), 3=>array(1=>' ',2=>0,3=>''), 4=>array(1=>' ',2=>1,3=>''), 5=>array(1=>' ',2=>1,3=>''), 11=>array(1=>'.',2=>1,3=>'land'), 12=>array(1=>'*',2=>0,3=>'tree'), 13=>array(1=>'~',2=>0,3=>'water'), 14=>array(1=>'&',2=>1,3=>'monster'), 15=>array(1=>'+',2=>1,3=>'dragon'), ); function seed($t, $n, &$r){ for($i=0;$i<$n;$i++){ $r[rand(0,60)][rand(0,60)] = $t; } } function genM(){ global $tls; $r = array(); for($y=0;$y<61;$y++) $r[$y] = array_fill(0,60,1); seed(2, rand(55,150), $r); seed(3, rand(40,150), $r); seed(4, rand(150,250), $r); seed(5, 1, $r); $r[2][2] = 1; return $r; } function init(){ global $s; $s['st'] = 1; $s['x'] = 2; $s['y'] = 2; $s['h'] = 10; $s['a'] = 2; $s['d'] = 2; $s['i'] = array(); $s['m'] = genM(); } function r($t){ printf('rp16g

rp16g

tiny rpg

%s', $t); } function st(){ r('
'); } function play(){ global $s; global $tl; global $p; for($y=$s['y']-1;$y<$s['y']+2;$y++){ for($x=$s['x']-1;$x<$s['x']+2;$x++){ if($s['m'][$y][$x]<10){ $s['m'][$y][$x] +=10; } } } $t='
';
$t.='';
$t.='';

$t.='';
$t.='';
$t.='
'; if (isset($p['run'])){ $t.='

You ran away from the battle. Shame on you

'; $s['st']=1; } $t.='
'; if($s['st']==1){ foreach($s['m'] as $y=>$r){ foreach($r as $x=>$otl){ if ($y==$s['y'] && $x==$s['x']){ $t.='@'; } else { $t.=$tl[$otl][1]; } } $t.="\n"; } $t.='
'; } else { if(isset($p['att'])){ $at = rnd($s['a']); if ($at== $at+2) $at *=2; $hit = $at-$s['mn']['d']; $hit = ($hit<1)?0:$hit; $t.=sprintf('

You attack and take %d HP

', $hit); $s['mn']['h'] -= $hit; if($s['mn']['h'] <1){ if($s['st']==2){ r('

You attack and kill the monster. You can continue your quest.

'); $s['m'][$s['y']][$s['x']]=11; $s['h'] += floor($s['mn']['mh']/2); $s['a'] +=1; $s['d'] +=1; unset($s['mn']); $s['st']=1; die(); } else { r('

You killed the mighty dragon. Now you can get the girl, jump into your red ferrary and ride to the beautyful sunset.

The end!

'); session_destroy(); die(); } } $at = rnd($s['mn']['a']); if ($at== $at+2) $at *=2; $hit = $at-$s['d']; $hit = ($hit<1)?0:$hit; $t.=sprintf('

Monster attacks and takes %d HP

', $hit); $s['h'] -= $hit; if($s['h']<1){ r('

You are dead!

Better luck next time. Start again.

'); session_destroy(); die(); } } $mn = $s['m'][$s['y']][$s['x']]; $t.='

'; $t.='

Fight

'; $t.=''; $t.=''; $t.=''; $t.=''; $t.='

'; $t.='
@'.$tl[$mn][1].'
hlt:'.$s['h'].''.$s['mn']['h'].'
att:'.$s['a'].''.$s['mn']['a'].'
def:'.$s['d'].''.$s['mn']['d'].'
'; $t.='
'; } $t.='
'; $t.='

Move

'; $t.='
  

  
'; $t.='

Hero stats

'; $t.='Health: '.$s['h']; $t.='
Attack: '.$s['a']; $t.='
Defense: '.$s['d']; $t.='
Position: '.$s['x'].'x'.$s['y']; $t.='

Legend

'; foreach($tl as $k=>$a){ if($k>10) $t.= $a[1].' '.$a[3].'
'; } $t.='
'; r($t); } function vp($n){ global $p; if (isset($p[$n])){ return $p[$n]; } else { return FALSE; } } function rnd($v){return mt_rand($v-2, $v+2);} function inp(){ global $s; global $tl; $x = $s['x']; $y = $s['y']; if ($s['st']==1){ if(vp('n'))$y-=1; if(vp('w'))$x-=1; if(vp('e'))$x+=1; if(vp('s'))$y+=1; } $ct = $s['m'][$y][$x]; if($tl[$ct][2]){ $s['x']=$x; $s['y']=$y; if ($s['st']==1 && $ct==14) { $s['st'] = 2; $h = rnd($s['h']); $s['mn'] = array('mh'=>$h, 'h'=>$h, 'a'=>rnd($s['a']), 'd'=>rnd($s['d'])); } if ($s['st']==1 && $ct==15) { $s['st'] = 3; $s['mn'] = array('mh'=>100, 'h'=>100, 'a'=>20, 'd'=>30); } } } if(isset($s['st'])){ inp(); play(); } elseif($p['start']){ init(); play(); } else{ st(); } ?>