Esempio n. 1
0
    // Handles game over when ball falls out of bounds
    // Clears powerups from gameboard, saves new game statistics, and shows "gameOverUI"
    // Returns:
    //  Void
    public void initiateGameOver()
    {
        gamePlayMusic.Pause();
        gameOver.Play();
        shakeEffect.ShakeIt();
        removeAllPowerups();

        StartCoroutine(waitForWhile());

        // Update 'final score' board then display game over screen
        finalBoard.updateText("Score: " + gameScore.ToString());

        // If a new highscore, set and save to device
        if (gameScore > PlayerPrefs.GetInt("highScore"))
        {
            PlayerPrefs.SetInt("highScore", gameScore);
        }

        // Set and save total score to device
        PlayerPrefs.SetInt("totalScore", PlayerPrefs.GetInt("totalScore") + gameScore);

        // Set and save total game count to device
        PlayerPrefs.SetInt("gamesPlayed", PlayerPrefs.GetInt("gamesPlayed") + 1);

        return;
    }
    // Handles game rounds every time ball fall out of bounds
    // Either displays game over screen (top or bottom player score reaches 3), or sets up next round
    // Returns:
    //  Void
    public void replayOrOver()
    {
        gameOver.Play();
        shakeEffect.ShakeIt();

        if (lastTouched == TOP)
        {
            topPlayerScore++;
            topPlayerScoreBoard.updateText(topPlayerScore.ToString());
        }
        else if (lastTouched == BOTTOM)
        {
            bottomPlayerScore++;
            bottomPlayerScoreBoard.updateText(bottomPlayerScore.ToString());
        }

        // If top or bottom player has reached the score to win, initiate game over screen
        if (topPlayerScore == scoreToWin || bottomPlayerScore == scoreToWin)
        {
            startingGameOver = true;
            gamePlayMusic.Pause();
            initiateGameOver();
        }
        else
        {
            // Else, setup for next round
            // Drop ball again, reset powerups, ball speed, and destory all power ups
            ballScript.dropBall();
            turnOffPowerUpBar(BOTH);
            ballScript.changeSpeed(1 - (multTimes / 1f));
            multTimes = 0f;
            removeAllPowerups();
        }

        return;
    }