private void RemovePlayingCards()
    {
        List <GameObject> cards = CardsPlayed.GetAsGameObject();

        foreach (var c in cards)
        {
            StartCoroutine(LerpCardY(c, 20.0f, 3.0f, true, false));
        }
    }
    private void Start()
    {
        //using the do, while loop, prevent multiple of the same card from spawning
        bool matchFound = false;

        do
        {
            //randomly generate the string used to find the correct card image
            suitNum = Random.Range(0, 4);
            cardNum = Random.Range(1, 14);

            for (int i = 0; i < CardsPlayed.GetCount(); i++)
            {
                if (CardsPlayed.Get()[i][0] == suitNum && CardsPlayed.Get()[i][1] == cardNum)
                {
                    Debug.Log("there was a card match, resolving issue.");
                    matchFound = true;
                    break;
                }
                else if (i + 1 == CardsPlayed.GetCount())
                {
                    //if all cards which were played were checked and no matches were flagged then set the bool to false
                    matchFound = false;
                }
            }
        } while (matchFound);

        string cardName = "card_" + _suit[suitNum] + "_" + cardNum;

        Debug.Log(cardName);

        transform.GetChild(0).GetComponent <SpriteRenderer>().sprite = Resources.Load <Sprite>("card_faces/" + cardName);

        //store this new card within the played cards list
        CardsPlayed.UpdateList(suitNum, cardNum, this.gameObject);

        //determine if the card that has been spawned is higher or lower than the previous card
        if (!IsFirstRound)
        {
            //check whether the cards value, ignoring the suit is the same as or higher than the card that was played before this one
            if (CardsPlayed.GetPrevCard()[1] >= CardsPlayed.GetPrevCard(1)[1])
            {
                Debug.Log("New card is higher than previous");
                Guess.NewCardHigher = true;
            }
            else
            {
                Debug.Log("New card is lower than previous");
                Guess.NewCardHigher = false;
            }
        }
    }
    private void DestroyCards()
    {
        List <GameObject> cards = CardsPlayed.GetAsGameObject();

        //removal all the cards
        foreach (var c in cards)
        {
            Destroy(c);
        }
        CardsPlayed.RemoveAll();

        _removingCards = false;

        //reset card pos
        cardRestPos = initalCardPos;
    }
    // Update is called once per frame
    private void Update()
    {
        //spawn a new playing card but set a limit of 6 on screen at once, then move the card to the centre of the screen
        if (State.Get() == State.GameState.SpawnPlayingCard && CardsPlayed.GetCount() < 6 && CardsPlayed.TotalCardsPlayedCount < 12)
        {
            PickCard();
        }

        //remove all the playing cards off the screen
        if (State.Get() == State.GameState.SpawnPlayingCard && !_removingCards && CardsPlayed.Get().Count > 0)
        {
            _removingCards = true;

            RemovePlayingCards();
        }
    }
Ejemplo n.º 5
0
    // Update is called once per frame
    private void Update()
    {
        //spawns the outcome popup
        if (State.Get() == State.GameState.ShowOutputPopup && !IsFirstRound)
        {
            GameObject showOutcomePopup = Instantiate(popupShowOutcome, Vector3.zero, Quaternion.identity) as GameObject;

            State.Increment();
        }
        //allow the usual game state progression order to be bypassed for the first round
        else if (State.Get() == State.GameState.ShowOutputPopup && IsFirstRound)
        {
            //instantly go to making a guess without showing an outcome
            State.Set(State.GameState.ShowGuessPopup);
            IsFirstRound = false;
        }

        //spawns the MakeGuess popup
        if (State.Get() == State.GameState.ShowGuessPopup && CardsPlayed.GetCount() < 6)
        {
            GameObject makeGuessPopup = Instantiate(popupMakeGuess, Vector3.zero, Quaternion.identity) as GameObject;

            State.Increment();
        }

        //if all the playing cards have been played then begin the next stage
        if (State.Get() == State.GameState.ShowGuessPopup && CardsPlayed.GetCount() == 6)
        {
            Instantiate(popupCardOutcome, Vector3.zero, Quaternion.identity);

            State.Set(State.GameState.MoveOutputCard);
        }

        //if all cards outcomes have been shown, now display the results
        if (State.Get() == State.GameState.ShowResults)
        {
            Instantiate(popupResults, Vector3.zero, Quaternion.identity);

            State.Increment();
        }

        //return to menu if in the return to menu state
        if (State.Get() == State.GameState.ReturnToMenu)
        {
            SceneManager.LoadScene("Menu");
        }
    }
Ejemplo n.º 6
0
 public void InitializeNewGame()
 {
     Deck = GenerateDeck();
     foreach (var player in Players)
     {
         player.Cards = Deck.GetAndRemove(0, 10);
         player.ExtraPoints.Clear();
     }
     foreach (var team in Teams)
     {
         team.Points = 0;
     }
     CardsPlayed.Clear();
     CardsDrew.Clear();
     CardsPlayedPreviousRound.Clear();
     RoundEnded   = false;
     IsFirstRound = true;
 }
    private IEnumerator LerpCardTransform(GameObject c, Vector3 finalPos, Vector3 finalScale, float speed)
    {
        float     lerpTimer     = 0.0f;
        Transform cardTransform = c.transform;

        //Transform t = c.transform;

        while (lerpTimer < speed)
        {
            lerpTimer += Time.deltaTime;

            float deltaT = lerpTimer / speed;

            //perform the lerps
            cardTransform.localPosition = Vector3.Lerp(cardTransform.localPosition, finalPos, deltaT);
            cardTransform.localScale    = Vector3.Lerp(cardTransform.localScale, finalScale, deltaT);

            //apply the transformations
            c.transform.position   = cardTransform.position;
            c.transform.localScale = cardTransform.localScale;

            yield return(null);
        }

        //ensure that this card will always be behind any new cards
        currentCard.GetComponent <SpriteRenderer>().sortingOrder = 1;
        currentCard.transform.GetChild(0).GetComponent <SpriteRenderer>().sortingOrder = 2;

        //ensure the scale once the lerp finishes is exactly 0.3f
        currentCard.transform.localScale = new Vector3(0.3f, 0.3f, 0.3f);

        //move the position for where the next card will spawn
        cardRestPos = new Vector3(cardRestPos.x + 3.5f, cardRestPos.y, 0.0f);
        if (CardsPlayed.GetCount() == 3)
        {
            cardRestPos = new Vector3(initalCardPos.x, cardRestPos.y - 4.6f, 0.0f);
        }

        //now that the card has stopped moving, move to the next state
        State.Increment();
        Debug.Log("Card has reached its destination");
    }
Ejemplo n.º 8
0
        public void InitializeNewGame()
        {
            Deck = GenerateDeck();
            ChooseFirstRoundPlayer();

            ExcludedCards.Clear();

            var cardsPerPlayer = 10;
            var excludedCards  = 0;

            // In evasion mode, cards are distributed "evenly" between players, with some cards remaining out,
            // when 3 or 5 players are playing. If 2 or 4 players are playing, 10 cards each are given, like
            // in plain mode.
            // I some cards remain out, they will be given to the player who got the last point.
            if (GameSetup.GameMode == GameMode.Evasion)
            {
                if (Players.Count != 2 && Players.Count != 4)
                {
                    cardsPerPlayer = Deck.Count / Players.Count;
                    excludedCards  = Deck.Count % Players.Count;
                }
            }

            foreach (var player in Players)
            {
                player.Cards = Deck.GetAndRemove(0, cardsPerPlayer);
                player.ExtraPoints.Clear();
            }

            ExcludedCards = Deck.GetAndRemove(0, excludedCards);

            foreach (var team in Teams)
            {
                team.Points = 0;
            }
            CardsPlayed.Clear();
            CardsDrew.Clear();
            CardsPlayedPreviousRound.Clear();
            RoundEnded   = false;
            IsFirstRound = true;
        }
Ejemplo n.º 9
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.º 10
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.º 11
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);
    }