Beispiel #1
0
 public void useItem(String itemName) {
   boolean itemInInventory = isInInventory(itemName);
   boolean itemInRoom = GameMap.getCurrentRoom().itemExistsInRoom(itemName);
   if (!itemInInventory && itemInRoom) {
     Item takenFromRoom = GameMap.getCurrentRoom().takeItemFromRoom(itemName);
     GameGUI.player.addToInventory(takenFromRoom);
     itemInInventory = true;
   }
   if (itemInInventory) {
     Item item = ItemLibrary.get(itemName);
     if (item instanceof Weapon) {
       equipItem(item);
     } else if (item instanceof ConsumableHealth) {
       GameGUI.addToConsole("Consuming " + item.getName() + "...");
       GameMap.getCurrentRoom().combat.healPlayerWith(item);
       GameGUI.updateGUI();
     } else if (item instanceof KeyItem) {
       GameLog.warning("THIS IS A KEY ITEM!");
     } else {
       GameLog.severe("MAJOR ISSUES!");
     }
   } else {
     GameGUI.addToConsole("I'm not sure how I would use that...");
   }
 }
Beispiel #2
0
 public static void start(String questXMLFile) {
   xml = new XMLparser(questXMLFile);
   GameGUI.player = new Player();
   GameGUI.player.getInventory().clear();
   GameGUI.resetConsole();
   roomsTable = new Hashtable<String, Room>();
   CartesianPoint.setCoordinates(0, 0);
   GameGUI.updateGUI();
   GameGUI.addToConsole("Loaded scenario from " + questXMLFile);
   loadRoom();
 }
Beispiel #3
0
 public void addToInventory(Item item) {
   if (isInventoryFull()) {
     GameGUI.addToConsole(
         "Your inventory is full. You cannot put "
             + item
             + " into your inventory without becuming encumbered");
   } else {
     inventory.add(item);
     GameGUI.addToConsole("You put " + item + " in inventory ");
     GameGUI.updateGUI();
   }
 }
Beispiel #4
0
  public static void movePlayerWest() {
    if (!xml.roomWestDescript().equals("an invisible wall")) {
      Door currentRoomDoor = currentRoom.getRoomDoor();
      if (currentRoom.containsLockedDoor()
          && currentRoomDoor.getDirection().equalsIgnoreCase("west")) {

        GameGUI.addToConsole("You run head first into a " + currentRoomDoor.getName());
      } else {
        CartesianPoint.x--;
        loadRoom();
      }
    } else
      GameGUI.addToConsole("You run head first into an invisible wall. You remain the same room.");
  }
Beispiel #5
0
 public void unEquipItem(Item item) {
   if (inventory.contains(item)) {
     if (item.equals(equipment.armor)) {
       equipment.armor = new Armor("", "", "", 0);
       GameGUI.addToConsole("You slip off your " + item);
     } else if (item.equals(equipment.weapon)) {
       equipment.weapon = new Weapon("", "", "", 0);
       GameGUI.addToConsole("You put your " + item + " away");
     } else {
       GameGUI.addToConsole(item + " is not equipped");
     }
   } else {
     GameGUI.addToConsole("You don't have that item");
   }
   GameGUI.updateGUI();
 }
Beispiel #6
0
 public void equipItem(Item item) {
   if (inventory.contains(item)) {
     if (item instanceof Armor) {
       equipment.armor = (Armor) item;
       GameGUI.addToConsole("You slip on your " + item);
     } else if (item instanceof Weapon) {
       equipment.weapon = (Weapon) item;
       GameGUI.addToConsole("You bring your " + item + " to the ready");
     } else {
       GameGUI.addToConsole(item + " is not equipable");
     }
   } else {
     GameGUI.addToConsole("You don't have that item");
   }
   GameGUI.updateGUI();
 }
Beispiel #7
0
 private static void loadRoom() {
   currentRoom = roomsTable.get(CartesianPoint.keyCreator());
   if (!(currentRoom instanceof Room)) {
     currentRoom = xml.loadRoom();
     roomsTable.put(CartesianPoint.keyCreator(), currentRoom);
   }
   GameGUI.addToConsole(currentRoom.getFullRoomDescription());
 }
Beispiel #8
0
  public void discardItem(Item item) {
    if (inventory.contains(item)) {
      if (item instanceof KeyItem) {
        GameGUI.addToConsole("You can not remove Key Items");
        return;
      }

      GameMap.getCurrentRoom().getAllItems().add(item);
      inventory.remove(item);
      if (item instanceof Armor) {
        if (!isInInventory(equipment.armor)) {
          equipment.armor = new Armor("", "", "", 0);
        }
      } else if (item instanceof Weapon) {
        if (!isInInventory(equipment.weapon)) {
          equipment.weapon = new Weapon("", "", "", 0);
        }
      }
      GameGUI.addToConsole("You toss away " + item + " in disgust");
    } else {
      GameGUI.addToConsole("You do not have " + item);
    }
    GameGUI.updateGUI();
  }
Beispiel #9
0
 public void inspectInventoryFor(Item item) {
   if (inventory.contains(item)) {
     GameGUI.addToConsole("You have " + item);
   }
   GameGUI.addToConsole("You dont have " + item);
 }