From 20e075db3c72a7a1a4627c3296bce0d4e213bfec Mon Sep 17 00:00:00 2001 From: bingor Date: Tue, 11 Oct 2022 18:09:07 +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-=E8=B4=A3=E4=BB=BB=E9=93=BE=E5=BA=94=E7=94=A81.1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/msb/chain/ColliderChain.java | 44 +++++++++++++++++++ src/main/java/com/msb/model/GameModel.java | 7 ++- 2 files changed, 47 insertions(+), 4 deletions(-) create mode 100644 src/main/java/com/msb/chain/ColliderChain.java diff --git a/src/main/java/com/msb/chain/ColliderChain.java b/src/main/java/com/msb/chain/ColliderChain.java new file mode 100644 index 0000000..1e22be9 --- /dev/null +++ b/src/main/java/com/msb/chain/ColliderChain.java @@ -0,0 +1,44 @@ +package com.msb.chain;/** + * @Author bingor + * @Date 2022/10/11 17:55 + * @Description: com.msb.chain + * @Version: 1.0 + */ + +import com.msb.inter.Collider; +import com.msb.inter.impl.BulletTankCollider; +import com.msb.inter.impl.TankTankCollider; +import com.msb.model.abstracts.GameObject; + +import java.util.LinkedList; +import java.util.List; + +/** + *@ClassName ColliderChain + *@Description TODO + *@Author bingor + *@Date 2022/10/11 17:55 + *@Version 3.0 + */ +public class ColliderChain { + List colliders = new LinkedList<>(); + + public ColliderChain() { + add(new BulletTankCollider()); + add(new TankTankCollider()); + } + + public void add(Collider collider) { + colliders.add(collider); + } + + public List getColliders() { + return colliders; + } + + public void collide(GameObject o1, GameObject o2) { + for (Collider collider : colliders) { + collider.collide(o1, o2); + } + } +} diff --git a/src/main/java/com/msb/model/GameModel.java b/src/main/java/com/msb/model/GameModel.java index a42816a..3387eba 100644 --- a/src/main/java/com/msb/model/GameModel.java +++ b/src/main/java/com/msb/model/GameModel.java @@ -6,6 +6,7 @@ package com.msb.model;/** */ import com.msb.base.PropertyMgr; +import com.msb.chain.ColliderChain; import com.msb.enums.DirEnum; import com.msb.enums.GroupEnum; import com.msb.factorys.CircleFactory; @@ -36,8 +37,7 @@ public class GameModel { public List explodes = new ArrayList<>(); //爆炸效果 */ public List gameObjects = new ArrayList<>(); - private BulletTankCollider bulletTankCollider = new BulletTankCollider(); - private TankTankCollider tankTankCollider = new TankTankCollider(); + private ColliderChain colliderChain = new ColliderChain(); // public GameFactory gameFactory = new DefaultFactory(); public GameModel() { @@ -88,8 +88,7 @@ public class GameModel { // bullets.get(i).collide(tanks.get(j)); GameObject o1 = gameObjects.get(i); GameObject o2 = gameObjects.get(j); - bulletTankCollider.collide(o1, o2); - tankTankCollider.collide(o1, o2); + colliderChain.collide(o1, o2); } }