From 8f7d6841d15837682e3a7ee1d148efe0507ee1cd Mon Sep 17 00:00:00 2001 From: Joshua Hegedus Date: Tue, 14 Nov 2023 23:20:55 +0100 Subject: [PATCH] minor fixes --- Nuget/.projects.conf | 4 ++-- _src/GameFramework.Impl/Core/GameManager.cs | 18 ++++++++---------- _src/GameFramework.Impl/Map/AMap2D.cs | 14 ++++++++++++++ _src/GameFramework/Map/IHasUnits2D.cs | 1 + 4 files changed, 25 insertions(+), 12 deletions(-) diff --git a/Nuget/.projects.conf b/Nuget/.projects.conf index 93a9ce1..555aab5 100644 --- a/Nuget/.projects.conf +++ b/Nuget/.projects.conf @@ -1,2 +1,2 @@ -GameFramework.Core:1.5.5 -GameFramework.UI.WPF:1.2.4 \ No newline at end of file +GameFramework.Core:1.5.6 +GameFramework.UI.WPF:1.2.5 \ No newline at end of file diff --git a/_src/GameFramework.Impl/Core/GameManager.cs b/_src/GameFramework.Impl/Core/GameManager.cs index 63882a0..3d633df 100644 --- a/_src/GameFramework.Impl/Core/GameManager.cs +++ b/_src/GameFramework.Impl/Core/GameManager.cs @@ -12,15 +12,13 @@ namespace GameFramework.Impl.Core { internal class GameManager : IGameManager { - private readonly IConfigurationService2D _configurationService; private readonly ICollection _listeners; public GameState State { get; private set; } public IStopwatch Timer { get; } - public GameManager(IStopwatch stopwatch, IConfigurationService2D configurationService) + public GameManager(IStopwatch stopwatch) { - _configurationService = configurationService ?? throw new ArgumentNullException(nameof(configurationService)); Timer = stopwatch ?? throw new ArgumentNullException(nameof(stopwatch)); _listeners = new List(); State = GameState.NotStarted; @@ -35,12 +33,12 @@ public void StartGame(IGameplayFeedback feedback) } Timer.Start(); - + State = GameState.InProgress; + foreach (var gameFeedbackListener in _listeners) { gameFeedbackListener.OnGameStarted(feedback); } - State = GameState.InProgress; } public void EndGame(IGameplayFeedback feedback, GameResolution resolution) @@ -51,8 +49,9 @@ public void EndGame(IGameplayFeedback feedback, GameResolution resolution) return; } - State = GameState.Finished; Timer.Stop(); + State = GameState.Finished; + foreach (var gameFeedbackListener in _listeners) { gameFeedbackListener.OnGameFinished(feedback, resolution); @@ -67,11 +66,11 @@ public void PauseGame() return; } Timer.Stop(); + State = GameState.Paused; foreach (var gameFeedbackListener in _listeners) { gameFeedbackListener.OnGamePaused(); } - State = GameState.Paused; } public void ResumeGame() @@ -83,11 +82,11 @@ public void ResumeGame() } Timer.Start(); + State = GameState.InProgress; foreach (var gameFeedbackListener in _listeners) { gameFeedbackListener.OnGameResumed(); } - State = GameState.InProgress; } public void ResetGame() @@ -97,13 +96,12 @@ public void ResetGame() Debug.WriteLine("Game is not in progress. Cannot reset."); return; } - Timer.Reset(); + State = GameState.NotStarted; foreach (var gameFeedbackListener in _listeners) { gameFeedbackListener.OnGameReset(); } - State = GameState.NotStarted; } public void AttachListener(IGameStateChangedListener changedListener) diff --git a/_src/GameFramework.Impl/Map/AMap2D.cs b/_src/GameFramework.Impl/Map/AMap2D.cs index 8533824..e4da4f5 100644 --- a/_src/GameFramework.Impl/Map/AMap2D.cs +++ b/_src/GameFramework.Impl/Map/AMap2D.cs @@ -74,6 +74,14 @@ public virtual IEnumerable MapPortion(IPosition2D center, int radi #endregion #region Units + public IEnumerable GetUnitsAtPortion(IMapObject2D mapObject) + { + return GetUnitsAtPortion(new[] + { + mapObject + }); + } + public virtual IEnumerable GetUnitsAtPortion(IEnumerable mapObjects) { var units = new List(); @@ -126,6 +134,12 @@ public virtual void MoveUnit(IUnit2D unit2D, Move2D move) { return; } + + foreach (var unit in GetUnitsAtPortion(mapObject)) + { + unit2D.SteppedOn(unit); + } + unit2D.Step(mapObject); } diff --git a/_src/GameFramework/Map/IHasUnits2D.cs b/_src/GameFramework/Map/IHasUnits2D.cs index c56d78d..eb28719 100644 --- a/_src/GameFramework/Map/IHasUnits2D.cs +++ b/_src/GameFramework/Map/IHasUnits2D.cs @@ -13,6 +13,7 @@ public interface IHasUnits2D void MoveUnit(IUnit2D unit2D, Move2D move); IMapObject2D? SimulateMove(IPosition2D position, Move2D move); + IEnumerable GetUnitsAtPortion(IMapObject2D mapObject); IEnumerable GetUnitsAtPortion(IEnumerable mapObjects); IEnumerable GetUnitsAtPortion(IPosition2D topLeft, IPosition2D bottomRight); IEnumerable GetUnitsOfTypeAtPortion(IEnumerable mapObjects) where TUnit : IUnit2D;