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
 /**
  * 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();
 }