|
|
|
@ -17,7 +17,7 @@ import java.util.Objects;
|
|
|
|
|
*/
|
|
|
|
|
public class TankFrame extends Frame {
|
|
|
|
|
|
|
|
|
|
Tank tank = new Tank(100, 500, DirEnum.RIGHT, this);
|
|
|
|
|
Tank myTank = new Tank(100, 500, DirEnum.RIGHT, GroupEnum.GOOD, this);
|
|
|
|
|
// Bullet bullet = new Bullet(200, 200, DirEnum.DOWN);
|
|
|
|
|
List<Bullet> bullets = new ArrayList<>();
|
|
|
|
|
List<Tank> tanks = new ArrayList<>(); //敌方坦克
|
|
|
|
@ -52,7 +52,7 @@ public class TankFrame extends Frame {
|
|
|
|
|
g.drawString("子弹的数量:" + bullets.size(), 10, 60);
|
|
|
|
|
g.drawString("敌方坦克数量:" + tanks.size(), 10, 90);
|
|
|
|
|
g.setColor(color);
|
|
|
|
|
tank.paint(g);
|
|
|
|
|
myTank.paint(g);
|
|
|
|
|
|
|
|
|
|
//画出敌方坦克
|
|
|
|
|
for (int i=0; i<tanks.size(); i++) {
|
|
|
|
@ -117,7 +117,7 @@ public class TankFrame extends Frame {
|
|
|
|
|
case KeyEvent.VK_RIGHT : bR = false; break;
|
|
|
|
|
case KeyEvent.VK_UP : bU = false; break;
|
|
|
|
|
case KeyEvent.VK_DOWN : bD = false; break;
|
|
|
|
|
case KeyEvent.VK_SPACE: tank.fire(); break;
|
|
|
|
|
case KeyEvent.VK_SPACE: myTank.fire(); break;
|
|
|
|
|
default: break;
|
|
|
|
|
}
|
|
|
|
|
setDir();
|
|
|
|
@ -126,16 +126,16 @@ public class TankFrame extends Frame {
|
|
|
|
|
private void setDir() {
|
|
|
|
|
//当没有任何方向键按下的时候,那么让坦克停止
|
|
|
|
|
if( !bL && !bR && !bU && !bD ) {
|
|
|
|
|
tank.setMove(false);
|
|
|
|
|
myTank.setMove(false);
|
|
|
|
|
} else {
|
|
|
|
|
tank.setMove(true);
|
|
|
|
|
myTank.setMove(true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//为什么不用if-else 因为有可能是一起按两个方向键,那最后拿到哪个算哪个
|
|
|
|
|
if(bL) tank.setDir(DirEnum.LEFT);
|
|
|
|
|
if(bR) tank.setDir(DirEnum.RIGHT);
|
|
|
|
|
if(bU) tank.setDir(DirEnum.UP);
|
|
|
|
|
if(bD) tank.setDir(DirEnum.DOWN);
|
|
|
|
|
if(bL) myTank.setDir(DirEnum.LEFT);
|
|
|
|
|
if(bR) myTank.setDir(DirEnum.RIGHT);
|
|
|
|
|
if(bU) myTank.setDir(DirEnum.UP);
|
|
|
|
|
if(bD) myTank.setDir(DirEnum.DOWN);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|