import java.awt.*;
import java.applet.*;
import java.math.*;
public class ss extends Applet implements Runnable
{ int m=150,n=100,x=0,y=70,win=0;
int x1=200,y1=200;
int x3=600,y3=350;
int x2=65,y2=260;
int x0=715,y0=260;
double y22;
Thread t1=null,t2=null,t3=null;
Font f=new Font("宋体",Font.BOLD,25);
String str="4991252班 27号 李文义";
Image img[]=new Image[7];
Image offimg;
Graphics offg;//定义Graphics对象,用一实现双缓冲
public void init()
{
//加载图片的初始化
for(int i=0;i<7;i++)
img[i]=getImage(getDocumentBase(),i+".gif");
offimg=createImage(800,600);
offg=offimg.getGraphics();
}
public void start()
{
if(t1==null)
{
t1=new Thread(this);
t1.start();
}
if(t2==null)
{
t2=new Thread(this);
t2.start();
}
if(t3==null)
{
t3=new Thread(this);
t3.start();
}
}
public void run()
{
while(t1==Thread.currentThread())
{
if(y1<250)
{
x1-=2;
y1++;}
if(y1<=340&&y1>=250)
{
x1++;
y1+=2;
}
if(y1>=340)
{x1+=5;}
if(x1>=600&&y3>250)
{x3++;
y3-=2;
}
if(y3<=250&&y3>=200)
{
x3--;
y3--;
}
if(y3<200) {x3-=8;}
if(x3<=20){
win=1;
t1.stop();
}
repaint();
try{t1.sleep(100);}
catch(Exception e) {}
}
while(t2==Thread.currentThread())
{
if(x2<600)
{
if(y2<400)
{ x2++;
y22=Math.sqrt(120*120-(x2-200)*(x2-200))+300;
y2=(int)y22;
}
if(y2>=400)
{x2+=6;}
}
else
{if(y2>240)
{
x2+=2;
y22=Math.sqrt(100*100-(x2-600)*(x2-600))+300;
y2=(int)y22;
}
if(y2<=240&&x0>=600)
{
x0-=2;
y0-=2;
}
}
if(x0<600)
{x0-=5;}
if(x0<=20)
t2.stop();
repaint();
try{t2.sleep(100);}
catch(Exception e) {}
}
while(t3==Thread.currentThread())
{
if(y<70)
y+=5;
else
y-=5;
if(n>450)
x=1;
if(x==0)
{
m++;
n+=2;
}
else
{
m-=2;
n-=2;
}
if(n<100)
x=0;
if(x0<=20)
t3.stop();
repaint();
try{t3.sleep(200);}
catch(Exception e) {}
}
}
public void update(Graphics g)
{
offg.setColor(Color.green);
offg.fillRect(0,0,800,600);
offg.setColor(Color.red);
offg.setFont(f);
offg.drawString(str,m,n);
offg.setColor(Color.red);
offg.drawLine(60,150,60,250);
offg.setColor(Color.blue);
offg.drawLine(0,250,600,250);
offg.drawLine(200,350,600,350);
offg.drawArc(150,250,100,100,90,180);
offg.drawArc(550,250,100,100,90,-180);
offg.drawLine(0,200,600,200);
offg.drawLine(200,400,600,400);
offg.drawArc(100,200,200,200,90,180);
offg.drawArc(500,200,200,200,90,-180);
offg.drawLine(0,150,600,150);
offg.drawLine(200,450,600,450);
offg.drawArc(50,150,300,300,90,180);
offg.drawArc(450,150,300,300,90,-180);
offg.setColor(Color.red);
offg.drawLine(200,250,200,200);
offg.drawLine(50,300,100,300);
offg.drawLine(600,350,600,400);
offg.drawLine(700,300,750,300);
if(x0<=715)
offg.drawImage(img[0],x0,y0,this);
if(x1<=600)
offg.drawImage(img[1],x1,y1,this);
if(y2>=240)
offg.drawImage(img[2],x2,y2,this);
offg.drawImage(img[3],x3,y3,this);
offg.drawImage(img[4],250,y,this);
offg.drawImage(img[5],350,y,this);
offg.drawImage(img[6],450,y,this);
if(win==1)
offg.drawString("我们赢了!",60,240);
offg.setColor(Color.blue);
offg.setFont( new Font("宋体",Font.BOLD,15));
{
offg.drawString("终点",48,145);
if(y<70)
{
offg.drawString("加油!",300,70);
offg.drawString("快跑!",400,70);
}
}
offg.setColor(Color.black);
offg.setFont( new Font("宋体",Font.BOLD,30));
{
offg.drawString("1",60,180);
offg.drawString("2",60,240);
offg.drawString("1",70,300);
offg.drawString("2",205,240);
}
g.drawImage(offimg,0,0,this);//用offg、offimg实现双缓冲,消除屏幕的闪烁现象
}
}