アットウィキロゴ

423

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

class pro0423 extends Frame implements Runnable{

Frame f;
Thread th;
int m,n,s;
int gun;
int x[]=new int[16];
int y[]=new int[16];
int z[]=new int[16];
int dx;

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

pro0423() {
addWindowListener(new stopwin());
gun=5;
s=1;
dx=1;
for (m=8;m<11;m++){
for (n=3;n<8;n++){
y[s]=m;
x[s]=n;
z[s]=1;
s=s+1;
}
}

th=new Thread(this);
th.start();
}

class stopwin extends WindowAdapter{
public void windowClosing(WindowEvent we){System.exit(0);}
}

public void paint( Graphics g ) {
g.setColor(Color.yellow);
g.fillRect(0,0,700,700);

g.setColor(Color.red);
g.fillRect(100+50*gun+10,590,10,10);
g.fillRect(100+50*gun,600,30,10);

for (s=1;s<16;s++){
g.setColor(Color.green);
g.fillRect(100+50*x[s],600-50*y[s],10,10);
}

}

public void update(Graphics g) {
paint(g);
}

public void run() {
int dg;
int maxx,minx,miny,xs,ys;
int t,mode;
t=0;
mode=0;
while (mode<50){
t=t+1;
dg=1;
if (Math.random()>0.5)dg=-1;
gun=gun+dg;
if (gun>10)gun=10;
if (gun<1)gun=1;

maxx=-999;
for (s=1;s<16;s++){
xs=x[s];
if (z[s]==0)xs=-999;
if (xs>maxx)maxx=xs;
}

minx=999;
for (s=1;s<16;s++){
xs=x[s];
if (z[s]==0)xs=999;
if (xs<minx)minx=xs;
}

if (maxx==10)dx=-1;
if (minx==1)dx=1;
for (s=1;s<16;s++){
if (maxx==10)y[s]=y[s]-1;
if (minx==1)y[s]=y[s]-1;
x[s]=x[s]+dx;
}

miny=999;
for (s=1;s<16;s++){
ys=y[s];
if (z[s]==0)ys=999;
if (ys<miny)miny=ys;
}

if (miny==0)mode=100;
if (t>100)mode=100;
repaint();
try{th.sleep(100);} catch(InterruptedException e) { }
}
}

}
最終更新:2010年09月21日 00:20