Slide 19
Slide 19 text
var s=[],win=window;win.onload=function(){function t(){return Math.
round(25*Math.random())*o}function n(){var t=b[g](e[x]("div"));t[w](i,
a),t[w]("class","s"),s.push(t)}var e=document,a="position:absolute;
background:black; width:20px; height:20px;",r="px",o=20,i="style",p="
up",l="down",u="right",v="left",c="top",d="left",h=parseInt,f="style",
w="setAttribute",g="appendChild",x="createElement";n();var m=b[g](e[x]
("div"));s[0][w](i,"top:"+t()+"px; left:"+t()+"px;"+a),m[w](i,a+"
background:green; top:"+t()+"px; left:"+t()+"px;"),win.
onkeyup=function(t){var n=t.which;87==n&&(y=p),83==n&&(y=l),65==n&&
(y=v),68==n&&(y=u)};var y=u,I=setInterval(function(){var e=s[0][f];j=h
(e[c]),k=h(e[d]);var a=h(m[f][c]),i=h(e[c]),w=h(m[f][d]),b=h(e[d]);
a==i&&w==b&&(n(),m[f][c]=t()+r,m[f][d]=t()+r);for(var g=s.length-1;
g>0;g--)e[c]==s[g][f][c]&&e[d]==s[g][f][d]&&clearInterval(I);var x=s
[s.length-1][f];y==p?(x[c]=j-o+r,x[d]=k+r):y==l?(x[c]=j+o+r,x[d]=k+r):
y==v?(x[c]=j+r,x[d]=k-o+r):y==u&&(x[c]=j+r,x[d]=k+o+r),s.unshift(s.
pop())},100)};