📄 missile.java
字号:
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Rectangle;
public class Missile {
public static final int XSPEED=10;
public static final int YSPEED=10;
int x,y;
Tank.Direction dir;
private boolean live=true;
private TankWar tw=null;
public Missile(int x, int y,Tank.Direction dir,TankWar tw) {
this.x = x;
this.y = y;
this.dir = dir;
this.tw=tw;
}
public void draw(Graphics g)
{
Color c=g.getColor();
g.setColor(Color.black);
g.fillOval(x, y, 10,10);
g.setColor(c);
Move();
}
private void Move(){
switch (dir) {
case L:
x-=XSPEED;
break;
case LU:
x-=XSPEED;
y-=YSPEED;
break;
case U:
y-=YSPEED;
break;
case RU:
x+=XSPEED;
y-=YSPEED;
break;
case R:
x+=XSPEED;
break;
case RD:
x+=XSPEED;
y+=YSPEED;
break;
case D:
y+=YSPEED;
break;
case LD:
x-=XSPEED;
y+=YSPEED;
break;
}
if(this.x>0&&this.x<800&&this.y>0&&this.y<600)
this.setLive(true);
else
this.setLive(false);
}
public boolean isLive() {
return live;
}
public Rectangle getRect()
{
return new Rectangle(x,y,10,10);
}
public boolean HitTank(Tank t)
{
if(this.getRect().intersects(t.getRect())&&t.isLive())
{
t.setLive(false);
this.setLive(false);
Explode e = new Explode(x, y, tw);
tw.explodes.add(e);
return true;
}
return false;
}
public void setLive(boolean live) {
this.live = live;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -