Пример #1
0
        // While this is running, the shells will be called to move.
        public IEnumerator PerformGame()
        {
            if (currentState == GameState.SHOW)
            {
                currentState = GameState.SHUFFLING;
                for (int iterating = 0; iterating < numberOfSwitches; ++iterating)
                {
                    // We pick two random shells to move
                    int randomIndex1 = Random.Range(0, InteractShell.shellList.Count);
                    int randomIndex2 = Random.Range(0, InteractShell.shellList.Count);
                    while (randomIndex1 == randomIndex2)
                    {
                        randomIndex2 = Random.Range(0, InteractShell.shellList.Count);
                    }

                    InteractShell currShell1 = InteractShell.shellList[randomIndex1];
                    InteractShell currShell2 = InteractShell.shellList[randomIndex2];
                    currShell1.SwapShellLocation(currShell2);

                    // While we are moving these shells, we wait
                    while (currShell1.IsMoving || currShell2.IsMoving)
                    {
                        yield return(null);
                    }
                }
                currentState = GameState.SELECTING;
            }
        }
Пример #2
0
        // Swaps this and the other shell's location
        public void SwapShellLocation(InteractShell otherShell)
        {
            if (isMoving == false && otherShell.isMoving == false)
            {
                startMoveLocation            = gameObject.transform.position;
                otherShell.startMoveLocation = otherShell.transform.position;

                newLocation            = otherShell.startMoveLocation;
                otherShell.newLocation = startMoveLocation;

                isMoving            = true;
                otherShell.isMoving = true;
            }
        }
Пример #3
0
        // When called, starts up the game
        public void StartGame()
        {
            if (currentState == GameState.BEGINNING || currentState == GameState.LOADING)
            {
                if (gameScore % turnDifficulty == 0 && gameScore != 0)
                {
                    // Every X sucessful rounds, we increase the difficulty.
                    IncreaseDifficulty();
                    soundPlayer.SpeedUpSong();
                }

                luckyShell = DetermineLuckyShell();

                currentState = GameState.SHOW;
                StartCoroutine(ShowLuckyShell());
            }
        }
Пример #4
0
        // This is called when the player has selected a shell to see if they are right
        public IEnumerator ConcludeGame(InteractShell selectedShell)
        {
            if (currentState == GameState.SELECTING)
            {
                // The reason we wait 3 seconds here is because we want to make sure the ShowLuckyShell method
                // completes running its course, since we called it in parallel to this method.
                if (selectedShell.IsWinner == true)
                {
                    currentState = GameState.WIN;
                    gameScore   += 1;
                    StartCoroutine(soundPlayer.WinSound());

                    while (selectedShell.AnimateOpenChest() == false)
                    {
                        yield return(null);
                    }
                    while (selectedShell.AnimateCloseChest() == false)
                    {
                        yield return(null);
                    }
                }
                else
                {
                    currentState = GameState.LOSE;
                    StartCoroutine(soundPlayer.LoseSound());

                    while (luckyShell.AnimateOpenChest() == false)
                    {
                        yield return(null);
                    }
                    while (luckyShell.AnimateCloseChest() == false)
                    {
                        yield return(null);
                    }

                    // If we lose once, we restart from the start
                    gameScore        = 0;
                    numberOfSwitches = origNumberOfSwitches;
                    soundPlayer.RestartSong();
                }
                yield return(new WaitForSeconds(1f));

                // We then reset the shells back
                foreach (InteractShell currShell in InteractShell.shellList)
                {
                    currShell.ResetShell();
                }

                // And depending if we won/lost, we proceed accordingly
                if (currentState == GameState.LOSE)
                {
                    currentState = GameState.BEGINNING;
                }
                else if (currentState == GameState.WIN)
                {
                    currentState = GameState.LOADING;
                    yield return(null);

                    StartGame();
                }
            }
        }