refactor(chess): 重构象棋程序基础结构,使用Nullable重构核心代码

- 更新了多个文件的代码结构和类型定义,提高了代码的健壮性和可维护性
- 优化了事件处理、棋子管理和移动逻辑,为后续功能扩展打下坚实基础
- 修复了一些潜在的空指针异常问题,提高了程序的稳定性
- 修复部分bug
This commit is contained in:
ZZY
2024-11-22 23:51:32 +08:00
parent 9c619784af
commit 327c2df94d
19 changed files with 307 additions and 117 deletions

View File

@ -46,10 +46,10 @@ public abstract class AbstractPiece : IPiece {
set => data = value;
}
public event EventHandler<Vector2I> OnPos;
public event EventHandler<Vector2I> OnMove;
public event EventHandler<bool> OnSelected;
public event EventHandler<string> OnName;
public event EventHandler<Vector2I>? OnPos;
public event EventHandler<Vector2I>? OnMove;
public event EventHandler<bool>? OnSelected;
public event EventHandler<string>? OnName;
public virtual bool Move(Vector2I pos) {
if (!CanMove(pos)) {
@ -66,7 +66,7 @@ public abstract class AbstractPiece : IPiece {
return $"{Name} at {pos}";
}
public AbstractPiece(string name = "", Vector2I pos = null) {
public AbstractPiece(string name = "", Vector2I? pos = null) {
this.name = name;
this.pos = pos ?? new();
}