mirror of
https://github.com/Rundll86/Dog-Lynx-And-HCN.git
synced 2026-05-29 23:41:54 +08:00
feat(多人游戏): 实现基础多人游戏功能
- 添加玩家位置同步功能 - 实现服务器和客户端连接管理 - 添加玩家名称输入和生成逻辑 - 完善多人游戏UI界面 - 移除单机模式下的预设玩家角色
This commit is contained in:
@@ -9,7 +9,7 @@ enum ConnectionState {
|
||||
}
|
||||
static var stateTextMap = {
|
||||
ConnectionState.DISCONNECTED: "未连接到服务器。",
|
||||
ConnectionState.CONNECTING: "连接中...",
|
||||
ConnectionState.CONNECTING: "正在连接到服务器...",
|
||||
ConnectionState.CONNECTED_HOST: "服务器启动成功!",
|
||||
ConnectionState.CONNECTED_CLIENT: "已连接到服务器!",
|
||||
}
|
||||
@@ -21,18 +21,17 @@ static var stateColorMap = {
|
||||
}
|
||||
|
||||
static var state: ConnectionState = ConnectionState.DISCONNECTED
|
||||
static var isMultiplayer: bool = false
|
||||
|
||||
static var maxPlayer: int = 10
|
||||
|
||||
static func isConnected():
|
||||
return [ConnectionState.CONNECTED_HOST, ConnectionState.CONNECTED_CLIENT].has(state)
|
||||
static func launchServer(port: int):
|
||||
static func launchServer(port: int) -> ENetMultiplayerPeer:
|
||||
var peer = ENetMultiplayerPeer.new()
|
||||
peer.create_server(port, maxPlayer)
|
||||
state = ConnectionState.CONNECTED_HOST
|
||||
return peer
|
||||
static func connectClient(host: String, port: int):
|
||||
static func connectClient(host: String, port: int) -> ENetMultiplayerPeer:
|
||||
var peer = ENetMultiplayerPeer.new()
|
||||
peer.create_client(host, port)
|
||||
state = ConnectionState.CONNECTED_CLIENT
|
||||
|
||||
Reference in New Issue
Block a user