|
|
|
|
@@ -97,7 +97,6 @@ class Game {
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Read the Exits
|
|
|
|
|
String roomExits = roomScanner.nextLine();
|
|
|
|
|
// An array of strings in the format E-RoomName
|
|
|
|
|
@@ -112,9 +111,9 @@ class Game {
|
|
|
|
|
// This puts the room we created (Without the exits in the masterMap)
|
|
|
|
|
masterRoomMap.put(roomName.toUpperCase().substring(10).trim().replaceAll(" ", "_"), room);
|
|
|
|
|
|
|
|
|
|
if(roomScanner.hasNextLine()) {
|
|
|
|
|
if (roomScanner.hasNextLine())
|
|
|
|
|
roomScanner.nextLine();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (String key : masterRoomMap.keySet()) {
|
|
|
|
|
@@ -199,12 +198,12 @@ class Game {
|
|
|
|
|
in.close();
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
System.out.println("That is not a valid response. Type \"play\" to play the game. If you wish to close the game, type \"quit\".");
|
|
|
|
|
System.out.println(
|
|
|
|
|
"That is not a valid response. Type \"play\" to play the game. If you wish to close the game, type \"quit\".");
|
|
|
|
|
}
|
|
|
|
|
in.close();
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
@@ -214,12 +213,13 @@ class Game {
|
|
|
|
|
if (printWelcome()) {
|
|
|
|
|
// Enter the main command loop. Here we repeatedly read commands and
|
|
|
|
|
// execute them until the game is over.
|
|
|
|
|
System.out.println("\nType 'help' if you need help, consult the wiki \non GitHub if you are confused and enjoy the game!\n");
|
|
|
|
|
System.out.println(
|
|
|
|
|
"\nType 'help' if you need help, consult the wiki \non GitHub if you are confused and enjoy the game!\n");
|
|
|
|
|
System.out.println("\n\nEscape Casa Loma");
|
|
|
|
|
System.out.println("---------------------\n");
|
|
|
|
|
System.out.print(currentRoom.longDescription());
|
|
|
|
|
System.out.println(currentRoom.exitString());
|
|
|
|
|
System.out.println(currentRoom.itemString());
|
|
|
|
|
System.out.println(currentRoom.exitString());
|
|
|
|
|
boolean finished = false;
|
|
|
|
|
while (!finished) {
|
|
|
|
|
if (currentCombat != null) {
|
|
|
|
|
@@ -227,8 +227,7 @@ class Game {
|
|
|
|
|
System.out.println("You destroyed " + currentCombat.getEnemy().getName());
|
|
|
|
|
masterEnemyMap.values().remove(currentRoom.getRoomName());
|
|
|
|
|
currentCombat = null;
|
|
|
|
|
}
|
|
|
|
|
else if(currentCombat.getTurn() == 1) {
|
|
|
|
|
} else if (currentCombat.getTurn() == 1) {
|
|
|
|
|
currentCombat.enemyAttack();
|
|
|
|
|
if (currentCombat.getPlayer().getHealth() <= 0.0) {
|
|
|
|
|
System.out.println("You were destroyed by " + currentCombat.getEnemy().getName());
|
|
|
|
|
@@ -237,7 +236,8 @@ class Game {
|
|
|
|
|
player.removeFromInventory(player.getInventory().get(i));
|
|
|
|
|
}
|
|
|
|
|
currentRoom = masterRoomMap.get("CIRCLE_ROOM");
|
|
|
|
|
System.out.println("Poof! You looked pretty banged up there, so I brought you back to the circle room. Your items are where you died.");
|
|
|
|
|
System.out.println(
|
|
|
|
|
"Poof! You looked pretty banged up there, so I brought you back to the circle room. Your items are where you died.");
|
|
|
|
|
player.setHealth(100.0);
|
|
|
|
|
currentCombat.getEnemy().setHealth(100.0);
|
|
|
|
|
currentCombat = null;
|
|
|
|
|
@@ -252,10 +252,9 @@ class Game {
|
|
|
|
|
System.out.println("Thank you for playing. Goodbye!");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Given a command, process (that is: execute) the command. If this command
|
|
|
|
|
* ends the game, true is returned, otherwise false is returned.
|
|
|
|
|
* Given a command, process (that is: execute) the command. If this command ends
|
|
|
|
|
* the game, true is returned, otherwise false is returned.
|
|
|
|
|
*/
|
|
|
|
|
private boolean processCommand(Command command) {
|
|
|
|
|
|
|
|
|
|
@@ -265,7 +264,8 @@ class Game {
|
|
|
|
|
}
|
|
|
|
|
String commandWord = command.getCommandWord();
|
|
|
|
|
switch (commandWord) {
|
|
|
|
|
case "open": case "unlock":
|
|
|
|
|
case "open":
|
|
|
|
|
case "unlock":
|
|
|
|
|
boolean hasLockPick = false;
|
|
|
|
|
for (int i = 0; i < player.getInventory().size(); i++) {
|
|
|
|
|
if (player.getInventory().get(i).equals(new Lockpick())) {
|
|
|
|
|
@@ -280,7 +280,8 @@ class Game {
|
|
|
|
|
if (nextRoom.getLocked()) {
|
|
|
|
|
nextRoom.setLocked(false);
|
|
|
|
|
player.removeFromInventory(new Lockpick());
|
|
|
|
|
System.out.println("After a little bit of picking, a click is heard and the door opens slightly!");
|
|
|
|
|
System.out.println(
|
|
|
|
|
"After a little bit of picking, a click is heard and the door opens slightly!");
|
|
|
|
|
} else {
|
|
|
|
|
System.out.println("That door is already unlocked!");
|
|
|
|
|
}
|
|
|
|
|
@@ -305,7 +306,8 @@ class Game {
|
|
|
|
|
if (nextRoom.getBoarded()) {
|
|
|
|
|
nextRoom.setBoarded(false);
|
|
|
|
|
player.removeFromInventory(new Crowbar());
|
|
|
|
|
System.out.println("With great effort, you pry the boards off the door with the crowbar! However, it breaks and is no longer useable.");
|
|
|
|
|
System.out.println(
|
|
|
|
|
"With great effort, you pry the boards off the door with the crowbar! However, it breaks and is no longer useable.");
|
|
|
|
|
} else {
|
|
|
|
|
System.out.println("That door is already unlocked!");
|
|
|
|
|
}
|
|
|
|
|
@@ -318,7 +320,19 @@ class Game {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case "go": case "n": case "s": case "e": case "w": case "north": case "south": case "west": case "east": case "up": case "down": case "d": case "u":
|
|
|
|
|
case "go":
|
|
|
|
|
case "n":
|
|
|
|
|
case "s":
|
|
|
|
|
case "e":
|
|
|
|
|
case "w":
|
|
|
|
|
case "north":
|
|
|
|
|
case "south":
|
|
|
|
|
case "west":
|
|
|
|
|
case "east":
|
|
|
|
|
case "up":
|
|
|
|
|
case "down":
|
|
|
|
|
case "d":
|
|
|
|
|
case "u":
|
|
|
|
|
if (currentCombat == null)
|
|
|
|
|
goRoom(command);
|
|
|
|
|
else
|
|
|
|
|
@@ -341,7 +355,9 @@ class Game {
|
|
|
|
|
Class<?> clazz;
|
|
|
|
|
Item object;
|
|
|
|
|
try {
|
|
|
|
|
clazz = Class.forName("com.bayviewglen.zork.Items." + command.getItem().substring(0, 1).toUpperCase().trim() + command.getItem().substring(1).trim());
|
|
|
|
|
clazz = Class.forName(
|
|
|
|
|
"com.bayviewglen.zork.Items." + command.getItem().substring(0, 1).toUpperCase().trim()
|
|
|
|
|
+ command.getItem().substring(1).trim());
|
|
|
|
|
Constructor<?> ctor = clazz.getConstructor();
|
|
|
|
|
object = (Item) ctor.newInstance();
|
|
|
|
|
boolean hasItem = false;
|
|
|
|
|
@@ -370,6 +386,7 @@ class Game {
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case "talk":
|
|
|
|
|
if (currentCombat == null) {
|
|
|
|
|
if (currentRoom.hasRiddler()) {
|
|
|
|
|
Scanner rScanner = new Scanner(System.in);
|
|
|
|
|
String message = currentRoom.getRiddler().getMessage();
|
|
|
|
|
@@ -396,6 +413,9 @@ class Game {
|
|
|
|
|
} else {
|
|
|
|
|
System.out.println("Talk to who?");
|
|
|
|
|
}
|
|
|
|
|
}else {
|
|
|
|
|
System.out.println("You can't talk to someone while in battle!");
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case "scream":
|
|
|
|
|
System.out.println("Aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaahhhhhhhhhhhhhhhhhhhhh!");
|
|
|
|
|
@@ -417,18 +437,18 @@ class Game {
|
|
|
|
|
}
|
|
|
|
|
System.out.println("Taken");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if(command.hasItem()) {
|
|
|
|
|
} else if (command.hasItem()) {
|
|
|
|
|
Class<?> clazz;
|
|
|
|
|
Item object;
|
|
|
|
|
try {
|
|
|
|
|
clazz = Class.forName("com.bayviewglen.zork.Items." + command.getItem().substring(0, 1).toUpperCase().trim() + command.getItem().substring(1).trim());
|
|
|
|
|
clazz = Class.forName(
|
|
|
|
|
"com.bayviewglen.zork.Items." + command.getItem().substring(0, 1).toUpperCase().trim()
|
|
|
|
|
+ command.getItem().substring(1).trim());
|
|
|
|
|
Constructor<?> ctor = clazz.getConstructor();
|
|
|
|
|
object = (Item) ctor.newInstance();
|
|
|
|
|
if (!currentRoom.hasItem(object)) {
|
|
|
|
|
System.out.println("This room has no " + command.getItem() + "!");
|
|
|
|
|
}
|
|
|
|
|
else if(player.addToInventory(object)) {
|
|
|
|
|
} else if (player.addToInventory(object)) {
|
|
|
|
|
currentRoom.removeItem(object);
|
|
|
|
|
System.out.println("Taken");
|
|
|
|
|
} else {
|
|
|
|
|
@@ -445,11 +465,12 @@ class Game {
|
|
|
|
|
|
|
|
|
|
case "look":
|
|
|
|
|
System.out.print(currentRoom.longDescription());
|
|
|
|
|
System.out.println(currentRoom.exitString());
|
|
|
|
|
System.out.println(currentRoom.itemString());
|
|
|
|
|
System.out.println(currentRoom.exitString());
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case "inventory": case "i":
|
|
|
|
|
case "inventory":
|
|
|
|
|
case "i":
|
|
|
|
|
boolean hasPlayerItems = false;
|
|
|
|
|
String itemsP = "";
|
|
|
|
|
for (Item i : player.getInventory()) {
|
|
|
|
|
@@ -469,7 +490,9 @@ class Game {
|
|
|
|
|
Class<?> clazz;
|
|
|
|
|
Item object;
|
|
|
|
|
try {
|
|
|
|
|
clazz = Class.forName("com.bayviewglen.zork.Items." + command.getItem().substring(0, 1).toUpperCase().trim() + command.getItem().substring(1).trim());
|
|
|
|
|
clazz = Class.forName(
|
|
|
|
|
"com.bayviewglen.zork.Items." + command.getItem().substring(0, 1).toUpperCase().trim()
|
|
|
|
|
+ command.getItem().substring(1).trim());
|
|
|
|
|
Constructor<?> ctor = clazz.getConstructor();
|
|
|
|
|
object = (Item) ctor.newInstance();
|
|
|
|
|
boolean has = false;
|
|
|
|
|
@@ -546,11 +569,10 @@ class Game {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// implementations of user commands:
|
|
|
|
|
/**
|
|
|
|
|
* Print out some help information. Here we print some stupid, cryptic
|
|
|
|
|
* message and a list of the command words.
|
|
|
|
|
* Print out some help information. Here we print some stupid, cryptic message
|
|
|
|
|
* and a list of the command words.
|
|
|
|
|
*/
|
|
|
|
|
private void printHelp() {
|
|
|
|
|
System.out.println("Here's what you can do:");
|
|
|
|
|
@@ -574,11 +596,9 @@ class Game {
|
|
|
|
|
System.out.println("There is no door!");
|
|
|
|
|
else if (nextRoom.getLocked() && nextRoom.getBoarded()) {
|
|
|
|
|
System.out.println("The door is locked and boarded shut. You need to find a key and crowbar to open it.");
|
|
|
|
|
}
|
|
|
|
|
else if(nextRoom.getLocked()) {
|
|
|
|
|
} else if (nextRoom.getLocked()) {
|
|
|
|
|
System.out.println("The door is locked. You need a key to open it.");
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
} else {
|
|
|
|
|
currentRoom = nextRoom;
|
|
|
|
|
System.out.print(currentRoom.longDescription());
|
|
|
|
|
boolean hasEnemy = false;
|
|
|
|
|
@@ -597,8 +617,10 @@ class Game {
|
|
|
|
|
}
|
|
|
|
|
if (hasEnemy) {
|
|
|
|
|
System.out.println(enemy.getName() + ", " + enemy.getDescription() + " has appeared!");
|
|
|
|
|
System.out.println(currentRoom.itemString());
|
|
|
|
|
System.out.println(currentRoom.exitString());
|
|
|
|
|
} else {
|
|
|
|
|
System.out.println(currentRoom.itemString());
|
|
|
|
|
System.out.println(currentRoom.exitString());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|