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;
            }
        }
    }
    // 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();
        }
    }
예제 #3
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");
        }
    }
    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");
    }