96 lines
1.8 KiB
C++
96 lines
1.8 KiB
C++
|
|
#ifndef Game_Creator_h__
|
|
#define Game_Creator_h__
|
|
|
|
#include "cocos2d.h"
|
|
#include <unordered_map>
|
|
#include "GameFrameBase.h"
|
|
#include "CreateRoomBase.h"
|
|
|
|
typedef std::function<GameFrameBase* ()> GAME_CREATE_SELECTOR;
|
|
typedef std::function<CreateRoomBase* ()> GAME_CREATE_NODE;
|
|
|
|
class CGameCreator
|
|
{
|
|
public:
|
|
// 游戏类型
|
|
enum GAMETYPE
|
|
{
|
|
UNKNOWN = 0, // 未知类型
|
|
NORMAL, // 常规游戏
|
|
BR, // 百人游戏
|
|
SINGLE, // 单人游戏
|
|
PRIVATE, // 私人场游戏
|
|
};
|
|
|
|
static const BYTE INVALID_PRIORITY = 0xFF;
|
|
|
|
struct ItemCreator
|
|
{
|
|
GAMETYPE type;
|
|
uint16 wKindId;
|
|
GAME_CREATE_SELECTOR gameSelector;
|
|
GAME_CREATE_NODE createNodeSelector;
|
|
|
|
ItemCreator() : wKindId(0), type(UNKNOWN), gameSelector(nullptr), createNodeSelector(nullptr)
|
|
{
|
|
|
|
}
|
|
|
|
bool validGame()
|
|
{
|
|
return (0 != wKindId) && (UNKNOWN != type) && (nullptr != gameSelector)/* && (nullptr != createNodeSelector)*/;
|
|
}
|
|
|
|
bool valid()
|
|
{
|
|
return (0 != wKindId) && (UNKNOWN != type) && (nullptr != gameSelector)/* && (nullptr != createNodeSelector)*/;
|
|
}
|
|
};
|
|
|
|
public:
|
|
// 获取单例
|
|
static CGameCreator* getInstance();
|
|
|
|
// 销毁单例
|
|
static void destroyInstance();
|
|
|
|
// 获取注册游戏数量
|
|
int getRegistGameCount();
|
|
|
|
public:
|
|
// 注册游戏
|
|
void addGame(uint16 uNameId, GAMETYPE type, GAME_CREATE_SELECTOR createGameSelector, GAME_CREATE_NODE createNodeSelector);
|
|
|
|
public:
|
|
// 启动游戏客户端
|
|
GameFrameBase* startGameClient(uint16 uNameId);
|
|
|
|
// 获取创建房间面板
|
|
CreateRoomBase* getCreateNode(uint16 uNameId);
|
|
|
|
protected:
|
|
// 校验游戏
|
|
BYTE validGame(uint16 uNameId);
|
|
|
|
private:
|
|
// 构造函数
|
|
CGameCreator();
|
|
|
|
// 析构函数
|
|
virtual ~CGameCreator();
|
|
|
|
private:
|
|
// 注册游戏列表
|
|
std::unordered_map<uint16, ItemCreator> _creators;
|
|
|
|
// 当前激活游戏
|
|
ItemCreator* _currentCreator;
|
|
|
|
// 游戏游戏数量
|
|
int _validCount;
|
|
|
|
};
|
|
|
|
#endif // Game_Creator_h__
|