Roguelike in 560 characters

Roguelike game with source code of 560 characters

by Noncho Savov

HTML

<p id=f></p>

JavaScript

// roguelike in 560 chars
// l:level, h:health, p:position, t:turns, g:health potion position, d:health modifier
a=e=>{
  k=k||e.keyCode;
  m=v="";r="__";d=i=0;
  switch(k){
    case 27:v="Game Over!";break;//b(5);//restart
    case 38:p-=l*2;
    case 40:p+=l+1;
    case 37:p--;
    default:p--;
    case 39:
      t++;p++;if(p<1)p=1;
      k=Math.random();
      t%2&&p%2&&(v+="HIT ",d=-l*k>>0);
      p>l*l&&(l++,p=1,g=l+t*k>>0);
      p==g&&(g=0,d+=5+k*l>>0,v+="HP+");
      k<l/(99+l*5)?(k=l*k*5>>0,v="BAT "+v,d-=k,k=32):k=0;
      for(h+=d;i<=l*l;i++){
        m+="|"+(i==p?"@":i==g?88:32==k?"**":i%2?t%2?".^:":"._.":r),i/l==i/l>>0&&(m+="|<br>")
      }
      if(h<=0)k=27
  }
  f.innerHTML=m+v+(d||"")+"<br>L:"+(l-4)+" M:"+t+" HP:"+h
}
b=c=>{
  l=c;
  p=t=k=0;
  g=h=13;
  onkeydown=a;
  a(0)
}
b(5)