From 8e5510d3615e6c476ece9eee0acc1dc63f201347 Mon Sep 17 00:00:00 2001 From: Syed zainul abedin Date: Thu, 3 Oct 2024 22:42:35 +0530 Subject: [PATCH 1/2] Added unit command --- Assets/Scripts/Action/ICommand.cs | 4 ++++ Assets/Scripts/Action/IUnitCommand.cs | 13 +++++++++++++ 2 files changed, 17 insertions(+) create mode 100644 Assets/Scripts/Action/ICommand.cs create mode 100644 Assets/Scripts/Action/IUnitCommand.cs diff --git a/Assets/Scripts/Action/ICommand.cs b/Assets/Scripts/Action/ICommand.cs new file mode 100644 index 00000000..ee93b73b --- /dev/null +++ b/Assets/Scripts/Action/ICommand.cs @@ -0,0 +1,4 @@ +interface ICommand +{ + void Execute(); +} \ No newline at end of file diff --git a/Assets/Scripts/Action/IUnitCommand.cs b/Assets/Scripts/Action/IUnitCommand.cs new file mode 100644 index 00000000..ae69506c --- /dev/null +++ b/Assets/Scripts/Action/IUnitCommand.cs @@ -0,0 +1,13 @@ +public class IUnitCommand : ICommand +{ + public int ActorUnitId { get; set; } + public int TargetUnitId { get; set; } + public int ActorPlayerId { get; set; } + public int TargetPlayerId { get; set; } + + protected UnitController actor; + protected UnitController target; + + public abstract void Execute(); + public abstract bool WillHitTarget(); +} \ No newline at end of file From e122c55033e2b77423da8d1d280ac0b7bc97ad43 Mon Sep 17 00:00:00 2001 From: Syed zainul abedin Date: Thu, 3 Oct 2024 22:45:32 +0530 Subject: [PATCH 2/2] Added command invoker --- Assets/Scripts/Command/CommandInvoker.cs | 16 ++++++++++++++++ Assets/Scripts/{Action => Command}/ICommand.cs | 0 .../Scripts/{Action => Command}/IUnitCommand.cs | 0 3 files changed, 16 insertions(+) create mode 100644 Assets/Scripts/Command/CommandInvoker.cs rename Assets/Scripts/{Action => Command}/ICommand.cs (100%) rename Assets/Scripts/{Action => Command}/IUnitCommand.cs (100%) diff --git a/Assets/Scripts/Command/CommandInvoker.cs b/Assets/Scripts/Command/CommandInvoker.cs new file mode 100644 index 00000000..594b7d5d --- /dev/null +++ b/Assets/Scripts/Command/CommandInvoker.cs @@ -0,0 +1,16 @@ +public class CommandInvoker { + private Stack commandHistory = new Stack(); + + public void ProcessCommand(ICommand command) { + ExecuteCommand(command); + RegisterCommand(command); + } + + private void ExecuteCommand(ICommand command) { + command.Execute(); + } + + private void RegisterCommand(ICommand command) { + commandHistory.Push(command); + } +} \ No newline at end of file diff --git a/Assets/Scripts/Action/ICommand.cs b/Assets/Scripts/Command/ICommand.cs similarity index 100% rename from Assets/Scripts/Action/ICommand.cs rename to Assets/Scripts/Command/ICommand.cs diff --git a/Assets/Scripts/Action/IUnitCommand.cs b/Assets/Scripts/Command/IUnitCommand.cs similarity index 100% rename from Assets/Scripts/Action/IUnitCommand.cs rename to Assets/Scripts/Command/IUnitCommand.cs