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:
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
Reference in New Issue
Block a user