refactor(chess): 重构象棋程序基础结构,使用Nullable重构核心代码
- 更新了多个文件的代码结构和类型定义,提高了代码的健壮性和可维护性 - 优化了事件处理、棋子管理和移动逻辑,为后续功能扩展打下坚实基础 - 修复了一些潜在的空指针异常问题,提高了程序的稳定性 - 修复部分bug
This commit is contained in:
@ -33,12 +33,19 @@ public class ChessCore {
|
||||
playerSelf = new(board, Player.PlayerType.Human);
|
||||
playerOpponent = new(board, Player.PlayerType.Human);
|
||||
|
||||
void func(object _self, IBoard.MoveEventArgs record) {
|
||||
void func(object? _self, IBoard.MoveEventArgs record) {
|
||||
// 防止 Undo 时 Selected Clear 出现 Null Pointer Exception
|
||||
playerSelf.SelectedClear();
|
||||
playerOpponent.SelectedClear();
|
||||
board.AddRecord(board.GetPiece(record.From), board.GetPiece(record.To),
|
||||
record.From, record.To);
|
||||
|
||||
// TODO FIXME it can be simple
|
||||
if (record.From is null || record.To is null) {
|
||||
return;
|
||||
}
|
||||
|
||||
IPiece? from = record.From is not null ? board.GetPiece(record.From) : null;
|
||||
IPiece? to = record.To is not null ? board.GetPiece(record.To) : null;
|
||||
board.AddRecord(from, to, record.From ?? new(), record.To ?? new());
|
||||
}
|
||||
playerSelf.OnMove += func;
|
||||
playerOpponent.OnMove += func;
|
||||
|
Reference in New Issue
Block a user