package com.game; import java.util.HashMap; import java.util.Map; import com.game.manager.RoomManager; import com.game.manager.SessionManager; import com.game.player.state.PlayerEndState; import com.game.player.state.PlayerInitState; import com.game.player.state.PlayerPauseState; import com.game.player.state.PlayerPopupState; import com.game.player.state.PlayerReadyState; import com.game.player.state.PlayerReloadState; import com.game.player.state.PlayerSpectatorState; import com.game.player.state.PlayerWaitState; import com.game.room.state.RoomDestoryGameState; import com.game.room.state.RoomEndState; import com.game.room.state.RoomInitState; import com.game.room.state.RoomReloadState; import com.game.room.state.RoomStartGameState; import com.game.room.state.RoomWaitState; import com.game.state.StateBase; import com.taurus.core.util.Logger; public class Global { /** * debug模式 */ public static boolean loggerDebug = false; // 日志 public static Logger logger; // session管理器 public static SessionManager sessionMgr; // 桌子管理器 public static RoomManager roomMgr; public static GameController gameCtr; public static EventController eventCtr; /** * 游戏ID */ public static int gameId = 1; /** * 游戏名字 */ public static String gameName = ""; public static void init() { Global.sessionMgr = new SessionManager(); Global.roomMgr = new RoomManager(); Global.eventCtr = new EventController(); registerState(RoomInitState.class, new RoomInitState()); registerState(RoomEndState.class, new RoomEndState()); registerState(RoomDestoryGameState.class, new RoomDestoryGameState()); registerState(RoomWaitState.class, new RoomWaitState()); registerState(RoomReloadState.class, new RoomReloadState()); registerState(RoomStartGameState.class, new RoomStartGameState()); registerState(PlayerInitState.class, new PlayerInitState()); registerState(PlayerPauseState.class, new PlayerPauseState()); registerState(PlayerReadyState.class, new PlayerReadyState()); registerState(PlayerReloadState.class, new PlayerReloadState()); registerState(PlayerWaitState.class, new PlayerWaitState()); registerState(PlayerSpectatorState.class, new PlayerSpectatorState()); registerState(PlayerPopupState.class, new PlayerPopupState()); registerState(PlayerEndState.class, new PlayerEndState()); } private static Map, StateBase> state_map = new HashMap<>(); public static void registerState(Class cls, StateBase state) { state_map.put(cls, state); } public static StateBase getState(Class cls) { StateBase state = state_map.get(cls); return state; } public static void info(String msg, Object... params) { if (loggerDebug) { logger.info(Util.stringFormat(msg, params)); } } public static void warn(String msg, Object... params) { if (loggerDebug) { logger.warn(Util.stringFormat(msg, params)); } } public static void error(String msg, Object... params) { if (loggerDebug) { logger.error(Util.stringFormat(msg, params)); } } }