Skip to content

Commit

Permalink
minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
joshika39 committed Nov 14, 2023
1 parent 90ca8a0 commit 8f7d684
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 12 deletions.
4 changes: 2 additions & 2 deletions Nuget/.projects.conf
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
GameFramework.Core:1.5.5
GameFramework.UI.WPF:1.2.4
GameFramework.Core:1.5.6
GameFramework.UI.WPF:1.2.5
18 changes: 8 additions & 10 deletions _src/GameFramework.Impl/Core/GameManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,13 @@ namespace GameFramework.Impl.Core
{
internal class GameManager : IGameManager
{
private readonly IConfigurationService2D _configurationService;
private readonly ICollection<IGameStateChangedListener> _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<IGameStateChangedListener>();
State = GameState.NotStarted;
Expand All @@ -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)
Expand All @@ -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);
Expand All @@ -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()
Expand All @@ -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()
Expand All @@ -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)
Expand Down
14 changes: 14 additions & 0 deletions _src/GameFramework.Impl/Map/AMap2D.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,14 @@ public virtual IEnumerable<IMapObject2D> MapPortion(IPosition2D center, int radi
#endregion

#region Units
public IEnumerable<IUnit2D> GetUnitsAtPortion(IMapObject2D mapObject)
{
return GetUnitsAtPortion(new[]
{
mapObject
});
}

public virtual IEnumerable<IUnit2D> GetUnitsAtPortion(IEnumerable<IMapObject2D> mapObjects)
{
var units = new List<IUnit2D>();
Expand Down Expand Up @@ -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);
}

Expand Down
1 change: 1 addition & 0 deletions _src/GameFramework/Map/IHasUnits2D.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public interface IHasUnits2D

void MoveUnit(IUnit2D unit2D, Move2D move);
IMapObject2D? SimulateMove(IPosition2D position, Move2D move);
IEnumerable<IUnit2D> GetUnitsAtPortion(IMapObject2D mapObject);
IEnumerable<IUnit2D> GetUnitsAtPortion(IEnumerable<IMapObject2D> mapObjects);
IEnumerable<IUnit2D> GetUnitsAtPortion(IPosition2D topLeft, IPosition2D bottomRight);
IEnumerable<TUnit> GetUnitsOfTypeAtPortion<TUnit>(IEnumerable<IMapObject2D> mapObjects) where TUnit : IUnit2D;
Expand Down

0 comments on commit 8f7d684

Please sign in to comment.