fixing item display

This commit is contained in:
Luca Carnegie
2019-05-31 20:10:16 -04:00
parent ad08e5482a
commit 389a7e3c05
4 changed files with 339 additions and 308 deletions

View File

@@ -2,7 +2,7 @@ Room name: Circle Room
Room Description: You are in a circular room. The windows to the east are covered with boards that<br>let in just enough light to see. You spot a man in a tailored suit moving some crates around.
Locked: false
Boarded: false
Items: Lightbulb,Candlestick
Items: Shavingcream
Riddler: "Hello there. My name is Kevin and I am Sir Pellatt's butler. I understand that my master<comma><br>Sir Pellatt has wrongfully imprisoned you. If you answer my riddle<comma> I can give you something to<br>help you with your escape - nothing comes for free you know!", "What goes moo?", "Cows", Lockpick
Exit Rooms: W-Apple Hallway
@@ -116,10 +116,10 @@ Locked: false
Boarded: false
Items:Shaving Cream,Toothbrush,Toothpaste
Riddler:
Exit Rooms: N-Sir Henry Mill Pellatt's Bathroom
Exit Rooms: N-Sir Henry Mill Pellatt's Bedroom
Room name: Linen Closet
Room Description: A whiff of lavender-scented laundry detergent enters your nostrils as you step into<br>a dark room. Ah, you must be in the Linen Closet. No one really comes in here other than the servants. I'm pretty sure Sir Pellatt and<br>Lady Pellat don't even know this room exists.
Room Description: A whiff of lavender-scented laundry detergent enters your nostrils as you step into<br>a dark room. Ah, you must be in the Linen Closet. No one really comes in here other than the servants. I'm pretty sure Sir Pellatt and<br>Lady Pellatt don't even know this room exists.
Locked: false
Boarded: false
Items:Clothes

View File

@@ -11,6 +11,7 @@ aid, help
benefit, help
man, riddler
butler, riddler
kevin, riddler
helper, riddler
leave, quit
move, go

View File

@@ -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());
}
}

View File

@@ -194,11 +194,19 @@ class Room {
}
public String itemString(){
String items = "Items in Room: " + this.items.get(0).getName();
for(int i = 1; i < this.items.size(); i++) {
items += ", " + this.items.get(i).getName();
boolean hasItems = false;
String items = "";
String itemString = "Items in room: ";
for(int i = 0; i < this.getItems().size() - 1; i++) {
hasItems = true;
items += this.getItems().get(i).getName() + ", ";
}
if(hasItems) {
items += this.getItems().get(this.getItems().size() - 1).getName();
return itemString + items;
}else {
return itemString + "none";
}
return items;
}
/**