Ejemplo n.º 1
0
        public bool MakeMove(string playerConnectionId, Card card)
        {
            var player = GetPlayerFromConnectionId(playerConnectionId);

            if (player.Cards.FirstOrDefault(x => x.Color == card.Color && x.Number == card.Number) == null)
            {
                return(false);
            }

            if (playerConnectionId != UserTurnToPlay.ConnectionId)
            {
                return(false);
            }


            if (CardsPlayed.Count == Players.Count)
            {
                CardsPlayed.Clear();
            }

            if (CardsPlayed.Count == Players.Count - 1)
            {
                CardsPlayedPreviousRound = CardsPlayed.ToList();
            }

            if (CardsDrew.Count == Players.Count)
            {
                CardsDrew.Clear();
            }

            if (CardsPlayed.Count != 0 && card.Color != _firstCardPlayedInRound.Card.Color && player.Cards.Any(x => x.Color == _firstCardPlayedInRound.Card.Color))
            {
                return(false);
            }


            CardsPlayed.Add(new CardAndUser(card, player.User));

            if (CardsPlayed.Count == Players.Count)
            {
                CardsPlayedPreviousRound = CardsPlayed.ToList();
            }


            _firstCardPlayedInRound = CardsPlayed.FirstOrDefault();
            _strongestCardInRound   = CardsPlayed.Where(x => x.Card.Color == _firstCardPlayedInRound.Card.Color).OrderByDescending(item => item.Card.Strength).First();
            RemoveCardFromHand(player, card);
            ChangePlayersTurn();


            if (CardsPlayed.Count == Players.Count)
            {
                var isLastPoint = Players.Where(x => x.Cards.Any()).Count() == 0;

                UserTurnToPlay = Players.FirstOrDefault(x => x.User.Name == _strongestCardInRound.User.Name).User;
                var teamRoundWinner = Teams.FirstOrDefault(x => x.Users.FirstOrDefault(y => y.ConnectionId == UserTurnToPlay.ConnectionId) != null);

                foreach (var cardPlayed in CardsPlayed)
                {
                    teamRoundWinner.Points += cardPlayed.Card.Value(GameSetup.GameMode);
                }

                if (isLastPoint)
                {
                    teamRoundWinner.Points += 3;

                    if (GameSetup.GameMode == GameMode.Evasion)
                    {
                        // In evasion mode, the spurious points of all players and the excluded cards go to the
                        // player who got the last point.
                        // However, if doing so, the player who got the last point gets maximum points (Cappotto),
                        // he/she transfers the total to each player, and he/she stays at 0 points.
                        foreach (var team in Teams)
                        {
                            if (team.Name != teamRoundWinner.Name)
                            {
                                var spurious = team.Points % 3;
                                teamRoundWinner.Points += spurious;
                                team.Points            -= spurious;
                            }
                        }

                        // Add points from excluded cards
                        // TODO: There should be an animation showing this happening
                        teamRoundWinner.Points += ExcludedCards.Sum(x => x.Value(GameSetup.GameMode));

                        // Cappotto
                        if (Teams.All(x => x.Name == teamRoundWinner.Name || x.Points == 0))
                        {
                            var total = teamRoundWinner.Points;
                            foreach (var team in Teams)
                            {
                                team.Points = total;
                            }
                            teamRoundWinner.Points = 0;
                        }
                    }
                }

                DrawCards();
            }
            if (CardsPlayed.Count == Players.Count && IsFirstRound)
            {
                IsFirstRound = false;
            }

            return(true);
        }
Ejemplo n.º 2
0
        public bool MakeMove(string playerConnectionId, Card card)
        {
            var player = GetPlayerFromConnectionId(playerConnectionId);

            if (player.Cards.FirstOrDefault(x => x.Color == card.Color && x.Number == card.Number) == null)
            {
                return(false);
            }

            if (playerConnectionId != UserTurnToPlay.ConnectionId)
            {
                return(false);
            }


            if (CardsPlayed.Count == Players.Count)
            {
                CardsPlayed.Clear();
            }

            if (CardsPlayed.Count == Players.Count - 1)
            {
                CardsPlayedPreviousRound = CardsPlayed.ToList();
            }

            if (CardsDrew.Count == Players.Count)
            {
                CardsDrew.Clear();
            }

            if (CardsPlayed.Count != 0 && card.Color != _firstCardPlayedInRound.Card.Color && player.Cards.Any(x => x.Color == _firstCardPlayedInRound.Card.Color))
            {
                return(false);
            }


            CardsPlayed.Add(new CardAndUser(card, player.User));

            if (CardsPlayed.Count == Players.Count)
            {
                CardsPlayedPreviousRound = CardsPlayed.ToList();
            }


            _firstCardPlayedInRound = CardsPlayed.FirstOrDefault();
            _strongestCardInRound   = CardsPlayed.Where(x => x.Card.Color == _firstCardPlayedInRound.Card.Color).OrderByDescending(item => item.Card.Strength).First();
            RemoveCardFromHand(player, card);
            ChangePlayersTurn();


            if (CardsPlayed.Count == Players.Count)
            {
                var isLastPoint = Players.Where(x => x.Cards.Any()).Count() == 0;

                UserTurnToPlay = Players.FirstOrDefault(x => x.User.Name == _strongestCardInRound.User.Name).User;
                var teamRoundWinner = Teams.FirstOrDefault(x => x.Users.FirstOrDefault(y => y.ConnectionId == UserTurnToPlay.ConnectionId) != null);

                foreach (var cardPlayed in CardsPlayed)
                {
                    teamRoundWinner.Points += cardPlayed.Card.Value;
                }

                if (isLastPoint)
                {
                    teamRoundWinner.Points += 3;
                }
                DrawCards();
            }
            if (CardsPlayed.Count == Players.Count && IsFirstRound)
            {
                IsFirstRound = false;
            }
            return(true);
        }