refactor(重构): 重构了事件驱动的代码体系,使用全新命名和版本,以及测试套件的初试

- 移除了.csproj文件
- 更新了.gitignore,添加了.editorconfig
- 重构了IBoard和IPiece接口,引入了新的事件处理机制
- 优化了CCBoard、CCPiece等类的实现,使用新的事件驱动模型
- 删除了冗余代码,提高了代码的可读性和可维护性
This commit is contained in:
ZZY
2024-11-24 15:42:30 +08:00
parent 327c2df94d
commit e16f76e11f
18 changed files with 416 additions and 274 deletions

View File

@ -3,11 +3,12 @@ using System.Collections;
using Vector2I = Vector.Vector2I;
namespace ChineseChess;
using static IBoard.IBoardOn;
public class Player {
private readonly CCBoard board;
private readonly SelectedPiece selectedNode;
public EventHandler<IBoard.MoveEventArgs>? OnMove;
public EventHandler<MoveEventArgs>? OnMove;
public bool CanMove { get; set; } = true;
public enum PlayerType {
@ -15,8 +16,7 @@ public class Player {
AI
}
public Player(CCBoard board, PlayerType type = PlayerType.Human)
{
public Player(CCBoard board, PlayerType type = PlayerType.Human) {
this.board = board;
this.selectedNode = new SelectedPiece(board);
}
@ -56,9 +56,9 @@ public class Player {
}
// MUST BE THERE !!! 防止删除节点后在启动回调导致错误
OnMove?.Invoke(this, new IBoard.MoveEventArgs
{ From = fromPos, To = toPos, Piece = fromChess });;
OnMove?.Invoke(this, new MoveEventArgs
(fromChess, fromPos, toPos));
if (toChess != null) {
board.RemovePiece(toPos);
}