public void StartNextRound(string gameId) { CardGame cardGame = cardGameRepository.GetCardGame(gameId); if (cardGame == null) { throw new NullReferenceException(); } else { cardGame.Players.ForEach(player => { if (player.HasCompletedPhase) { int value = (int)player.Phase.PhaseType; value++; PhaseType nextPhase = (PhaseType)value; player.Phase = phaseService.CreateNewPhase(player.Id, nextPhase); player.HasCompletedPhase = false; } else { player.Phase = phaseService.CreateNewPhase(player.Id, player.Phase.PhaseType); } player.Stage = Stage.Waiting; }); int startPlayerIndex = cardGame.Players.FindIndex(player => player.Id == cardGame.StartPlayerId); startPlayerIndex = (startPlayerIndex + 1) % cardGame.Players.Count; cardGame.Players[startPlayerIndex].Stage = Stage.Draw; cardGame.DealRound(); cardGame.SetActivePlayer(cardGame.Players[startPlayerIndex].Id); cardGame.StartPlayerId = cardGame.Players[startPlayerIndex].Id; cardGameRepository.UpdateGame(cardGame); } }
public void StartNewGame(string lobbyId) { var lobby = lobbyService.GetLobby(lobbyId); if (lobby == null) { throw new NullReferenceException("Lobby could not be found"); } else { CardGame cardGame = cardGameRepository.CreateNewGame(lobbyId, lobby.Players); cardGame.Players.ForEach(player => { player.Phase = phaseService.CreateNewPhase(player.Id, PhaseType.One); player.Stage = Stage.Waiting; }); cardGame.Players[0].Stage = Stage.Draw; cardGame.DealRound(); cardGame.SetActivePlayer(cardGame.Players[0].Id); cardGame.StartPlayerId = cardGame.Players[0].Id; cardGameRepository.UpdateGame(cardGame); lobbyHub.Clients.Group(lobbyId).StartGame(); } }