diff --git a/assets/Scripts/Game/Data/UserData.ts b/assets/Scripts/Game/Data/UserData.ts index 93ca860..fac3a67 100644 --- a/assets/Scripts/Game/Data/UserData.ts +++ b/assets/Scripts/Game/Data/UserData.ts @@ -7,6 +7,7 @@ export class UserData { export class GameData { public goldCoins = 0; public metaUpgrades = new MetaUpgradesData(); + public highscore = 0; } export class MetaUpgradesData { diff --git a/assets/Scripts/Game/Game.ts b/assets/Scripts/Game/Game.ts index cee5992..3224abf 100644 --- a/assets/Scripts/Game/Game.ts +++ b/assets/Scripts/Game/Game.ts @@ -59,7 +59,7 @@ export class Game extends Component { this.gamePauser.pause(); } - public async playGame(userData: UserData): Promise { + public async playGame(userData: UserData): Promise { const translationData = this.translationAsset.json; const settings = this.settingsAsset.json; const metaUpgrades = new MetaUpgrades(userData.game.metaUpgrades, settings.metaUpgrades); @@ -123,7 +123,7 @@ export class Game extends Component { await delay(1000000); this.gamePauser.pause(); Game.instance = null; - return 1; + return { goldCoins: 1, score: Math.floor(this.timeAlive) }; } public update(deltaTime: number): void { @@ -159,3 +159,8 @@ export class Game extends Component { return playerData; } } + +export class GameResult { + public goldCoins = 0; + public score = 0; +} diff --git a/assets/Scripts/Menu/GameRunner.ts b/assets/Scripts/Menu/GameRunner.ts index f469de1..883aa95 100644 --- a/assets/Scripts/Menu/GameRunner.ts +++ b/assets/Scripts/Menu/GameRunner.ts @@ -1,7 +1,7 @@ import { director } from "cc"; import { AppRoot } from "../AppRoot/AppRoot"; import { UserData } from "../Game/Data/UserData"; -import { Game } from "../Game/Game"; +import { Game, GameResult } from "../Game/Game"; import { delay } from "../Services/Utils/AsyncUtils"; export class GameRunner { @@ -25,8 +25,12 @@ export class GameRunner { director.loadScene("Game"); const userData: UserData = AppRoot.Instance.SaveSystem.load(); while (Game.Instance == null) await delay(10); - const result: number = await Game.Instance.playGame(); - userData.game.goldCoins += result; + const result: GameResult = await Game.Instance.playGame(userData); + userData.game.goldCoins += result.goldCoins; + + if (userData.game.highscore < result.score) { + userData.game.highscore = result.score; + } AppRoot.Instance.SaveSystem.save(userData); console.log("Gold coins: " + result);