Exemple #1
0
        /// <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);
            }
        }
Exemple #2
0
 public Square(CoOrdinate bottomLeft, CoOrdinate topRight)
 {
     BottomLeft = bottomLeft;
     TopRight   = topRight;
 }
Exemple #3
0
 public Square()
 {
     BottomLeft = new CoOrdinate(0, 0);
     TopRight   = new CoOrdinate(1, 1);
 }