public override void MoveTo(int i, int j)
{
if (CanMoveTo(i, j))
{
foreach (ChessBase chess in AppHelper.AgainstChess.Where(o => o.IsAlive == true))//遍历判断存活
{
if (i >= ArrayIndex.Key)
{
if (chess.ArrayIndex.Key == i && chess.ArrayIndex.Value == j)
{
chess.IsAlive = false;
chess.Hide();
break;
}
}
}
this.Location = AppHelper.Axis[i, j];
if (i==0 && j<9)
{
Direction = ChinaChess.Controls.Direction.Up;
}
else if (i <=9 && j >=0)
{
this.Direction = Direction.UpLeft;
}
else if (i <=0 && j >=0)
{
this.Direction = Direction.UpRight;
}
else if(i<=0 && j>9)
{
this.Direction = Direction.Down;
}
this.ArrayIndex = new KeyValuePair<int, int>(i, j);
}
}
/// <summary>
///
/// </summary>
/// <param name="i">1象限</param>
/// <param name="j"></param>
/// <returns></returns>
public override bool CanMoveTo(int i, int j)
{
if (Direction == Direction.Up)
{
if ((this.ArrayIndex.Key - i >= 1) && (this.ArrayIndex.Value - j >= 0))
{
return true;
}
}
else if (Direction == Direction.UpLeft)
{
if ((this.ArrayIndex.Key - i >= 1) && (this.ArrayIndex.Value - j >= 0))
{
return true;
}
else if ((this.ArrayIndex.Key - i ==0) && (this.ArrayIndex.Value - j >= 1))
{
return true;
}
}
else if (Direction == Direction.UpRight)
{
if ((this.ArrayIndex.Key - i >= 1) && (this.ArrayIndex.Value - j >= 0))
{
return true;
}
else if ((this.ArrayIndex.Key - i ==0) && (this.ArrayIndex.Value - j >= 1))
{
return true;
}
}
else if (Direction ==Direction.Down)
{
if ((this.ArrayIndex.Key - i >=0) && (this.ArrayIndex.Value - j >=1))
{
return true;
}