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;
  }
  /**
   * 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;
      }
    }
  }
Exemple #3
0
  private void neuesLaufwerkDialog() {
    Object[] options = {"Quell", "Ziel", "Abbruch"};

    System.out.println("windowClosing()");

    int retValue =
        JOptionPane.showOptionDialog(
            null,
            "Neues Laufwerk wurde gefunden. Soll es eingebunden werden?",
            "Laufwerk endeckt",
            JOptionPane.YES_NO_CANCEL_OPTION,
            JOptionPane.QUESTION_MESSAGE,
            null,
            options,
            options[2]);

    if (retValue == JOptionPane.CANCEL_OPTION || retValue == JOptionPane.CLOSED_OPTION) return;
    else if (retValue == JOptionPane.YES_OPTION) addQListBoxEintrag(dateiAuswählen(neuesLaufwerk));
    else if (retValue == JOptionPane.NO_OPTION) addZListBoxEintrag(dateiAuswählen(neuesLaufwerk));
  }
Exemple #4
0
 // If this is a new installation, ask the user for a
 // port for the server; otherwise, return the negative
 // of the configured port. If the user selects an illegal
 // port, return zero.
 private int getPort() {
   // Note: directory points to the parent of the CTP directory.
   File ctp = new File(directory, "CTP");
   if (suppressFirstPathElement) ctp = ctp.getParentFile();
   File config = new File(ctp, "config.xml");
   if (!config.exists()) {
     // No config file - must be a new installation.
     // Figure out whether this is Windows or something else.
     String os = System.getProperty("os.name").toLowerCase();
     int defPort = ((os.contains("windows") && !programName.equals("ISN")) ? 80 : 1080);
     int userPort = 0;
     while (userPort == 0) {
       String port =
           JOptionPane.showInputDialog(
               null,
               "This is a new "
                   + programName
                   + " installation.\n\n"
                   + "Select a port number for the web server.\n\n",
               Integer.toString(defPort));
       try {
         userPort = Integer.parseInt(port.trim());
       } catch (Exception ex) {
         userPort = -1;
       }
       if ((userPort < 80) || (userPort > 32767)) userPort = 0;
     }
     return userPort;
   } else {
     try {
       Document doc = getDocument(config);
       Element root = doc.getDocumentElement();
       Element server = getFirstNamedChild(root, "Server");
       String port = server.getAttribute("port");
       return -Integer.parseInt(port);
     } catch (Exception ex) {
     }
   }
   return 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);
  }