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

Modify structure of Home & Team #36

Merged
merged 3 commits into from
Dec 3, 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
12 changes: 3 additions & 9 deletions logic/GameClass/GameObj/Areas/Home.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,13 @@ namespace GameClass.GameObj.Areas;

public class Home : Immovable, IHome
{
private long teamID;
public long TeamID => teamID;
public AtomicLong TeamID { get; }
public LongInTheVariableRange HP => new LongInTheVariableRange(GameData.HomeHP);
public AtomicLong Score => new AtomicLong(0);

public override bool IsRigid => false;
public override ShapeType Shape => ShapeType.Square;
public void AddScore(long add)
{
Score.Add(add);
}
public Home(XY initPos, long teamID)
public Home(XY initPos)
: base(initPos, GameData.NumOfPosGridPerCell / 2, GameObjType.Home)
{
this.teamID = teamID;
}
}
3 changes: 1 addition & 2 deletions logic/GameClass/GameObj/Map/Map.cs
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,6 @@ public Map(uint[,] mapResource)
}
protoGameMap = new uint[mapResource.GetLength(0), mapResource.GetLength(1)];
Array.Copy(mapResource, protoGameMap, mapResource.Length);
long teamID = 0;
for (int i = 0; i < GameData.MapRows; ++i)
{
for (int j = 0; j < GameData.MapCols; ++j)
Expand Down Expand Up @@ -355,7 +354,7 @@ public Map(uint[,] mapResource)
}
break;
case (uint)PlaceType.Home:
Add(new Home(GameData.GetCellCenterPos(i, j), teamID++));
Add(new Home(GameData.GetCellCenterPos(i, j)));
break;
}
}
Expand Down
2 changes: 2 additions & 0 deletions logic/GameClass/GameObj/Ship.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ public override bool IgnoreCollideExecutor(IGameObj targetObj)
public ShipStateType ShipState => shipState;
public IOccupation Occupation { get; }
public IntNumUpdateEachCD BulletNum { get; }
public AtomicLong Money { get; } = new(0);
public AtomicLong Score { get; } = new(0);

#region Producer
private ProducerType producerType = ProducerType.Null;
Expand Down
62 changes: 51 additions & 11 deletions logic/GameClass/GameObj/Team.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ public class Team
private readonly Dictionary<uint, XY> birthPointList;
public Dictionary<uint, XY> BirthPointList => birthPointList;
private Home home;
public AtomicLong Money { get; } = new AtomicLong(0);
public AtomicLong Score { get; } = new AtomicLong(0);
public Ship? GetShip(long shipID)
{
foreach (Ship ship in shipList)
Expand Down Expand Up @@ -47,17 +45,57 @@ public bool AddShip(Ship ship)
default:
return false;
}
shipList.Add(ship);
//shipList.Add(ship);
return true;
}
public void AddMoney(long add)
public bool AddMoney(long shipID, long add)
{
Money.Add(add);
Score.Add(add);
foreach (Ship ship in shipList)
{
if (ship.ShipID == shipID)
{
ship.Money.Add(add);
ship.Score.Add(add);
return true;
}
}
return false;
}
public bool SubMoney(long shipID, long sub)
{
foreach (Ship ship in shipList)
{
if (ship.ShipID == shipID && ship.Money >= sub)
{
ship.Money.Sub(sub);
return true;
}
}
return false;
}
public void SubMoney(long sub)

public bool MoveMoney(long srcShipID, long dstShipID, long move)
{
Money.Sub(sub);
Ship? srcShip = null;
Ship? dstShip = null;
foreach (Ship ship in shipList)
{
if (ship.ShipID == srcShipID)
{
srcShip = ship;
}
if (ship.ShipID == dstShipID)
{
dstShip = ship;
}
}
if (srcShip != null && dstShip != null && srcShip.Money >= move)
{
srcShip.Money.Sub(move);
dstShip.Money.Add(move);
return true;
}
return false;
}
public void SetHome(Home home)
{
Expand Down Expand Up @@ -124,10 +162,12 @@ public static bool TeamExists(long teamID)
}
public void UpdateBirthPoint()
{ }
public Team()
public Team(Home home)
{
teamID = currentMaxTeamID++;
shipList = new List<Ship>();
this.teamID = currentMaxTeamID++;
this.shipList = new List<Ship>(GameData.MaxShipNum);
this.home = home;
this.home.TeamID.SetReturnOri(teamID);
}
}
}
12 changes: 10 additions & 2 deletions logic/Gaming/Game.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using Preparation.Utility;
using Preparation.Interface;
using GameClass.GameObj;
using GameClass.GameObj.Areas;

namespace Gaming
{
Expand Down Expand Up @@ -82,9 +83,16 @@ public Game(uint[,] mapResource, int numOfTeam)
{
gameMap = new Map(mapResource);
teamList = new List<Team>();
for (int i = 0; i < numOfTeam; i++)
foreach (GameObj gameObj in gameMap.GameObjDict[GameObjType.Home])
{
teamList.Add(new Team());
if (gameObj.Type == GameObjType.Home)
{
teamList.Add(new Team((Home)gameObj));
}
if (teamList.Count == numOfTeam)
{
break;
}
}
}
}
Expand Down
4 changes: 1 addition & 3 deletions logic/Preparation/Interface/IHome.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ namespace Preparation.Interface
{
public interface IHome
{
public long TeamID { get; }
public AtomicLong TeamID { get; }
public LongInTheVariableRange HP { get; }
public AtomicLong Score { get; }
public void AddScore(long add);
}
}
14 changes: 7 additions & 7 deletions logic/Server/Program.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
//using CommandLine;
//using Grpc.Core;
//using Protobuf;

namespace Server
//using CommandLine;
//using Grpc.Core;
//using Protobuf;
namespace Server
{
public class Program
{
Expand Down Expand Up @@ -70,5 +70,5 @@ static int Main(string[] args)
// }
return 0;
}
}
}
}
}
Loading