Beispiel #1
0
  /**
   * Initialize this new projectile in a given world, at given position, with given propulsion, in
   * given direction, with given radius and with which weapon it is fired.
   *
   * @param position the position of the projectile
   * @param world the world the projectile is in
   * @param Propulsion the propulsion with what the projectile is launched
   * @param Direction the direction of the projectile
   * @param radius the radius of the projectile
   * @param weapon the weapon from which the projectile is fired
   * @post The yield of this new projectile equals the given propulsion | new.getYield() ==
   *     propulsion
   * @effect The weapon with which this new projectile will be fired equals the given weapon |
   *     setWeapon(weapon)
   * @effect This new projectile is initialized as a moving object with given radius, given
   *     direction, in given world and at the given position. | super(radius, position, world,
   *     weapon.getMass(),Direction)
   */
  public Projectile(
      Position position,
      World world,
      int Propulsion,
      double Direction,
      double radius,
      Weapon weapon)
      throws IllegalArgumentException, IllegalPositionException, IllegalWorldException {
    super(radius, position, world, weapon.getMass(), Direction);
    if (!isValidYield(Propulsion)) throw new IllegalArgumentException("not a valid yield");

    this.setWeapon(weapon);

    this.yield = Propulsion;
  }
Beispiel #2
0
 /** This method makes the worm select the next weapon. */
 @Raw
 public void selectNextWeapon() {
   weapon.changeWeapon();
 }
Beispiel #3
0
 /** This method returns the name of the selected weapon. */
 @Raw
 public String getSelectedWeapon() {
   return weapon.getName();
 }
Beispiel #4
0
 /** This method returns the mass of the projectile of the selected weapon. */
 @Raw
 public int getMassProjectile() {
   return weapon.getMass();
 }
Beispiel #5
0
 /**
  * checks whether a weapon is a valid for this projectile.
  *
  * @param weapon the weapon to be checked
  * @return true if and only if the weapon is not null and the weapon is not terminated |result ==
  *     | (weapon != null && (!weapon.isTerminated()))
  */
 @Raw
 public static boolean isValidWeapon(Weapon weapon) {
   return ((weapon != null) && (!weapon.isTerminated()));
 }