From 72573b4c1810ac646d9e6fd73bcf20ce08c209e4 Mon Sep 17 00:00:00 2001 From: bingor_yhj Date: Mon, 3 Oct 2022 13:51:34 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9D=A6=E5=85=8B=E5=A4=A7=E6=88=98(=E4=B8=80?= =?UTF-8?q?=E6=9C=9F)-=E7=94=BB=E5=87=BA=E6=95=8C=E6=96=B9=E5=9D=A6?= =?UTF-8?q?=E5=85=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/com/msb/TankDemo.java | 5 +++++ src/com/msb/TankFrame.java | 9 ++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) 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