This commit is contained in:
2025-10-26 20:44:58 +08:00
parent e287aadd3c
commit e73c08abf7
45 changed files with 280774 additions and 0 deletions

View File

@@ -0,0 +1,71 @@
#pragma once
#include "BattleRoom.h"
#include <map>
#include <mutex>
#include <memory>
// 前向声明
class GameServer;
/**
* @brief 战斗房间管理器
*
* 技术点: STL - std::map, std::mutex
*/
class BattleRoomManager {
private:
GameServer* m_server;
std::map<int, std::shared_ptr<BattleRoom>> m_rooms; // STL
std::mutex m_mutex; // STL
int m_nextRoomId;
public:
/**
* @brief 构造函数
*/
explicit BattleRoomManager(GameServer* server);
/**
* @brief 析构函数
*/
~BattleRoomManager();
/**
* @brief 创建战斗房间
* @param player1 玩家1用户名
* @param player2 玩家2用户名
* @return int 房间ID失败返回 -1
*/
int createBattle(const std::string& player1, const std::string& player2);
/**
* @brief 获取战斗房间
*/
std::shared_ptr<BattleRoom> getBattleRoom(int roomId);
/**
* @brief 处理战斗行动
*/
bool handleBattleAction(int roomId,
const std::string& username,
int skillIndex,
const std::string& targetName);
/**
* @brief 移除战斗房间
*/
void removeBattleRoom(int roomId);
/**
* @brief 检查玩家是否在战斗中
*/
bool isPlayerInBattle(const std::string& username);
private:
/**
* @brief 创建角色实例
*/
std::shared_ptr<ICharacter> createCharacter(const std::string& className,
const std::string& name,
int level = 1);
};