/// <summary> /// Gets a specific player connected in the match by the username given. /// </summary> /// <param name="username">Username of the player to get.</param> /// <returns>A PlayerInMatch object.</returns> public ServicePlayer GetPlayer(string username) { ServicePlayer playerRetrieved = null; foreach (var player in _players) { if (player.Username.Equals(username)) { return(player); } } return(playerRetrieved); }
/// <summary> /// Gets the player with the best score in the match. /// </summary> /// <returns>A PlayerInMatch object.</returns> public ServicePlayer GetPlayerWithBestScore() { ServicePlayer playerWithBestScore = _players[0]; for (int currentIndex = 0; currentIndex < _players.Count - 1; currentIndex++) { if (playerWithBestScore.Score < _players[currentIndex + 1].Score) { playerWithBestScore = _players[currentIndex + 1]; } } return(playerWithBestScore); }
/// <summary> /// Get the playuer with the active turn in the match form the list of connected players. /// </summary> /// <returns>A PlayerInMatch Object</returns> public ServicePlayer GetPlyerWithActiveTurn() { ServicePlayer playerWithActiveTurn = null; foreach (var player in _players) { if (player.HasActiveTurn) { playerWithActiveTurn = player; } } return(playerWithActiveTurn); }
/// <summary> /// Removes a player from the list of connected players in the match. /// </summary> /// <param name="playerUsername">Username of the player to remove.</param> public void RemovePlayer(string playerUsername) { ServicePlayer playerToRemove = this.GetPlayer(playerUsername); _players.Remove(playerToRemove); }
/// <summary> /// Adds a player to the list of players connected to the match. /// </summary> /// <param name="player">Contains the player information.</param> public void AddPlayer(ServicePlayer player) { _players.Add(player); }