Convert field to jagged arrays; add local SignalR UI
Change game field representation to jagged arrays (int[][]) for JSON/SignalR compatibility and add conversion helpers in GameManager. Make Coordinates JSON-serializable (constructor and JsonPropertyName attributes). Update GameHubSocket: validate field size, fix JoinGame parameter order/Group join, rename Place->Drop and send proper game id. Add client-side local play support: GameConnection SignalR client, LocalGame orchestration for two local players, and UI components (GameCreationMenu, Slider) plus GameSettings interface. Update LocalMode route to use the new creation UI and start local games. These changes enable reliable serialization over SignalR and a local two-player flow with a creation UI.
This commit is contained in:
@@ -11,6 +11,12 @@ public class GameHubSocket(IGameManager gameManager) : Hub
|
||||
|
||||
public async Task CreateGame(string playerName, Coordinates gFs)
|
||||
{
|
||||
if (gFs.X <= 0 || gFs.Y <= 0)
|
||||
{
|
||||
await Clients.Caller.SendAsync("Error", "Ungültige Spielfeldgröße.");
|
||||
return;
|
||||
}
|
||||
|
||||
var player = new Player(playerName, Context.ConnectionId);
|
||||
|
||||
var result = _gameManager.CreateGame(gFs, player);
|
||||
@@ -24,7 +30,7 @@ public class GameHubSocket(IGameManager gameManager) : Hub
|
||||
});
|
||||
}
|
||||
|
||||
public async Task JoinGame(int gameCode, string playerName)
|
||||
public async Task JoinGame(string playerName, int gameCode)
|
||||
{
|
||||
var player = new Player(playerName, Context.ConnectionId);
|
||||
|
||||
@@ -36,7 +42,7 @@ public class GameHubSocket(IGameManager gameManager) : Hub
|
||||
return;
|
||||
}
|
||||
|
||||
await Groups.AddToGroupAsync(Context.ConnectionId, gameCode.ToString());
|
||||
await Groups.AddToGroupAsync(Context.ConnectionId, result);
|
||||
|
||||
await Clients.Caller.SendAsync("GameJoined", new
|
||||
{
|
||||
@@ -50,7 +56,7 @@ public class GameHubSocket(IGameManager gameManager) : Hub
|
||||
await _gameManager.RequestGameInformation(gameId, Context.ConnectionId);
|
||||
}
|
||||
|
||||
public async Task Place(string gameId, int column)
|
||||
public async Task Drop(string gameId, int column)
|
||||
{
|
||||
await _gameManager.Drop(gameId, column, Context.ConnectionId);
|
||||
}
|
||||
@@ -61,4 +67,4 @@ public class GameHubSocket(IGameManager gameManager) : Hub
|
||||
|
||||
await base.OnDisconnectedAsync(exception);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user