/// <summary> /// It will call when client wants to move Robot. It'll take particular direction along with number of steps in that direction /// </summary> /// <param name="RobotDirection">North, East, South, West</param> /// <param name="NumberOfSteps">number of steps in particular direction</param> private void MoveInDrictionForNSteps(Direction RobotDirection, int NumberOfSteps) { PreviousDirection = CurrentDirection; CurrentDirection = RobotDirection; switch (RobotDirection) { case Direction.North: for (int step = 1; step <= NumberOfSteps; step++) { CoOrdinate bottomLeftForNorthMove = new CoOrdinate(CurrentSquareOfRobot.BottomLeft.X, CurrentSquareOfRobot.BottomLeft.Y + 1); CoOrdinate topRightforNorthMove = new CoOrdinate(CurrentSquareOfRobot.TopRight.X, CurrentSquareOfRobot.TopRight.Y + 1); CurrentSquareOfRobot = new Square(bottomLeftForNorthMove, topRightforNorthMove); _robotMovementTracker.Add(CurrentSquareOfRobot); } break; case Direction.East: for (int step = 1; step <= NumberOfSteps; step++) { CoOrdinate bottomLeftForEastMove = new CoOrdinate(CurrentSquareOfRobot.BottomLeft.X + 1, CurrentSquareOfRobot.BottomLeft.Y); CoOrdinate topRightForEastMove = new CoOrdinate(CurrentSquareOfRobot.TopRight.X + 1, CurrentSquareOfRobot.TopRight.Y); CurrentSquareOfRobot = new Square(bottomLeftForEastMove, topRightForEastMove); _robotMovementTracker.Add(CurrentSquareOfRobot); } break; case Direction.South: for (int step = 1; step <= NumberOfSteps; step++) { CoOrdinate bottomLeftForSouthMove = new CoOrdinate(CurrentSquareOfRobot.BottomLeft.X, CurrentSquareOfRobot.BottomLeft.Y - 1); CoOrdinate topRightForSouthMove = new CoOrdinate(CurrentSquareOfRobot.TopRight.X, CurrentSquareOfRobot.TopRight.Y - 1); CurrentSquareOfRobot = new Square(bottomLeftForSouthMove, topRightForSouthMove); _robotMovementTracker.Add(CurrentSquareOfRobot); } break; case Direction.West: for (int step = 1; step <= NumberOfSteps; step++) { CoOrdinate bottomLeftForWestMove = new CoOrdinate(CurrentSquareOfRobot.BottomLeft.X - 1, CurrentSquareOfRobot.BottomLeft.Y); CoOrdinate topRightForWestMove = new CoOrdinate(CurrentSquareOfRobot.TopRight.X - 1, CurrentSquareOfRobot.TopRight.Y); CurrentSquareOfRobot = new Square(bottomLeftForWestMove, topRightForWestMove); _robotMovementTracker.Add(CurrentSquareOfRobot); } break; default: break; } if (IsRobotTurnedRight()) { OnRightHandTurned(EventArgs.Empty); } }
public Square(CoOrdinate bottomLeft, CoOrdinate topRight) { BottomLeft = bottomLeft; TopRight = topRight; }
public Square() { BottomLeft = new CoOrdinate(0, 0); TopRight = new CoOrdinate(1, 1); }