Beispiel #1
0
    private void Update()
    {
        if (isShowingWinPattern)
        {
            int      btnIdx = winPattern[showPatternIdx];
            Animator anim   = pushButtons[btnIdx].GetComponent <Animator>();

            bool activated = anim.GetBool("HasBeenActivated");

            if (!activated)
            {
                anim.SetBool("Activate", true);
                timeSinceLastActivation = 0;

                pushButtons[btnIdx].PlayButtonSound();
            }
            else if (timeSinceLastActivation > pauseTimeBetweenButtonActivations)
            {
                // Button was lit up reset to light next one (if more to light)
                anim.SetBool("HasBeenActivated", false);

                isShowingWinPattern = (++showPatternIdx) < winPattern.Count;
            }

            timeSinceLastActivation += Time.deltaTime;
        }

        if (isCheckingPlayerGuesses)
        {
            //Debug.Log("Checking Player Guesses");
            if (playerGuessQueue.Count > 0)
            {
                PushButton btn  = playerGuessQueue.Peek();
                Animator   anim = btn.gameObject.GetComponent <Animator>();

                bool activated = anim.GetBool("HasBeenActivated");

                if (!activated)
                {
                    anim.SetBool("Activate", true);

                    btn.PlayButtonSound();
                }
                else
                {
                    // Button was lit up reset to light next one (if more to light)
                    anim.SetBool("HasBeenActivated", false);

                    // Remove the guess from the queue
                    btn = playerGuessQueue.Dequeue();

                    if (playerGuessIdx >= winPattern.Count)
                    {
                        Debug.Log("Too many guesses");
                        isLastPlayerGuessCorrect = false;
                        isCheckingPlayerGuesses  = false;
                    }
                    else
                    {
                        // Check the guess for correctness.
                        int btnIdx = winPattern[playerGuessIdx++];

                        if (pushButtons[btnIdx] == btn)
                        {
                            isLastPlayerGuessCorrect = true;
                            //Debug.Log("Correct guess, more? " + ((playerGuessIdx < winPattern.Count) ? "Yes." : "No."));
                        }
                        else
                        {
                            Debug.Log("Wrong guess");
                            isLastPlayerGuessCorrect = false;
                            isCheckingPlayerGuesses  = false;
                        }

                        // Check the guess count against the number of buttons in the win pattern.
                        if (playerGuessIdx == winPattern.Count)
                        {
                            isCorrectGuessCount = true;
                        }
                    }

                    hasBegunCheckingGuesses = true;
                }
            }

            if (hasBegunCheckingGuesses)
            {
                hasCheckDelayEnded = ((Time.time - timeOfLastGuess) > 1 && playerGuessQueue.Count == 0);
            }
        }
    }