/// <summary> /// Removes a player from this match and stops the required timers /// </summary> /// <param name="playerUid">Unique uid of this player</param> /// <returns>true if a player was removed, false if no player was removed</returns> public bool RemovePlayer(string playerUid) { var player = Players.FirstOrDefault(p => p.Uid == playerUid); if (player != null) { Players.Remove(player); PlayedPlayers.Remove(player); if (Players.Count < 2) { StopMatch(); } else { if (player.Status == PlayerStatus.Drawing) { StopSubRoundTimer(); } else if (player.Status == PlayerStatus.Preparing) { StopPreparationTimer(); StopSubRoundTimer(); } } PlayerRemoved?.Invoke(this, new PlayerRemovedEventArgs(playerUid)); return(true); } return(false); }
private Player GetPlayerWhoHasNotPlayed() { foreach (var player in Players) { if (!PlayedPlayers.Contains(player)) { return(player); } } return(null); }
private void Match_SubRoundFinished(object sender, EventArgs e) { WordToDraw = null; RemainingTime = RoundLength; ResetHasGuessed(); var player = GetCurrentlyDrawingPlayer(); if (player != null) { player.Status = PlayerStatus.Guessing; PlayedPlayers.Add(player); } if (PlayedPlayers.Count >= Players.Count) { //Runde Beendet PlayedPlayers.Clear(); RoundFinished?.Invoke(this, EventArgs.Empty); if (CurrentRound == Rounds) { IsRunning = false; IsFinished = true; MatchFinished?.Invoke(this, EventArgs.Empty); return; } CurrentRound++; RoundStarted?.Invoke(this, new RoundStartedEventArgs(CurrentRound)); } player = GetPlayerWhoHasNotPlayed(); StartPreparationTimer(player); }