import java.awt.*;
import java.awt.Graphics;
import java.awt.event.*;
class pro0922 extends Frame implements Runnable{
Frame f;
Thread th;
int t,m,n;
int x[][]=
new int[9][9];
int px,py,mx,my;
int score;
public static void main(String[] args){
Frame f=new pro0922();
f.setTitle("
pro0922");
f.setSize(700,700);
f.setBackground(Color.yellow);
f.show();
}
pro0922() {
addWindowListener(new stopwin());
for (m=1;m<9;m++){
for (n=1;n<9;n++){
x[m][n]=0;
}
}
score=0;
px=1;
py=1;
mx=8;
my=8;
t=0;
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*mx,600-50*my,10,10);
g.setColor(Color.blue);
g.fillRect(100+50*px,600-50*py,10,10);
for (m=1;m<9;m++){
for (n=1;n<9;n++){
g.setColor(Color.green);
if (x[m][n]==0)g.fillRect(100+50*m,600-50*n,5,5);
}
}
}
public void update(Graphics g) {
paint(g);
}
public void run() {
int dx,dy;
int h;
while(t<1000){
dx=1;
dy=1;
if (Math.random()>0.5)dx=-1;
if (Math.random()>0.5)dy=-1;
px=px+dx;
py=py+dy;
if (px<1)px=1;
if (px>8)px=8;
if (py<1)py=1;
if (py>8)py=8;
dx=1;
dy=1;
if (Math.random()>0.5)dx=-1;
if (Math.random()>0.5)dy=-1;
mx=mx+dx;
my=my+dy;
if (mx<1)mx=1;
if (mx>8)mx=8;
if (my<1)my=1;
if (my>8)my=8;
x[px][py]=1;
score=0;
for (m=1;m<9;m++){
for (n=1;n<9;n++){
score=score+x[m][n];
}
}
if (score==64)t=10000;
if (score==64)System.out.println("Clear");
h=0;
if (mx==px)h=h+1;
if (my==py)h=h+1;
if (h==2)System.out.println("Game over");
if (h==2)t=10000;
System.out.println(score);
t=t+1;
repaint();
try{th.sleep(100);} catch(InterruptedException e) { }
}
}
}
最終更新:2010年09月22日 06:34