X-Git-Url: https://git.dogcows.com/gitweb?p=chaz%2Fcarfire;a=blobdiff_plain;f=CarFire%2FCarFire%2FCarFire%2FMovementManager.cs;fp=CarFire%2FCarFire%2FCarFire%2FMovementManager.cs;h=7d818681993a47e22b09e4566046992e9072bdd3;hp=73caa5775b02eca70e009bff5874bf2946cfad13;hb=122c062297acac44673e947b666c1d72cd23fb1b;hpb=198cb6056e93fecd69e65351ca8d0b34a077523f diff --git a/CarFire/CarFire/CarFire/MovementManager.cs b/CarFire/CarFire/CarFire/MovementManager.cs index 73caa57..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. @@ -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. ///