Files
4Gewinnt/API/Models/Game/Game.cs
T
Jonas ce52d1462f Add player list and wire repo/manager
Replace the nullable PlayerConnectionIds array with a private List<Player> inside Game and add AddPlayer/RemovePlayer methods to manage membership. Have GameRepository.Create attach the initial player to the newly created game. Implement GameManager.CreateGame and JoinGame to call the repository (using the injected gameRepository) — CreateGame returns the created game's code and JoinGame looks up the game and tries to add the player. Also update imports accordingly. These changes centralize player handling in the Game model and connect repository/manager flows to use it.
2026-03-12 23:20:05 +01:00

33 lines
790 B
C#

using API.Models.DataClasses;
namespace API.Models.Game;
public enum GameState
{
Lobby,
Running,
Ended
}
public class Game(Coordinates gFs, SixDigitInt gameCode)
{
public string Id { get; init; } = Guid.NewGuid().ToString();
public SixDigitInt GameCode { get; } = gameCode;
private List<Player> Players { get; set; } = new();
public GameState State { get; private set; } = GameState.Lobby;
public GameField Field { get; } = new(gFs);
public bool AddPlayer(Player player)
{
if(Players.Count >= 2)
return false;
Players.Add(player);
return true;
}
public void RemovePlayer(string playerConnectionId)
{
Players.RemoveAll(x => x.ConnectionId == playerConnectionId);
}
}