mirror of
https://github.com/MartinKral/Slash-The-Hordes
synced 2025-10-09 16:46:00 +00:00
game runner
This commit is contained in:
28
assets/Scripts/Menu/GameRunner.ts
Normal file
28
assets/Scripts/Menu/GameRunner.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
import { director } from "cc";
|
||||
import { AppRoot } from "../AppRoot/AppRoot";
|
||||
import { UserData } from "../Game/Data/UserData";
|
||||
import { Game } from "../Game/Game";
|
||||
import { delay } from "../Services/Utils/AsyncUtils";
|
||||
|
||||
export class GameRunner {
|
||||
private static instance: GameRunner = new GameRunner();
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
||||
private constructor() {}
|
||||
|
||||
public static get Instance(): GameRunner {
|
||||
return this.instance;
|
||||
}
|
||||
|
||||
public async playGame(): Promise<void> {
|
||||
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;
|
||||
AppRoot.Instance.SaveSystem.save(userData);
|
||||
|
||||
console.log("Gold coins: " + result);
|
||||
console.log("All gold coins: " + userData.game.goldCoins);
|
||||
}
|
||||
}
|
9
assets/Scripts/Menu/GameRunner.ts.meta
Normal file
9
assets/Scripts/Menu/GameRunner.ts.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "c3869838-2d3a-4a22-a2f4-77d11a8226d5",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
10
assets/Scripts/Menu/Menu.ts
Normal file
10
assets/Scripts/Menu/Menu.ts
Normal file
@@ -0,0 +1,10 @@
|
||||
import { _decorator, Component, Node } from "cc";
|
||||
import { GameRunner } from "./GameRunner";
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
@ccclass("Menu")
|
||||
export class Menu extends Component {
|
||||
public start(): void {
|
||||
GameRunner.Instance.playGame();
|
||||
}
|
||||
}
|
9
assets/Scripts/Menu/Menu.ts.meta
Normal file
9
assets/Scripts/Menu/Menu.ts.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "22c61cc5-77b8-4d45-a02d-b5f7da4ba7a9",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
Reference in New Issue
Block a user