public int MoveTowardPosition(Position other, int movePoints) { while (movePoints > 0 && (DistanceFromPosition(other) != 1)) { if (X > other.X) { X--; } else if (X < other.X) { X++; } if (Y > other.Y) { Y--; } else if (Y < other.Y) { Y++; } movePoints--; } return movePoints; }
public int DistanceFromPosition(Position other) { var diffX = Math.Abs(X - other.X); var diffY = Math.Abs(Y - other.Y); return Math.Max(diffX, diffY); }