changed types of some collections

This commit is contained in:
RaffaeleMorganti 2022-11-19 08:48:21 +01:00
parent 2e12ab7f1f
commit 4a7eca5302
10 changed files with 130 additions and 112 deletions

View File

@ -8,9 +8,11 @@ package com.github.dtschust.zork;
import com.github.dtschust.zork.parser.ZorkGame; import com.github.dtschust.zork.parser.ZorkGame;
import com.github.dtschust.zork.parser.ZorkReader; import com.github.dtschust.zork.parser.ZorkReader;
import java.util.HashMap; import java.util.Map;
import java.util.Scanner; import java.util.Scanner;
import static java.util.Map.entry;
/* And away we go*/ /* And away we go*/
public class Zork { public class Zork {
@ -140,21 +142,21 @@ public class Zork {
if (destinationType.equals("room")) { if (destinationType.equals("room")) {
ZorkRoom tempRoom = game.Rooms.get(destination); ZorkRoom tempRoom = game.Rooms.get(destination);
if (objectType.equals("item")) if (objectType.equals("item"))
tempRoom.item.put(object, object); tempRoom.item.add(object);
else if (objectType.equals("creature")) else if (objectType.equals("creature"))
tempRoom.creature.put(object, object); tempRoom.creature.add(object);
else if (objectType.equals("container")) else if (objectType.equals("container"))
tempRoom.container.put(object, object); tempRoom.container.add(object);
else else
System.out.println("Error"); System.out.println("Error");
game.Rooms.put(tempRoom.name, tempRoom); game.Rooms.put(tempRoom);
} else if (destinationType.equals("container")) { } else if (destinationType.equals("container")) {
ZorkContainer tempContainer = game.Containers.get(destination); ZorkContainer tempContainer = game.Containers.get(destination);
if (objectType.equals("item")) if (objectType.equals("item"))
tempContainer.item.put(object, object); tempContainer.item.add(object);
else else
System.out.println("Error"); System.out.println("Error");
game.Containers.put(tempContainer.name, tempContainer); game.Containers.put(tempContainer);
} else { } else {
System.out.println("Error"); System.out.println("Error");
} }
@ -172,37 +174,37 @@ public class Zork {
tempRoom.border.remove(key2); tempRoom.border.remove(key2);
} }
} }
game.Rooms.put(tempRoom.name, tempRoom); game.Rooms.put(tempRoom);
} }
} else if (objectType.equals("item")) { } else if (objectType.equals("item")) {
for (String key : game.Rooms.keySet()) { for (String key : game.Rooms.keySet()) {
ZorkRoom tempRoom = game.Rooms.get(key); ZorkRoom tempRoom = game.Rooms.get(key);
if (tempRoom.item.get(object) != null) { if (tempRoom.item.contains(object)) {
tempRoom.item.remove(object); tempRoom.item.remove(object);
game.Rooms.put(tempRoom.name, tempRoom); game.Rooms.put(tempRoom);
} }
} }
for (String key : game.Containers.keySet()) { for (String key : game.Containers.keySet()) {
ZorkContainer tempContainer = game.Containers.get(key); ZorkContainer tempContainer = game.Containers.get(key);
if (tempContainer.item.get(object) != null) { if (tempContainer.item.contains(object)) {
tempContainer.item.remove(object); tempContainer.item.remove(object);
game.Containers.put(tempContainer.name, tempContainer); game.Containers.put(tempContainer);
} }
} }
} else if (objectType.equals("container")) { } else if (objectType.equals("container")) {
for (String key : game.Rooms.keySet()) { for (String key : game.Rooms.keySet()) {
ZorkRoom tempRoom = game.Rooms.get(key); ZorkRoom tempRoom = game.Rooms.get(key);
if (tempRoom.container.get(object) != null) { if (tempRoom.container.contains(object)) {
tempRoom.container.remove(object); tempRoom.container.remove(object);
game.Rooms.put(tempRoom.name, tempRoom); game.Rooms.put(tempRoom);
} }
} }
} else if (objectType.equals("creature")) { } else if (objectType.equals("creature")) {
for (String key : game.Rooms.keySet()) { for (String key : game.Rooms.keySet()) {
ZorkRoom tempRoom = game.Rooms.get(key); ZorkRoom tempRoom = game.Rooms.get(key);
if (tempRoom.creature.get(object) != null) { if (tempRoom.creature.contains(object)) {
tempRoom.creature.remove(object); tempRoom.creature.remove(object);
game.Rooms.put(tempRoom.name, tempRoom); game.Rooms.put(tempRoom);
} }
} }
} }
@ -214,30 +216,30 @@ public class Zork {
if (objectType.equals("room")) { if (objectType.equals("room")) {
ZorkRoom tempRoom = game.Rooms.get(object); ZorkRoom tempRoom = game.Rooms.get(object);
tempRoom.status = newStatus; tempRoom.status = newStatus;
game.Rooms.put(tempRoom.name, tempRoom); game.Rooms.put(tempRoom);
} else if (objectType.equals("container")) { } else if (objectType.equals("container")) {
ZorkContainer tempContainer = game.Containers.get(object); ZorkContainer tempContainer = game.Containers.get(object);
tempContainer.status = newStatus; tempContainer.status = newStatus;
game.Containers.put(tempContainer.name, tempContainer); game.Containers.put(tempContainer);
} else if (objectType.equals("creature")) { } else if (objectType.equals("creature")) {
ZorkCreature tempCreature = game.Creatures.get(object); ZorkCreature tempCreature = game.Creatures.get(object);
tempCreature.status = newStatus; tempCreature.status = newStatus;
game.Creatures.put(tempCreature.name, tempCreature); game.Creatures.put(tempCreature);
} else if (objectType.equals("item")) { } else if (objectType.equals("item")) {
ZorkItem tempItem = game.Items.get(object); ZorkItem tempItem = game.Items.get(object);
tempItem.status = newStatus; tempItem.status = newStatus;
game.Items.put(tempItem.name, tempItem); game.Items.put(tempItem);
} }
} }
private void doActionAttack(String tempString, String weapon) { private void doActionAttack(String tempString, String weapon) {
ZorkCreature tempCreature; ZorkCreature tempCreature;
if (game.Rooms.get(currentRoom).creature.get(tempString) != null) { if (game.Rooms.get(currentRoom).creature.contains(tempString)) {
tempCreature = game.Creatures.get(tempString); tempCreature = game.Creatures.get(tempString);
if (tempCreature != null && game.Inventory.get(weapon) != null) { if (tempCreature != null && game.Inventory.contains(weapon)) {
if (tempCreature.attack(this, weapon)) { if (tempCreature.attack(this, weapon)) {
System.out.println("You assault the " + tempString + " with the " + weapon + "."); System.out.println("You assault the " + tempString + " with the " + weapon + ".");
for (String print: tempCreature.print) { for (String print: tempCreature.print) {
@ -254,7 +256,7 @@ public class Zork {
} }
private void doActionTurnOn(String tempString) { private void doActionTurnOn(String tempString) {
if (game.Inventory.get(tempString) != null) { if (game.Inventory.contains(tempString)) {
ZorkItem tempItem = game.Items.get(tempString); ZorkItem tempItem = game.Items.get(tempString);
System.out.println("You activate the " + tempString + "."); System.out.println("You activate the " + tempString + ".");
if (tempItem != null) { if (tempItem != null) {
@ -271,21 +273,23 @@ public class Zork {
} }
private void doActionPutItem(String tempString, String destination) { private void doActionPutItem(String tempString, String destination) {
if (game.Rooms.get(currentRoom).container.get(destination) != null && game.Containers.get(destination).isOpen && game.Inventory.get(tempString) != null) { if (game.Rooms.get(currentRoom).container.contains(destination)){
ZorkContainer tempContainer = game.Containers.get(destination); if(game.Containers.get(destination).isOpen && game.Inventory.contains(tempString)) {
tempContainer.item.put(tempString, tempString); ZorkContainer tempContainer = game.Containers.get(destination);
game.Inventory.remove(tempString); tempContainer.item.add(tempString);
System.out.println("Item " + tempString + " added to " + destination + "."); game.Inventory.remove(tempString);
} else { System.out.println("Item " + tempString + " added to " + destination + ".");
System.out.println("Error"); return;
}
} }
System.out.println("Error");
} }
private void doActionDropItem(String tempString) { private void doActionDropItem(String tempString) {
if (game.Inventory.get(tempString) != null) { if (game.Inventory.contains(tempString)) {
ZorkRoom tempRoom = game.Rooms.get(currentRoom); ZorkRoom tempRoom = game.Rooms.get(currentRoom);
tempRoom.item.put(tempString, tempString); tempRoom.item.add(tempString);
game.Rooms.put(tempRoom.name, tempRoom); game.Rooms.put(tempRoom);
game.Inventory.remove(tempString); game.Inventory.remove(tempString);
System.out.println(tempString + " dropped."); System.out.println(tempString + " dropped.");
} else { } else {
@ -294,7 +298,7 @@ public class Zork {
} }
private void doActionReadObject(String tempString) { private void doActionReadObject(String tempString) {
if (game.Inventory.get(tempString) != null) { if (game.Inventory.contains(tempString)) {
ZorkItem tempItem = game.Items.get(tempString); ZorkItem tempItem = game.Items.get(tempString);
if (tempItem.writing != null && tempItem.writing != "") { if (tempItem.writing != null && tempItem.writing != "") {
System.out.println(tempItem.writing); System.out.println(tempItem.writing);
@ -308,11 +312,20 @@ public class Zork {
private void doActionOpenContainer(String tempString) { private void doActionOpenContainer(String tempString) {
ZorkContainer tempContainer; ZorkContainer tempContainer;
String found = game.Rooms.get(currentRoom).container.get(tempString); if (game.Rooms.get(currentRoom).container.contains(tempString)) {
if (found != null) {
tempContainer = game.Containers.get(tempString); tempContainer = game.Containers.get(tempString);
tempContainer.isOpen = true; tempContainer.isOpen = true;
doActionContainerInventory(tempContainer.item, tempString); String output = "";
if (tempContainer.item.isEmpty()) {
System.out.println(tempString + " is empty");
} else {
System.out.print(tempString + " contains ");
for (String key : tempContainer.item) {
output += key + ", ";
}
output = output.substring(0, output.length() - 2);
System.out.println(output + ".");
}
} else { } else {
System.out.println("Error"); System.out.println("Error");
} }
@ -329,18 +342,14 @@ public class Zork {
/*Basic movement function */ /*Basic movement function */
private void doActionMove(String direction) { private void doActionMove(String direction) {
String fullDirection = ""; final Map<String, String> fullDirections = Map.ofEntries(
if (direction.equals("n")) { entry("n", "north"),
fullDirection = "north"; entry("s", "south"),
} else if (direction.equals("s")) { entry("e", "east"),
fullDirection = "south"; entry("w", "west")
} else if (direction.equals("e")) { );
fullDirection = "east";
} else if (direction.equals("w")) {
fullDirection = "west";
}
String destination = (game.Rooms.get(currentRoom)).border.get(fullDirection); String destination = (game.Rooms.get(currentRoom)).border.get(fullDirections.get(direction));
if (destination != null) { if (destination != null) {
currentRoom = destination; currentRoom = destination;
System.out.println(game.Rooms.get(currentRoom).description); System.out.println(game.Rooms.get(currentRoom).description);
@ -349,20 +358,6 @@ public class Zork {
} }
} }
/* Print out the what's in a container when it's been opened*/
public void doActionContainerInventory(HashMap<String, String> Container, String Name) {
String output = "";
if (Container.isEmpty()) {
System.out.println(Name + " is empty");
} else {
System.out.print(Name + " contains ");
for (String key : Container.keySet()) {
output += key + ", ";
}
output = output.substring(0, output.length() - 2);
System.out.println(output + ".");
}
}
/* Print out the inventory when user types i */ /* Print out the inventory when user types i */
private void doActionInventory() { private void doActionInventory() {
@ -370,7 +365,7 @@ public class Zork {
if (game.Inventory.isEmpty()) { if (game.Inventory.isEmpty()) {
System.out.println("Inventory: empty"); System.out.println("Inventory: empty");
} else { } else {
for (String key : game.Inventory.keySet()) { for (String key : game.Inventory) {
output += key + ", "; output += key + ", ";
} }
output = output.substring(0, output.length() - 2); output = output.substring(0, output.length() - 2);
@ -379,21 +374,21 @@ public class Zork {
} }
private void doActionTake(String tempString) { private void doActionTake(String tempString) {
if ((game.Rooms.get(currentRoom)).item.get(tempString) != null) { if ((game.Rooms.get(currentRoom)).item.contains(tempString)) {
game.Inventory.put(tempString, tempString); game.Inventory.add(tempString);
ZorkRoom tempRoom = (game.Rooms.get(currentRoom)); ZorkRoom tempRoom = (game.Rooms.get(currentRoom));
tempRoom.item.remove(tempString); tempRoom.item.remove(tempString);
game.Rooms.put(tempRoom.name, tempRoom); game.Rooms.put(tempRoom);
System.out.println("Item " + tempString + " added to inventory."); System.out.println("Item " + tempString + " added to inventory.");
} else { } else {
/*Search all containers in the current room for the item!*/ /*Search all containers in the current room for the item!*/
boolean found = false; boolean found = false;
for (String key : game.Rooms.get(currentRoom).container.keySet()) { for (String key : game.Rooms.get(currentRoom).container) {
ZorkContainer tempContainer = game.Containers.get(key); ZorkContainer tempContainer = game.Containers.get(key);
if (tempContainer != null && tempContainer.isOpen && tempContainer.item.get(tempString) != null) { if (tempContainer != null && tempContainer.isOpen && tempContainer.item.contains(tempString)) {
game.Inventory.put(tempString, tempString); game.Inventory.add(tempString);
tempContainer.item.remove(tempString); tempContainer.item.remove(tempString);
game.Containers.put(tempContainer.name, tempContainer); game.Containers.put(tempContainer);
System.out.println("Item " + tempString + " added to inventory."); System.out.println("Item " + tempString + " added to inventory.");
found = true; found = true;
break; break;
@ -429,7 +424,7 @@ public class Zork {
private boolean doTriggersContainersInRoom() { private boolean doTriggersContainersInRoom() {
boolean skip = false; boolean skip = false;
for (String key : game.Rooms.get(currentRoom).container.keySet()) { for (String key : game.Rooms.get(currentRoom).container) {
skip = skip || doZorkTriggers(game.Containers.get(key)); skip = skip || doZorkTriggers(game.Containers.get(key));
} }
return skip; return skip;
@ -437,9 +432,9 @@ public class Zork {
private boolean doTriggersItemsInContainersInRoom() { private boolean doTriggersItemsInContainersInRoom() {
boolean skip = false; boolean skip = false;
for (String key : game.Rooms.get(currentRoom).container.keySet()) { for (String key : game.Rooms.get(currentRoom).container) {
ZorkContainer tempContainer = game.Containers.get(key); ZorkContainer tempContainer = game.Containers.get(key);
for (String key2 : tempContainer.item.keySet()) { for (String key2 : tempContainer.item) {
skip = skip || doZorkTriggers(game.Items.get(key2)); skip = skip || doZorkTriggers(game.Items.get(key2));
} }
} }
@ -448,7 +443,7 @@ public class Zork {
private boolean doTriggersItemsInRoom() { private boolean doTriggersItemsInRoom() {
boolean skip = false; boolean skip = false;
for (String key : game.Rooms.get(currentRoom).item.keySet()) { for (String key : game.Rooms.get(currentRoom).item) {
skip = skip || doZorkTriggers(game.Items.get(key)); skip = skip || doZorkTriggers(game.Items.get(key));
} }
return skip; return skip;
@ -456,7 +451,7 @@ public class Zork {
private boolean doTriggersItemsInInventory() { private boolean doTriggersItemsInInventory() {
boolean skip = false; boolean skip = false;
for (String key : game.Inventory.keySet()) { for (String key : game.Inventory) {
skip = skip || doZorkTriggers(game.Items.get(key)); skip = skip || doZorkTriggers(game.Items.get(key));
} }
return skip; return skip;
@ -464,7 +459,7 @@ public class Zork {
private boolean doTriggersCreaturesInRoom() { private boolean doTriggersCreaturesInRoom() {
boolean skip = false; boolean skip = false;
for (String key : game.Rooms.get(currentRoom).creature.keySet()) { for (String key : game.Rooms.get(currentRoom).creature) {
skip = skip || doZorkTriggers(game.Creatures.get(key)); skip = skip || doZorkTriggers(game.Creatures.get(key));
} }
return skip; return skip;

View File

@ -1,5 +1,7 @@
package com.github.dtschust.zork; package com.github.dtschust.zork;
import java.util.Set;
/* Has conditions*/ /* Has conditions*/
public class ZorkConditionHas extends ZorkCondition { public class ZorkConditionHas extends ZorkCondition {
private final String has; private final String has;
@ -15,23 +17,28 @@ public class ZorkConditionHas extends ZorkCondition {
public boolean evaluate(Zork zork) { public boolean evaluate(Zork zork) {
/*Inventory is a special case as it isn't the name of any object in the game, check for it specifically*/ /*Inventory is a special case as it isn't the name of any object in the game, check for it specifically*/
if (owner.equals("inventory")) { if (owner.equals("inventory")) {
return zork.game.Inventory.get(object) != null && has.equals("yes") || zork.game.Inventory.get(object) == null && has.equals("no"); return evaluateCondition(zork.game.Inventory, object);
} else { } else {
/* is it a room?*/ /* is it a room?*/
ZorkRoom roomObject = zork.game.Rooms.get(owner); ZorkRoom roomObject = zork.game.Rooms.get(owner);
if (roomObject != null) { if (roomObject != null) {
return (roomObject).item.get(object) != null && has.equals("yes") || (roomObject).item.get(object) == null && has.equals("no"); return evaluateCondition(roomObject.item, object);
} }
/* is it a container?*/ /* is it a container?*/
else { else {
ZorkContainer containerObject = zork.game.Containers.get(owner); ZorkContainer containerObject = zork.game.Containers.get(owner);
if (containerObject != null) { if (containerObject != null) {
return (containerObject).item.get(object) != null && has.equals("yes") || (containerObject).item.get(object) == null && has.equals("no"); return evaluateCondition(containerObject.item, object);
} }
} }
} }
return false; return false;
} }
private boolean evaluateCondition(Set items, String object){
if(has.equals("yes")) return items.contains(object);
else if(has.equals("no")) return !items.contains(object);
return false;
}
} }

View File

@ -2,11 +2,12 @@ package com.github.dtschust.zork;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet;
import java.util.Set;
/* Container*/ /* Container*/
public class ZorkContainer extends ZorkObject { public class ZorkContainer extends ZorkObject {
public String name; public Set<String> item = new HashSet<String>();
public HashMap<String, String> item = new HashMap<>();
public String description; public String description;
public ArrayList<String> accept = new ArrayList<>(); public ArrayList<String> accept = new ArrayList<>();
public boolean isOpen; public boolean isOpen;

View File

@ -2,12 +2,13 @@ package com.github.dtschust.zork;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet;
import java.util.Set;
/* Creature*/ /* Creature*/
public class ZorkCreature extends ZorkObject { public class ZorkCreature extends ZorkObject {
public String name;
public String description; public String description;
public HashMap<String, String> vulnerability = new HashMap<>(); public Set<String> vulnerability = new HashSet<>();
public ArrayList<ZorkCondition> conditions = new ArrayList<>(); public ArrayList<ZorkCondition> conditions = new ArrayList<>();
public ArrayList<String> print = new ArrayList<>(); public ArrayList<String> print = new ArrayList<>();
public ArrayList<String> action = new ArrayList<>(); public ArrayList<String> action = new ArrayList<>();
@ -17,7 +18,7 @@ public class ZorkCreature extends ZorkObject {
/* Evaluate the success of an attack*/ /* Evaluate the success of an attack*/
public boolean attack(Zork zork, String weapon) { public boolean attack(Zork zork, String weapon) {
if (vulnerability.get(weapon) == null) { if (!vulnerability.contains(weapon)) {
return false; return false;
} }
for (ZorkCondition condition : conditions) { for (ZorkCondition condition : conditions) {

View File

@ -4,7 +4,6 @@ import java.util.ArrayList;
/* Item*/ /* Item*/
public class ZorkItem extends ZorkObject { public class ZorkItem extends ZorkObject {
public String name;
public String description; public String description;
public String writing; public String writing;
public ArrayList<String> turnOnPrint = new ArrayList<>(); public ArrayList<String> turnOnPrint = new ArrayList<>();

View File

@ -5,6 +5,8 @@ import java.util.ArrayList;
/* Generic object, everything inherits from this*/ /* Generic object, everything inherits from this*/
public class ZorkObject { public class ZorkObject {
public String status; public String status;
public String name;
public ArrayList<ZorkTrigger> trigger = new ArrayList<>(); public ArrayList<ZorkTrigger> trigger = new ArrayList<>();
public ZorkObject() { public ZorkObject() {

View File

@ -1,16 +1,17 @@
package com.github.dtschust.zork; package com.github.dtschust.zork;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet;
import java.util.Set;
/* Room*/ /* Room*/
public class ZorkRoom extends ZorkObject { public class ZorkRoom extends ZorkObject {
public String name;
public String type = "regular"; public String type = "regular";
public String description; public String description;
public HashMap<String, String> border = new HashMap<>(); public HashMap<String, String> border = new HashMap<>();
public HashMap<String, String> container = new HashMap<>(); public Set<String> container = new HashSet<>();
public HashMap<String, String> item = new HashMap<>(); public Set<String> item = new HashSet<>();
public HashMap<String, String> creature = new HashMap<>(); public Set<String> creature = new HashSet<>();
public ZorkRoom() { public ZorkRoom() {
} }

View File

@ -2,17 +2,17 @@ package com.github.dtschust.zork.parser;
import com.github.dtschust.zork.*; import com.github.dtschust.zork.*;
import java.io.File;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet;
import java.util.Set;
public class ZorkGame { public class ZorkGame {
public HashMap<String, ZorkRoom> Rooms = new HashMap<>(); public ZorkMap<ZorkRoom> Rooms = new ZorkMap<>();
public HashMap<String, ZorkItem> Items = new HashMap<>(); public ZorkMap<ZorkItem> Items = new ZorkMap<>();
public HashMap<String, ZorkContainer> Containers = new HashMap<>(); public ZorkMap<ZorkContainer> Containers = new ZorkMap<>();
public HashMap<String, ZorkObject> Objects = new HashMap<>(); public ZorkMap<ZorkObject> Objects = new ZorkMap<>();
public HashMap<String, ZorkCreature> Creatures = new HashMap<>(); public ZorkMap<ZorkCreature> Creatures = new ZorkMap<>();
public HashMap<String, String> Inventory = new HashMap<>(); public Set<String> Inventory = new HashSet<>();
public HashMap<String, String> ObjectLookup = new HashMap<>(); public HashMap<String, String> ObjectLookup = new HashMap<>();
} }

View File

@ -0,0 +1,13 @@
package com.github.dtschust.zork.parser;
import com.github.dtschust.zork.ZorkObject;
import java.util.HashMap;
public class ZorkMap<T extends ZorkObject> extends HashMap<String, T>{
public T put(T object){
return put(object.name, object);
}
}

View File

@ -81,14 +81,14 @@ public class ZorkReader {
for (j = 0; j < items.getLength(); j++) { for (j = 0; j < items.getLength(); j++) {
Element item = (Element) items.item(j); Element item = (Element) items.item(j);
String itemName = getString(item); String itemName = getString(item);
tempRoom.item.put(itemName, itemName); tempRoom.item.add(itemName);
} }
NodeList creatures = element.getElementsByTagName("creature"); NodeList creatures = element.getElementsByTagName("creature");
for (j = 0; j < creatures.getLength(); j++) { for (j = 0; j < creatures.getLength(); j++) {
Element creature = (Element) creatures.item(j); Element creature = (Element) creatures.item(j);
String creatureName = getString(creature); String creatureName = getString(creature);
tempRoom.creature.put(creatureName, creatureName); tempRoom.creature.add(creatureName);
} }
readTriggersInObject(element, tempRoom); readTriggersInObject(element, tempRoom);
@ -97,7 +97,7 @@ public class ZorkReader {
for (j = 0; j < containers.getLength(); j++) { for (j = 0; j < containers.getLength(); j++) {
Element container = (Element) containers.item(j); Element container = (Element) containers.item(j);
String containerName = getString(container); String containerName = getString(container);
tempRoom.container.put(containerName, containerName); tempRoom.container.add(containerName);
} }
NodeList borders = element.getElementsByTagName("border"); NodeList borders = element.getElementsByTagName("border");
@ -107,10 +107,9 @@ public class ZorkReader {
String borderName = getString((Element) border.getElementsByTagName("name").item(0)); String borderName = getString((Element) border.getElementsByTagName("name").item(0));
tempRoom.border.put(borderDirection, borderName); tempRoom.border.put(borderDirection, borderName);
} }
/*Add this room to the rooms hashmap, put it in the generic objects hashmap, and store it's type in the objectlookup hashmap*/ /*Add this room to the rooms hashmap, put it in the generic objects hashmap, and store it's type in the objectlookup hashmap*/
data.Rooms.put(tempRoom.name, tempRoom); data.Rooms.put(tempRoom);
data.Objects.put(tempRoom.name, tempRoom); data.Objects.put(tempRoom);
data.ObjectLookup.put(tempRoom.name, "room"); data.ObjectLookup.put(tempRoom.name, "room");
} }
@ -154,8 +153,8 @@ public class ZorkReader {
readTriggersInObject(element, tempItem); readTriggersInObject(element, tempItem);
/* Put each item in the items hashmap, the generic objects hashmap, and store its type in objectlookup*/ /* Put each item in the items hashmap, the generic objects hashmap, and store its type in objectlookup*/
data.Items.put(tempItem.name, tempItem); data.Items.put(tempItem);
data.Objects.put(tempItem.name, tempItem); data.Objects.put(tempItem);
data.ObjectLookup.put(tempItem.name, "item"); data.ObjectLookup.put(tempItem.name, "item");
} }
@ -191,14 +190,14 @@ public class ZorkReader {
for (j = 0; j < citems.getLength(); j++) { for (j = 0; j < citems.getLength(); j++) {
Element item = (Element) citems.item(j); Element item = (Element) citems.item(j);
String itemName = getString(item); String itemName = getString(item);
tempCont.item.put(itemName, itemName); tempCont.item.add(itemName);
} }
readTriggersInObject(element, tempCont); readTriggersInObject(element, tempCont);
/* Put each container in the containers hashmap, the generic object hashmap, and the objectlookup hashmap*/ /* Put each container in the containers hashmap, the generic object hashmap, and the objectlookup hashmap*/
data.Containers.put(tempCont.name, tempCont); data.Containers.put(tempCont);
data.Objects.put(tempCont.name, tempCont); data.Objects.put(tempCont);
data.ObjectLookup.put(tempCont.name, "container"); data.ObjectLookup.put(tempCont.name, "container");
} }
@ -223,7 +222,7 @@ public class ZorkReader {
NodeList vulns = element.getElementsByTagName("vulnerability"); NodeList vulns = element.getElementsByTagName("vulnerability");
for (j = 0; j < vulns.getLength(); j++) { for (j = 0; j < vulns.getLength(); j++) {
String vulnString = getString((Element) vulns.item(j)); String vulnString = getString((Element) vulns.item(j));
tempCreature.vulnerability.put(vulnString, vulnString); tempCreature.vulnerability.add(vulnString);
} }
NodeList attacks = element.getElementsByTagName("attack"); NodeList attacks = element.getElementsByTagName("attack");
@ -247,8 +246,8 @@ public class ZorkReader {
readTriggersInObject(element, tempCreature); readTriggersInObject(element, tempCreature);
/* Put each creature in the creatures hashmap, the generic object hashmap, and the objectlookup hashmap*/ /* Put each creature in the creatures hashmap, the generic object hashmap, and the objectlookup hashmap*/
data.Creatures.put(tempCreature.name, tempCreature); data.Creatures.put(tempCreature);
data.Objects.put(tempCreature.name, tempCreature); data.Objects.put(tempCreature);
data.ObjectLookup.put(tempCreature.name, "creature"); data.ObjectLookup.put(tempCreature.name, "creature");
} }