///<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(); }