feat(重构): 重构棋盘和棋子的逻辑
- 重构了 ChessBoard 和 ChessPiece 类的逻辑 - 添加了新版本的 ChineseChess 库 - 删除了旧版本的 VirtualBoard 和 VirtualPiece 类 - 更新了相关的场景和脚本
This commit is contained in:
@ -45,15 +45,18 @@ public partial class ChessGame : Node2D {
|
||||
Game = new(ChessCore.Mode.SingleMode, sideSelf);
|
||||
}
|
||||
board.LoadBoard(Game.board);
|
||||
Game.InitGame();
|
||||
Game.Init();
|
||||
|
||||
Game.board.OnMove += (sender, e) => {
|
||||
Game.board.OnStepsChanged += (sender, e) => {
|
||||
turnSideEdit.Text = Game.GetTurnsType() == ChessCore.TurnsSideType.Red ? "red" : "black";
|
||||
};
|
||||
|
||||
board.OnPosClicked += (sender, pos) => {
|
||||
int posX = (int)pos.X;
|
||||
int posY = (int)pos.Y;
|
||||
Vector.Vector2I vector = new(posX, posY);
|
||||
if (isSession) {
|
||||
Game.OnPosClicked(pos, ChessCore.PlayerSideType.Self);
|
||||
Game.OnPosClicked(vector, ChessCore.PlayerSideType.Self);
|
||||
var res = global.RPClient.SendSessionToAll(global.sessionId, new Dictionary {
|
||||
{"type", "mouseClicked"},
|
||||
{"X", pos.X},
|
||||
@ -61,7 +64,7 @@ public partial class ChessGame : Node2D {
|
||||
{"id", global.RPClient.GetUserId()}
|
||||
});
|
||||
} else {
|
||||
Game.OnPosClicked(pos);
|
||||
Game.OnPosClicked(vector);
|
||||
}
|
||||
};
|
||||
|
||||
@ -99,7 +102,8 @@ public partial class ChessGame : Node2D {
|
||||
}
|
||||
Vector2 mouseClicked = new(GD.StrToVar(msg["X"].ToString()).AsInt32(),
|
||||
GD.StrToVar(msg["Y"].ToString()).AsInt32());
|
||||
Game.OnPosClicked(mouseClicked, ChessCore.PlayerSideType.Opponent);
|
||||
Vector.Vector2I vector = new((int)mouseClicked.X, (int)mouseClicked.Y);
|
||||
Game.OnPosClicked(vector, ChessCore.PlayerSideType.Opponent);
|
||||
break;
|
||||
case "undo":
|
||||
Game.Undo();
|
||||
@ -137,6 +141,7 @@ public partial class ChessGame : Node2D {
|
||||
{"id", global.RPClient.GetUserId()},
|
||||
});
|
||||
} else {
|
||||
if (Game.board.Steps == 0) board.Clear();
|
||||
Game.Undo();
|
||||
}
|
||||
}
|
||||
@ -150,6 +155,7 @@ public partial class ChessGame : Node2D {
|
||||
});
|
||||
} else {
|
||||
Game.ReInit();
|
||||
board.Clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user