diff --git a/src/com/msb/TankDemo.java b/src/com/msb/TankDemo.java index 4e41ec8..cbeb8d7 100644 --- a/src/com/msb/TankDemo.java +++ b/src/com/msb/TankDemo.java @@ -11,6 +11,11 @@ public class TankDemo { public static void main(String[] args) throws InterruptedException { TankFrame tankFrame = new TankFrame(); + //创建5个敌方坦克 + for (int i=0; i<5; i++) { + tankFrame.tanks.add(new Tank(100 + i*80, 100, DirEnum.DOWN, tankFrame)); + } + //现实当中,虽然可以过按键来改变方块的坐标并且重新刷新画板来实现移动,但是敌方的坦克应该是自动在跑 while (true) { Thread.sleep(50); diff --git a/src/com/msb/TankFrame.java b/src/com/msb/TankFrame.java index f5d37ca..cc5cf4a 100644 --- a/src/com/msb/TankFrame.java +++ b/src/com/msb/TankFrame.java @@ -17,9 +17,10 @@ import java.util.Objects; */ public class TankFrame extends Frame { - Tank tank = new Tank(200, 200, DirEnum.RIGHT, this); + Tank tank = new Tank(100, 500, DirEnum.RIGHT, this); // Bullet bullet = new Bullet(200, 200, DirEnum.DOWN); List bullets = new ArrayList<>(); + List tanks = new ArrayList<>(); //敌方坦克 public static final int GAME_WIDTH = 800; public static final int GAME_HEIGHT = 600; @@ -51,6 +52,12 @@ public class TankFrame extends Frame { g.drawString("子弹的数量:" + bullets.size(), 10, 60); g.setColor(color); tank.paint(g); + + //画出敌方坦克 + for (Tank tank : tanks) { + tank.paint(g); + } + for (int i=0; i