import java.awt.*;
import java.awt.event.*;
class game0201 extends Frame implements Runnable{
int s,t;
int m;
int gun;
int dg;
int mx[]=new int[501];
int my[]=new int[501];
int mz[]=new int[501];
int x[]=new int[16];
int y[]=new int[16];
int z[]=new int[16];
int mode;
public static void main(String [] args) {
Frame f=new game0201();
f.setTitle("game0201");
f.setSize(700,700);
f.setBackground(Color.yellow);
f.setVisible(true);
}
game0201(){
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 dx,dy,maxx,minx;
int h;
int point;
for (s=1;s<6;s++){
x[s]=2+s;
y[s]=10;
z[s]=1;
}
for (s=6;s<11;s++){
x[s]=s-3;
y[s]=9;
z[s]=1;
}
for (s=11;s<16;s++){
x[s]=s-8;
y[s]=8;
z[s]=1;
}
mode=0;
t=1;
dg=1;
dx=1;
gun=5;
while(t<200){
dg=1;
if (Math.random()>0.5)dg=-1;
gun=gun+dg;
if (gun<1)gun=1;
if (gun>10)gun=10;
mx[t]=gun;
my[t]=0;
mz[t]=1;
for (m=1;m<t;m++){
my[m]=my[m]+1;
}
for (s=1;s<16;s++){
x[s]=x[s]+dx;
}
maxx=-999;
for (s=1;s<16;s++){
if (x[s]>maxx)maxx=x[s];
}
minx=999;
for (s=1;s<16;s++){
if (x[s]<minx)minx=x[s];
}
dy=0;
if (maxx>9)dx=-1;
if (minx<2)dx=1;
if (maxx>9)dy=-1;
if (minx<2)dy=-1;
for (s=1;s<16;s++){
y[s]=y[s]+dy;
}
for (m=1;m<t;m++){
for(s=1;s<16;s++){
h=0;
if (x[s]==mx[m])h=h+1;
if (y[s]==my[m])h=h+1;
if (z[s]==1)h=h+1;
if (mz[m]==1)h=h+1;
if (h==4)z[s]=0;
if (h==4)mz[m]=0;
}
}
point=0;
for(s=1;s<16;s++){
if (z[s]==0)point=point+1;
}
repaint();
try{
Thread.sleep(100);
}catch(InterruptedException e){}
t=t+1;
if(point==15)mode=1;
if(t>100)mode=1;
}
repaint();
}
public void paint(Graphics g){
if(mode==0){
g.fillRect(100+50*gun,600,50,50);
for (m=1;m<t;m++){
if (mz[m]==1)g.fillRect(100+50*mx[m],500-50*my[m],10,10);
}
for (s=1;s<16;s++){
if(z[s]==1)g.fillRect(100+50*x[s],500-50*y[s],20,20);
}
}
if (mode==1){
g.setColor(Color.blue);
g.fillRect(0,0,700,700);
g.setColor(Color.black);
g.drawString("Game over",100,100);
}
}
}
最終更新:2011年01月31日 21:45