X-Git-Url: https://git.dogcows.com/gitweb?p=chaz%2Fcarfire;a=blobdiff_plain;f=CarFire%2FCarFire%2FCarFire%2FMovementManager.cs;h=ad26e478a317f8921f9b14e512f97f9df2690e42;hp=73caa5775b02eca70e009bff5874bf2946cfad13;hb=9fc306c489b446612f0fc1b363e490a5ff217d2c;hpb=198cb6056e93fecd69e65351ca8d0b34a077523f diff --git a/CarFire/CarFire/CarFire/MovementManager.cs b/CarFire/CarFire/CarFire/MovementManager.cs index 73caa57..ad26e47 100644 --- a/CarFire/CarFire/CarFire/MovementManager.cs +++ b/CarFire/CarFire/CarFire/MovementManager.cs @@ -44,7 +44,7 @@ namespace CarFire /// Get the grid coordinates where the object is at or /// is moving to. /// - public Point Coordinates { get { return mCoordinates; } } + public Point Coordinates { get { return mCoordinates; } set { mCoordinates = value; } } /// /// Get and set the speed of movement in grid cells / second. @@ -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. @@ -212,6 +212,28 @@ 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. ///