- 抽象出 ChessCore 类,包含游戏初始化、行棋逻辑、悔棋等功能 - 重构 Player 类,优化行棋和记录逻辑 - 更新 ChessBoard 和 ChessPiece 类,适应新逻辑 - 移除冗余代码,提高代码可读性和可维护性
38 lines
871 B
C#
38 lines
871 B
C#
using Vector2 = Godot.Vector2;
|
|
using System;
|
|
|
|
public class VirtualPiece {
|
|
private Vector2 pos; // 注意这个坐标的非像素坐标而是棋盘坐标
|
|
|
|
public readonly string name;
|
|
private bool isSelected;
|
|
public object data;
|
|
|
|
public event Action<Vector2> OnMove;
|
|
public event Action<bool> OnSelected;
|
|
|
|
public void Move(Vector2 pos) {
|
|
this.pos = pos;
|
|
OnMove?.Invoke(pos);
|
|
}
|
|
|
|
public Vector2 Pos() {
|
|
return pos;
|
|
}
|
|
|
|
public void Selected(bool isSelected) {
|
|
if (this.isSelected != isSelected) {
|
|
OnSelected?.Invoke(isSelected);
|
|
this.isSelected = isSelected;
|
|
}
|
|
}
|
|
|
|
public bool IsSelected() {
|
|
return isSelected;
|
|
}
|
|
|
|
public VirtualPiece(string name = "", Vector2 pos = new Vector2()) {
|
|
this.name = name;
|
|
this.pos = pos;
|
|
}
|
|
} |