var a,b,ma,mb;
var x=new Array();
var y=new Array();
var c=new Array();
function sample(){
ma=500;
mb=500;
tx=0;
for(s=1;s<11;s++){
for(sx=1;sx<11;sx++){
tx=tx+1;
y[tx]=s;
x[tx]=sx;
c[tx]=0;
}
}
var timer;
var delay = 100;
a=1;
b=1;
var loop = function () {
n1=10*Math.random();
n2=Math.floor(n1)+1;
a=a+n2;
if(a>100)a=a-100;
if(c[a]==0)ma=ma-5;
if(c[a]==0)c[a]=1;
if(c[a]==2)ma=ma-1;
if(c[a]==2)mb=mb+1;
n1=10*Math.random();
n2=Math.floor(n1)+1;
b=b+n2;
if(b>100)b=b-100;
if(c[b]==0)mb=mb-10;
if(c[b]==0)c[b]=2;
if(c[b]==1)mb=mb-1;
if(c[b]==1)ma=ma+1;
if(ma<0)fresh();
if(mb<0)fresh();
var sub=new svgpaint();
str="<svg width=\"500\" height=\"500\">";
str=str+sub.rect(0,0,500,500,"green");
for(s=1;s<101;s++){
if(c[s]==1)str=str+sub.rect(50*x[s]-50,50*y[s]-50,50,50,"red");
if(c[s]==2)str=str+sub.rect(50*x[s]-50,50*y[s]-50,50,50,"blue");
}
str=str+"</svg>";
$("#memo").html(str);
$("#point").html(ma+","+mb)
clearTimeout(timer);
timer = setTimeout(loop, delay);
}
loop();
}
function fresh(){
ma=500;
mb=500;
a=1;
b=1;
for(tx=1;tx<101;tx++){
c[tx]=0;
}
}
最終更新:2015年12月10日 11:10