Ejemplo n.º 1
0
 /**
  * temp method for npc interactions
  *
  * @param command
  * @param index
  */
 private static void interact(String[] command, int index) {
   Scene curScene = DungeonMaster.player.scene;
   int npcIndex = -1;
   String npcName = "";
   boolean found = false;
   NPC testNpc = new NPC(null, npcName, null, curScene, null);
   if (command[index + 1].equals("to")) index++;
   if (command[index + 1].equals("with")) index++;
   for (int i = 1; i < command.length - index; i++) {
     npcName += command[index + i];
     npcIndex = curScene.findActor(npcName);
     if (npcIndex != -1) {
       if (curScene.actors[npcIndex].getClass().equals(testNpc.getClass())) {
         NPC realNpc = (NPC) curScene.actors[npcIndex];
         realNpc.talk.run();
       } else {
         System.out.println("System: You can't talk to that");
         if (DungeonMaster.help) System.out.println("Help: That actor isn't a NPC");
       }
       break;
     } else {
       npcName += " ";
     }
     if ((i == 3 || i == command.length - index - 1) && npcIndex != -1) {
       System.out.println("System: NPC not found");
       if (DungeonMaster.help) System.out.println("Help: Given NPC not found in current scene");
     }
   }
   testNpc = null;
 }
Ejemplo n.º 2
0
  /**
   * outputs the inventory of the given actorIndex or the players inventory or the players equipment
   *
   * @param command
   * @param index
   */
  private static void check(String[] command, int index) {
    String output = "";
    Item[] inventory = null;
    boolean possible = true;
    if (command[index + 1].equals("inventory")) {
      inventory = DungeonMaster.player.inventory;
      output = "System: You have ";
    }
    if (command[index + 1].equals("equipment")) {
      System.out.println("System: You have equiped:");
      check(new String[] {"check", "armor"}, 0);
      check(new String[] {"check", "weapon"}, 0);
      check(new String[] {"check", "misc"}, 0);
      DungeonMaster.inputCommand();
    } else if (command[index + 1].equals("armor")) {
      inventory = DungeonMaster.player.gear.armorArray;
      output = "  Armor: ";
    } else if (command[index + 1].equals("weapon")) {
      inventory = DungeonMaster.player.gear.weaponArray;
      output = "  Weapon: ";
    } else if (command[index + 1].equals("misc")) {
      inventory = DungeonMaster.player.gear.miscArray;
      output = "  Misc: ";
    } else {
      String invenName = "";
      Scene curScene = DungeonMaster.player.scene;
      for (int i = 1; i < command.length - index; i++) {
        invenName += command[index + i];

        int objectIndex = curScene.findObject(invenName);
        if (objectIndex != -1) {
          inventory = curScene.objects[objectIndex].inventory;
          output = "System: You found ";
          break;
        } else {
          invenName += " ";
        }
      }
    }
    if (inventory != null && possible) {
      output += nameList(inventory);
      System.out.println(output);
    }
    if (inventory == null && possible) {
      System.out.println("System: Object not found");
      if (DungeonMaster.help) System.out.println("Help: Given object isn't in your current scene");
    }
  }
Ejemplo n.º 3
0
 /**
  * starts a fight with the given actorIndex
  *
  * @param command
  * @param index
  */
 private static void attack(String[] command, int index) {
   Scene curScene = DungeonMaster.player.scene;
   String actorName = "";
   for (int i = 1; i < command.length - index; i++) {
     actorName += command[index + i];
     int actorIndex = curScene.findActor(actorName);
     if (actorIndex != -1) {
       // if (curScene.actors[actorIndex].location == DungeonMaster.player.location) {
       DungeonMaster.player.fight(curScene.actors[actorIndex]);
       // }
       // else {
       //    System.out.println("You can't attack that from here");
       //    if (DungeonMaster.help)System.out.println("Help: Try Go To-");
       // }
     } else {
       actorName += " ";
     }
     if ((i == 3 || i == command.length - index - 1) && actorIndex == -1) {
       System.out.println("System: Actor not found");
       if (DungeonMaster.help) System.out.println("Help: Given actor not found in current scene");
     }
   }
 }
Ejemplo n.º 4
0
  /**
   * Sends the player to the given actorIndex, door, or item
   *
   * @param command
   * @param index
   */
  private static void go(String[] command, int index) {
    Scene curScene = DungeonMaster.player.scene; // look for actors
    int actorIndex = -1;
    String place = "";
    boolean found = false;
    if (command[index + 1].equals("to")) index++;
    for (int i = 1; i < command.length - index; i++) {
      place += command[index + i];
      actorIndex = curScene.findActor(place);
      if (actorIndex != -1) found = true;
      else place += " ";
    }
    if (found) {
      DungeonMaster.player.location = curScene.actors[actorIndex].location;
      System.out.println(
          "System: You're new loctaion is: "
              + DungeonMaster.player.location.x
              + ", "
              + DungeonMaster.player.location.y);
      for (int i = 0; i < DungeonMaster.player.inventory.length; i++) {
        DungeonMaster.player.inventory[i].location = DungeonMaster.player.location;
      }
      DungeonMaster.inputCommand();
    }
    if (!found) {
      actorIndex = -1; // look for objects
      place = "";
      found = false;
      for (int i = 1; i < command.length - index; i++) {
        place += command[index + i];
        actorIndex = curScene.findObject(place);
        if (actorIndex != -1) found = true;
        else place += " ";
      }
    }
    if (found) {
      DungeonMaster.player.location = curScene.objects[actorIndex].location;
      System.out.println(
          "System: You're new loctaion is: "
              + DungeonMaster.player.location.x
              + ", "
              + DungeonMaster.player.location.y);
      for (int i = 0; i < DungeonMaster.player.inventory.length; i++) {
        DungeonMaster.player.inventory[i].location = DungeonMaster.player.location;
      }
      DungeonMaster.inputCommand();
    }
    int itemIndex = -1;
    if (!found) {

      String item = ""; // look for actors
      for (int i = 1; i < command.length - index; i++) {
        item += command[index + i];
        for (int j = 0; j < curScene.inventory.length; j++) {
          if (curScene.inventory[j].name.equals(item)) {
            itemIndex = j;
            break;
          }
        }
        if (itemIndex != -1) found = true;
        else item += " ";
      }
    }
    if (found) {
      DungeonMaster.player.location = curScene.inventory[itemIndex].location;
      System.out.println(
          "System: You're new loctaion is: "
              + DungeonMaster.player.location.x
              + ", "
              + DungeonMaster.player.location.y);
      for (int i = 0; i < DungeonMaster.player.inventory.length; i++) {
        DungeonMaster.player.inventory[i].location = DungeonMaster.player.location;
      }
      DungeonMaster.inputCommand();
    }
    if (!found) {
      place = ""; // look for doors
      for (int i = 1; i < command.length - index; i++) {
        place += command[index + i];
        for (int j = 0; j < curScene.doors.size(); j++) {
          if (curScene.doors.get(j).name.equals(place)) {
            actorIndex = j;
            found = true;
            ;
          }
        }
        place += " ";
      }
    }
    if (found) {
      if (!curScene.doors.get(actorIndex).locked) {
        DungeonMaster.player.location = curScene.doors.get(actorIndex).location;
        String[] temp = new String[1];
        temp[0] = "enter";
        enter();
        DungeonMaster.inputCommand();
      } else {
        System.out.println("System: It's locked");
        for (int i = 0; i < DungeonMaster.player.inventory.length; i++) {
          if (DungeonMaster.player.inventory[i].name.equals(
              curScene.doors.get(actorIndex).name + " key")) {
            System.out.println("System: Key used");
            DungeonMaster.player.invenRemov(DungeonMaster.player.inventory[i]);
            curScene.doors.get(actorIndex).locked = false;
            DungeonMaster.player.location = curScene.doors.get(actorIndex).location;
            String[] temp = new String[1];
            temp[0] = "enter";
            enter();
          }
        }
      }

    } else if (isNum(command[index + 1]) && isNum(command[index + 2])) { // check if it's a location
      DungeonMaster.player.location =
          new Point(Integer.parseInt(command[index + 1]), Integer.parseInt(command[index + 2]));
      System.out.println(
          "System: You're new loctaion is: "
              + DungeonMaster.player.location.x
              + ", "
              + DungeonMaster.player.location.y);
      for (int i = 0; i < DungeonMaster.player.inventory.length; i++) {
        DungeonMaster.player.inventory[i].location = DungeonMaster.player.location;
      }
    } else {
      System.out.println("System: Location not found");
      if (DungeonMaster.help) System.out.println("Help: Try Look Around");
    }
  }