riddler gives you a prize when riddle is successfully answered
This commit is contained in:
@@ -3,7 +3,7 @@ Room Description: You are in a circular room. The windows to the east are covere
|
|||||||
Locked: false
|
Locked: false
|
||||||
Boarded: false
|
Boarded: false
|
||||||
Items:Lockpick,Milk
|
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
|
Exit Rooms: W-Apple Hallway
|
||||||
|
|
||||||
Room name: Apple Hallway
|
Room name: Apple Hallway
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ take, verb
|
|||||||
open, verb
|
open, verb
|
||||||
unlock, verb
|
unlock, verb
|
||||||
inventory, verb
|
inventory, verb
|
||||||
|
i, verb
|
||||||
die, verb
|
die, verb
|
||||||
drop, verb
|
drop, verb
|
||||||
attack, verb
|
attack, verb
|
||||||
|
|||||||
@@ -6,10 +6,11 @@ public class Riddler extends Entity {
|
|||||||
String message;
|
String message;
|
||||||
Item prize;
|
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);
|
super(health, hunger);
|
||||||
this.riddle = riddle;
|
this.riddle = riddle;
|
||||||
this.message = message;
|
this.message = message;
|
||||||
|
this.prize = prize;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Riddle getRiddle() {
|
public Riddle getRiddle() {
|
||||||
|
|||||||
@@ -78,15 +78,21 @@ class Game {
|
|||||||
}catch(Exception e) {
|
}catch(Exception e) {
|
||||||
}
|
}
|
||||||
//Initialize the riddle in the room, if it exists
|
//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 {
|
try {
|
||||||
int comma1 = riddle.indexOf(",");
|
int comma1 = riddlerInfo.indexOf(",");
|
||||||
int comma2 = riddle.indexOf(",", riddle.indexOf(",") + 1);
|
int comma2 = riddlerInfo.indexOf(",", riddlerInfo.indexOf(",") + 1);
|
||||||
String message = riddle.substring(1, comma1 - 1).replaceAll("<comma>", ",");
|
int comma3 = riddlerInfo.indexOf(",", comma2 +1);
|
||||||
String question = riddle.substring(comma1 + 3, comma2 - 1).replaceAll("<comma>", ",");
|
String message = riddlerInfo.substring(1, comma1 - 1).replaceAll("<comma>", ",");
|
||||||
String answer = riddle.substring(comma2 + 3, riddle.length() - 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);
|
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);
|
room.addRiddler(butler);
|
||||||
}catch(Exception e) {
|
}catch(Exception e) {
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user