坦克大战(一期)-画出敌方坦克

Network
bingor_yhj 2 years ago
parent c7a49ad7ab
commit 72573b4c18

@ -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);

@ -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<Bullet> bullets = new ArrayList<>();
List<Tank> 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<bullets.size(); i++) {
bullets.get(i).paint(g);
}

Loading…
Cancel
Save