Example #1
0
        /// <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);
                }
            }
        }
Example #2
0
        /// <inheritdoc/>
        public void NotifyCardWasUncoveredd(PlayerMovementDto playerMovementDto)
        {
            string       host      = playerMovementDto.Host;
            ServiceMatch gameMatch = GetMatch(host);

            ServicePlayer player = gameMatch.GetPlayer(playerMovementDto.Username);

            if (playerMovementDto.HasFormedAPair)
            {
                player.AddUncoveredCard(playerMovementDto.CardIndex);
                gameMatch.TotalPairs++;
            }
            else
            {
                if (playerMovementDto.MovementsLeft == 0)
                {
                    player.RemoveUncoveredCard();
                }
                else
                {
                    player.AddUncoveredCard(playerMovementDto.CardIndex);
                }
            }

            IList <ServicePlayer> playersInMatch = gameMatch.GetPlayersConnectedToMatch();

            foreach (var playerInMatch in playersInMatch)
            {
                playerInMatch.MatchServiceConnection.UncoverCardd(playerMovementDto.CardIndex);
            }
        }
Example #3
0
        /// <inheritdoc/>
        public void EndTurn(string host, string username, CardPairDto cardPairDto)
        {
            ServiceMatch  gameMatch = GetMatch(host);
            ServicePlayer player    = gameMatch.GetPlayer(username);
            int           indexOfPlayerWithCurrentTurn = gameMatch.GetPlayersConnectedToMatch().IndexOf(player);

            if (cardPairDto.BothCardsAreEqual)
            {
                player.Score += 100;
            }
            else
            {
                indexOfPlayerWithCurrentTurn = ChangeTurn(gameMatch, indexOfPlayerWithCurrentTurn);
            }

            ServicePlayer nextPlayer = gameMatch.GetPlayersConnectedToMatch()[indexOfPlayerWithCurrentTurn];

            player.HasActiveTurn     = false;
            nextPlayer.HasActiveTurn = true;

            IList <ServicePlayer> playersInMatch = gameMatch.GetPlayersConnectedToMatch();

            foreach (var playerInMatch in playersInMatch)
            {
                playerInMatch.MatchServiceConnection.NotifyTurnHasEnded(nextPlayer.Username, cardPairDto);
            }

            if (gameMatch.TotalPairs == gameMatch.ServiceCardDeck.NumberOfPairs)
            {
                this.NotifyMatchHasEnded(host);
            }
        }
Example #4
0
        /// <inheritdoc/>
        public IList <string> GetPlayersVoted(string host, string username)
        {
            ServiceMatch gameMatch = GetMatch(host);

            ServicePlayer  player       = gameMatch.GetPlayer(username);
            IList <string> playersVoted = player.GetPlayersVoted();

            return(playersVoted);
        }
Example #5
0
        /// <inheritdoc/>
        public void LeaveMatch(string host, string username)
        {
            ServiceMatch gameMatch = GetMatch(host);

            IList <ServicePlayer> playersInMatch       = gameMatch.GetPlayersConnectedToMatch();
            ServicePlayer         playerWithActiveTurn = gameMatch.GetPlyerWithActiveTurn();
            ServicePlayer         leavePlayer          = gameMatch.GetPlayer(username);

            if (playerWithActiveTurn.Username.Equals(username))
            {
                leavePlayer = 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 = leavePlayer.GetUncoveredCards();

            foreach (var playerConnected in playersInMatch)
            {
                var channel = playerConnected.MatchServiceConnection;
                channel.NotifyPlayerLeaveMatch(username, cardsUncovered);
            }

            RemovePairs(gameMatch, cardsUncovered);
            gameMatch.RemovePlayer(username);

            if (playersInMatch.Count == 1)
            {
                this.NotifyMatchHasEnded(host);
            }
        }