Esempio n. 1
0
  private void spawnRandomers() {
    for (int i = 0; i < randomN; i++) {
      float x = (float) Math.random() * width;
      float y = (float) Math.random() * height;
      float r =
          (float)
              Math.sqrt(
                  Math.pow(((Player) players.get(0)).getX() - x, 2)
                      + Math.pow(((Player) players.get(0)).getY() - x, 2));

      while (r < distanceLimit) {
        x = (float) Math.random() * width;
        y = (float) Math.random() * height;
        r =
            (float)
                Math.sqrt(
                    Math.pow(((Player) players.get(0)).getX() - x, 2)
                        + Math.pow(((Player) players.get(0)).getY() - y, 2));
      }

      enemies.add(new EnemyTypes.Random(x, y, 0.5f, borders));
    }

    spawnRandomersB = false;
  }
Esempio n. 2
0
 private void spawnBomb() {
   float x, y;
   for (int i = 0; i < bombN; i++) {
     if (Math.random() > .5) { // top/bottom
       y = (Math.random() > .5) ? borders[1] : borders[3];
       x = (float) Math.random() * borders[2] - borders[0]; // width
     } else {
       x = (Math.random() > .5) ? borders[0] : borders[2];
       y = (float) Math.random() * borders[3] - borders[1]; // height
     }
     enemies.add(new EnemyTypes.Bomb(x, y, 1f, borders, scbInstance));
   }
 }
Esempio n. 3
0
  private void levelSetup() {
    reset();

    switch (level) {
      case 1:
        distance = 600;
        monsterN = 0;
        randomN = 0;
        rainN = 30;
        defaultDistance = 600;
        timeLast = 10000;
        spawnCircleB = true;
        break;
      case 2:
        distance = 600;
        monsterN = 0;
        randomN = 30;
        rainN = 30;
        defaultDistance = 600;
        timeLast += 10000;
        spawnCircleB = true;
        break;
      case 3:
        distance = 600;
        monsterN = 30;
        randomN = 0;
        rainN = 0;
        defaultDistance = 600;
        timeLast += 10000;
        spawnCircleB = true;
        break;
      default:
        distance = (float) (Math.random() * 200 + 400 - level * 5);
        monsterN = (int) (Math.random() * 25 + 10 + level);
        randomN = (int) (Math.random() * 25 + 10 + level);
        rainN = (int) (Math.random() * 10 + 10 + level);
        defaultDistance = distance;
        timeLast += 5000 + level * 1000;
        spawnCircleB = true;
    }

    monsterN *= monsterMultiplier;
    randomN *= monsterMultiplier;
    spawnMonsterB = true;
    spawnRandomersB = true;
    spawnIncrease = true;
    spawnRainB = true;
  }
 public V put(K key, V value) {
   V oldValue = null;
   int index = Math.abs(key.hashCode()) % SIZE;
   if (buckets[index] == null) buckets[index] = new ArrayList<MapEntry<K, V>>();
   ArrayList<MapEntry<K, V>> bucket = buckets[index];
   MapEntry<K, V> pair = new MapEntry<K, V>(key, value);
   boolean found = false;
   ListIterator<MapEntry<K, V>> it = bucket.listIterator();
   // int probes=0;
   while (it.hasNext()) {
     //	probes++;
     MapEntry<K, V> iPair = it.next();
     //  if(!iPair.getKey().equals(key)) System.out.println("HashCode collision on put, have
     // key:"+key+" hascode:"+key.hashCode()+" found key:"+iPair.getKey()+" hashcode:"+
     // iPair.getKey().hashCode());
     if (iPair.getKey().equals(key)) {
       oldValue = iPair.getValue();
       it.set(pair); // Replace old with new
       found = true;
       break;
     }
   }
   // System.out.println("put() probes for key "+ key+" :"+probes);
   if (!found) buckets[index].add(pair);
   return oldValue;
 }
Esempio n. 5
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;
 }
Esempio n. 6
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()
  @Override
  public V remove(Object key) {

    int index = Math.abs(key.hashCode()) % SIZE;
    if (buckets[index] == null) return null;
    for (MapEntry<K, V> iPair : buckets[index]) {
      if (iPair.getKey().equals(key)) {
        buckets[index].remove(iPair);
        return iPair.getValue();
      }
    }
    return null;
  }
Esempio n. 8
0
  private void spawnCircles() {
    if (circular) {
      for (int i = 0; i < ballN; i++) {
        double degree = Math.random() * 2 * Math.PI;
        float x = ((Player) players.get(0)).getX() + distance * (float) Math.sin(degree * i);
        float y = ((Player) players.get(0)).getY() + distance * (float) Math.cos(degree * i);
        enemies.add(new EnemyTypes.Circle(x, y, invSpeed));
      }
    } else {
      for (int i = 1; i < (ballN / 2); i++) {
        float x = (i * 2 * width) / (ballN);
        float y = 0;
        enemies.add(new EnemyTypes.Circle(x, y, invSpeed));
      }

      for (int i = (ballN / 2) + 1; i < ballN; i++) {
        float x = ((i - ballN / 2) * 2 * width) / ballN;
        float y = height;
        enemies.add(new EnemyTypes.Circle(x, y, invSpeed));
      }
    }
    spawnIncrease = false;
  }
 public V get(Object key) {
   int index = Math.abs(key.hashCode()) % SIZE;
   if (buckets[index] == null) return null;
   //  int probes=0;
   for (MapEntry<K, V> iPair : buckets[index]) {
     //      probes++;
     // 	if(!iPair.getKey().equals(key)) System.out.println("HashCode collision on put, have
     // key:"+key+" hascode:"+key.hashCode()+" foune key:"+iPair.getKey()+" hashcode:"+
     // iPair.getKey().hashCode());
     if (iPair.getKey().equals(key)) return iPair.getValue();
   }
   //  System.out.println("get() probes for key "+ key+" :"+probes);
   return null;
 }
Esempio n. 10
0
 public double getHitPoints() {
   return getStrength() + getHealth() * .5 * Math.random();
 }
Esempio n. 11
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);
 }