/// <inheritdoc/> public void ExpelPlayer(ExpelVoteDto expelVote) { string host = expelVote.Host; ServiceMatch gameMatch = GetMatch(host); string usernameOfExpelPlayer = expelVote.UsernameOfExpelPlayer; int playerExpelVotes = gameMatch.AddExpelVote(usernameOfExpelPlayer); ServicePlayer voterPlayer = gameMatch.GetPlayer(expelVote.UsernameOfVoterPlayer); voterPlayer.AddPlayerVoted(usernameOfExpelPlayer); IList <ServicePlayer> playersInMatch = gameMatch.GetPlayersConnectedToMatch(); int numOfPlayers = playersInMatch.Count; if (playerExpelVotes > (numOfPlayers / 2)) { ServicePlayer playerWithActiveTurn = gameMatch.GetPlyerWithActiveTurn(); ServicePlayer expelPlayer = gameMatch.GetPlayer(usernameOfExpelPlayer); if (playerWithActiveTurn.Username.Equals(usernameOfExpelPlayer)) { expelPlayer = playerWithActiveTurn; int indexOfPlayerWithCurrentTurn = gameMatch.GetPlayersConnectedToMatch().IndexOf(playerWithActiveTurn); indexOfPlayerWithCurrentTurn = ChangeTurn(gameMatch, indexOfPlayerWithCurrentTurn); ServicePlayer nextPlayer = gameMatch.GetPlayersConnectedToMatch()[indexOfPlayerWithCurrentTurn]; playerWithActiveTurn.HasActiveTurn = false; nextPlayer.HasActiveTurn = true; foreach (var playerInMatch in playersInMatch) { playerInMatch.MatchServiceConnection.EndTurnOfExpelPlayer(nextPlayer.Username); } } IList <int> cardsUncovered = expelPlayer.GetUncoveredCards(); foreach (var playerConnected in playersInMatch) { var channel = playerConnected.MatchServiceConnection; channel.NotifyPlayerWasExpel(usernameOfExpelPlayer, cardsUncovered); } RemovePairs(gameMatch, cardsUncovered); gameMatch.RemovePlayer(usernameOfExpelPlayer); if (playersInMatch.Count == 1) { this.NotifyMatchHasEnded(host); } } }
private void VoteToExpelPlayer() { var selectedPlayer = ExpelPlayerDataGrid.SelectedItem; if (selectedPlayer != null) { string usernameOfSelectedPlayer = selectedPlayer.ToString(); ExpelVoteDto expelVote = new ExpelVoteDto() { Host = MatchHost, UsernameOfExpelPlayer = usernameOfSelectedPlayer, UsernameOfVoterPlayer = PlayerUsername }; _matchServiceClient.ExpelPlayer(expelVote); } else { MessageBox.Show(Properties.Langs.Resources.SelectPlayerToBeExpeled); } }