アットウィキロゴ

pろ0307

class pro0307{
public static void main(String [] args) {
int[][] x=new int[5][5];
int px,py;
int tx,ty;
int m,n;
int t;
int score;
int h;
double sai;
for (m=0;m<5;m++){
for (n=0;n<5;n++){
x[m][n]=0;
}
}

px=0;
py=0;
tx=4;
ty=4;
t=0;
while(t<1000){
sai=Math.random();
if (sai>0.5)px=px+1;
if (sai<0.5)px=px-1;
if (px<0)px=0;
if (px>4)px=4;
sai=Math.random();
if (sai>0.5)py=py+1;
if (sai<0.5)py=py-1;
if (py<0)py=0;
if (py>4)py=4;
x[px][py]=1;
score=0;
for (m=0;m<5;m++){
for (n=0;n<5;n++){
score=score+x[m][n];
}
}
sai=Math.random();
if (sai>0.5)tx=tx+1;
if (sai<0.5)tx=tx-1;
if (tx<0)tx=0;
if (tx>4)tx=4;
sai=Math.random();
if (sai>0.5)ty=ty+1;
if (sai<0.5)ty=ty-1;
if (ty<0)ty=0;
if (ty>4)ty=4;
h=0;
if (px==tx)h=h+1;
if (py==ty)h=h+1;
if (h==2)t=1000;
if (h==2)System.out.println("game over");
System.out.println(score);
if (score==25)t=1000;
t=t+1;
}



}
}
最終更新:2010年09月19日 02:03