feat(chess): 初始化棋盘和玩家颜色,优化代码结构,重构多人游戏代码
- 在 ChessGame 中初始化棋盘,根据玩家颜色设置棋子 - 更新 UI 显示玩家颜色 - 调整棋盘位置和 UI 布局 - 重构部分代码以提高可读性和维护性
This commit is contained in:
@ -10,6 +10,7 @@ public partial class GameLobby : Control {
|
||||
|
||||
string URL;
|
||||
string userName;
|
||||
bool isAcceptedPart = false;
|
||||
|
||||
// Called when the node enters the scene tree for the first time.
|
||||
public override void _Ready() {
|
||||
@ -26,8 +27,11 @@ public partial class GameLobby : Control {
|
||||
global.RPClient.SessionAckCreate(dialog.GetMeta("sessionId").ToString(), false);
|
||||
};
|
||||
dialog.Confirmed += () => {
|
||||
if (dialog.Title == "Session Created")
|
||||
global.RPClient.SessionAckCreate(dialog.GetMeta("sessionId").ToString(), true);
|
||||
if (dialog.Title == "Session Created") {
|
||||
// FIXME
|
||||
isAcceptedPart = true;
|
||||
global.RPClient.SessionAckCreate(dialog.GetMeta("sessionId").ToString(), true);
|
||||
}
|
||||
};
|
||||
|
||||
global.RPClient.OnOpen += (string eventName, object[] args) => {
|
||||
@ -56,7 +60,14 @@ public partial class GameLobby : Control {
|
||||
dialog.Visible = true;
|
||||
} else {
|
||||
if (res) {
|
||||
// TODO FIXME
|
||||
global.sessionId = sessionId;
|
||||
if (!isAcceptedPart) {
|
||||
global.GlobalData["player_color"] = "red";
|
||||
} else {
|
||||
global.GlobalData["player_color"] = "black";
|
||||
}
|
||||
// GD.PrintErr("sessionId: ", reqUserId, "color: ", global.GlobalData["player_color"].AsString());
|
||||
global.GotoScene("res://Scenes/ChessGame.tscn");
|
||||
} else {
|
||||
dialog.Title = "Failed";
|
||||
|
Reference in New Issue
Block a user