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;
                }

                if (isLastPoint)
                {
                    teamRoundWinner.Points += 3;
                }
                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(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.º 3
0
    public int PlayCards()
    {
        //TODO: Find the cards that are outside of the hand panel
        //      if they aren't in the play panel return them to the hand
        //      if they are in the play panel reveal them
        int  nCardsPlayed    = 0;
        bool bMomentumPlayed = false;

        m_bBlockCardPlayed = false;

        int nAttackValue = 0;

        m_nHighestAttackValuePlayed = 0;

        //Debug.Log(hand.Count.ToString());

        //Set the amount of cards playable based on a combo card being played or momentum card played
        for (int i = hand.Count - 1; i > -1; i--)
        {
            GameObject card = hand[i] as GameObject;
            if (CheckCollisionWithPlayPanel(card))
            {
                nCardsPlayed++;

                if (card.GetComponent <CardDetails>().CardName == CardDetails.Card_Name.MOMENTUM)
                {
                    bMomentumPlayed = true;
                }
                else if (card.GetComponent <CardDetails>().CardType == CardDetails.Card_Type.COMBO)
                {
                    AmountOfCardsPlayable += card.GetComponent <CardDetails>().nComboAmount;
                }
            }
        }

        //Debug.Log("Cards played = " + nCardsPlayed.ToString());
        //Debug.Log("Amount of playable cards = " + AmountOfCardsPlayable.ToString());


        // Check to see if amount of cards played is greater than nAmountOfCardsPlayable
        if (nCardsPlayed > AmountOfCardsPlayable)
        {
            //intantiate a warning to player that they are not playing a valid amount of cards
            return(-1); // this will play the warning sound
        }

        // Resolve play of any additional cards based on how many cards are playable

        //Seperate out the cards into the PlayedCards array
        for (int i = hand.Count - 1; i > -1; i--)
        {
            GameObject card = hand[i] as GameObject;
            if (CheckCollisionWithPlayPanel(card))
            {
                CardsPlayed.Add(card);
                //Destroy(card);
                hand.RemoveAt(i);
            }
        }

        // Debug.Log("Hand size = " + hand.Count.ToString());
        //Debug.Log("Play Amount = " + CardsPlayed.Count.ToString());

        // Play the cards; starting with the attack cards
        // If there is a movement card that cannot be used, move it to the sstaging area for the next turn
        for (int i = CardsPlayed.Count - 1; i > -1; i--)
        {
            GameObject card = CardsPlayed[i] as GameObject;

            if (card.GetComponent <CardDetails>().CardType == CardDetails.Card_Type.ATTACK)
            {
                //Does the attack card require a movement
                if (card.GetComponent <CardDetails>().bRequiresMovement == true)
                {
                    //If yes, do we have the movement card (look through CardsPlayed and
                    if (HaveRequiredMovementCard(card.GetComponent <CardDetails>().MovementRequired))
                    {
                        //if yes, nAttackValue += the card's attack value
                        nAttackValue += card.GetComponent <CardDetails>().nAttackValue;
                        SetHighestAttackValue(card.GetComponent <CardDetails>().nAttackValue);

                        Debug.Log("Movement card found and attack applied");
                    }
                    else //If no, set the card to destroy
                    {
                        //discard is happening automatically for all cards played unless it is the last movement card
                    }
                }
                else //If no, nAttackValue += the card's attack value
                {
                    nAttackValue += card.GetComponent <CardDetails>().nAttackValue;
                    SetHighestAttackValue(card.GetComponent <CardDetails>().nAttackValue);
                }
            }
        }

        int  card_tobe_removed = 0;
        int  currentcard       = 0;
        bool bremovecard       = false;

        foreach (GameObject card in CardsPlayed)
        {
            if (card.GetComponent <CardDetails>().CardType == CardDetails.Card_Type.MOVEMENT)
            {
                if (card.GetComponent <CardDetails>().CardName == CardDetails.Card_Name.BLOCK ||
                    card.GetComponent <CardDetails>().CardName == CardDetails.Card_Name.BOXING_BLOCK)
                {
                    m_bBlockCardPlayed = true;
                }
                else
                {
                    if (card.GetComponent <CardDetails>().IsSetToBeUsed() == true)
                    {
                        continue;
                    }
                    else if (StagedMovementCard == null)
                    {
                        StagedMovementCard = Instantiate(card);                                          //new GameObject(card);
                        StagedMovementCard.transform.SetParent(stagingPanelObject.transform);
                        StagedMovementCard.transform.position   = stagingPanelObject.transform.position; //card.transform.position = stagingPanelObject.transform.position;
                        StagedMovementCard.transform.localScale = new Vector3(1.0f, 1.0f, 1.0f);
                        //CardsPlayed.Remove(card);
                        card_tobe_removed = currentcard;
                        bremovecard       = true;
                    }
                }
            }

            currentcard++;
        }

        if (bremovecard == true)
        {
            GameObject tempCard = CardsPlayed[card_tobe_removed] as GameObject;
            CardsPlayed.RemoveAt(card_tobe_removed);
            Destroy(tempCard);
        }


        if (StagedMovementCard != null)
        {
            if (StagedMovementCard.GetComponent <CardDetails>().nTurnsLasted >= 1)
            {
                Destroy(StagedMovementCard);
                StagedMovementCard = null;
            }
            if (StagedMovementCard != null)
            {
                StagedMovementCard.GetComponent <CardDetails>().nTurnsLasted += 1;
            }
        }


        UpdateCards();

        //reset the amount of cards playable
        AmountOfCardsPlayable = 1;

        return(nAttackValue);
    }