diff --git a/src/main/java/com/msb/TankDemo.java b/src/main/java/com/msb/TankDemo.java index 9b94ca9..4e41ec8 100644 --- a/src/main/java/com/msb/TankDemo.java +++ b/src/main/java/com/msb/TankDemo.java @@ -1,12 +1,5 @@ package com.msb; -import com.msb.base.PropertyMgr; -import com.msb.enums.DirEnum; -import com.msb.enums.GroupEnum; -import com.msb.model.Tank; - -import java.util.Random; - /** * @Author bingor * @Date 2022-09-29 11:02 @@ -17,15 +10,6 @@ public class TankDemo { public static void main(String[] args) throws InterruptedException { TankFrame tankFrame = new TankFrame(); - Random random = new Random(); - - int initTankCount = Integer.parseInt(PropertyMgr.getString("initTankCount")); - - //创建5个敌方坦克 - for (int i=0; i bullets = new ArrayList<>(); - public List tanks = new ArrayList<>(); //敌方坦克 - public List explodes = new ArrayList<>(); //爆炸效果 + GameModel gameModel = new GameModel(); public static final int GAME_WIDTH = 1000; public static final int GAME_HEIGHT = 800; - public GameFactory gameFactory = new CircleFactory(); + public TankFrame() { @@ -60,36 +46,7 @@ public class TankFrame extends Frame { @Override public void paint(Graphics g) { // super.paint(g); - Color color = g.getColor(); - g.setColor(Color.WHITE); - g.drawString("子弹的数量:" + bullets.size(), 10, 60); - g.drawString("敌方坦克数量:" + tanks.size(), 10, 90); - g.drawString("爆炸的数量:" + explodes.size(), 10, 120); - g.setColor(color); - myTank.paint(g); - -// explode.paint(g); - - //画出敌方坦克 - for (int i=0; i= 10) { step = 0; - tankFrame.explodes.remove(this); + gameModel.explodes.remove(this); } g.setColor(color); diff --git a/src/main/java/com/msb/model/Explode.java b/src/main/java/com/msb/model/Explode.java index 12da812..76584b1 100644 --- a/src/main/java/com/msb/model/Explode.java +++ b/src/main/java/com/msb/model/Explode.java @@ -1,6 +1,5 @@ package com.msb.model; -import com.msb.TankFrame; import com.msb.base.ResourcesMgr; import com.msb.model.abstracts.BaseExplode; @@ -15,16 +14,16 @@ import java.awt.*; public class Explode extends BaseExplode { private int x,y; - private TankFrame tankFrame; + private GameModel gameModel; public static final int WIDTH = ResourcesMgr.explodeImages[0].getWidth(); public static final int HEIGHT = ResourcesMgr.explodeImages[0].getHeight(); // private boolean live = true; private int step = 0; - public Explode(int x, int y, TankFrame tankFrame) { + public Explode(int x, int y, GameModel gameModel) { this.x = x; this.y = y; - this.tankFrame = tankFrame; + this.gameModel = gameModel; } @Override @@ -33,7 +32,7 @@ public class Explode extends BaseExplode { g.drawImage(ResourcesMgr.explodeImages[step++], x, y, null); if(step >= ResourcesMgr.explodeImages.length) { step = 0; - tankFrame.explodes.remove(this); + gameModel.explodes.remove(this); } } diff --git a/src/main/java/com/msb/model/GameModel.java b/src/main/java/com/msb/model/GameModel.java new file mode 100644 index 0000000..9a360f1 --- /dev/null +++ b/src/main/java/com/msb/model/GameModel.java @@ -0,0 +1,83 @@ +package com.msb.model;/** + * @Author bingor + * @Date 2022/10/10 16:30 + * @Description: com.msb.model + * @Version: 1.0 + */ + +import com.msb.base.PropertyMgr; +import com.msb.enums.DirEnum; +import com.msb.enums.GroupEnum; +import com.msb.factorys.CircleFactory; +import com.msb.factorys.DefaultFactory; +import com.msb.factorys.abstracts.GameFactory; +import com.msb.model.abstracts.BaseExplode; + +import java.awt.*; +import java.util.ArrayList; +import java.util.List; + +/** + *@ClassName GameModel + *@Description TODO + *@Author bingor + *@Date 2022/10/10 16:30 + *@Version 3.0 + */ +public class GameModel { + + Tank myTank = new Tank(100, 500, DirEnum.RIGHT, GroupEnum.GOOD, this); + // Explode explode = new Explode(100, 100, this); +// Bullet bullet = new Bullet(200, 200, DirEnum.DOWN); + public List bullets = new ArrayList<>(); + public List tanks = new ArrayList<>(); //敌方坦克 + public List explodes = new ArrayList<>(); //爆炸效果 +// public GameFactory gameFactory = new DefaultFactory(); + + public GameModel() { +// Random random = new Random(); + int initTankCount = Integer.parseInt(PropertyMgr.getString("initTankCount")); + + //创建5个敌方坦克 + for (int i=0; i