/* * * * UI setup * * * */

    private void showHardModeToggleIfNecessary()
    {
        this.hardModeRect.SetActive(DataAndSettingsManager.getNumBoughtForStoreItem(StoreManager.ITEM_KEY_HARD_MODE) > 0);
        this.hardModeToggle.isOn = DataAndSettingsManager.getHardModeState();
        if (this.hardModeRect.activeSelf)   // need to adjust text position to make room for the toggle
        {
            this.helpText.anchoredPosition = new Vector2(0f, 400f);
        }
        else
        {
            this.helpText.anchoredPosition = new Vector2(0f, 300f);
        }
    }
Exemple #2
0
    ///<summary>Calculates highscore, average, and gold earned, and writes the data.</summary>
    private void updateAndSaveData()
    {
        this.score     = GameStateManager.getScore();
        this.highscore = DataAndSettingsManager.getHighscore();
        if (this.score > this.highscore)
        {
            this.highscore = this.score;
            DataAndSettingsManager.setHighscore(this.highscore);
        }

        this.gold           = GameStateManager.getGoldAmount();
        this.isHardMode     = DataAndSettingsManager.getHardModeState();
        this.goldFromApples = GameStateManager.getApples() / 2 - this.goldFromApplesBeforeRevive;
        int addition = this.goldFromApples;

        if (this.isHardMode)
        {
            addition = (int)(addition * 1.5);
        }
        this.gold += addition;
        DataAndSettingsManager.setGoldAmount(this.gold);
        this.goldFromApplesBeforeRevive += this.goldFromApples;

        float average  = DataAndSettingsManager.getAverageScore();
        int   numGames = DataAndSettingsManager.getGamesPlayed();

        if (consecutiveRevivals > 0)
        {
            average += (float)(this.score - this.scoreBeforeRevive) / numGames;
        }
        else
        {
            average = (average * numGames + this.score) / (numGames + 1);
            DataAndSettingsManager.setGamesPlayed(numGames + 1);
        }
        this.averageScore = average;
        DataAndSettingsManager.setAverageScore(average);
        this.scoreBeforeRevive = this.score;

        DataAndSettingsManager.writeData();
    }
    /* * * * Game pathway steps * * * */

    ///<summary>Initializes objects, the game space array, and counters, flags, and labels.</summary>
    private void setupGame()
    {
        //Debug.Log("setup game");
        this.destroyObjects();
        this.initializeObjects();

        this.space           = new int[SIZE, SIZE, SIZE];
        this.space[2, 2, 2]  = SPACE_SNAKE;
        this.space[3, 2, 2]  = SPACE_SNAKE;
        this.space[4, 2, 2]  = SPACE_SNAKE;
        this.score           = 0;
        this.applesCollected = 0;
        this.goldAmount      = DataAndSettingsManager.getGoldAmount();
        this.isHardMode      = DataAndSettingsManager.getHardModeState();
        this.isPaused        = false;

        this.generateApple();

        this.updateScoreLabel();
        this.updateGoldLabel();
        DataAndSettingsManager.updateColorblindModeListeners();
    }