Пример #1
0
 /**
  * Returns the cost in actionpoints for a given number of steps in the current direction.
  *
  * @param steps the number of steps the worm is going to move.
  * @return The cost of steps (integer) in the current direction, rounded up to the next integer.
  *     |(steps*(int) Math.round((Math.abs(Math.cos(this.getDirection()))
  *     |+Math.abs((4*Math.sin(this.getDirection()))))))
  */
 @Basic
 @Raw
 private int computeCostStep(int steps) {
   return Math.abs(
       (int)
           Math.round(
               (steps)
                   * (Math.abs(Math.cos(this.getDirection()))
                       + Math.abs((4.0 * Math.sin(this.getDirection()))))));
 }
Пример #2
0
 /**
  * Returns the cost in actionpoints for a turn of a given angle.
  *
  * @param angle the angle over which the worm would like to turn in radians.
  * @return the cost in actionpoints for a turn of a given angle rounded up to the nearest integer.
  *     |(int) Math.abs(Math.round(((60*angle)/(2*Math.PI))))
  */
 @Basic
 @Raw
 private int computeCostTurn(double angle) {
   return (int) Math.abs(Math.round(((60 * angle) / (2 * Math.PI))));
 }
Пример #3
0
 /**
  * Returns the cost in actionpoints to move in the current direction.
  *
  * @param prevXpos The x-position of the worm before he moved.
  * @param prevYpos The y-position of the worm before he moved.
  */
 @Raw
 private int computeCost2(double prevXpos, double prevYpos) {
   return (int)
       (Math.round(Math.abs(this.getXpos() - prevXpos))
           + Math.round(4 * Math.abs(this.getYpos() - prevYpos)));
 }
Пример #4
0
  /**
   * Set the maximal amount of hit points of this worm.
   *
   * @param mass The hit points change along with the mass.
   * @post The amount of hit points must be equal to the mass of the worm rounded to the nearest
   *     integer. | this.maxHitPoints = (int) Math.round(mass)
   * @post If the mass of a worm changes, the maximal must be adjusted accordingly. | new.getMass()
   *     = mass | this.maxHitPoints == (int) Math.round(new.getMass()) == int Math.round(mass)
   * @effect The maximal amount of hit points has been set.
   */
  @Raw
  private void setMaxHitPoints() {

    if (this.getMass() < Integer.MAX_VALUE) this.maxHitPoints = (int) Math.round(this.getMass());
    else this.maxHitPoints = Integer.MAX_VALUE;
  }