import java.awt.*;
import java.awt.event.*;
class game0202 extends Frame implements Runnable{
int t;
int bx,by;
int dx;
int donx,dony;
int dd;
public static void main(String [] args) {
Frame f=new game0202();
f.setTitle("game0202");
f.setSize(700,700);
f.setBackground(Color.yellow);
f.setVisible(true);
}
game0202(){
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 h;
dx=1;
bx=1;
by=1;
donx=1;
dony=10;
dd=1;
t=1;
while(t<100){
bx=bx+dx;
if (bx==10)dx=-1;
if (bx==10)by=by+1;
if (bx==1)dx=1;
if (bx==1)by=by+1;
donx=donx+dd;
if (donx==10)dd=-1;
if (donx==10)dony=dony-1;
if (donx==1)dd=1;
if (donx==1)dony=dony-1;
h=0;
if (donx==bx)h=h+1;
if (dony==by)h=h+1;
if(h==2)t=1000;
repaint();
try{
Thread.sleep(100);
}catch(InterruptedException e){}
t=t+1;
if(by==11)t=1000;
}
repaint();
}
public void paint(Graphics g){
int m;
g.fillOval(100+50*bx,50*by,30,30);
g.fillRect(100+50*donx,50*dony,50,50);
for (m=1;m<11;m++){
g.drawLine(100,50*m,600,50*m);
}
}
}
最終更新:2011年02月02日 00:06