import java.awt.*;
import java.awt.event.*;
class game0209 extends Frame implements Runnable{
Image img;
int car;
int right[]=new int[1001];
int left[]=new int[1001];
public static void main(String [] args) {
Frame f=new game0209();
f.setTitle("game0209");
f.setSize(700,700);
f.setBackground(Color.yellow);
f.setVisible(true);
}
game0209(){
img = Toolkit.getDefaultToolkit().getImage("an.jpg");
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 n,t;
for (n=1;n<1001;n++){
right[n]=0;
if(Math.random()>0.3)right[n]=1;
left[n]=0;
if(Math.random()>0.8)left[n]=1;
}
car=100;
t=1;
while(t<500){
car=car+1;
repaint();
try{
Thread.sleep(200);
}catch(InterruptedException e){}
t=t+1;
}
repaint();
}
public void paint(Graphics g){
int m;
g.setColor(Color.yellow);
g.fillRect(400,0,100,500);
g.fillRect(100,0,100,500);
g.drawImage(img,300,300,50,50,this);
for (m=1;m<100;m++){
g.setColor(Color.red);
if(right[car+m]==1)g.fillRect(400,500-5*m,100,5);
if(left[car+m]==1)g.fillRect(100,500-5*m,100,5);
System.out.println(left[car+m]);
}
}
}
最終更新:2011年02月09日 03:55