public ActionResult Join(string playerId, string playerNick) { if (_players.Any(p => p.Id == playerId)) { return(new ActionResult(false, "Player already registered")); } if (_players.Any(p => p.PlayerNick == playerNick)) { return(new ActionResult(false, "Name already in use")); } if (_players.Count >= _config.nPlayersMax) { return(new ActionResult(false, "Game is full")); } if (_started) { return(new ActionResult(false, "Game has already started")); } var newPlayer = new ConnectFourPlayer { Id = playerId, PlayerNick = playerNick, PlayerColor = _colors[_players.Count], IsHost = _config.CreatorId == playerId }; _players.Add(newPlayer); return(new ActionResult(true)); }
private void UpdateWinByResignations() { if (_players.Count(p => !p.Resigned) < 2) { _gameOver = true; _winner = _players.FirstOrDefault(p => !p.Resigned); _winner.Wins++; } }
private void UpdateWinConventional() { var gameWinnerColor = _game.GetWinner(); if (gameWinnerColor != null) { _winner = _players.FirstOrDefault(p => p.PlayerColor == gameWinnerColor); _winner.Wins++; _gameOver = true; } }