var x,y,z,r; function sample(){ w=0; x=500; y=500; var timer; var delay = 100; var loop = function () { if(Math.random()>0.8)ex(); if(x<1000)plan(); if(y<300)sup(); con(); $("#memo").html(x+","+y); clearTimeout(timer); timer = setTimeout(loop, delay); } loop(); } function con(){ c=w; if(c>y)c=y; w=w-c; y=y-c; } function sup(){ w=w+25; x=x-50; y=y+100; } function plan(){ w=w+25; x=x+50; } function ex(){ x=x-100; if(x<0)x=0; }