mirror of
https://github.com/LHY0125/Gobang-Game.git
synced 2026-05-10 02:19:46 +08:00
feat(network): 集成ENet库并实现局域网联机对战功能
- 添加ENet库作为网络通信基础,替换原有的原生Socket实现 - 扩展游戏模式支持局域网联机对战(PvP网络模式) - 重构网络状态结构以适配ENet的Host/Peer模型 - 在图形界面中添加网络对战菜单,支持创建房间和加入房间 - 实现网络消息的发送与接收,包括落子、断开连接等消息类型 - 为网络对战添加定时器轮询机制,实时处理网络事件 - 更新构建系统以编译和链接ENet库
This commit is contained in:
+9
-6
@@ -80,15 +80,18 @@ typedef struct
|
||||
* @brief 网络游戏状态结构
|
||||
* @details 用于管理网络游戏状态
|
||||
*/
|
||||
// ENet 头文件需要前置声明或直接包含,但在 type.h 中包含可能引起循环依赖
|
||||
// 我们可以使用 void* 来避免在 type.h 中包含 enet.h
|
||||
typedef struct
|
||||
{
|
||||
uintptr_t socket; // 套接字 (使用uintptr_t代替SOCKET以避免引入winsock2.h)
|
||||
bool is_server; // 是否为服务器
|
||||
bool is_connected; // 是否已连接
|
||||
int local_player_id; // 本地玩家ID
|
||||
void *host; // ENetHost * (Server 或 Client)
|
||||
void *peer; // ENetPeer * (连接的对象)
|
||||
bool is_server; // 是否为服务器(主机)
|
||||
bool is_connected; // 是否已连接
|
||||
int local_player_id; // 本地玩家ID
|
||||
int remote_player_id; // 远程玩家ID
|
||||
char remote_ip[16]; // 远程IP地址(MAX_IP_LENGTH = 16)
|
||||
int port; // 端口号
|
||||
char remote_ip[64]; // 远程IP
|
||||
int port; // 端口
|
||||
} NetworkGameState;
|
||||
|
||||
#endif // TYPE_H
|
||||
Reference in New Issue
Block a user