import java.awt.*;
import java.awt.event.*;
class game0224 extends Frame implements Runnable{
int x,y;
Image img1,img2;
public static void main(String [] args) {
Frame f=new game0224();
f.setTitle("game0224");
f.setSize(700,700);
f.setBackground(Color.yellow);
f.setVisible(true);
}
game0224(){
img1 = Toolkit.getDefaultToolkit().getImage("robin3.jpg");
img2 = Toolkit.getDefaultToolkit().getImage("tokyo.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 t;
int dx,xmode;
int dy,ymode;
int mode;
int coin;
int h;
mode=0;
x=60;
xmode=0;
y=40;
ymode=0;
t=0;
while(t<200){
coin=seekcoin();
dx=0;
if(xmode>0)xmode=xmode+1;
if(xmode==4)xmode=0;
h=0;
if (coin==2)h=h+1;
if (xmode==0)h=h+1;
if(h==2)dx=1;
h=0;
if (coin==3)h=h+1;
if (xmode==0)h=h+1;
if(h==2)dx=-1;
x=x+dx;
h=0;
if (coin==4)h=h+1;
if (xmode==0)h=h+1;
if(h==2)xmode=1;
coin=seekcoin();
dy=0;
if(ymode>0)ymode=ymode+1;
if(ymode==4)ymode=0;
h=0;
if (coin==2)h=h+1;
if (ymode==0)h=h+1;
if(h==2)dy=1;
h=0;
if (coin==3)h=h+1;
if (ymode==0)h=h+1;
if(h==2)dy=-1;
y=y+dy;
h=0;
if (coin==4)h=h+1;
if (ymode==0)h=h+1;
if(h==2)ymode=1;
h=0;
if(xmode==2)h=h+1;
if(ymode==2)h=0;
if(x-y<20)h=h+1;
if(h==2)mode=1;
h=0;
if(ymode==2)h=h+1;
if(xmode==2)h=0;
if(x-y<20)h=h+1;
if(h==2)mode=2;
if(mode==1)t=1000;
if(mode==2)t=1000;
repaint();
try{
Thread.sleep(100);
}catch(InterruptedException e){}
t=t+1;
}
repaint();
}
public void paint(Graphics g){
g.drawImage(img1,100+5*x,400,100,200,this);
g.drawImage(img2,100+5*y,400,100,200,this);
}
public static int seekcoin(){
double p;
int c;
p=Math.random();
c=1;
if(p>0.25)c=2;
if(p>0.5)c=3;
if(p>0.75)c=4;
return c;
}
}
最終更新:2011年02月16日 06:18