From bec5df7e88ca841d487e2a80bf7a113922bd795f Mon Sep 17 00:00:00 2001 From: Jonas <77726472+kobolol@users.noreply.github.com> Date: Thu, 5 Mar 2026 17:33:56 +0100 Subject: [PATCH] Add turn tracking and enforce turn order Introduce CurrentTurn to Game (default 1) and expose it via GameInformationDto. Update GameManager to include CurrentTurn in the GameInformation payload, validate that a player can only Drop when it is their turn, and toggle CurrentTurn between 1 and 2 after a successful move. Also use a safe fallback (0) when game is null. --- API/Models/Game/Game.cs | 1 + API/Models/Game/GameInformationDto.cs | 1 + API/Services/GameManager/GameManager.cs | 8 +++++++- 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/API/Models/Game/Game.cs b/API/Models/Game/Game.cs index 43ebb25..1c786d4 100644 --- a/API/Models/Game/Game.cs +++ b/API/Models/Game/Game.cs @@ -14,6 +14,7 @@ public class Game(Coordinates gFs, SixDigitInt gameCode) public string Id { get; init; } = Guid.NewGuid().ToString(); public SixDigitInt GameCode { get; } = gameCode; public List Players { get; set; } = new(); + public int CurrentTurn { get; set; } = 1; public GameState State { get; private set; } = GameState.Lobby; public GameField Field { get; } = new(gFs); diff --git a/API/Models/Game/GameInformationDto.cs b/API/Models/Game/GameInformationDto.cs index d3dfa51..108a2f3 100644 --- a/API/Models/Game/GameInformationDto.cs +++ b/API/Models/Game/GameInformationDto.cs @@ -6,5 +6,6 @@ public List Players { get; set; } public GameState? State { get; set; } public int[,] CurrentField { get; set; } + public int CurrentTurn { get; set; } } } diff --git a/API/Services/GameManager/GameManager.cs b/API/Services/GameManager/GameManager.cs index 362cad8..446ed13 100644 --- a/API/Services/GameManager/GameManager.cs +++ b/API/Services/GameManager/GameManager.cs @@ -43,7 +43,8 @@ public class GameManager(IGameRepository gameRepository, IHubContext