アットウィキロゴ

java0117

class game0117 extends Frame implements Runnable,MouseMotionListener{

int t;
int gun;
int dg;
int ufo;
int mx[]=new int[101];
int my[]=new int[101];
int mz[]=new int[101];
int fire;

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

game0117(){

addMouseMotionListener(this);

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 s;
fire=0;
t=1;
dg=1;
gun=5;
ufo=20;
while(t<100){
gun=gun+dg;

ufo=ufo-1;

mx[t]=gun;
my[t]=0;
if(fire>50)mz[t]=100;
for(s=1;s<t;s++){
my[s]=my[s]+1;
}
if (ufo<0)ufo=20;
if (gun>10)gun=10;
if(gun<1)gun=1;
repaint();
try{
Thread.sleep(200);
}catch(InterruptedException e){}
t=t+1;    
}
repaint();
}


public void paint(Graphics g){
int ss;
g.fillRect(100+50*gun,600,50,50);
g.fillRect(100+50*ufo,100,50,50);
for(ss=1;ss<t;ss++){
if(mz[ss]>50)g.fillRect(100+50*mx[ss],600-50*my[ss],10,10);
}


}

public void mouseDragged(MouseEvent e) {
    }

public void mouseMoved(MouseEvent e) {
int x;  
x=e.getX();
dg=0;
fire=0;
if (x>50*gun+150)dg=1;
if (x<100+50*gun-50)dg=-1;
if (dg==0)fire=100;
}



}
最終更新:2011年02月09日 20:12