热心网友
回答时间:2024-05-14 23:16
public class Point
{
private int _x;
public int X
{
get { return _x; }
set { _x = value; }
}
private int _y;
public int Y
{
get { return _y; }
set { _y = value; }
}
public void MoveUp() { this._y--; }
public void MoveDown() { this._y++; }
public void MoveLeft() { this._x--; }
public void MoveRight() { this._x++; }
/// <summary>
/// 计算距离
/// </summary>
public static double Equl(Point a, Point b)
{
int chang = Math.Abs(a.X - b.X);
int kuan = Math.Abs(a.Y - b.Y);
return Math.Sqrt(chang * chang + kuan * kuan);
}
/// <summary>
/// 重载==
/// </summary>
public static bool operator ==(Point a, Point b)
{
return a.X == b.X && a.Y == b.Y;
}
public static bool operator !=(Point a, Point b)
{
return a.X != b.X || a.Y != b.Y;
}
}
测试用例我就不写了,你创建测试项目,然后在里面创建几个这样的类运行一下就行了。我没有测试,大体的思路就是这样的。
收起