Exemplo n.º 1
0
 /**
  * Lets the given robot pick up and use an item.
  *
  * @param robot The robot that has to execute this command.
  * @effect The given robot picks up and use a random item on its current position, provided
  *     there is an item on the same position.
  */
 @Override
 public void execute(Robot robot)
     throws NullPointerException, IllegalArgumentException, IllegalStateException {
   try {
     Item item = robot.getBoard().getRandomItemOnPosition(robot.getPosition());
     if (item != null) robot.pickUp(item);
     robot.use(item);
   } catch (NullPointerException exc) {
     assert false;
   } catch (IllegalArgumentException exc) {
     System.err.println(exc.getMessage());
   } catch (IllegalStateException exc) {
     assert false;
   } catch (NoSuchElementException exc) {
     System.err.println(exc.getMessage());
   }
 }