Пример #1
0
 private double distanceTo(Actor opponent) {
   double actorToMoveX = opponent.getAvatar().getTranslateX();
   double actorToMoveY = opponent.getAvatar().getTranslateY();
   double currentX = getAvatar().getTranslateX();
   double currentY = getAvatar().getTranslateY();
   double deltaX = actorToMoveX - currentX;
   double deltaY = actorToMoveY - currentY;
   double calculatedDistance = Math.sqrt(deltaX * deltaX + deltaY * deltaY);
   return calculatedDistance;
 }
Пример #2
0
  /**
   * processes a single round of combat between two Actor objects: the <b>attacker</b> is this
   * object; the <b>defender</b> is received as an argument. This method is called by the
   * <b>attacker</b> <i>Actor</i> object. This <b>attacker</b> <i>Actor</i> object chooses another
   * <i>Actor</i> object as the <b>defender</b> by sending a reference-to the second <i>Actor</i>
   * object. When program execution arrives in <i>combatRound</i>, the method will have access to 2
   * sets of <i>Actor</i> attributes (a.k.a. instance fields). In particular, this method will need
   * to use <i>health</i> and <i>strength</i> to process a single round of combat. As an outcome of
   * the single round, both <i>Actor</i> objects: the <b>attacker</b> and the <b>defender</b> are
   * likely to loose some <i>health</i> value, but the <i>Actor</i> object with less <i>strength</i>
   * will likely incur more damage to their <i>health</i>. You access the <b>attacker</b> instance
   * fields (such as <i>health</i> using <i>this.health</i> and the <b>defender</b> instance fields
   * using <i>defender.health</i>. Of course, <i>defender</i> is the name of the stack-oriented
   * reference-to variable that is sent to the method.
   *
   * @param defender a reference to a different <i>Actor</i> object that will engage in combat with
   *     this <i>Actor</i> object.
   * @return <i>health</i> of the <i>Actor</i> following the combat round.
   */
  public double combatRound(Actor defender) {
    final double MAX_COMBAT_HEALTH_REDUCTION_OF_LOOSER =
        10.0; // health ranges 0.0 to 100.0, thus could loose 0.0 to 10.0
    final double MAX_COMBAT_HEALTH_REDUCTION_OF_WINNER = 3.0; // could loose 0.0 to 3.0
    double healthAdjustmentOfLooser =
        -(Math.random() * MAX_COMBAT_HEALTH_REDUCTION_OF_LOOSER)
            - 1.0; // looser looses at least 1.0
    double healthAdjustmentOfWinner =
        -(Math.random() * MAX_COMBAT_HEALTH_REDUCTION_OF_WINNER) + 1.0; // winner gains at least 1.0

    double proportionHitPoints =
        getHitPoints() / (getHitPoints() + defender.getHitPoints()); // between 0.0 and 1.0
    if (Math.random() > proportionHitPoints) {
      adjustHealth(healthAdjustmentOfLooser);
      defender.adjustHealth(healthAdjustmentOfWinner);
    } else {
      defender.adjustHealth(healthAdjustmentOfLooser);
      adjustHealth(healthAdjustmentOfWinner);
    }
    return getHealth();
  } // end combatRound()
Пример #3
0
  void drawingCommands() {
    // Rotation about z:
    double theta = Math.PI / 3.0;
    double a11 = Math.cos(theta);
    double a12 = -Math.sin(theta);
    double a21 = Math.sin(theta);
    double a22 = Math.cos(theta);
    double[][] A = {
      {a11, a12, 0, 0},
      {a21, a22, 0, 0},
      {0, 0, 1, 0},
      {0, 0, 0, 1}
    };

    /*
    // INSERT YOUR CODE for rotation about x by 30 degrees
    double[][] B = {

    };

    // INSERT YOUR CODE for translation by (2,3,4)
    double[][] C = {

    };

    double[][] temp = MatrixTool.matrixMult (B,A);
    double[][] transform = MatrixTool.matrixMult (C,temp);
    */

    // Replace this transform with the above after implementing
    // matrices B and C
    double[][] transform = A;

    double x0 = 0, y0 = 0; // Center of original 2D ellipse.
    double a = 7; // Major axis
    double b = 4; // Minor axis
    double delT = 0.25; // t-increment for drawing

    d3.setDrawColor(Color.RED);
    for (double t = 0; t <= 2 * Math.PI + delT; t += delT) {
      double[] x = new double[4];
      x[0] = a * Math.cos(t);
      x[1] = b * Math.sin(t);
      x[2] = 0;
      x[3] = 1;
      double[] z = MatrixTool.matrixVectorMult(transform, x);
      d3.drawPoint(z[0], z[1], z[2]);
    }
  }
Пример #4
0
 public double getHitPoints() {
   return getStrength() + getHealth() * .5 * Math.random();
 }
Пример #5
0
 /**
  * <i>Actor</i> regain health on each cycle of the simulation (and loose health in battles handled
  * by other code).
  */
 public void gameCycleHealthGain() {
   final double MAX_CYCLE_HEALTH_GAIN = 2.0;
   adjustHealth(Math.random() * MAX_CYCLE_HEALTH_GAIN);
 }