Skip to content

Commit

Permalink
feat: ✨ add Game related and Move
Browse files Browse the repository at this point in the history
Ships can move now (probably)
  • Loading branch information
panxuc committed Oct 28, 2023
1 parent 79dbb18 commit a546c6e
Show file tree
Hide file tree
Showing 13 changed files with 172 additions and 29 deletions.
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@
| 子目录 | 说明 | 主要开发组 |
| :--------: | :--------------------------------------------------------: | :----------------------------: |
| .github | CI,用于选手包同步到服务器上供选手下载 | 运维组 |
| CAPI | 选手接口,生成可执行文件 | 通信组 |
| docs | 比赛的说明文档 | 逻辑组、通信组、运维组、界面组 |
| CAPI | 选手接口,生成可执行文件 | 通信组 |
| docs | 比赛的说明文档 | 逻辑组、通信组、运维组、界面组 |
| dependency | 项目依赖文件,如 proto、dll、lib、dockerfile、shell 脚本等 | 逻辑组、通信组、运维组、界面组 |
| installer | 下载器,用于选手包的下载与更新,生成可执行文件 | 运维组 |
| interface | Unity 界面 | 界面组 |
| launcher | 游戏启动器,用于快速启动游戏,生成可执行文件 | 运维组 |
| logic | 游戏逻辑、Server,生成可执行文件 | 通信组、逻辑组 |
| playback | 游戏回放组件,生成类库 | 逻辑组 |
| logic | 游戏逻辑、Server,生成可执行文件 | 通信组、逻辑组 |
| playback | 游戏回放组件,生成类库 | 逻辑组 |
| resource | 资源文件目录,用于存储主目录下 README 所用图片 | 端茶倒水 |

### 分支管理
Expand Down Expand Up @@ -137,11 +137,11 @@ THUAI7 开发组成员与其他贡献者应当遵循以下流程:

仓库的文档使用 Markdown 语法,具体语法可以参照 [Markdown 语法文档](https://docs.github.com/zh/get-started/writing-on-github/getting-started-with-writing-and-formatting-on-github/basic-writing-and-formatting-syntax)

中文文档的书写须严格遵循:[中午技术文档规范](https://github.com/ruanyf/document-style-guide)[中文文案排版指北](https://mazhuang.org/wiki/chinese-copywriting-guidelines/),以写出更美观的中文文档。例如:[中文文字与西文文字间空格](https://github.com/ruanyf/document-style-guide/blob/master/docs/text.md#%E5%AD%97%E9%97%B4%E8%B7%9D)[全角标点符号的正确使用](https://github.com/ruanyf/document-style-guide/blob/master/docs/marks.md),等等。
中文文档的书写须严格遵循:[中文技术文档规范](https://github.com/ruanyf/document-style-guide)[中文文案排版指北](https://mazhuang.org/wiki/chinese-copywriting-guidelines/),以写出更美观的中文文档。例如:[中文文字与西文文字间空格](https://github.com/ruanyf/document-style-guide/blob/master/docs/text.md#%E5%AD%97%E9%97%B4%E8%B7%9D)[全角标点符号的正确使用](https://github.com/ruanyf/document-style-guide/blob/master/docs/marks.md),等等。

西文文档的书写须遵循:

+[中午技术文档规范](https://github.com/ruanyf/document-style-guide)[中文文案排版指北](https://mazhuang.org/wiki/chinese-copywriting-guidelines/) 中规定的数字和西文的规范
+[中文技术文档规范](https://github.com/ruanyf/document-style-guide)[中文文案排版指北](https://mazhuang.org/wiki/chinese-copywriting-guidelines/) 中规定的数字和西文的规范
+ 半角空格的标点符号的使用:
+ 半角的逗号 `,`、分号 `;`、句号 `.`、叹号 `!`、问号 `?` 等标点,在不位于行尾时,后需加空格,除非其后紧跟全角标点符号。例如:`"Hello, world",是一句学习编程语言常用的句子`
+ 半角的括号 `()``[]``{}``<>` 等在左半括号前加空格、右半括号后加空格,除非其空格处紧跟全角标点符号或位于行首或行尾。例如:`Tsinghua University (THU) and Peking University (PKU)(我是全角括号)`
Expand Down
4 changes: 2 additions & 2 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@

## 中文文档

中文文档的书写须严格遵循:[中午技术文档规范](https://github.com/ruanyf/document-style-guide)[中文文案排版指北](https://mazhuang.org/wiki/chinese-copywriting-guidelines/),以写出更美观的中文文档。例如:[中文文字与西文文字间空格](https://github.com/ruanyf/document-style-guide/blob/master/docs/text.md#%E5%AD%97%E9%97%B4%E8%B7%9D)[全角标点符号的正确使用](https://github.com/ruanyf/document-style-guide/blob/master/docs/marks.md),等等。
中文文档的书写须严格遵循:[中文技术文档规范](https://github.com/ruanyf/document-style-guide)[中文文案排版指北](https://mazhuang.org/wiki/chinese-copywriting-guidelines/),以写出更美观的中文文档。例如:[中文文字与西文文字间空格](https://github.com/ruanyf/document-style-guide/blob/master/docs/text.md#%E5%AD%97%E9%97%B4%E8%B7%9D)[全角标点符号的正确使用](https://github.com/ruanyf/document-style-guide/blob/master/docs/marks.md),等等。

## 西文文档

西文文档的书写须遵循:

+[中午技术文档规范](https://github.com/ruanyf/document-style-guide)[中文文案排版指北](https://mazhuang.org/wiki/chinese-copywriting-guidelines/) 中规定的数字和西文的规范
+[中文技术文档规范](https://github.com/ruanyf/document-style-guide)[中文文案排版指北](https://mazhuang.org/wiki/chinese-copywriting-guidelines/) 中规定的数字和西文的规范
+ 半角空格的标点符号的使用:
+ 半角的逗号 `,`、分号 `;`、句号 `.`、叹号 `!`、问号 `?` 等标点,在不位于行尾时,后需加空格,除非其后紧跟全角标点符号。例如:`"Hello, world",是一句学习编程语言常用的句子`
+ 半角的括号 `()``[]``{}``<>` 等在左半括号前加空格、右半括号后加空格,除非其空格处紧跟全角标点符号或位于行首或行尾。例如:`Tsinghua University (THU) and Peking University (PKU)(我是全角括号)`
2 changes: 2 additions & 0 deletions docs/temp.url
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[InternetShortcut]
URL=https://thuai7.panxuc.com/
2 changes: 1 addition & 1 deletion logic/GameClass/GameObj/Areas/Construction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace GameClass.GameObj.Areas;
public class Construction : Immovable
{
public LongWithVariableRange HP => throw new NotImplementedException();
public override bool IsRigid => true;
public override bool IsRigid => constructionType == ConstructionType.Community;
public override ShapeType Shape => ShapeType.Square;
private ConstructionType constructionType = ConstructionType.Null;
public ConstructionType ConstructionType => constructionType;
Expand Down
2 changes: 1 addition & 1 deletion logic/GameClass/GameObj/Areas/Home.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ 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 => true;
public override bool IsRigid => false;
public override ShapeType Shape => ShapeType.Square;
public void AddScore(long add)
{
Expand Down
10 changes: 1 addition & 9 deletions logic/GameClass/GameObj/Areas/Wormhole.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,8 @@ public class Wormhole : Immovable, IWormhole
public LongWithVariableRange HP => throw new NotImplementedException();
public List<XY> Entrance => throw new NotImplementedException();
public List<XY> Content => throw new NotImplementedException();
public override bool IsRigid => true;
public override bool IsRigid => HP > GameData.WormholeHP / 2;
public override ShapeType Shape => ShapeType.Square;
public override bool IgnoreCollideExecutor(IGameObj targetObj)
{
if (HP > GameData.WormholeHP / 2)
{
return true;
}
return false;
}
public Wormhole(XY initPos)
: base(initPos, GameData.NumOfPosGridPerCell / 2, GameObjType.Wormhole)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,28 @@ public IOutOfBound GetOutOfBound(XY pos)
{
foreach (Ship s in gameObjDict[GameObjType.Ship])
{
if (s.ShipID == ID)
if (s.ID == ID)
{
ship = s;
break;
}
}
}
finally
{
gameObjLockDict[GameObjType.Ship].ExitReadLock();
}
return ship;
}
public Ship? FindShipInShipID(long shipID)
{
Ship? ship = null;
gameObjLockDict[GameObjType.Ship].EnterReadLock();
try
{
foreach (Ship s in gameObjDict[GameObjType.Ship])
{
if (s.ShipID == shipID)
{
ship = s;
break;
Expand Down
File renamed without changes.
9 changes: 9 additions & 0 deletions logic/GameClass/GameObj/Ship.cs
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,15 @@ public bool TryToRemoveFromGame(ShipStateType shipStateType)
}
return true;
}
public bool Commandable()
{
lock (ActionLock)
{
return (shipState != ShipStateType.Stunned
&& shipState != ShipStateType.Swinging
&& shipState != ShipStateType.Attacking);
}
}
public Ship(XY initPos, int initRadius, ShipType shipType) :

Check warning on line 171 in logic/GameClass/GameObj/Ship.cs

View workflow job for this annotation

GitHub Actions / dotnet-build

Non-nullable property 'Armor' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.

Check warning on line 171 in logic/GameClass/GameObj/Ship.cs

View workflow job for this annotation

GitHub Actions / dotnet-build

Non-nullable property 'Shield' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.

Check warning on line 171 in logic/GameClass/GameObj/Ship.cs

View workflow job for this annotation

GitHub Actions / dotnet-build

Non-nullable property 'BulletNum' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.
base(initPos, initRadius, GameObjType.Ship)
{
Expand Down
4 changes: 4 additions & 0 deletions logic/GameClass/GameObj/Team.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ public class Team
public const long invalidTeamID = long.MaxValue;
public const long noneTeamID = long.MinValue;
private readonly List<Ship> shipList;
private readonly Dictionary<uint, XY> birthPointList;

Check warning on line 16 in logic/GameClass/GameObj/Team.cs

View workflow job for this annotation

GitHub Actions / dotnet-build

Field 'Team.birthPointList' is never assigned to, and will always have its default value null
public Dictionary<uint, XY> BirthPointList => birthPointList;
private Home home;
public int Score { get; private set; } = 0;
public Ship? GetShip(long shipID)
Expand Down Expand Up @@ -109,6 +111,8 @@ public static bool TeamExists(long teamID)
{
return teamID < currentMaxTeamID;
}
public void UpdateBirthPoint()
{ }
public Team()

Check warning on line 116 in logic/GameClass/GameObj/Team.cs

View workflow job for this annotation

GitHub Actions / dotnet-build

Non-nullable field 'birthPointList' must contain a non-null value when exiting constructor. Consider declaring the field as nullable.

Check warning on line 116 in logic/GameClass/GameObj/Team.cs

View workflow job for this annotation

GitHub Actions / dotnet-build

Non-nullable field 'home' must contain a non-null value when exiting constructor. Consider declaring the field as nullable.
{
teamID = currentMaxTeamID++;
Expand Down
60 changes: 60 additions & 0 deletions logic/Gaming/ActionManager.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
using System;
using System.Threading;
using GameClass.GameObj;
using GameEngine;
using Preparation.Utility;
using Protobuf;
using Timothy.FrameRateTask;

namespace Gaming
{
public partial class Game
{
private readonly ActionManager actionManager;
private class ActionManager
{
public readonly MoveEngine moveEngine;

Check warning on line 16 in logic/Gaming/ActionManager.cs

View workflow job for this annotation

GitHub Actions / dotnet-build

Non-nullable field 'moveEngine' must contain a non-null value when exiting constructor. Consider declaring the field as nullable.
public bool MoveShip(Ship shipToMove, int moveTimeInMilliseconds, double moveDirection)
{
if (moveTimeInMilliseconds < 5)
{
return false;
}
long stateNum = shipToMove.SetShipState(RunningStateType.Waiting, ShipStateType.Moving);
if (stateNum == -1)
{
return false;
}
new Thread
(
() =>
{
shipToMove.ThreadNum.WaitOne();
if (!shipToMove.StartThread(stateNum, RunningStateType.RunningActively))
{
shipToMove.ThreadNum.Release();
return;
}
moveEngine.MoveObj(shipToMove, moveTimeInMilliseconds, moveDirection, shipToMove.StateNum);
Thread.Sleep(moveTimeInMilliseconds);
shipToMove.ResetShipState(stateNum);
}
)
{ IsBackground = true }.Start();
return true;
}
public static bool Stop(Ship ship)
{
lock (ship.ActionLock)
{
if(ship.Commandable())
{
ship.SetShipState(RunningStateType.Null);
return true;
}
}
return false;
}
}
}
}
57 changes: 56 additions & 1 deletion logic/Gaming/Game.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,71 @@ public struct ShipInitInfo
{
public long teamID;
public long playerID;
public ShipInitInfo(long teamID, long playerID)
public uint birthPoint;
public ShipType shipType;
public ShipInitInfo(long teamID, long playerID, uint birthPoint, ShipType shipType)
{
this.teamID = teamID;
this.playerID = playerID;
this.birthPoint = birthPoint;
this.shipType = shipType;
}
}
private readonly List<Team> teamList;
public List<Team> TeamList => teamList;
private readonly Map gameMap;
public Map GameMap => gameMap;
public long AddShip(ShipInitInfo shipInitInfo)
{
if (!Team.TeamExists(shipInitInfo.teamID))
{
return GameObj.invalidID;
}
// 由于BirthPoint实质上是可变且每支队伍不同的,所以暂时把它放到Team里?
XY pos = teamList[(int)shipInitInfo.teamID].BirthPointList[shipInitInfo.birthPoint];
Ship? newShip = shipManager.AddShip(pos, shipInitInfo.teamID, shipInitInfo.playerID, shipInitInfo.shipType);
if (newShip == null)
{
return GameObj.invalidID;
}
teamList[(int)shipInitInfo.teamID].AddShip(newShip);
return newShip.ShipID;
}
public bool StartGame(int milliSeconds)
{
if (gameMap.Timer.IsGaming)
return false;
// 开始游戏
new Thread
(
() =>
{
if (!gameMap.Timer.StartGame(milliSeconds))
return;

EndGame(); // 游戏结束时要做的事
}
)
{ IsBackground = true }.Start();
return true;
}
public void EndGame()
{
}
public bool MoveShip(long shipID, int moveTimeInMilliseconds, double angle)
{
if (!gameMap.Timer.IsGaming)
return false;
Ship? ship = gameMap.FindShipInShipID(shipID);
if(ship!=null)
{
return actionManager.MoveShip(ship, moveTimeInMilliseconds, angle);
}
else
{
return false;
}
}
public Game(uint[,] mapResource, int numOfTeam)

Check warning on line 81 in logic/Gaming/Game.cs

View workflow job for this annotation

GitHub Actions / dotnet-build

Non-nullable field 'actionManager' must contain a non-null value when exiting constructor. Consider declaring the field as nullable.

Check warning on line 81 in logic/Gaming/Game.cs

View workflow job for this annotation

GitHub Actions / dotnet-build

Non-nullable field 'healthManager' must contain a non-null value when exiting constructor. Consider declaring the field as nullable.

Check warning on line 81 in logic/Gaming/Game.cs

View workflow job for this annotation

GitHub Actions / dotnet-build

Non-nullable field 'moduleManager' must contain a non-null value when exiting constructor. Consider declaring the field as nullable.
{
gameMap = new Map(mapResource);
Expand Down
16 changes: 8 additions & 8 deletions logic/Gaming/ShipManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,18 @@ public partial class Game
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);
gameMap.Add(newShip);
newShip.TeamID.SetReturnOri(teamID);
newShip.ShipID.SetReturnOri(shipID);
return newShip;
}
public ShipManager(Map gameMap)
{
this.gameMap = gameMap;
}
}
public Ship? AddShip(XY pos, long teamID, long shipID, ShipType shipType)
{
Ship newShip = new Ship(pos, GameData.ShipRadius, shipType);
gameMap.Add(newShip);
newShip.TeamID.SetReturnOri(teamID);
newShip.ShipID.SetReturnOri(shipID);
return newShip;
}
}
}

0 comments on commit a546c6e

Please sign in to comment.