Skip to content

Commit 6b569bb

Browse files
authored
Merge pull request #16 from asdawej/dev
Create null default for all factories
2 parents 71d8193 + b181e0f commit 6b569bb

File tree

15 files changed

+115
-48
lines changed

15 files changed

+115
-48
lines changed

logic/GameClass/GameObj/Areas/AreaFactory.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public static class AreaFactory
1313
PlaceType.Resource => new Resource(pos),
1414
PlaceType.Construction => new Construction(pos),
1515
PlaceType.Wormhole => new Wormhole(pos),
16-
_ => throw new System.NotImplementedException()
16+
_ => new NullArea(pos)
1717
};
1818
public static OutOfBoundBlock GetOutOfBoundBlock(XY pos) => new(pos);
1919
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using Preparation.Utility;
2+
3+
namespace GameClass.GameObj.Areas;
4+
5+
public class NullArea : Immovable
6+
{
7+
public override bool IsRigid => false;
8+
public override ShapeType Shape => ShapeType.Null;
9+
public NullArea(XY initPos)
10+
: base(initPos, int.MaxValue, GameObjType.Null)
11+
{
12+
}
13+
}

logic/GameClass/GameObj/Bullets/Arc.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ internal sealed class Arc : Bullet
88
public Arc(Ship ship, XY pos, int radius = GameData.BulletRadius) :
99
base(ship, radius, pos)
1010
{
11-
Random random = new Random();
11+
Random random = new();
1212
this.AP.SetReturnOri(random.Next(GameData.ArcDamageMin, GameData.ArcDamageMax));
1313
}
1414
public override double BulletBombRange => 0;

logic/GameClass/GameObj/Bullets/BulletFactory.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@ public static class BulletFactory
1111
BulletType.Shell => new Shell(ship, pos),
1212
BulletType.Missile => new Missile(ship, pos),
1313
BulletType.Arc => new Arc(ship, pos),
14-
_ => throw new System.NotImplementedException()
14+
_ => new NullBullet(ship, pos)
1515
};
1616
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
using Preparation.Utility;
2+
3+
namespace GameClass.GameObj.Bullets;
4+
5+
internal sealed class NullBullet : Bullet
6+
{
7+
public override double BulletBombRange => 0;
8+
public override double AttackDistance => 0;
9+
public override int Speed => 0;
10+
public override int CastTime => 0;
11+
public override int SwingTime => 0;
12+
public override int CD => 0;
13+
public override int MaxBulletNum => 0;
14+
public override BulletType TypeOfBullet => BulletType.Null;
15+
public override bool CanAttack(GameObj target) => false;
16+
public override bool CanBeBombed(GameObjType gameObjType) => false;
17+
public NullBullet(Ship ship, XY Position, int radius = GameData.BulletRadius)
18+
: base(ship, radius, Position)
19+
{
20+
}
21+
}

logic/GameClass/GameObj/Map/Map.cs

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ public bool RemoveJustFromMap(GameObj gameObj)
260260
GameObjLockDict[gameObj.Type].ExitWriteLock();
261261
}
262262
}
263-
public void Add(GameObj gameObj)
263+
public void Add(IGameObj gameObj)
264264
{
265265
GameObjLockDict[gameObj.Type].EnterWriteLock();
266266
try
@@ -290,30 +290,7 @@ public Map(uint[,] mapResource)
290290
{
291291
for (int j = 0; j < GameData.MapCols; ++j)
292292
{
293-
switch (mapResource[i, j])
294-
{
295-
case (uint)PlaceType.Asteroid:
296-
Add(new Areas.Asteroid(GameData.GetCellCenterPos(i, j)));
297-
break;
298-
case (uint)PlaceType.Construction:
299-
Add(new Areas.Construction(GameData.GetCellCenterPos(i, j)));
300-
break;
301-
case (uint)PlaceType.Home:
302-
Add(new Areas.Home(GameData.GetCellCenterPos(i, j)));
303-
break;
304-
case (uint)PlaceType.Resource:
305-
Add(new Areas.Resource(GameData.GetCellCenterPos(i, j)));
306-
break;
307-
case (uint)PlaceType.Ruin:
308-
Add(new Areas.Ruin(GameData.GetCellCenterPos(i, j)));
309-
break;
310-
case (uint)PlaceType.Shadow:
311-
Add(new Areas.Shadow(GameData.GetCellCenterPos(i, j)));
312-
break;
313-
case (uint)PlaceType.Wormhole:
314-
Add(new Areas.Wormhole(GameData.GetCellCenterPos(i, j)));
315-
break;
316-
}
293+
Add(Areas.AreaFactory.GetArea(GameData.GetCellCenterPos(i, j), (PlaceType)mapResource[i, j]));
317294
}
318295
}
319296
}

logic/GameClass/GameObj/Modules/ModuleFactory.cs

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@ public static class ModuleFactory
1212
ProducerType.Producer1 => new CivilProducer1(),
1313
ProducerType.Producer2 => new CivilProducer2(),
1414
ProducerType.Producer3 => new CivilProducer3(),
15-
_ => throw new System.NotImplementedException()
15+
_ => new NullProducer()
1616
},
1717
ShipType.FlagShip => producerType switch
1818
{
1919
ProducerType.Producer1 => new FlagProducer1(),
20-
_ => throw new System.NotImplementedException()
20+
_ => new NullProducer()
2121
},
22-
_ => throw new System.NotImplementedException()
22+
_ => new NullProducer()
2323
};
2424
public static IConstructor FindIConstructor(ShipType shipType, ConstructorType constructorType) => shipType switch
2525
{
@@ -28,67 +28,67 @@ public static class ModuleFactory
2828
ConstructorType.Constructor1 => new CivilConstructor1(),
2929
ConstructorType.Constructor2 => new CivilConstructor2(),
3030
ConstructorType.Constructor3 => new CivilConstructor3(),
31-
_ => throw new System.NotImplementedException()
31+
_ => new NullConstructor()
3232
},
3333
ShipType.FlagShip => constructorType switch
3434
{
3535
ConstructorType.Constructor1 => new FlagConstructor1(),
36-
_ => throw new System.NotImplementedException()
36+
_ => new NullConstructor()
3737
},
38-
_ => throw new System.NotImplementedException()
38+
_ => new NullConstructor()
3939
};
4040
public static IArmor FindIArmor(ShipType shipType, ArmorType armorType) => shipType switch
4141
{
4242
ShipType.CivilShip => armorType switch
4343
{
4444
ArmorType.Armor1 => new CivilArmor1(),
45-
_ => throw new System.NotImplementedException()
45+
_ => new NullArmor()
4646
},
4747
ShipType.WarShip => armorType switch
4848
{
4949
ArmorType.Armor1 => new WarArmor1(),
5050
ArmorType.Armor2 => new WarArmor2(),
5151
ArmorType.Armor3 => new WarArmor3(),
52-
_ => throw new System.NotImplementedException()
52+
_ => new NullArmor()
5353
},
5454
ShipType.FlagShip => armorType switch
5555
{
5656
ArmorType.Armor1 => new FlagArmor1(),
5757
ArmorType.Armor2 => new FlagArmor2(),
5858
ArmorType.Armor3 => new FlagArmor3(),
59-
_ => throw new System.NotImplementedException()
59+
_ => new NullArmor()
6060
},
61-
_ => throw new System.NotImplementedException()
61+
_ => new NullArmor()
6262
};
6363
public static IShield FindIShield(ShipType shipType, ShieldType shieldType) => shipType switch
6464
{
6565
ShipType.CivilShip => shieldType switch
6666
{
6767
ShieldType.Shield1 => new CivilShield1(),
68-
_ => throw new System.NotImplementedException()
68+
_ => new NullShield()
6969
},
7070
ShipType.WarShip => shieldType switch
7171
{
7272
ShieldType.Shield1 => new WarShield1(),
7373
ShieldType.Shield2 => new WarShield2(),
7474
ShieldType.Shield3 => new WarShield3(),
75-
_ => throw new System.NotImplementedException()
75+
_ => new NullShield()
7676
},
7777
ShipType.FlagShip => shieldType switch
7878
{
7979
ShieldType.Shield1 => new FlagShield1(),
8080
ShieldType.Shield2 => new FlagShield2(),
8181
ShieldType.Shield3 => new FlagShield3(),
82-
_ => throw new System.NotImplementedException()
82+
_ => new NullShield()
8383
},
84-
_ => throw new System.NotImplementedException()
84+
_ => new NullShield()
8585
};
8686
public static IWeapon FindIWeapon(ShipType shipType, WeaponType weaponType) => shipType switch
8787
{
8888
ShipType.CivilShip => weaponType switch
8989
{
9090
WeaponType.LaserGun => new CivilLaserGun(),
91-
_ => throw new System.NotImplementedException()
91+
_ => new NullWeapon()
9292
},
9393
ShipType.WarShip => weaponType switch
9494
{
@@ -97,7 +97,7 @@ public static class ModuleFactory
9797
WeaponType.ShellGun => new WarShellGun(),
9898
WeaponType.MissileGun => new WarMissileGun(),
9999
WeaponType.ArcGun => new WarArcGun(),
100-
_ => throw new System.NotImplementedException()
100+
_ => new NullWeapon()
101101
},
102102
ShipType.FlagShip => weaponType switch
103103
{
@@ -106,8 +106,8 @@ public static class ModuleFactory
106106
WeaponType.ShellGun => new FlagShellGun(),
107107
WeaponType.MissileGun => new FlagMissileGun(),
108108
WeaponType.ArcGun => new FlagArcGun(),
109-
_ => throw new System.NotImplementedException()
109+
_ => new NullWeapon()
110110
},
111-
_ => throw new System.NotImplementedException()
111+
_ => new NullWeapon()
112112
};
113113
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
using Preparation.Interface;
2+
3+
namespace GameClass.GameObj.Modules;
4+
5+
public class NullArmor : IArmor
6+
{
7+
public int ArmorHP => 0;
8+
public int Cost => 0;
9+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
using Preparation.Interface;
2+
3+
namespace GameClass.GameObj.Modules;
4+
5+
public class NullConstructor : IConstructor
6+
{
7+
public int ConstructSpeed => 0;
8+
public int Cost => 0;
9+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
using Preparation.Interface;
2+
3+
namespace GameClass.GameObj.Modules;
4+
5+
public class NullProducer : IProducer
6+
{
7+
public int ProduceSpeed => 0;
8+
public int Cost => 0;
9+
}

0 commit comments

Comments
 (0)