riddler gives you a prize when riddle is successfully answered

This commit is contained in:
Luca Carnegie
2019-05-29 21:39:16 -04:00
parent 657b859686
commit 0fc289deb0
4 changed files with 17 additions and 9 deletions

View File

@@ -3,7 +3,7 @@ Room Description: You are in a circular room. The windows to the east are covere
Locked: false
Boarded: false
Items:Lockpick,Milk
Riddler: "I can help you in your quest<comma> but only if you answer my riddle.", "Who is never hungry during Christmas?", "The turkey because he is always stuffed"
Riddler: "I can help you in your quest<comma> but only if you answer my riddle.", "Who is never hungry during Christmas?", "The turkey because he is always stuffed", ShavingCream
Exit Rooms: W-Apple Hallway
Room name: Apple Hallway

View File

@@ -10,6 +10,7 @@ take, verb
open, verb
unlock, verb
inventory, verb
i, verb
die, verb
drop, verb
attack, verb

View File

@@ -6,10 +6,11 @@ public class Riddler extends Entity {
String message;
Item prize;
public Riddler(double health, double hunger, Riddle riddle, String message) {
public Riddler(double health, double hunger, Riddle riddle, String message, Item prize) {
super(health, hunger);
this.riddle = riddle;
this.message = message;
this.prize = prize;
}
public Riddle getRiddle() {

View File

@@ -78,15 +78,21 @@ class Game {
}catch(Exception e) {
}
//Initialize the riddle in the room, if it exists
String riddle = roomScanner.nextLine().split(":", 2)[1].trim();
String riddlerInfo = roomScanner.nextLine().split(":", 2)[1].trim();
try {
int comma1 = riddle.indexOf(",");
int comma2 = riddle.indexOf(",", riddle.indexOf(",") + 1);
String message = riddle.substring(1, comma1 - 1).replaceAll("<comma>", ",");
String question = riddle.substring(comma1 + 3, comma2 - 1).replaceAll("<comma>", ",");
String answer = riddle.substring(comma2 + 3, riddle.length() - 1).replaceAll("<comma>", ",");
int comma1 = riddlerInfo.indexOf(",");
int comma2 = riddlerInfo.indexOf(",", riddlerInfo.indexOf(",") + 1);
int comma3 = riddlerInfo.indexOf(",", comma2 +1);
String message = riddlerInfo.substring(1, comma1 - 1).replaceAll("<comma>", ",");
String question = riddlerInfo.substring(comma1 + 3, comma2 - 1).replaceAll("<comma>", ",");
String answer = riddlerInfo.substring(comma2 + 3, riddlerInfo.length() - 1).replaceAll("<comma>", ",");
Riddle riddleObj = new Riddle(question, answer);
Riddler butler = new Riddler(100, 100, riddleObj, message);
String item = riddlerInfo.substring(comma3 + 2, riddlerInfo.length());
// Initializes prize object
Class<?> clazz = Class.forName("com.bayviewglen.zork.Items." + item.trim());
Constructor<?> ctor = clazz.getConstructor();
Item prize = (Item) ctor.newInstance();
Riddler butler = new Riddler(100, 100, riddleObj, message, prize);
room.addRiddler(butler);
}catch(Exception e) {
}