import { EventManager, StageState } from "../Tools/EventManager";
import { ViewManager, ViewType } from "../View/ViewManager";
import { GameManager } from "./GameManager";
import { AudioManager, MusicType } from "../Tools/AudioManager";

export class MainGame{
    private static ins:MainGame;
    constructor(){
        MainGame.ins = this;
        EventManager.StageOn(StageState.Lose,this,this.GameFailure);
        EventManager.StageOn(StageState.Win,this,this.GameWin);
        // EventManager.StageOn(StageState.Revive,this,this.Revive);
    }
    public static get Instance():MainGame{
        if(MainGame.ins){
            return MainGame.ins
        }
        else{
            return new MainGame();
        }
    }
    GameFailure(){
        if(GameManager.Instance.ReviveNum>0){
            ViewManager.Instance.ShowView(ViewType.CompleteView,3)
        }
        else{
            AudioManager.StopMusic();
            AudioManager.playMusic(MusicType.Lose);
            ViewManager.Instance.ShowView(ViewType.CompleteView,2)
        }
    }
    GameWin(){
        AudioManager.StopMusic();
        AudioManager.playMusic(MusicType.Win);
        ViewManager.Instance.ShowView(ViewType.CompleteView,1)
    }
    Revive(){
        ViewManager.Instance.ShowView(ViewType.CompleteView,3);
    }
}