Return game ID+code; update hub and Player model

Change GameManager/CreateGame to return (gameId, gameCode) and Make JoinGame return the game Id (or null) instead of a bool. Update IGameManager signature accordingly. Refactor Hub methods to construct Player objects, accept Coordinates for game creation, use the manager results to add connections to groups and send GameCreated with GameId and GameCode, and handle join failures with an error message. Simplify Player class to use a primary-constructor style with property initialization; add necessary using directives.
This commit is contained in:
Jonas
2026-03-01 20:43:18 +01:00
parent ce52d1462f
commit 85521f3b23
4 changed files with 41 additions and 16 deletions
+6 -4
View File
@@ -6,17 +6,19 @@ namespace API.Services.GameManager;
public class GameManager(IGameRepository gameRepository) : IGameManager
{
public int CreateGame(Coordinates gFs, Player player)
public (string, int) CreateGame(Coordinates gFs, Player player)
{
var game = gameRepository.Create(gFs, player);
return game.GameCode;
return (game.Id, game.GameCode);
}
public bool JoinGame(Player player, int gameCode)
public string? JoinGame(Player player, int gameCode)
{
var game = gameRepository.GetOne(new SixDigitInt(gameCode));
return game != null && game.AddPlayer(player);
var success = game != null && game.AddPlayer(player);
return success ? game?.Id : null;
}
}
+2 -2
View File
@@ -4,6 +4,6 @@ namespace API.Services.GameManager;
public interface IGameManager
{
public int CreateGame(Coordinates gFs, Player player);
public bool JoinGame(Player playerName, int gameCode);
public (string, int) CreateGame(Coordinates gFs, Player player);
public string? JoinGame(Player playerName, int gameCode);
}