worked on riddle class

This commit is contained in:
Luca Carnegie
2019-05-28 22:49:21 -04:00
parent 015c8508ee
commit 00ba095757
5 changed files with 77 additions and 18 deletions

View File

@@ -72,6 +72,16 @@ class Game {
}
}catch(Exception e) {
}
//Initialize the riddle in the room, if it exists
String riddle = roomScanner.nextLine().split(":", 2)[1].trim();
try {
String question = riddle.split(",")[0].trim().substring(1, riddle.split(",")[0].length()-1).replaceAll("<comma>", ",");
String answer = riddle.split(",")[1].trim().substring(1, riddle.split(",")[1].length()-2).replaceAll("<comma>", ",");
Riddle r = new Riddle(question, answer);
room.addRiddle(r);
}catch(Exception e) {
}
// Read the Exits
String roomExits = roomScanner.nextLine();
@@ -84,8 +94,7 @@ class Game {
exits.put(roomName.substring(10).trim().toUpperCase().replaceAll(" ", "_"), temp);
// This puts the room we created (Without the exits in the
// masterMap)
// This puts the room we created (Without the exits in the masterMap)
masterRoomMap.put(roomName.toUpperCase().substring(10).trim().replaceAll(" ", "_"), room);
if(roomScanner.hasNextLine()) {
@@ -213,7 +222,7 @@ class Game {
player.removeFromInventory(player.getInventory().get(i));
}
currentRoom = masterRoomMap.get("CIRCLE_ROOM");
System.out.println("You are now back in the circle room. Your items remain 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;

View File

@@ -1,12 +1,28 @@
package com.bayviewglen.zork.Items;
public class Riddle {
String question;
String answer;
public class Riddle extends Item{
private String question;
private String answer;
public Riddle() {
super(36, "Riddle", "A faded engraving on the wall. It may help you, or hurt you.", false, 0, 0);
this.question = "The quick brown fox jumped over the lazy dog";
}
public Riddle(String question, String answer) {
super(36, "Riddle", "A faded engraving on the wall. It may help you, or hurt you.", false, 0, 0);
this.question = question;
this.answer = answer;
}
public String getQuestion() {
return question;
}
public String getAnswer() {
return answer;
}
}

View File

@@ -1,11 +0,0 @@
package com.bayviewglen.zork.Items;
public class Scroll {
private String message;
public Scroll(String message) {
this.message = message;
}
public String getMessage() {
return message;
}
}

View File

@@ -25,6 +25,7 @@ class Room {
private String description;
private HashMap<String, Room> exits; // stores exits of this room.
private ArrayList<Item> items;
private Riddle riddle;
private boolean locked;
/**
@@ -82,6 +83,13 @@ class Room {
exits.put(dir, r);
}
/*
* Assigns a Riddle object to the Room
*/
public void addRiddle(Riddle riddle) {
this.riddle = riddle;
}
/*
* Add passed in item to item array list
*/
@@ -213,4 +221,5 @@ class Room {
}
return hasItem;
}
}