예제 #1
0
  public BufferedImage getImage(String Direct, String FName) {
    // JOptionPane.showMessageDialog(null, "GameCharacter");
    try {
      BufferedImage bg = ImageIO.read(getClass().getResource(Direct + FName));
      return bg;

    } catch (Exception e) {
      JOptionPane.showMessageDialog(null, getClass().toString());
    }
    return null;
  }
예제 #2
0
  /**
   * do damage to character
   *
   * @param Dmg Amount of Damage
   */
  public void Damage(int Dmg, int Type) {
    // If character is already dead then dont do damage
    if (ISDEAD) return;

    // Do damage
    if (Type == 1) {
      // DAMAGE FROM PHYSICAL ATTACK
      if (STATS.ARMOR > Dmg) return;
      HEALTH = HEALTH - Dmg + STATS.ARMOR;
    } else if (Type == 2) {
      // DAMAGE FROM MAGIC ATTACK
      if (STATS.MAGIC_RESIST > Dmg) return;
      HEALTH = HEALTH - Dmg + STATS.MAGIC_RESIST;
    }
    // If an Npc then run and hide
    if (NAI != null) {
      NAI.State = "alarmed";
    }

    // Death condition
    if (HEALTH <= 0) {
      // If player is dead
      if (this.CLASS.equals("Player")) {

        HEALTH = 0;

        // Quit game
        JOptionPane.showMessageDialog(null, "You are dead");
        X = 100;
        Y = 100;
        Opify(50);
        HEALTH = (int) MAX_HEALTH;

      } else {
        // If other character
        // set Death stats
        ISDEAD = true;
        HEALTH = 0;
        // display death
        CLASS = Cl + " (Dead)";

        // Rot effect
        for (int i = 0; i < imgCHARAC.getWidth(); i++) {
          for (int j = 0; j < imgCHARAC.getHeight(); j++) {
            imgCHARAC.setRGB(i, j, imgCHARAC.getRGB(i, j) * (int) Math.pow(3, 3));
          }
        }

        // Make inventory open to looting
        INVENTORY.OPEN_INVEN = true;
      }
    }
  }
예제 #3
0
  /**
   * Buy an item from a shopkeeper
   *
   * @param Targ Target Inventory
   * @param Index Item Index
   */
  public void Buy(ItemList Targ, int Index) {
    // If item is too expensive
    if (Targ.ITEM_PRICE.elementAt(Index) > this.GOLD) {
      JOptionPane.showMessageDialog(null, "Too rich for your blood");
      return;
    }

    // add Item to character inventory
    this.INVENTORY.addItem(
        Targ.ITEM_NAME.elementAt(Index),
        Targ.ITEM_PRICE.elementAt(Index),
        1,
        Targ.ITEM_IMAGE.elementAt(Index),
        Targ.ITEM_TAG.elementAt(Index),
        Targ.STATS.elementAt(Index));

    // remove Gold
    this.GOLD -= Targ.ITEM_PRICE.elementAt(Index);

    // remove item from target inventory
    Targ.removeItem(Index, 1);
  }