Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create null default for all factories #16

Merged
merged 5 commits into from
Nov 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion logic/GameClass/GameObj/Areas/AreaFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public static class AreaFactory
PlaceType.Resource => new Resource(pos),
PlaceType.Construction => new Construction(pos),
PlaceType.Wormhole => new Wormhole(pos),
_ => throw new System.NotImplementedException()
_ => new NullArea(pos)
};
public static OutOfBoundBlock GetOutOfBoundBlock(XY pos) => new(pos);
}
13 changes: 13 additions & 0 deletions logic/GameClass/GameObj/Areas/NullArea.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using Preparation.Utility;

namespace GameClass.GameObj.Areas;

public class NullArea : Immovable
{
public override bool IsRigid => false;
public override ShapeType Shape => ShapeType.Null;
public NullArea(XY initPos)
: base(initPos, int.MaxValue, GameObjType.Null)
{
}
}
2 changes: 1 addition & 1 deletion logic/GameClass/GameObj/Bullets/Arc.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ internal sealed class Arc : Bullet
public Arc(Ship ship, XY pos, int radius = GameData.BulletRadius) :
base(ship, radius, pos)
{
Random random = new Random();
Random random = new();
this.AP.SetReturnOri(random.Next(GameData.ArcDamageMin, GameData.ArcDamageMax));
}
public override double BulletBombRange => 0;
Expand Down
2 changes: 1 addition & 1 deletion logic/GameClass/GameObj/Bullets/BulletFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ public static class BulletFactory
BulletType.Shell => new Shell(ship, pos),
BulletType.Missile => new Missile(ship, pos),
BulletType.Arc => new Arc(ship, pos),
_ => throw new System.NotImplementedException()
_ => new NullBullet(ship, pos)
};
}
21 changes: 21 additions & 0 deletions logic/GameClass/GameObj/Bullets/NullBullet.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using Preparation.Utility;

namespace GameClass.GameObj.Bullets;

internal sealed class NullBullet : Bullet
{
public override double BulletBombRange => 0;
public override double AttackDistance => 0;
public override int Speed => 0;
public override int CastTime => 0;
public override int SwingTime => 0;
public override int CD => 0;
public override int MaxBulletNum => 0;
public override BulletType TypeOfBullet => BulletType.Null;
public override bool CanAttack(GameObj target) => false;
public override bool CanBeBombed(GameObjType gameObjType) => false;
public NullBullet(Ship ship, XY Position, int radius = GameData.BulletRadius)
: base(ship, radius, Position)
{
}
}
27 changes: 2 additions & 25 deletions logic/GameClass/GameObj/Map/Map.cs
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ public bool RemoveJustFromMap(GameObj gameObj)
GameObjLockDict[gameObj.Type].ExitWriteLock();
}
}
public void Add(GameObj gameObj)
public void Add(IGameObj gameObj)
{
GameObjLockDict[gameObj.Type].EnterWriteLock();
try
Expand Down Expand Up @@ -290,30 +290,7 @@ public Map(uint[,] mapResource)
{
for (int j = 0; j < GameData.MapCols; ++j)
{
switch (mapResource[i, j])
{
case (uint)PlaceType.Asteroid:
Add(new Areas.Asteroid(GameData.GetCellCenterPos(i, j)));
break;
case (uint)PlaceType.Construction:
Add(new Areas.Construction(GameData.GetCellCenterPos(i, j)));
break;
case (uint)PlaceType.Home:
Add(new Areas.Home(GameData.GetCellCenterPos(i, j)));
break;
case (uint)PlaceType.Resource:
Add(new Areas.Resource(GameData.GetCellCenterPos(i, j)));
break;
case (uint)PlaceType.Ruin:
Add(new Areas.Ruin(GameData.GetCellCenterPos(i, j)));
break;
case (uint)PlaceType.Shadow:
Add(new Areas.Shadow(GameData.GetCellCenterPos(i, j)));
break;
case (uint)PlaceType.Wormhole:
Add(new Areas.Wormhole(GameData.GetCellCenterPos(i, j)));
break;
}
Add(Areas.AreaFactory.GetArea(GameData.GetCellCenterPos(i, j), (PlaceType)mapResource[i, j]));
}
}
}
Expand Down
36 changes: 18 additions & 18 deletions logic/GameClass/GameObj/Modules/ModuleFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ public static class ModuleFactory
ProducerType.Producer1 => new CivilProducer1(),
ProducerType.Producer2 => new CivilProducer2(),
ProducerType.Producer3 => new CivilProducer3(),
_ => throw new System.NotImplementedException()
_ => new NullProducer()
},
ShipType.FlagShip => producerType switch
{
ProducerType.Producer1 => new FlagProducer1(),
_ => throw new System.NotImplementedException()
_ => new NullProducer()
},
_ => throw new System.NotImplementedException()
_ => new NullProducer()
};
public static IConstructor FindIConstructor(ShipType shipType, ConstructorType constructorType) => shipType switch
{
Expand All @@ -28,67 +28,67 @@ public static class ModuleFactory
ConstructorType.Constructor1 => new CivilConstructor1(),
ConstructorType.Constructor2 => new CivilConstructor2(),
ConstructorType.Constructor3 => new CivilConstructor3(),
_ => throw new System.NotImplementedException()
_ => new NullConstructor()
},
ShipType.FlagShip => constructorType switch
{
ConstructorType.Constructor1 => new FlagConstructor1(),
_ => throw new System.NotImplementedException()
_ => new NullConstructor()
},
_ => throw new System.NotImplementedException()
_ => new NullConstructor()
};
public static IArmor FindIArmor(ShipType shipType, ArmorType armorType) => shipType switch
{
ShipType.CivilShip => armorType switch
{
ArmorType.Armor1 => new CivilArmor1(),
_ => throw new System.NotImplementedException()
_ => new NullArmor()
},
ShipType.WarShip => armorType switch
{
ArmorType.Armor1 => new WarArmor1(),
ArmorType.Armor2 => new WarArmor2(),
ArmorType.Armor3 => new WarArmor3(),
_ => throw new System.NotImplementedException()
_ => new NullArmor()
},
ShipType.FlagShip => armorType switch
{
ArmorType.Armor1 => new FlagArmor1(),
ArmorType.Armor2 => new FlagArmor2(),
ArmorType.Armor3 => new FlagArmor3(),
_ => throw new System.NotImplementedException()
_ => new NullArmor()
},
_ => throw new System.NotImplementedException()
_ => new NullArmor()
};
public static IShield FindIShield(ShipType shipType, ShieldType shieldType) => shipType switch
{
ShipType.CivilShip => shieldType switch
{
ShieldType.Shield1 => new CivilShield1(),
_ => throw new System.NotImplementedException()
_ => new NullShield()
},
ShipType.WarShip => shieldType switch
{
ShieldType.Shield1 => new WarShield1(),
ShieldType.Shield2 => new WarShield2(),
ShieldType.Shield3 => new WarShield3(),
_ => throw new System.NotImplementedException()
_ => new NullShield()
},
ShipType.FlagShip => shieldType switch
{
ShieldType.Shield1 => new FlagShield1(),
ShieldType.Shield2 => new FlagShield2(),
ShieldType.Shield3 => new FlagShield3(),
_ => throw new System.NotImplementedException()
_ => new NullShield()
},
_ => throw new System.NotImplementedException()
_ => new NullShield()
};
public static IWeapon FindIWeapon(ShipType shipType, WeaponType weaponType) => shipType switch
{
ShipType.CivilShip => weaponType switch
{
WeaponType.LaserGun => new CivilLaserGun(),
_ => throw new System.NotImplementedException()
_ => new NullWeapon()
},
ShipType.WarShip => weaponType switch
{
Expand All @@ -97,7 +97,7 @@ public static class ModuleFactory
WeaponType.ShellGun => new WarShellGun(),
WeaponType.MissileGun => new WarMissileGun(),
WeaponType.ArcGun => new WarArcGun(),
_ => throw new System.NotImplementedException()
_ => new NullWeapon()
},
ShipType.FlagShip => weaponType switch
{
Expand All @@ -106,8 +106,8 @@ public static class ModuleFactory
WeaponType.ShellGun => new FlagShellGun(),
WeaponType.MissileGun => new FlagMissileGun(),
WeaponType.ArcGun => new FlagArcGun(),
_ => throw new System.NotImplementedException()
_ => new NullWeapon()
},
_ => throw new System.NotImplementedException()
_ => new NullWeapon()
};
}
9 changes: 9 additions & 0 deletions logic/GameClass/GameObj/Modules/NullModules/NullArmor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using Preparation.Interface;

namespace GameClass.GameObj.Modules;

public class NullArmor : IArmor
{
public int ArmorHP => 0;
public int Cost => 0;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using Preparation.Interface;

namespace GameClass.GameObj.Modules;

public class NullConstructor : IConstructor
{
public int ConstructSpeed => 0;
public int Cost => 0;
}
9 changes: 9 additions & 0 deletions logic/GameClass/GameObj/Modules/NullModules/NullProducer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using Preparation.Interface;

namespace GameClass.GameObj.Modules;

public class NullProducer : IProducer
{
public int ProduceSpeed => 0;
public int Cost => 0;
}
9 changes: 9 additions & 0 deletions logic/GameClass/GameObj/Modules/NullModules/NullShield.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using Preparation.Interface;

namespace GameClass.GameObj.Modules;

public class NullShield : IShield
{
public int ShieldHP => 0;
public int Cost => 0;
}
10 changes: 10 additions & 0 deletions logic/GameClass/GameObj/Modules/NullModules/NullWeapon.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using Preparation.Interface;
using Preparation.Utility;

namespace GameClass.GameObj.Modules;

public class NullWeapon : IWeapon
{
public BulletType BulletType => BulletType.Null;
public int Cost => 0;
}
10 changes: 10 additions & 0 deletions logic/GameClass/GameObj/Occupations/NullOccupation.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using Preparation.Interface;

namespace GameClass.GameObj.Occupations;

public class NullOccupation : IOccupation
{
public int MoveSpeed => 0;
public int MaxHp => 0;
public int ViewRange => 0;
}
2 changes: 1 addition & 1 deletion logic/GameClass/GameObj/Occupations/OccupationFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ public static class OccupationFactory
ShipType.CivilShip => new CivilShip(),
ShipType.WarShip => new WarShip(),
ShipType.FlagShip => new FlagShip(),
_ => throw new System.NotImplementedException(),
_ => new NullOccupation()
};
}
2 changes: 1 addition & 1 deletion logic/Gaming/ShipManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ private partial class ShipManager
readonly Map gameMap;
public Ship? AddShip(XY pos, long teamID, long shipID, ShipType shipType)
{
Ship newShip = new Ship(pos, GameData.ShipRadius, shipType);
Ship newShip = new(pos, GameData.ShipRadius, shipType);
gameMap.Add(newShip);
newShip.TeamID.SetReturnOri(teamID);
newShip.ShipID.SetReturnOri(shipID);
Expand Down
Loading