Add player tags, game lifecycle and win checks

Additions and refactors across controllers, models, repo and services to support game lifecycle and win detection. Key changes:

- Models: Player now has PlayerTag; Game assigns tags, starts when 2 players join, exposes GetPlayerByConnectionId, StartGame and EndGame helpers.
- GameField: Implemented win-detection (CountInDirection, CheckLine, CheckForWin) and minor backing-field init.
- Repository/API: GameRepository.Create no longer accepts a Player (repo only creates games); minor variable cleanups; IGameRepository signature updated accordingly.
- Services: GameManager now injects IHubContext<GameHubSocket>, moves player-adding into manager (CreateGame), makes JoinGame async and notifies the SignalR group when a game starts, and adds a placeholder async Place method. Controller (GameHubSocket) also exposes a Place method stub to match the service API.

Motivation: separate responsibilities so repository only creates games, manager handles player joins and notifications, and add core game logic (player tagging and win checks) needed for gameplay. Place methods are added as placeholders for future move handling.
This commit is contained in:
Jonas
2026-03-03 19:12:54 +01:00
parent 85521f3b23
commit 955d1e18c6
8 changed files with 104 additions and 13 deletions
+3 -4
View File
@@ -22,11 +22,10 @@ public class GameRepository : IGameRepository
return _games.FirstOrDefault(g => g.GameCode == gameCode);
}
public Game Create(Coordinates gameFieldSize, Player player)
public Game Create(Coordinates gameFieldSize)
{
Game newGame = new(gameFieldSize, GenerateGameCode());
_games.Add(newGame);
newGame.AddPlayer(player);
return newGame;
}
@@ -40,9 +39,9 @@ public class GameRepository : IGameRepository
{
while (true)
{
int value = RandomNumberGenerator.GetInt32(100000, 1000000);
var value = RandomNumberGenerator.GetInt32(100000, 1000000);
bool exists = _games.Any(g => g.GameCode.Value == value);
var exists = _games.Any(g => g.GameCode.Value == value);
if (!exists)
{
return new SixDigitInt(value);