refactor(重构): 重构了事件驱动的代码体系,使用全新命名和版本,以及测试套件的初试
- 移除了.csproj文件 - 更新了.gitignore,添加了.editorconfig - 重构了IBoard和IPiece接口,引入了新的事件处理机制 - 优化了CCBoard、CCPiece等类的实现,使用新的事件驱动模型 - 删除了冗余代码,提高了代码的可读性和可维护性
This commit is contained in:
@ -1,62 +1,61 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Vector2I = Vector.Vector2I;
|
||||
|
||||
public abstract class AbstractPiece : IPiece {
|
||||
private Vector2I pos; // 注意这个坐标的非像素坐标而是棋盘坐标
|
||||
using static IPiece;
|
||||
public abstract class AbstractPiece(string name = "", Vector2I? pos = null,
|
||||
IPieceOn? on = null) : IPiece {
|
||||
private Vector2I pos = pos ?? new(); // 注意这个坐标的非像素坐标而是棋盘坐标
|
||||
private bool isSelected = false;
|
||||
protected string name;
|
||||
private Dictionary<string, object> data = new();
|
||||
protected string name = name;
|
||||
private Dictionary<string, object> data = [];
|
||||
protected IPieceOn? on = on;
|
||||
|
||||
public Vector2I Pos {
|
||||
public virtual IPieceOn? On { get => on; set => on = value; }
|
||||
|
||||
public virtual Vector2I Pos {
|
||||
get => pos;
|
||||
set {
|
||||
if (pos != value) {
|
||||
var oldPos = pos;
|
||||
pos = value;
|
||||
OnPos?.Invoke(this, oldPos);
|
||||
on?.OnPos(this, oldPos);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsSelected {
|
||||
public virtual bool IsSelected {
|
||||
get => isSelected;
|
||||
set {
|
||||
if (isSelected != value) {
|
||||
var oldIsSelected = isSelected;
|
||||
isSelected = value;
|
||||
OnSelected?.Invoke(this, oldIsSelected);
|
||||
on?.OnSelected(this, oldIsSelected);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public string Name {
|
||||
public virtual string Name {
|
||||
get => name;
|
||||
set {
|
||||
if (name != value) {
|
||||
var oldName = name;
|
||||
name = value;
|
||||
OnName?.Invoke(this, oldName);
|
||||
on?.OnName(this, oldName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Dictionary<string, object> Data {
|
||||
public virtual Dictionary<string, object> Data {
|
||||
get => data;
|
||||
set => data = value;
|
||||
}
|
||||
|
||||
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)) {
|
||||
return false;
|
||||
}
|
||||
Pos = pos;
|
||||
OnMove?.Invoke(this, pos);
|
||||
on?.OnMove(this, pos);
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -65,9 +64,4 @@ public abstract class AbstractPiece : IPiece {
|
||||
public override string ToString() {
|
||||
return $"{Name} at {pos}";
|
||||
}
|
||||
|
||||
public AbstractPiece(string name = "", Vector2I? pos = null) {
|
||||
this.name = name;
|
||||
this.pos = pos ?? new();
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user