From c4e50967ce18352f6c672fe40c10029207ca4c13 Mon Sep 17 00:00:00 2001 From: TCL <1620508360@qq.com> Date: Tue, 21 Sep 2021 13:46:37 +0800 Subject: [PATCH 1/2] chore: Add abstract class GameObj and MoveableObj --- logic/Preparation/GameObj/GameObj.cs | 116 +++++++++++++++++++++++ logic/Preparation/GameObj/MoveableObj.cs | 52 ++++++++++ logic/Preparation/Interface/IGameObj.cs | 1 - logic/Preparation/Preparation.csproj | 8 ++ logic/Preparation/Utility/XYPosition.cs | 4 + logic/README.md | 2 +- logic/logic.sln | 16 +++- 7 files changed, 195 insertions(+), 4 deletions(-) create mode 100644 logic/Preparation/GameObj/GameObj.cs create mode 100644 logic/Preparation/GameObj/MoveableObj.cs create mode 100644 logic/Preparation/Preparation.csproj diff --git a/logic/Preparation/GameObj/GameObj.cs b/logic/Preparation/GameObj/GameObj.cs new file mode 100644 index 00000000..dfcfbefb --- /dev/null +++ b/logic/Preparation/GameObj/GameObj.cs @@ -0,0 +1,116 @@ +using Preparation.Interface; +using Preparation.Utility; + +namespace Preparation.GameObj +{ + public abstract class GameObj:IGameObj + { + public enum GameObjType + { + Character = 0, + Obj = 1 + } + protected readonly object gameObjLock = new object(); + protected readonly XYPosition birthPos; + + public long ID { get;} + + private XYPosition position; + public XYPosition Position + { + get => position; + protected set + { + lock (gameObjLock) + { + position = value; + } + } + } + public abstract bool IsRigid { get; } + + private double facingDirection = 0; + public double FacingDirection + { + get => facingDirection; + set + { + lock (gameObjLock) + facingDirection = value; + } + } + public abstract ShapeType Shape { get; } + + private bool canMove; + public bool CanMove + { + get => canMove; + set + { + lock(gameObjLock) + { + canMove = value; + } + } + } + + private bool isMoving; + public bool IsMoving + { + get => isMoving; + set + { + lock(gameObjLock) + { + isMoving = value; + } + } + } + + private bool isResetting; + public bool IsResetting + { + get => isResetting; + set + { + lock(gameObjLock) + { + isResetting = value; + } + } + } + public bool IsAvailable => !IsMoving && CanMove && !IsResetting; //是否能接收指令 + public int Radius { get; } + + private PlaceType place; + public PlaceType Place + { + get => place; + set + { + lock(gameObjLock) + { + place = value; + } + } + } + + public virtual bool CanSee(GameObj obj) + { + if (obj.Place == PlaceType.Invisible) //先判断是否隐身 + return false; + if (obj.Place == PlaceType.Land) + return true; + if (obj.Place == this.Place) + return true; + return false; + } + + public GameObj(XYPosition initPos,int initRadius,PlaceType initPlace) + { + this.birthPos = initPos; + this.Radius = initRadius; + this.place = initPlace; + } + } +} diff --git a/logic/Preparation/GameObj/MoveableObj.cs b/logic/Preparation/GameObj/MoveableObj.cs new file mode 100644 index 00000000..cc03079b --- /dev/null +++ b/logic/Preparation/GameObj/MoveableObj.cs @@ -0,0 +1,52 @@ +using Preparation.Interface; +using Preparation.Utility; + +namespace Preparation.GameObj +{ + public abstract class MoveableObj: GameObj,IMoveable + { + private int moveSpeed; + public int MoveSpeed + { + get => moveSpeed; + set + { + lock(gameObjLock) + { + moveSpeed = value; + } + } + } + protected readonly object moveLock = new object(); + public override ShapeType Shape => ShapeType.Circle; //会移动的一定是圆形 + public MoveableObj(XYPosition initPos, int initRadius, PlaceType initPlace,int initSpeed):base(initPos,initRadius,initPlace) + { + moveSpeed = initSpeed; + } + public long Move(Vector moveVec) + { + var XYVec = Vector.Vector2XY(moveVec); + lock (moveLock) + { + FacingDirection = moveVec.angle; + this.Position += XYVec; + } + return (long)(XYVec.ToVector2()* new Vector2(0, 0)); + } + + public virtual void Reset() //复活时数据重置 + { + lock (moveLock) + { + this.Position = birthPos; + } + lock(gameObjLock) + { + FacingDirection = 0.0; + IsMoving = false; + CanMove = false; + IsResetting = true; + } + } + } +} diff --git a/logic/Preparation/Interface/IGameObj.cs b/logic/Preparation/Interface/IGameObj.cs index 6af3b9a9..067431df 100644 --- a/logic/Preparation/Interface/IGameObj.cs +++ b/logic/Preparation/Interface/IGameObj.cs @@ -27,7 +27,6 @@ public interface IGameObj public bool IsResetting { get; set; } //reviving public bool IsAvailable { get; } public int Radius { get; } //if Square, Radius equals half length of one side - public object MoveLock { get; } public PlaceType Place { get; set; } } diff --git a/logic/Preparation/Preparation.csproj b/logic/Preparation/Preparation.csproj new file mode 100644 index 00000000..20827042 --- /dev/null +++ b/logic/Preparation/Preparation.csproj @@ -0,0 +1,8 @@ + + + + Exe + net5.0 + + + diff --git a/logic/Preparation/Utility/XYPosition.cs b/logic/Preparation/Utility/XYPosition.cs index 03332ec2..302f28e7 100644 --- a/logic/Preparation/Utility/XYPosition.cs +++ b/logic/Preparation/Utility/XYPosition.cs @@ -28,5 +28,9 @@ public static double Distance(XYPosition p1,XYPosition p2) { return Math.Sqrt((p1.x - p2.x) * (p1.x - p2.x) + (p1.y - p2.y) * (p1.y - p2.y)); } + public Vector2 ToVector2() + { + return new Vector2(this.x, this.y); + } } } diff --git a/logic/README.md b/logic/README.md index b118dad5..bd6bc43b 100644 --- a/logic/README.md +++ b/logic/README.md @@ -46,5 +46,5 @@ ## 开发人员 -+ ……(自己加) ++ 唐昌礼,张鹤龄,刘浩然 diff --git a/logic/logic.sln b/logic/logic.sln index a87fc8f2..46184770 100644 --- a/logic/logic.sln +++ b/logic/logic.sln @@ -3,9 +3,13 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 16 VisualStudioVersion = 16.0.31410.357 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Server", "Server\Server.csproj", "{5B5FD8F7-1B73-4189-8AEF-48B3ED077ADB}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Server", "Server\Server.csproj", "{5B5FD8F7-1B73-4189-8AEF-48B3ED077ADB}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Client", "Client\Client.csproj", "{3B18D60F-EECF-4E5D-B5FF-6A8E29422335}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Client", "Client\Client.csproj", "{3B18D60F-EECF-4E5D-B5FF-6A8E29422335}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Preparation", "Preparation\Preparation.csproj", "{84B5D876-B6DE-499C-9EF2-D924FDC984B2}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GameEngine", "GameEngine\GameEngine.csproj", "{C1CEF591-E65C-4E16-A369-F5F9EA46F978}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -21,6 +25,14 @@ Global {3B18D60F-EECF-4E5D-B5FF-6A8E29422335}.Debug|Any CPU.Build.0 = Debug|Any CPU {3B18D60F-EECF-4E5D-B5FF-6A8E29422335}.Release|Any CPU.ActiveCfg = Release|Any CPU {3B18D60F-EECF-4E5D-B5FF-6A8E29422335}.Release|Any CPU.Build.0 = Release|Any CPU + {84B5D876-B6DE-499C-9EF2-D924FDC984B2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {84B5D876-B6DE-499C-9EF2-D924FDC984B2}.Debug|Any CPU.Build.0 = Debug|Any CPU + {84B5D876-B6DE-499C-9EF2-D924FDC984B2}.Release|Any CPU.ActiveCfg = Release|Any CPU + {84B5D876-B6DE-499C-9EF2-D924FDC984B2}.Release|Any CPU.Build.0 = Release|Any CPU + {C1CEF591-E65C-4E16-A369-F5F9EA46F978}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {C1CEF591-E65C-4E16-A369-F5F9EA46F978}.Debug|Any CPU.Build.0 = Debug|Any CPU + {C1CEF591-E65C-4E16-A369-F5F9EA46F978}.Release|Any CPU.ActiveCfg = Release|Any CPU + {C1CEF591-E65C-4E16-A369-F5F9EA46F978}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE From 1c161035e43176634a5282e87b78c51b682ce170 Mon Sep 17 00:00:00 2001 From: TCL <1620508360@qq.com> Date: Tue, 21 Sep 2021 13:48:44 +0800 Subject: [PATCH 2/2] chore: Add abstract class GameObj and MoveableObj --- logic/Server/Server.csproj | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/logic/Server/Server.csproj b/logic/Server/Server.csproj index 20827042..50384d50 100644 --- a/logic/Server/Server.csproj +++ b/logic/Server/Server.csproj @@ -5,4 +5,8 @@ net5.0 + + + +