X-Git-Url: https://git.dogcows.com/gitweb?a=blobdiff_plain;ds=sidebyside;f=CarFire%2FCarFire%2FCarFire%2FMovementManager.cs;h=7d818681993a47e22b09e4566046992e9072bdd3;hb=122c062297acac44673e947b666c1d72cd23fb1b;hp=3511e4202d1af2e711f2485a81088ee781cfd7f2;hpb=af9deb873b24dadd0d509ce199fc6cac2b3efbc9;p=chaz%2Fcarfire
diff --git a/CarFire/CarFire/CarFire/MovementManager.cs b/CarFire/CarFire/CarFire/MovementManager.cs
index 3511e42..7d81868 100644
--- a/CarFire/CarFire/CarFire/MovementManager.cs
+++ b/CarFire/CarFire/CarFire/MovementManager.cs
@@ -195,7 +195,7 @@ namespace CarFire
///
- /// Helper method to get neighbor cells from a point and directions.
+ /// Helper method to get a neighbor cell from a point and directions.
///
/// The point.
/// To the left.
@@ -203,7 +203,7 @@ namespace CarFire
/// Above.
/// Below.
/// The neighbor cell coordinates.
- public static Point GetNeighborCell(Point point, bool left, bool right, bool up, bool down)
+ public static Point GetNeighbor(Point point, bool left, bool right, bool up, bool down)
{
if (left) point.X--;
if (right) point.X++;
@@ -212,6 +212,43 @@ namespace CarFire
return point;
}
+ ///
+ /// Helper method to get a neighbor cell from a point and a direction.
+ ///
+ /// The point.
+ /// The direction.
+ /// The neighbor cell coordinates.
+ public static Point GetNeighbor(Point point, Direction direction)
+ {
+ switch (direction)
+ {
+ case Direction.Left: return new Point(point.X - 1, point.Y);
+ case Direction.UpperLeft: return new Point(point.X - 1, point.Y - 1);
+ case Direction.Up: return new Point(point.X, point.Y - 1);
+ case Direction.UpperRight: return new Point(point.X + 1, point.Y - 1);
+ case Direction.Right: return new Point(point.X + 1, point.Y);
+ case Direction.LowerRight: return new Point(point.X + 1, point.Y + 1);
+ case Direction.Down: return new Point(point.X, point.Y + 1);
+ case Direction.LowerLeft: return new Point(point.X - 1, point.Y + 1);
+ }
+ return point;
+ }
+
+ ///
+ /// Helper method to get the two neighbor cells of two nearby cells.
+ ///
+ /// A point.
+ /// Another point.
+ /// An array of two points representing the neighbor cells.
+ public static Point[] GetNeighbors(Point a, Point b)
+ {
+ Point[] neighbors = new Point[2];
+ neighbors[0] = new Point(a.X, b.Y);
+ neighbors[1] = new Point(b.X, a.Y);
+ return neighbors;
+ }
+
+
///
/// Helper method to get a Direction type from directions.
///
@@ -282,7 +319,7 @@ namespace CarFire
void UpdateCoordinates(bool moveLeft, bool moveRight, bool moveUp, bool moveDown)
{
mLastCoordinates = mCoordinates;
- mCoordinates = GetNeighborCell(mCoordinates, moveLeft, moveRight, moveUp, moveDown);
+ mCoordinates = GetNeighbor(mCoordinates, moveLeft, moveRight, moveUp, moveDown);
if ((moveLeft && moveUp) || (moveUp && moveRight) || (moveRight && moveDown) || (moveDown && moveLeft))
{