/** * 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"); } }
/** * 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"); } }