Exemplo n.º 1
0
 /**
  * The given robot shoots in the direction it is facing.
  *
  * @param robot The robot that has to execute this command.
  * @effect The given robot shoots in the direction it is facing, provided it has the energy to
  *     do so.
  */
 @Override
 public void execute(Robot robot) {
   try {
     if (robot.getEnergy().compareTo(Robot.getEnergyToShoot()) != -1) robot.shoot();
   } catch (NullPointerException exc) {
     System.err.println(exc.getMessage());
   }
 }
Exemplo n.º 2
0
 /**
  * Move the robot one step forward.
  *
  * @param robot The robot that has to execute this command.
  * @effect The given robot moves one step forward.
  */
 @Override
 public void execute(Robot robot) {
   try {
     if (robot.getEnergy().compareTo(robot.getEnergyToMove()) != -1) robot.move();
   } catch (NullPointerException exc) {
     System.err.println(exc.getMessage());
   } catch (IllegalStateException exc) {
     System.err.println(exc.getMessage());
   } catch (IllegalArgumentException exc) {
     System.err.println(exc.getMessage());
   }
 }
Exemplo n.º 3
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());
   }
 }
Exemplo n.º 4
0
 /**
  * The given robot turns in counterclockwise direction
  *
  * @param robot The robot that has to execute this command.
  * @effect The given robot turns in counterclockwise direction, provided it has the energy to do
  *     so.
  */
 @Override
 public void execute(Robot robot) {
   if (robot.getEnergy().compareTo(Robot.getEnergyToTurn()) != -1) robot.turnCounterclockwise();
 }