| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105 |
- import { _decorator } from 'cc';
- import { FMS } from '../../core_tgx/util_class/FMS';
- import { FMSType } from './fms/FMSGameInit';
- import { rootMgr } from '../scene/RootMgr';
- import { Player } from '../data/player/Player';
- import { aa } from '../../scripts/aa';
- import { UI_NeedLife } from '../ui/UIDialog/needLife/UI_NeedLife';
- const { ccclass, property } = _decorator;
- class Check {
- type: FMSType
- constructor(type: FMSType) {
- this.type = type
- }
- doEnter(): boolean {
- return true
- }
- }
- export interface evt {
- // 通关游戏
- 'gameClear': () => void;
- 'toNextStage': () => void
- // 是否强制更新
- 'save': (force?: boolean) => void
- "revive_request": () => void, // 请求复活
- "revive_fail": () => void
- "addbottles": () => void//增加一个空瓶子
- "swapcolors": () => void//点击一个瓶子重新打乱里面的颜色
- "withdraw": () => void//撤回一步
- "openbottlesBtn":(rebtn:boolean)=>void//是否打开撤回按钮
- "openaddbottlesBtn":(rebtn:boolean)=>void//是否打开增加一个空瓶子按钮
- "rewardUnlocked":()=>void//奖励解锁
- }
- export class GameControl {
- private _fms: FMS<FMSType>
- private check: Map<FMSType, Check>
- // 这里可以拿到所有的实例
- private _evt = chsdk.get_new_event<evt>();
- get evt() {
- return this._evt;
- }
- get FMS() {
- return this._fms
- }
- constructor() {
- this._fms = new FMS
- this.check = new Map
- this.register(FMSType.Start, Check1)
- // this.register(FMSType.LongBottle, Check2)
- }
- register(type: FMSType, cCheck: new (...t: any) => Check) {
- let check = new cCheck(type)
- this.check.set(type, check)
- }
- clear() {
- this._fms = null
- this.check = null
- }
- Change(type: FMSType) {
- let check = this.check.get(type)
- if (check) {
- let bool = check.doEnter()
- if (!bool) {
- return false
- }
- }
- this._fms.Change(type)
- return true
- }
- init() {
- this.Change(this._fms.CurrentType as FMSType)
- }
- }
- class Check1 extends Check {
- type: FMSType
- doEnter(): boolean {
- let player = rootMgr.dataControl.getCompent(Player)
- let bool = player.life > 0
- if (bool) {
- player.life -= 1
- // rootMgr.game.evt.emit('save',true)
- } else {
- // Notify("体力不足")
- aa.uIMgr.showUI(UI_NeedLife)
- }
- return bool
- }
- }
|