Exemple #1
0
 public static Item getItemFromString(String s) throws DemigodsException {
   Item item = null;
   for (Item i : allTheItems) {
     if (i.toString().equalsIgnoreCase(s)) {
       item = i;
       break;
     }
   }
   if (item == null) throw new DemigodsException("Item not found.");
   return item;
 }
Exemple #2
0
 /** Prints the bag's content */
 public void listContents() {
   System.out.println("Your bag contains :");
   Item current;
   for (int i = 0; i < listItems.size(); i++) {
     current = listItems.get(i);
     if (!current.hasAnUnlimitedLife())
       System.out.println(
           "- "
               + current.getName()
               + " (can still be used "
               + current.getLifeRemaining()
               + " time(s))");
     else System.out.println("- " + current.getName());
   }
 }
Exemple #3
0
 public static int getItemID(Item item) {
   for (int i = 0; i < allTheItems.length; ++i) {
     if (item.toString().equalsIgnoreCase(allTheItems[i].toString())) {
       return i;
     }
   }
   throw new UncheckedDemigodsException(
       "Item " + item + " does not have a spot in the ID list. Check the spelling.");
 }
  @Override
  public void event(Hero hero) {
    isHappened = true;
    // TODO Auto-generated method stub
    System.out.println(
        "Behold Hephaestus the God of blacksmiths. "
            + "The great Hephaestus is here to grant god-like armour and weapon "
            + "to heroes who are on their ways to kill Roshan.");

    if (hero.getBaseGold() >= this.requiredGold) {
      hero.setBaseGold(hero.getBaseGold() - this.requiredGold);
      for (Item item : hero.getInvt()) {
        item.increaseLevel(1);
      }
      System.out.println("You have successfully upgraded your items!");
    } else {

    }
  }
Exemple #5
0
  @Override
  public void render(GameContainer gc, StateBasedGame sbg, Graphics g) throws SlickException {

    bg.draw(0, 0);
    espace.draw(60, 500);
    rubis.draw(230, 120);
    saphirs.draw(200, 200);
    score.draw(230, 0);
    timing.draw(175, 300);
    point.draw(380, 400);
    int Nb_rubis = Item.getNB_Rubis();
    int Nb_saphirs = Item.getNB_Saphir();
    int time = Event.time * 60;
    int score =
        (int) (3000 * Math.exp(-0.00075 * (time - 15 * 60)) + 50 * Nb_rubis + 20 * Nb_saphirs);
    uFont.drawString(400, 130, "" + Nb_rubis);
    uFont.drawString(400, 210, "" + Nb_saphirs);
    uFont.drawString(350, 310, "" + time / 60);
    uFont.drawString(250, 420, "" + score);
  }
  /** Detects keyboard and mouse input and makes the main player react accordingly. */
  private void getKeyboardAndMouseInput() {
    Player player = Crissaegrim.getPlayer();
    EntityMovementHelper pmh = player.getMovementHelper();
    if (Keyboard.isKeyDown(Keyboard.KEY_A)) {
      pmh.requestLeftMovement();
    }
    if (Keyboard.isKeyDown(Keyboard.KEY_D)) {
      pmh.requestRightMovement();
    }
    if (Keyboard.isKeyDown(Keyboard.KEY_W) || Keyboard.isKeyDown(Keyboard.KEY_SPACE)) {
      pmh.requestJumpMovement();
    }

    while (Keyboard.next()) {
      if (Keyboard.getEventKeyState()) { // Key was pressed (not released)
        int pressedKey = Keyboard.getEventKey();

        //				if (pressedKey == Keyboard.KEY_B) {
        //					DialogBoxRunner dbr = new DialogBoxRunner();
        //					DialogBox.Result res = dbr.run(new DialogBox(
        //							Arrays.asList("A wild dialog box appeared!", "Do you want to set this location as
        // your respawn point?"),
        //							Arrays.asList("Yes", "No", "I-I don't know, I thought I heard a thump?")));
        //					if (res == DialogBox.Result.BUTTON_1) { Crissaegrim.addSystemMessage("Cool."); }
        //					else if (res == DialogBox.Result.BUTTON_2) { Crissaegrim.addSystemMessage("Fine!"); }
        //					else if (res == DialogBox.Result.BUTTON_3) {
        // Crissaegrim.addSystemMessage("P-President Fabio?"); }
        //				}
        //				if (pressedKey == Keyboard.KEY_B) {
        //					new SmithingRunner().run(); // Incomplete
        //				}
        if (pressedKey == Keyboard.KEY_B) {
          player.receiveItem(Items.tameikeSword());
          player.receiveItem(Items.tameikePickaxe());
          player.receiveItem(Items.bluePartyPopper());
        }

        if (pressedKey == Keyboard.KEY_T
            || pressedKey == Keyboard.KEY_RETURN) { // T or Enter: Enter chat mode
          Crissaegrim.getChatBox().enableTypingMode();
          return; // Don't process any more keys!
        } else if (pressedKey == Keyboard.KEY_UP) { // Up arrow: Select previous inventory item
          player.getInventory().selectPreviousItem();
        } else if (pressedKey == Keyboard.KEY_DOWN) { // Down arrow: Select next inventory item
          player.getInventory().selectNextItem();
        } else if (pressedKey >= Keyboard.KEY_1
            && pressedKey <= Keyboard.KEY_8) { // 1-8: Select inventory item
          player.getInventory().selectSpecificItem(pressedKey - Keyboard.KEY_1);
        } else if (pressedKey == 41) { // Backtick (`) key
          Crissaegrim.toggleDebugMode();
        } else if (pressedKey == Keyboard.KEY_TAB) { // Tab key: Toggle zoom
          Crissaegrim.toggleZoom();
        } else if (pressedKey == Keyboard.KEY_M) { // M key: Toggle window size
          Crissaegrim.toggleWindowSize();
        } else if (pressedKey == Keyboard.KEY_E) { // E key: Open inventory
          new InventoryRunner().run();
        } else if (pressedKey == Keyboard.KEY_F) { // F key: Activate F-key doodads or pick up items
          boolean pickedUpAnItem = false;
          Iterator<LocalDroppedItem> localDroppedItemsIter = localDroppedItems.iterator();
          while (localDroppedItemsIter.hasNext()) {
            LocalDroppedItem localDroppedItem = localDroppedItemsIter.next();
            if (!player.isBusy()
                && player.getCurrentBoardName().equals(localDroppedItem.getBoardName())
                && RectUtils.rectsOverlap(
                    Crissaegrim.getPlayer().getEntityEntireRect(), localDroppedItem.getBounds())) {
              if (player.getInventory().isFull()) {
                Crissaegrim.addSystemMessage("Your inventory is full.");
              } else {
                Item item = localDroppedItem.getItem();
                if (item instanceof StackableItem) {
                  Crissaegrim.addSystemMessage(
                      "You picked up "
                          + ((StackableItem) (item)).getNumberInStack()
                          + " "
                          + item.getName()
                          + "s.");
                } else {
                  Crissaegrim.addSystemMessage(
                      "You picked up "
                          + TextUtils.aOrAn(item.getName())
                          + " "
                          + item.getName()
                          + ".");
                }
                player.getInventory().addItem(item);
                localDroppedItemsIter.remove();
                pickedUpAnItem = true;
              }
              break;
            }
          }
          if (!pickedUpAnItem) { // If the F key was not used to pick up an item, it will be used to
            // activate a doodad
            for (Doodad doodad : Crissaegrim.getCurrentBoard().getDoodads().values()) {
              if (!player.isBusy()
                  && RectUtils.coordinateIsInRect(player.getPosition(), doodad.getBounds())) {
                switch (doodad.getDoodadAction()) {
                  case DoodadActions.GO_THROUGH_DOORWAY:
                    Door door = (Door) doodad;
                    pmh.resetMovementRequests();
                    setNewDestination(
                        door.getDestinationBoardName(), door.getDestinationCoordinate());
                    requestTravelToDestinationBoard();
                    break;
                  case DoodadActions.SMELT_ORE:
                    new SmeltingRunner().run();
                    break;
                  case DoodadActions.READ_SIGNPOST:
                    Signpost signpost = (Signpost) doodad;
                    new DialogBoxRunner().run(new DialogBox(signpost.getMessages(), "Ok"));
                    break;
                  default:
                    break;
                }
                break; // Found the relevant Doodad; ignore the rest
              }
            }
          }
        }
      }
    }

    if (!Crissaegrim.getChatBox().isTypingMode()) {
      while (Mouse.next()) {
        if (Mouse.getEventButtonState()) { // Button was clicked (not released)
          if (Mouse.getEventButton() == 0) {
            pmh.requestUseItem(
                getCoordinatesForMouse(), Crissaegrim.getPlayer().getInventory().getCurrentItem());
          }
        }
      }
      int scrollDelta = Mouse.getDWheel();
      if (scrollDelta < 0) {
        Crissaegrim.getPlayer().getInventory().selectNextItem();
      } else if (scrollDelta > 0) {
        Crissaegrim.getPlayer().getInventory().selectPreviousItem();
      }
    }
  }