worked on riddle class
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user