/// Get the grid coordinates where the object is at or\r
/// is moving to.\r
/// </summary>\r
- public Point Coordinates { get { return mCoordinates; } }\r
+ public Point Coordinates { get { return mCoordinates; } set { mCoordinates = value; } }\r
\r
/// <summary>\r
/// Get and set the speed of movement in grid cells / second.\r
\r
\r
/// <summary>\r
- /// Helper method to get neighbor cells from a point and directions.\r
+ /// Helper method to get a neighbor cell from a point and directions.\r
/// </summary>\r
/// <param name="point">The point.</param>\r
/// <param name="left">To the left.</param>\r
/// <param name="up">Above.</param>\r
/// <param name="down">Below.</param>\r
/// <returns>The neighbor cell coordinates.</returns>\r
- public static Point GetNeighborCell(Point point, bool left, bool right, bool up, bool down)\r
+ public static Point GetNeighbor(Point point, bool left, bool right, bool up, bool down)\r
{\r
if (left) point.X--;\r
if (right) point.X++;\r
return point;\r
}\r
\r
+ /// <summary>\r
+ /// Helper method to get a neighbor cell from a point and a direction.\r
+ /// </summary>\r
+ /// <param name="point">The point.</param>\r
+ /// <param name="direction">The direction.</param>\r
+ /// <returns>The neighbor cell coordinates.</returns>\r
+ public static Point GetNeighbor(Point point, Direction direction)\r
+ {\r
+ switch (direction)\r
+ {\r
+ case Direction.Left: return new Point(point.X - 1, point.Y);\r
+ case Direction.UpperLeft: return new Point(point.X - 1, point.Y - 1);\r
+ case Direction.Up: return new Point(point.X, point.Y - 1);\r
+ case Direction.UpperRight: return new Point(point.X + 1, point.Y - 1);\r
+ case Direction.Right: return new Point(point.X + 1, point.Y);\r
+ case Direction.LowerRight: return new Point(point.X + 1, point.Y + 1);\r
+ case Direction.Down: return new Point(point.X, point.Y + 1);\r
+ case Direction.LowerLeft: return new Point(point.X - 1, point.Y + 1);\r
+ }\r
+ return point;\r
+ }\r
+\r
+ /// <summary>\r
+ /// Helper method to get the two neighbor cells of two nearby cells.\r
+ /// </summary>\r
+ /// <param name="a">A point.</param>\r
+ /// <param name="b">Another point.</param>\r
+ /// <returns>An array of two points representing the neighbor cells.</returns>\r
+ public static Point[] GetNeighbors(Point a, Point b)\r
+ {\r
+ Point[] neighbors = new Point[2];\r
+ neighbors[0] = new Point(a.X, b.Y);\r
+ neighbors[1] = new Point(b.X, a.Y);\r
+ return neighbors;\r
+ }\r
+\r
+\r
/// <summary>\r
/// Helper method to get a Direction type from directions.\r
/// </summary>\r
void UpdateCoordinates(bool moveLeft, bool moveRight, bool moveUp, bool moveDown)\r
{\r
mLastCoordinates = mCoordinates;\r
- mCoordinates = GetNeighborCell(mCoordinates, moveLeft, moveRight, moveUp, moveDown);\r
+ mCoordinates = GetNeighbor(mCoordinates, moveLeft, moveRight, moveUp, moveDown);\r
\r
if ((moveLeft && moveUp) || (moveUp && moveRight) || (moveRight && moveDown) || (moveDown && moveLeft))\r
{\r