import { EventManager, StageMode } from "../Tool/EventManager";
import { ViewManager, ViewType } from "../View/ViewManager";
import { GameManager } from "./GameManager";
import { GamePool } from "../Tool/GamePool";

export class GameControl{
    private static ins:GameControl;

    
    
    constructor(){
        GameControl.ins = this;
        this.Init();
    }
    public static get Instance():GameControl{
        if(GameControl.ins){
            return GameControl.ins
        }
        else{
            return new GameControl();
        }
    }
    Init(){
        EventManager.StageOn(StageMode.Start,this,this.GameStart)
        EventManager.StageOn(StageMode.Lose,this,this.GameLose)
        EventManager.StageOn(StageMode.Win,this,this.GameWin)
    }
    GameStart(){
        ViewManager.Instance.ShowView(ViewType.InGameView);
        GamePool.Instance.FallDown(30);
    }
    GameLose(){
        Laya.timer.once(2000,this,()=>{
            if(GameManager.Instance.ReviveNum>0){
                ViewManager.Instance.OpenPopView(ViewType.ReviveView);
                GameManager.Instance.ReviveNum--;
            }
            else{
                ViewManager.Instance.OpenPopView(ViewType.FailureView);
            }
        })
    }
    GameWin(){
        Laya.timer.once(2000,this,()=>{
            ViewManager.Instance.OpenPopView(ViewType.WinView);
        })
    }
}