import java.awt.*;
import java.awt.event.*;
class game05 extends Frame implements Runnable{
int px,py;
public static void main(String [] args) {
Frame f=new game05();
f.setTitle("game05");
f.setSize(700,700);
f.setBackground(Color.yellow);
f.setVisible(true);
}
game05(){
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;
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);
}
}
最終更新:2011年01月29日 10:05