アットウィキロゴ

game03p

import java.awt.*;
import java.awt.event.*;

class game03 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];

public static void main(String [] args) {
        Frame f=new game03();
        f.setTitle("game03");
        f.setSize(700,700);
        f.setBackground(Color.yellow);
        f.setVisible(true);
    }

game03(){

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;

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;
}


t=1;
dg=1;
dx=1;
gun=5;
while(t<500){
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;
}

repaint();
try{
Thread.sleep(500);
}catch(InterruptedException e){}
t=t+1;
}

}


public void paint(Graphics g){
g.fillRect(100+50*gun,600,50,50);
for (m=1;m<t;m++){
g.fillRect(100+50*mx[m],500-50*my[m],10,10);
}
for (s=1;s<16;s++){
g.fillRect(100+50*x[s],500-50*y[s],20,20);
}





}

}
最終更新:2011年01月27日 18:09