+ /// <summary>\r
+ /// Helper method to get a Direction type from directions.\r
+ /// </summary>\r
+ /// <param name="left">Left.</param>\r
+ /// <param name="right">Right.</param>\r
+ /// <param name="up">Up.</param>\r
+ /// <param name="down">Down.</param>\r
+ /// <returns>The direction.</returns>\r
+ public static Direction GetDirection(bool left, bool right, bool up, bool down)\r
+ {\r
+ if (left && !right)\r
+ {\r
+ if (up) return Direction.UpperLeft;\r
+ else if (down) return Direction.LowerLeft;\r
+ else return Direction.Left;\r
+ }\r
+ else if (right && !left)\r
+ {\r
+ if (up) return Direction.UpperRight;\r
+ else if (down) return Direction.LowerRight;\r
+ else return Direction.Right;\r
+ }\r
+ else if (up) return Direction.Up;\r
+ else if (down) return Direction.Down;\r
+ else return Direction.None;\r
+ }\r
+\r
+ /// <summary>\r
+ /// Helper method to get the general Direction type if you want to move\r
+ /// from one cell to another.\r
+ /// <param name="a">Starting point.</param>\r
+ /// <param name="b">Destination point.</param>\r
+ /// <returns>The direction toward the cell.</returns>\r
+ public static Direction GetDirection(Point a, Point b)\r
+ {\r
+ int dx = b.X - a.X;\r
+ int dy = b.Y - a.Y;\r
+\r
+ if (dx < 0)\r
+ {\r
+ if (dy < 0) return Direction.UpperLeft;\r
+ else if (dy > 0) return Direction.LowerLeft;\r
+ else return Direction.Left;\r
+ }\r
+ else if (dx > 0)\r
+ {\r
+ if (dy < 0) return Direction.UpperRight;\r
+ else if (dy > 0) return Direction.LowerRight;\r
+ else return Direction.Right;\r
+ }\r
+ else if (dy < 0) return Direction.Up;\r
+ else if (dy > 0) return Direction.Down;\r
+ else return Direction.None;\r
+ }\r
+\r