import java.awt.*;
import java.awt.event.*;
class game0212 extends Frame implements Runnable{
int t;
int cx,cy,dx,dy;
int m,n;
int map[][]=new int[501][501];
int mode;
public static void main(String [] args) {
Frame f=new game0212();
f.setTitle("game0212");
f.setSize(500,500);
f.setBackground(Color.yellow);
f.setVisible(true);
}
game0212(){
for (m=0;m<501;m++){
for(n=0;n<501;n++){
map[m][n]=1;
}
}
for (m=100;m<400;m++){
for(n=100;n<400;n++){
map[m][n]=2;
}
}
for (m=150;m<351;m++){
for(n=150;n<351;n++){
map[m][n]=3;
}
}
cx=380;
cy=250;
dy=-1;
dx=0;
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(){
mode=1;
t=1;
while(t<1000){
cx=cx+dx;
cy=cy+dy;
if(mode==1)dx=0;
if(mode==1)dy=-2;
if(mode==2)dx=-2;
if(mode==2)dy=0;
if(mode==3)dx=0;
if(mode==3)dy=2;
if(mode==4)dx=2;
if(mode==4)dy=0;
int h;
h=0;
if(mode==1)h=h+1;
if(cy<125)h=h+1;
if(h==2)mode=2;
h=0;
if(mode==2)h=h+1;
if(cx<125)h=h+1;
if(h==2)mode=3;
h=0;
if(mode==3)h=h+1;
if(cy>375)h=h+1;
if(h==2)mode=4;
h=0;
if(mode==4)h=h+1;
if(cx>375)h=h+1;
if(h==2)mode=1;
repaint();
try{
Thread.sleep(30);
}catch(InterruptedException e){}
t=t+1;
}
repaint();
}
public void paint(Graphics g){
int px,py;
for(m=-50;m<51;m++){
for(n=-50;n<51;n++){
g.setColor(Color.green);
if(map[cx+m][cy+n]==1)g.fillRect(5*(m+50),5*(n+50),5,5);
g.setColor(Color.black);
if(map[cx+m][cy+n]==2)g.fillRect(5*(m+50),5*(n+50),5,5);
g.setColor(Color.green);
if(map[cx+m][cy+n]==3)g.fillRect(5*(m+50),5*(n+50),5,5);
}
}
g.setColor(Color.red);
g.fillOval(250,250,50,50);
}
}
最終更新:2011年02月11日 18:09