public void RestartGame() { if (client == null || !client.IsConnected()) { ConnectPlayer(); } RestartGameRequest request = new RestartGameRequest(); client.SendData((int)DataTypes.RestartGameRequest, request); }
public async Task <IActionResult> RestartGame(RestartGameRequest restartGameRequest) { if (game.GameState != GameState.GameOver) { return(BadRequest("Game not in gameover state")); } if (config["secretCode"] != restartGameRequest.SecretCode) { return(BadRequest("Secret code doesn't match, unable to restart game.")); } game.Restarting(); return(Ok()); }
private void ProcessRestartGameRequest(RestartGameRequest request, int clientID) { Console.WriteLine($"Request to restart game from player {clientID}"); Player player = players.FirstOrDefault(p => p.ClientID == clientID); if (player == null) { Console.WriteLine($"Player {clientID} doesn't exist"); return; } if (player.Match == null) { Console.WriteLine($"Player {clientID} is not in the game"); return; } GameMatch match = player.Match; if (!match.IsRunning) { Console.WriteLine($"Match isn't running"); return; } int[,] field = CreateField(match.Width - match.Difficulty, match.Height - match.Difficulty); StartGameResponse response = new StartGameResponse(); response.CardPackName = match.CardPackName; response.Difficulty = match.Difficulty; response.PlayerID = 0; response.Field = field; Server.SendDataToClient(match.Player1.ClientID, (int)DataTypes.StartGameResponse, response); response.PlayerID = 1; Server.SendDataToClient(match.Player2.ClientID, (int)DataTypes.StartGameResponse, response); Console.WriteLine($"Player {clientID} successfully joined"); }