コード例 #1
0
        public void Place(ITable table, Point.Point desiredPosition, Direction.Direction desiredDirection)
        {
            if (table == null)
            {
                throw new ArgumentNullException(nameof(table));
            }
            if (!Enum.IsDefined(typeof(Direction.Direction), desiredDirection))
            {
                throw new ArgumentOutOfRangeException(nameof(desiredDirection));
            }

            //Check desiredPosition validity
            if (table.IsPositionAvailableOnTable(desiredPosition))
            {
                //Create new Status instance (if needed) and set properties
                if (Status == null)
                {
                    Status = new Status(table, desiredPosition, desiredDirection);
                }
                else
                {
                    Status.Table     = table;
                    Status.Position  = desiredPosition;
                    Status.Direction = desiredDirection;
                }
            }
            else
            {
                throw new InvalidOperationException(NotAvailablePositionText);
            }
        }
コード例 #2
0
 ///<summary>Initializes a new instance of the ToyRobotSimulatorCore.Robot.RobotStatus.Status class with the provided table, position and direction.</summary>
 ///<param name ="table">The table the robot is placed on.</param>
 ///<param name="position">The position of the robot.</param>
 ///<param name="direction">The direction of the robot.</param>
 ///<exception cref="System.ArgumentNullException">Thrown if <paramref name="table"/> is null.</exception>
 public Status(ITable table, Point.Point position, Direction.Direction direction)
 {
     if (table == null)
     {
         throw new ArgumentNullException(nameof(table));
     }
     this.Table     = table;
     this.Position  = position;
     this.Direction = direction;
 }
コード例 #3
0
 public bool IsPositionAvailableOnTable(Point.Point position)
 {
     return((position.x >= 0 && position.x < HorizontalSize) && (position.y >= 0 && position.y < VerticalSize));
 }