From 0092ad544ecfb8204cc9589b71ffcb2adfd0cc10 Mon Sep 17 00:00:00 2001 From: bingor Date: Mon, 10 Oct 2022 17:04:45 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9D=A6=E5=85=8B=E5=A4=A7=E6=88=98=EF=BC=88?= =?UTF-8?q?=E4=B8=80=E6=9C=9F=EF=BC=89-=E8=AE=BE=E8=AE=A1=E6=A8=A1?= =?UTF-8?q?=E5=BC=8F-=E5=B0=86=E9=97=A8=E9=9D=A2=E6=A8=A1=E5=9E=8B?= =?UTF-8?q?=E4=BD=BF=E7=94=A8=E5=88=B0=E9=A1=B9=E7=9B=AE=E4=B8=AD=EF=BC=8C?= =?UTF-8?q?=E4=BD=BF=E7=94=A8GameModel=E4=BD=9C=E4=B8=BAfacade=E4=B8=8EFra?= =?UTF-8?q?me=E6=89=93=E4=BA=A4=E9=81=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/msb/TankDemo.java | 16 ---- src/main/java/com/msb/TankFrame.java | 65 +++------------ .../java/com/msb/factorys/CircleFactory.java | 11 ++- .../java/com/msb/factorys/DefaultFactory.java | 10 +-- .../msb/factorys/abstracts/GameFactory.java | 8 +- .../msb/inter/impl/DefaultFireStrategy.java | 2 +- .../com/msb/inter/impl/FourFireStrategy.java | 2 +- src/main/java/com/msb/model/Bullet.java | 10 +-- .../java/com/msb/model/CircleExplode.java | 10 +-- src/main/java/com/msb/model/Explode.java | 9 +- src/main/java/com/msb/model/GameModel.java | 83 +++++++++++++++++++ src/main/java/com/msb/model/Tank.java | 16 ++-- 12 files changed, 131 insertions(+), 111 deletions(-) create mode 100644 src/main/java/com/msb/model/GameModel.java 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