アットウィキロゴ

0426

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

class pro0426 extends Frame implements Runnable{

Frame f;
Thread th;
int t,m,n,s,num;
int gun;
int x[]=new int[16];
int y[]=new int[16];
int z[]=new int[16];
int mx[]=new int[1000];
int my[]=new int[1000];
int mz[]=new int[1000];
int dx;
int score;
int miny;

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

pro0426() {
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);
if (z[s]==1)g.fillRect(100+50*x[s],600-50*y[s],10,10);
}

for (num=1;num<t;num++){
g.setColor(Color.red);
if (mz[num]==1)g.fillRect(100+50*mx[num],600-50*my[num],5,5);
}

g.setColor(Color.yellow);
if (score==15)g.fillRect(0,0,700,700);
if (miny==0)g.fillRect(0,0,700,700);
g.setColor(Color.red);
Font f=new Font("TimesRoman",Font.ITALIC,50);
g.setFont(f);
if (score==15)g.drawString("Clear",100,100);
if (miny==0)g.drawString("Game over",100,100);
}

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

public void run() {
int dg;
int maxx,minx,xs,ys;
int mode;
int h;
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;
mx[t]=gun;
my[t]=0;
mz[t]=1;
for (num=1;num<t;num++){
my[num]=my[num]+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;
}

for (num=1;num<t;num++){

for (s=1;s<16;s++){
h=0;
if (x[s]==mx[num])h=h+1;
if (y[s]==my[num])h=h+1;
if (z[s]==1)h=h+1;
if (mz[num]==1)h=h+1;
if (h==4)z[s]=0;
if (h==4)mz[num]=0;
}
}

score=0;
for (s=1;s<16;s++){
if (z[s]==0)score=score+1;
}
if (score==15)mode=100;
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日 01:02