Exemplo n.º 1
0
  /**
   * This method applies the player's damage to the zombie without an item.
   *
   * @param p The player
   * @param z The zombie
   * @return true if the zombie is defeated, false otherwise
   */
  public boolean attackZombie(Player p, Zombie z) {

    int playerDamage = (int) (Player.MAX_DAMAGE * Math.random()) + 1;

    z.setHitPoints(z.getHitPoints() - playerDamage);

    if (z.getHitPoints() <= 0) {
      return true;
    } else {
      return false;
    }
  }
Exemplo n.º 2
0
  /**
   * Damages a zombie using the player's damage plus the item damage
   *
   * @param p the player
   * @param z the zombie
   * @param i the item being used
   * @return true if the item breaks, false otherwise
   */
  public boolean attackZombieWithItem(Player p, Zombie z, Item i) {

    int playerDamage = (int) (Player.MAX_DAMAGE * Math.random()) + 1 + i.getHitPoints();

    i.setDurability(i.getDurability() - 1);

    z.setHitPoints(z.getHitPoints() - playerDamage);

    if (i.getDurability() <= 0) {
      // We need to remove this item from the player's inventory
      p.getItems().remove(i);
      return true;
    }

    return false;
  }