From 48b8545cc682696a1fa5f258a49a59875e8e3702 Mon Sep 17 00:00:00 2001
From: Luca Carnegie <41924665+lcarnegie@users.noreply.github.com>
Date: Wed, 29 May 2019 22:32:44 -0400
Subject: [PATCH] riddles are done!
---
data/rooms.dat | 4 ++--
data/words.dat | 1 +
src/com/bayviewglen/zork/Entities/Player.java | 5 -----
.../bayviewglen/zork/Entities/Riddler.java | 4 ++++
src/com/bayviewglen/zork/Game.java | 19 ++++++++++++++-----
5 files changed, 21 insertions(+), 12 deletions(-)
diff --git a/data/rooms.dat b/data/rooms.dat
index 7fe3ea5..312c683 100644
--- a/data/rooms.dat
+++ b/data/rooms.dat
@@ -1,9 +1,9 @@
Room name: Circle Room
-Room Description: You are in a circular room. The windows to the east are covered with boards that let in just enough light to see. You spot a man in a tailored suit.
+Room Description: You are in a circular room. The windows to the east are covered with boards that
let in just enough light to see. You spot a man in a tailored suit.
Locked: false
Boarded: false
Items:Lockpick,Milk
-Riddler: "I can help you in your quest but only if you answer my riddle.", "Who is never hungry during Christmas?", "The turkey because he is always stuffed", ShavingCream
+Riddler: "Hello there. My name is Kevin and I am Sir Pellatt's butler. I understand that my master
Sir Pellatt has wrongfully imprisoned you. If you answer my riddle I can give you something to
help you with your escape - nothing comes for free you know!", "What goes moo?", "Cows", ShavingCream
Exit Rooms: W-Apple Hallway
Room name: Apple Hallway
diff --git a/data/words.dat b/data/words.dat
index 4c0766f..e90ed99 100644
--- a/data/words.dat
+++ b/data/words.dat
@@ -60,6 +60,7 @@ mop, item
bucket, item
towels, item
henrypellatt, enemy
+riddler, friend
clock, item
keyboard, item
lightbulb, item
\ No newline at end of file
diff --git a/src/com/bayviewglen/zork/Entities/Player.java b/src/com/bayviewglen/zork/Entities/Player.java
index 670a863..1f6701e 100644
--- a/src/com/bayviewglen/zork/Entities/Player.java
+++ b/src/com/bayviewglen/zork/Entities/Player.java
@@ -40,15 +40,10 @@ public class Player extends Entity{
}
public void eat() {
- // TODO Do we want health or hunger?
health+=5;
- hunger+=5;
if(health > 100.0) {
health = 100.0;
}
- if(hunger > 100.0) {
- hunger = 100.0;
- }
}
}
diff --git a/src/com/bayviewglen/zork/Entities/Riddler.java b/src/com/bayviewglen/zork/Entities/Riddler.java
index 6395839..28f1e95 100644
--- a/src/com/bayviewglen/zork/Entities/Riddler.java
+++ b/src/com/bayviewglen/zork/Entities/Riddler.java
@@ -21,5 +21,9 @@ public class Riddler extends Entity {
return message;
}
+ public Item getPrize() {
+ return prize;
+ }
+
}
diff --git a/src/com/bayviewglen/zork/Game.java b/src/com/bayviewglen/zork/Game.java
index aa74325..63d38c6 100644
--- a/src/com/bayviewglen/zork/Game.java
+++ b/src/com/bayviewglen/zork/Game.java
@@ -83,9 +83,9 @@ class Game {
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("", ",");
- String question = riddlerInfo.substring(comma1 + 3, comma2 - 1).replaceAll("", ",");
- String answer = riddlerInfo.substring(comma2 + 3, riddlerInfo.length() - 1).replaceAll("", ",");
+ String message = riddlerInfo.substring(1, comma1 - 1).replaceAll("", ",").replaceAll("
", "\n");
+ String question = riddlerInfo.substring(comma1 + 3, comma2 - 1).replaceAll("", ",").replaceAll("
", "\n");
+ String answer = riddlerInfo.substring(comma2 + 3, comma3 - 1).replaceAll("", ",").replaceAll("
", "\n");
Riddle riddleObj = new Riddle(question, answer);
String item = riddlerInfo.substring(comma3 + 2, riddlerInfo.length());
// Initializes prize object
@@ -375,10 +375,19 @@ class Game {
String message = currentRoom.getRiddler().getMessage();
String riddle = currentRoom.getRiddler().getRiddle().getQuestion();
String answer = currentRoom.getRiddler().getRiddle().getAnswer();
- System.out.println(message + "\n" + riddle + "\nWhat is your answer?:");
+ System.out.println(message + "\n\nHere's my riddle: " + riddle);
+ System.out.print("Enter your guess here: ");
String guess = rScanner.nextLine();
if(guess.toLowerCase().equals(answer.toLowerCase())) {
- System.out.println("Good Job!");
+ Item prize = currentRoom.getRiddler().getPrize();
+ String prizeName = prize.getName();
+ System.out.println("Congratulations! You solved my riddle! As your reward, you get a " + prizeName + "!");
+ if(player.addToInventory(prize)) {
+ player.addToInventory(prize);
+ System.out.println("A " + prizeName + " has been added to your inventory.");
+ }else {
+ System.out.println("Sorry, you can't carry any more ");
+ }
}else {
System.out.println("Sorry, that isn't the answer. Think about it, then try again.");
}