示例#1
0
文件: Robot.cs 项目: chriscwej/robot
        // Updates the robot's bearing if the new bearing is valid
        public void SetBearing(string newBearing)
        {
            if (!Bearing.IsValidBearing(newBearing))
            {
                throw new ArgumentOutOfRangeException("newBearing", "Invalid bearing specified");
            }

            bearing = newBearing;
        }
示例#2
0
文件: Robot.cs 项目: chriscwej/robot
        // Updates the robot's position by moving one step in the current direction
        public void MoveForward()
        {
            if (xPos == null || yPos == null || bearing == null)
            {
                throw new InvalidOperationException("Cannot move without a current position and bearing");
            }

            int xMove, yMove;

            Bearing.GetMovementOffset(bearing, out xMove, out yMove);
            if (!ValidPosition(xPos.Value + xMove))
            {
                throw new InvalidOperationException("Cannot move - out of bounds");
            }
            if (!ValidPosition(yPos.Value + yMove))
            {
                throw new InvalidOperationException("Cannot move - out of bounds");
            }

            xPos += xMove;
            yPos += yMove;
        }
示例#3
0
文件: Robot.cs 项目: chriscwej/robot
 // Updates the robot's bearing by turning 90 degrees in the specified direction
 // Throws: InvalidOperationException if current bearing is bad
 public void Turn(bool clockwise)
 {
     bearing = Bearing.GetNewBearing(bearing, clockwise);
 }