アットウィキロゴ

game06 java

import java.awt.*;
import java.awt.event.*;

class game06 extends Frame implements Runnable{

int px,py;
int m,n;
int z[][]=new int[11][11];


public static void main(String [] args) {
        Frame f=new game06();
        f.setTitle("game06");
        f.setSize(700,700);
        f.setBackground(Color.yellow);
        f.setVisible(true);
    }

game06(){


Thread th=new Thread(this);
th.start();
addWindowListener(new stopwin());
}


class stopwin extends WindowAdapter{
    public void windowClosing(WindowEvent we){System.exit(0);}
}  


public void run(){
int t,coin;
t=1;
for (m=1;m<11;m++){
for (n=1;n<11;n++){
z[m][n]=1;
}
}

px=1;
py=1;
while(t<500){
coin=(int)(4*Math.random())+1;
if (coin==1)px=px+1;
if (coin==2)px=px-1;
if (coin==3)py=py+1;
if (coin==4)py=py-1;
if (px<1)px=1;
if (px>10)px=10;
if (py<1)py=1;
if (py>10)py=10;
repaint();
try{
Thread.sleep(500);
}catch(InterruptedException e){}
t=t+1;
}

}


public void paint(Graphics g){
g.fillRect(100+50*px,100+50*py,50,50);
for (m=1;m<11;m++){
for (n=1;n<11;n++){
if (z[m][n]==1)g.fillRect(100+50*m,100+50*n,10,10);
}
}

}

}
最終更新:2011年01月29日 10:21