GameControl.ts 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. import { _decorator } from 'cc';
  2. import { FMS } from '../../core_tgx/util_class/FMS';
  3. import { FMSType } from './fms/FMSGameInit';
  4. import { rootMgr } from '../scene/RootMgr';
  5. import { Player } from '../data/player/Player';
  6. import { aa } from '../../scripts/aa';
  7. import { UI_NeedLife } from '../ui/UIDialog/needLife/UI_NeedLife';
  8. const { ccclass, property } = _decorator;
  9. class Check {
  10. type: FMSType
  11. constructor(type: FMSType) {
  12. this.type = type
  13. }
  14. doEnter(): boolean {
  15. return true
  16. }
  17. }
  18. export interface evt {
  19. // 通关游戏
  20. 'gameClear': () => void;
  21. 'toNextStage': () => void
  22. // 是否强制更新
  23. 'save': (force?: boolean) => void
  24. "revive_request": () => void, // 请求复活
  25. "revive_fail": () => void
  26. "addbottles": () => void//增加一个空瓶子
  27. "swapcolors": () => void//点击一个瓶子重新打乱里面的颜色
  28. "withdraw": () => void//撤回一步
  29. "openbottlesBtn":(rebtn:boolean)=>void//是否打开撤回按钮
  30. "openaddbottlesBtn":(rebtn:boolean)=>void//是否打开增加一个空瓶子按钮
  31. "rewardUnlocked":()=>void//奖励解锁
  32. }
  33. export class GameControl {
  34. private _fms: FMS<FMSType>
  35. private check: Map<FMSType, Check>
  36. // 这里可以拿到所有的实例
  37. private _evt = chsdk.get_new_event<evt>();
  38. get evt() {
  39. return this._evt;
  40. }
  41. get FMS() {
  42. return this._fms
  43. }
  44. constructor() {
  45. this._fms = new FMS
  46. this.check = new Map
  47. this.register(FMSType.Start, Check1)
  48. // this.register(FMSType.LongBottle, Check2)
  49. }
  50. register(type: FMSType, cCheck: new (...t: any) => Check) {
  51. let check = new cCheck(type)
  52. this.check.set(type, check)
  53. }
  54. clear() {
  55. this._fms = null
  56. this.check = null
  57. }
  58. Change(type: FMSType) {
  59. let check = this.check.get(type)
  60. if (check) {
  61. let bool = check.doEnter()
  62. if (!bool) {
  63. return false
  64. }
  65. }
  66. this._fms.Change(type)
  67. return true
  68. }
  69. init() {
  70. this.Change(this._fms.CurrentType as FMSType)
  71. }
  72. }
  73. class Check1 extends Check {
  74. type: FMSType
  75. doEnter(): boolean {
  76. let player = rootMgr.dataControl.getCompent(Player)
  77. let bool = player.life > 0
  78. if (bool) {
  79. player.life -= 1
  80. // rootMgr.game.evt.emit('save',true)
  81. } else {
  82. // Notify("体力不足")
  83. aa.uIMgr.showUI(UI_NeedLife)
  84. }
  85. return bool
  86. }
  87. }