From 65532b5dec98e7f9d12ac9f1aa66268ab8c40ba9 Mon Sep 17 00:00:00 2001 From: 964293341 Date: Fri, 27 Oct 2023 23:13:33 +0800 Subject: [PATCH] feat: :sparkles: add Areas - add GameObj of Areas - add AreaFactory - adjust the switch-expr of other factories --- logic/GameClass/GameObj/Areas/AreaFactory.cs | 19 ++ logic/GameClass/GameObj/Areas/Asteroid.cs | 14 ++ logic/GameClass/GameObj/Areas/Construction.cs | 14 ++ logic/GameClass/GameObj/Areas/Home.cs | 22 ++ .../GameObj/Areas/OutOfBoundBlock.cs | 18 ++ logic/GameClass/GameObj/Areas/Resource.cs | 14 ++ logic/GameClass/GameObj/Areas/Ruin.cs | 14 ++ logic/GameClass/GameObj/Areas/Shadow.cs | 14 ++ logic/GameClass/GameObj/Areas/Wormhole.cs | 18 ++ .../GameObj/Bullets/BulletFactory.cs | 19 +- logic/GameClass/GameObj/Home.cs | 13 -- logic/GameClass/GameObj/Immovable.cs | 12 +- .../GameObj/Modules/ModuleFactory.cs | 205 ++++++++---------- .../GameObj/Occupations/OccupationFactory.cs | 15 +- logic/GameClass/GameObj/OutOfBoundBlock.cs | 19 -- logic/GameClass/GameObj/Team.cs | 5 +- 16 files changed, 265 insertions(+), 170 deletions(-) create mode 100644 logic/GameClass/GameObj/Areas/AreaFactory.cs create mode 100644 logic/GameClass/GameObj/Areas/Asteroid.cs create mode 100644 logic/GameClass/GameObj/Areas/Construction.cs create mode 100644 logic/GameClass/GameObj/Areas/Home.cs create mode 100644 logic/GameClass/GameObj/Areas/OutOfBoundBlock.cs create mode 100644 logic/GameClass/GameObj/Areas/Resource.cs create mode 100644 logic/GameClass/GameObj/Areas/Ruin.cs create mode 100644 logic/GameClass/GameObj/Areas/Shadow.cs create mode 100644 logic/GameClass/GameObj/Areas/Wormhole.cs delete mode 100644 logic/GameClass/GameObj/Home.cs delete mode 100644 logic/GameClass/GameObj/OutOfBoundBlock.cs diff --git a/logic/GameClass/GameObj/Areas/AreaFactory.cs b/logic/GameClass/GameObj/Areas/AreaFactory.cs new file mode 100644 index 00000000..5f89d9f3 --- /dev/null +++ b/logic/GameClass/GameObj/Areas/AreaFactory.cs @@ -0,0 +1,19 @@ +using Preparation.Utility; + +namespace GameClass.GameObj.Areas; + +public static class AreaFactory +{ + public static Immovable GetArea(XY pos, PlaceType placeType) => placeType switch + { + PlaceType.Home => new Home(pos, GameObjType.Home), + PlaceType.Ruin => new Ruin(pos, GameObjType.Ruin), + PlaceType.Shadow => new Shadow(pos, GameObjType.Shadow), + PlaceType.Asteroid => new Asteroid(pos, GameObjType.Asteroid), + PlaceType.Resource => new Resource(pos, GameObjType.Resource), + PlaceType.Construction => new Construction(pos, GameObjType.Construction), + PlaceType.Wormhole => new Wormhole(pos, GameObjType.Wormhole), + _ => throw new System.NotImplementedException() + }; + public static OutOfBoundBlock GetOutOfBoundBlock(XY pos) => new(pos); +} diff --git a/logic/GameClass/GameObj/Areas/Asteroid.cs b/logic/GameClass/GameObj/Areas/Asteroid.cs new file mode 100644 index 00000000..e4a10832 --- /dev/null +++ b/logic/GameClass/GameObj/Areas/Asteroid.cs @@ -0,0 +1,14 @@ +using Preparation.Utility; +using System; + +namespace GameClass.GameObj.Areas; + +public class Asteroid : Immovable +{ + public override bool IsRigid => throw new NotImplementedException(); + public override ShapeType Shape => ShapeType.Square; + public Asteroid(XY initPos, GameObjType initType) + : base(initPos, int.MaxValue, initType) + { + } +} diff --git a/logic/GameClass/GameObj/Areas/Construction.cs b/logic/GameClass/GameObj/Areas/Construction.cs new file mode 100644 index 00000000..bc012e4a --- /dev/null +++ b/logic/GameClass/GameObj/Areas/Construction.cs @@ -0,0 +1,14 @@ +using Preparation.Utility; +using System; + +namespace GameClass.GameObj.Areas; + +public class Construction : Immovable +{ + public override bool IsRigid => throw new NotImplementedException(); + public override ShapeType Shape => ShapeType.Square; + public Construction(XY initPos, GameObjType initType) + : base(initPos, int.MaxValue, initType) + { + } +} diff --git a/logic/GameClass/GameObj/Areas/Home.cs b/logic/GameClass/GameObj/Areas/Home.cs new file mode 100644 index 00000000..0f75bbce --- /dev/null +++ b/logic/GameClass/GameObj/Areas/Home.cs @@ -0,0 +1,22 @@ +using Preparation.Interface; +using Preparation.Utility; +using System; + +namespace GameClass.GameObj.Areas; + +public class Home : Immovable, IHome +{ + public AtomicLong TeamID => throw new NotImplementedException(); + public LongWithVariableRange HP => throw new NotImplementedException(); + public long Score => throw new NotImplementedException(); + public override bool IsRigid => throw new NotImplementedException(); + public override ShapeType Shape => ShapeType.Square; + public void AddScore(long add) + { + throw new NotImplementedException(); + } + public Home(XY initPos, GameObjType initType) + : base(initPos, int.MaxValue, initType) + { + } +} diff --git a/logic/GameClass/GameObj/Areas/OutOfBoundBlock.cs b/logic/GameClass/GameObj/Areas/OutOfBoundBlock.cs new file mode 100644 index 00000000..984adebd --- /dev/null +++ b/logic/GameClass/GameObj/Areas/OutOfBoundBlock.cs @@ -0,0 +1,18 @@ +using Preparation.Interface; +using Preparation.Utility; + +namespace GameClass.GameObj.Areas; + +/// +/// 逻辑墙 +/// +public class OutOfBoundBlock : Immovable, IOutOfBound +{ + public OutOfBoundBlock(XY initPos) + : base(initPos, int.MaxValue, GameObjType.OutOfBoundBlock) + { + } + + public override bool IsRigid => true; + public override ShapeType Shape => ShapeType.Square; +} diff --git a/logic/GameClass/GameObj/Areas/Resource.cs b/logic/GameClass/GameObj/Areas/Resource.cs new file mode 100644 index 00000000..4bbd2df6 --- /dev/null +++ b/logic/GameClass/GameObj/Areas/Resource.cs @@ -0,0 +1,14 @@ +using Preparation.Utility; +using System; + +namespace GameClass.GameObj.Areas; + +public class Resource : Immovable +{ + public override bool IsRigid => throw new NotImplementedException(); + public override ShapeType Shape => ShapeType.Square; + public Resource(XY initPos, GameObjType initType) + : base(initPos, int.MaxValue, initType) + { + } +} diff --git a/logic/GameClass/GameObj/Areas/Ruin.cs b/logic/GameClass/GameObj/Areas/Ruin.cs new file mode 100644 index 00000000..350124a9 --- /dev/null +++ b/logic/GameClass/GameObj/Areas/Ruin.cs @@ -0,0 +1,14 @@ +using Preparation.Utility; +using System; + +namespace GameClass.GameObj.Areas; + +public class Ruin : Immovable +{ + public override bool IsRigid => throw new NotImplementedException(); + public override ShapeType Shape => ShapeType.Square; + public Ruin(XY initPos, GameObjType initType) + : base(initPos, int.MaxValue, initType) + { + } +} diff --git a/logic/GameClass/GameObj/Areas/Shadow.cs b/logic/GameClass/GameObj/Areas/Shadow.cs new file mode 100644 index 00000000..afe4392e --- /dev/null +++ b/logic/GameClass/GameObj/Areas/Shadow.cs @@ -0,0 +1,14 @@ +using Preparation.Utility; +using System; + +namespace GameClass.GameObj.Areas; + +public class Shadow : Immovable +{ + public override bool IsRigid => throw new NotImplementedException(); + public override ShapeType Shape => ShapeType.Square; + public Shadow(XY initPos, GameObjType initType) + : base(initPos, int.MaxValue, initType) + { + } +} \ No newline at end of file diff --git a/logic/GameClass/GameObj/Areas/Wormhole.cs b/logic/GameClass/GameObj/Areas/Wormhole.cs new file mode 100644 index 00000000..1993f423 --- /dev/null +++ b/logic/GameClass/GameObj/Areas/Wormhole.cs @@ -0,0 +1,18 @@ +using Preparation.Interface; +using Preparation.Utility; +using System; +using System.Collections.Generic; + +namespace GameClass.GameObj.Areas; + +public class Wormhole : Immovable, IWormhole +{ + public List Entrance => throw new NotImplementedException(); + public List Content => throw new NotImplementedException(); + public override bool IsRigid => throw new NotImplementedException(); + public override ShapeType Shape => ShapeType.Square; + public Wormhole(XY initPos, GameObjType initType) + : base(initPos, int.MaxValue, initType) + { + } +} \ No newline at end of file diff --git a/logic/GameClass/GameObj/Bullets/BulletFactory.cs b/logic/GameClass/GameObj/Bullets/BulletFactory.cs index ddd0be0d..6dae1c49 100644 --- a/logic/GameClass/GameObj/Bullets/BulletFactory.cs +++ b/logic/GameClass/GameObj/Bullets/BulletFactory.cs @@ -4,16 +4,13 @@ namespace GameClass.GameObj.Bullets; public static class BulletFactory { - public static Bullet? GetBullet(Ship ship, XY pos, BulletType bulletType) + public static Bullet? GetBullet(Ship ship, XY pos, BulletType bulletType) => bulletType switch { - return bulletType switch - { - BulletType.Laser => new Laser(ship, pos), - BulletType.Plasma => new Plasma(ship, pos), - BulletType.Shell => new Shell(ship, pos), - BulletType.Missile => new Missile(ship, pos), - BulletType.Arc => new Arc(ship, pos), - _ => null, - }; - } + BulletType.Laser => new Laser(ship, pos), + BulletType.Plasma => new Plasma(ship, pos), + BulletType.Shell => new Shell(ship, pos), + BulletType.Missile => new Missile(ship, pos), + BulletType.Arc => new Arc(ship, pos), + _ => throw new System.NotImplementedException() + }; } \ No newline at end of file diff --git a/logic/GameClass/GameObj/Home.cs b/logic/GameClass/GameObj/Home.cs deleted file mode 100644 index d0dc8812..00000000 --- a/logic/GameClass/GameObj/Home.cs +++ /dev/null @@ -1,13 +0,0 @@ -using Preparation.Interface; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace GameClass.GameObj -{ - public class Home : IHome - { - } -} diff --git a/logic/GameClass/GameObj/Immovable.cs b/logic/GameClass/GameObj/Immovable.cs index 00c769f8..07211f59 100644 --- a/logic/GameClass/GameObj/Immovable.cs +++ b/logic/GameClass/GameObj/Immovable.cs @@ -1,12 +1,12 @@ using Preparation.Utility; -namespace GameClass.GameObj +namespace GameClass.GameObj; + +public abstract class Immovable : GameObj { - public abstract class Immovable : GameObj + public override XY Position => position; + public Immovable(XY initPos, int initRadius, GameObjType initType) + : base(initPos, initRadius, initType) { - public override XY Position => position; - public Immovable(XY initPos, int initRadius, GameObjType initType) : base(initPos, initRadius, initType) - { - } } } diff --git a/logic/GameClass/GameObj/Modules/ModuleFactory.cs b/logic/GameClass/GameObj/Modules/ModuleFactory.cs index 382daebc..aef2dd48 100644 --- a/logic/GameClass/GameObj/Modules/ModuleFactory.cs +++ b/logic/GameClass/GameObj/Modules/ModuleFactory.cs @@ -5,124 +5,109 @@ namespace GameClass.GameObj.Modules; public static class ModuleFactory { - public static IProducer FindIProducer(ShipType shipType, ProducerType producerType) + public static IProducer FindIProducer(ShipType shipType, ProducerType producerType) => shipType switch { - return shipType switch + ShipType.CivilShip => producerType switch { - ShipType.CivilShip => producerType switch - { - ProducerType.Producer1 => new CivilProducer1(), - ProducerType.Producer2 => new CivilProducer2(), - ProducerType.Producer3 => new CivilProducer3(), - _ => new CivilProducer1(), - }, - ShipType.FlagShip => producerType switch - { - ProducerType.Producer1 => new FlagProducer1(), - _ => new FlagProducer1(), - }, - _ => new CivilProducer1(), - }; - } - public static IConstructor FindIConstructor(ShipType shipType, ConstructorType constructorType) + ProducerType.Producer1 => new CivilProducer1(), + ProducerType.Producer2 => new CivilProducer2(), + ProducerType.Producer3 => new CivilProducer3(), + _ => throw new System.NotImplementedException() + }, + ShipType.FlagShip => producerType switch + { + ProducerType.Producer1 => new FlagProducer1(), + _ => throw new System.NotImplementedException() + }, + _ => throw new System.NotImplementedException() + }; + public static IConstructor FindIConstructor(ShipType shipType, ConstructorType constructorType) => shipType switch { - return shipType switch + ShipType.CivilShip => constructorType switch + { + ConstructorType.Constructor1 => new CivilConstructor1(), + ConstructorType.Constructor2 => new CivilConstructor2(), + ConstructorType.Constructor3 => new CivilConstructor3(), + _ => throw new System.NotImplementedException() + }, + ShipType.FlagShip => constructorType switch { - ShipType.CivilShip => constructorType switch - { - ConstructorType.Constructor1 => new CivilConstructor1(), - ConstructorType.Constructor2 => new CivilConstructor2(), - ConstructorType.Constructor3 => new CivilConstructor3(), - _ => new CivilConstructor1(), - }, - ShipType.FlagShip => constructorType switch - { - ConstructorType.Constructor1 => new FlagConstructor1(), - _ => new FlagConstructor1(), - }, - _ => new CivilConstructor1(), - }; - } - public static IArmor FindIArmor(ShipType shipType, ArmorType armorType) + ConstructorType.Constructor1 => new FlagConstructor1(), + _ => throw new System.NotImplementedException() + }, + _ => throw new System.NotImplementedException() + }; + public static IArmor FindIArmor(ShipType shipType, ArmorType armorType) => shipType switch { - return shipType switch + ShipType.CivilShip => armorType switch + { + ArmorType.Armor1 => new CivilArmor1(), + _ => throw new System.NotImplementedException() + }, + ShipType.WarShip => armorType switch + { + ArmorType.Armor1 => new WarArmor1(), + ArmorType.Armor2 => new WarArmor2(), + ArmorType.Armor3 => new WarArmor3(), + _ => throw new System.NotImplementedException() + }, + ShipType.FlagShip => armorType switch { - ShipType.CivilShip => armorType switch - { - ArmorType.Armor1 => new CivilArmor1(), - _ => new CivilArmor1(), - }, - ShipType.WarShip => armorType switch - { - ArmorType.Armor1 => new WarArmor1(), - ArmorType.Armor2 => new WarArmor2(), - ArmorType.Armor3 => new WarArmor3(), - _ => new WarArmor1(), - }, - ShipType.FlagShip => armorType switch - { - ArmorType.Armor1 => new FlagArmor1(), - ArmorType.Armor2 => new FlagArmor2(), - ArmorType.Armor3 => new FlagArmor3(), - _ => new FlagArmor1(), - }, - _ => new CivilArmor1(), - }; - } - public static IShield FindIShield(ShipType shipType, ShieldType shieldType) + ArmorType.Armor1 => new FlagArmor1(), + ArmorType.Armor2 => new FlagArmor2(), + ArmorType.Armor3 => new FlagArmor3(), + _ => throw new System.NotImplementedException() + }, + _ => throw new System.NotImplementedException() + }; + public static IShield FindIShield(ShipType shipType, ShieldType shieldType) => shipType switch { - return shipType switch + ShipType.CivilShip => shieldType switch { - ShipType.CivilShip => shieldType switch - { - ShieldType.Shield1 => new CivilShield1(), - _ => new CivilShield1(), - }, - ShipType.WarShip => shieldType switch - { - ShieldType.Shield1 => new WarShield1(), - ShieldType.Shield2 => new WarShield2(), - ShieldType.Shield3 => new WarShield3(), - _ => new WarShield1(), - }, - ShipType.FlagShip => shieldType switch - { - ShieldType.Shield1 => new FlagShield1(), - ShieldType.Shield2 => new FlagShield2(), - ShieldType.Shield3 => new FlagShield3(), - _ => new FlagShield1(), - }, - _ => new CivilShield1(), - }; - } - public static IWeapon FindIWeapon(ShipType shipType, WeaponType weaponType) + ShieldType.Shield1 => new CivilShield1(), + _ => throw new System.NotImplementedException() + }, + ShipType.WarShip => shieldType switch + { + ShieldType.Shield1 => new WarShield1(), + ShieldType.Shield2 => new WarShield2(), + ShieldType.Shield3 => new WarShield3(), + _ => throw new System.NotImplementedException() + }, + ShipType.FlagShip => shieldType switch + { + ShieldType.Shield1 => new FlagShield1(), + ShieldType.Shield2 => new FlagShield2(), + ShieldType.Shield3 => new FlagShield3(), + _ => throw new System.NotImplementedException() + }, + _ => throw new System.NotImplementedException() + }; + public static IWeapon FindIWeapon(ShipType shipType, WeaponType weaponType) => shipType switch { - return shipType switch + ShipType.CivilShip => weaponType switch + { + WeaponType.LaserGun => new CivilLaserGun(), + _ => throw new System.NotImplementedException() + }, + ShipType.WarShip => weaponType switch + { + WeaponType.LaserGun => new WarLaserGun(), + WeaponType.PlasmaGun => new WarPlasmaGun(), + WeaponType.ShellGun => new WarShellGun(), + WeaponType.MissileGun => new WarMissileGun(), + WeaponType.ArcGun => new WarArcGun(), + _ => throw new System.NotImplementedException() + }, + ShipType.FlagShip => weaponType switch { - ShipType.CivilShip => weaponType switch - { - WeaponType.LaserGun => new CivilLaserGun(), - _ => new CivilLaserGun(), - }, - ShipType.WarShip => weaponType switch - { - WeaponType.LaserGun => new WarLaserGun(), - WeaponType.PlasmaGun => new WarPlasmaGun(), - WeaponType.ShellGun => new WarShellGun(), - WeaponType.MissileGun => new WarMissileGun(), - WeaponType.ArcGun => new WarArcGun(), - _ => new WarLaserGun(), - }, - ShipType.FlagShip => weaponType switch - { - WeaponType.LaserGun => new FlagLaserGun(), - WeaponType.PlasmaGun => new FlagPlasmaGun(), - WeaponType.ShellGun => new FlagShellGun(), - WeaponType.MissileGun => new FlagMissileGun(), - WeaponType.ArcGun => new FlagArcGun(), - _ => new FlagLaserGun(), - }, - _ => new CivilLaserGun(), - }; - } + WeaponType.LaserGun => new FlagLaserGun(), + WeaponType.PlasmaGun => new FlagPlasmaGun(), + WeaponType.ShellGun => new FlagShellGun(), + WeaponType.MissileGun => new FlagMissileGun(), + WeaponType.ArcGun => new FlagArcGun(), + _ => throw new System.NotImplementedException() + }, + _ => throw new System.NotImplementedException() + }; } \ No newline at end of file diff --git a/logic/GameClass/GameObj/Occupations/OccupationFactory.cs b/logic/GameClass/GameObj/Occupations/OccupationFactory.cs index 05436500..8ee514a1 100644 --- a/logic/GameClass/GameObj/Occupations/OccupationFactory.cs +++ b/logic/GameClass/GameObj/Occupations/OccupationFactory.cs @@ -5,14 +5,11 @@ namespace GameClass.GameObj.Occupations; public static class OccupationFactory { - public static IOccupation FindIOccupation(ShipType shipType) + public static IOccupation FindIOccupation(ShipType shipType) => shipType switch { - return shipType switch - { - ShipType.CivilShip => new CivilShip(), - ShipType.WarShip => new WarShip(), - ShipType.FlagShip => new FlagShip(), - _ => new CivilShip(), - }; - } + ShipType.CivilShip => new CivilShip(), + ShipType.WarShip => new WarShip(), + ShipType.FlagShip => new FlagShip(), + _ => throw new System.NotImplementedException(), + }; } \ No newline at end of file diff --git a/logic/GameClass/GameObj/OutOfBoundBlock.cs b/logic/GameClass/GameObj/OutOfBoundBlock.cs deleted file mode 100644 index 8f0c45d5..00000000 --- a/logic/GameClass/GameObj/OutOfBoundBlock.cs +++ /dev/null @@ -1,19 +0,0 @@ -using Preparation.Interface; -using Preparation.Utility; - -namespace GameClass.GameObj -{ - /// - /// 逻辑墙 - /// - public class OutOfBoundBlock : Immovable, IOutOfBound - { - public OutOfBoundBlock(XY initPos) : - base(initPos, int.MaxValue, GameObjType.OutOfBoundBlock) - { - } - - public override bool IsRigid => true; - public override ShapeType Shape => ShapeType.Square; - } -} diff --git a/logic/GameClass/GameObj/Team.cs b/logic/GameClass/GameObj/Team.cs index ab858227..6d97b0f8 100644 --- a/logic/GameClass/GameObj/Team.cs +++ b/logic/GameClass/GameObj/Team.cs @@ -1,4 +1,5 @@ -using Preparation.Utility; +using GameClass.GameObj.Areas; +using Preparation.Utility; using System.Collections.Generic; namespace GameClass.GameObj @@ -12,7 +13,7 @@ public class Team public const long invalidTeamID = long.MaxValue; public const long noneTeamID = long.MinValue; private readonly List shipList; - private Home home = new Home(); + private Home home = new(); public int Score { get; private set; } = 0; public Ship? GetShip(long shipID) {