GameManager.ts 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /** @format */
  2. import {Data, Mgr} from '../GameControl'
  3. import {ccUtils} from '../utils/ccUtils'
  4. import {UI} from '../enums/UI'
  5. import {GAME_TYPE, GOODS} from '../enums/Enum'
  6. import {IGameResult, IStageChoose} from '../interface/UIInterface'
  7. /** @format */
  8. export class GameManager {
  9. async gotoGame() {
  10. Data.game.gameBundle = await ccUtils.getBundleAsync('game')
  11. Mgr.ui.show(UI.GameLoadingUI)
  12. }
  13. initNormal() {}
  14. initElite() {}
  15. async startNormalGame(stageID: number, currentRound: number, currentCost: number) {
  16. let isFightStage = stageID == Math.floor(currentRound / 100)
  17. Data.game.stageID = stageID
  18. Data.game.stageRound = isFightStage ? currentRound : stageID * 100 + 1
  19. //if (CC_DEV) Data.game.cost += 100
  20. Data.game.gameType = GAME_TYPE.normal
  21. Data.game.dropOut = null
  22. await this.gotoGame()
  23. }
  24. async startEliteGame(stageID: number) {
  25. Data.game.stageID = stageID
  26. Data.game.stageRound = Data.game.stageID * 100 + 1
  27. Data.game.gameType = GAME_TYPE.elite
  28. Data.game.dropOut = null
  29. await this.gotoGame()
  30. }
  31. exitGame(result?: IGameResult) {
  32. Mgr.ui.closeAll()
  33. Mgr.ui.show(UI.MainUI)
  34. let stageChooseArgs: IStageChoose = {gameType: Data.game.gameType}
  35. switch (Data.game.gameType) {
  36. case GAME_TYPE.normal:
  37. case GAME_TYPE.elite:
  38. Mgr.ui.show(UI.CurrencyUI, [GOODS.coin, GOODS.diamond, GOODS.fatigue])
  39. Mgr.ui.show(UI.StageChooseUI, stageChooseArgs)
  40. break
  41. }
  42. }
  43. }