made riddler for rooms, etc...

This commit is contained in:
Luca Carnegie
2019-05-29 13:42:53 -04:00
parent 7c2e8f8df6
commit c50c63477c
9 changed files with 61 additions and 64 deletions

View File

@@ -1,5 +1,5 @@
Room name: Circle Room 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.<br>There seems to be some writing on the wall. 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 Locked: false
Items:Lockpick,Milk Items:Lockpick,Milk
Riddle: "Who is never hungry during Christmas?", "The turkey because he is always stuffed." Riddle: "Who is never hungry during Christmas?", "The turkey because he is always stuffed."

View File

@@ -29,13 +29,14 @@ class Command {
private ArrayList<String> otherWords; private ArrayList<String> otherWords;
private String item; private String item;
private String enemy; private String enemy;
private String riddler;
/** /**
* Create a command object. First and second word must be supplied, but * Create a command object. First and second word must be supplied, but
* either one (or both) can be null. The command word should be null to * either one (or both) can be null. The command word should be null to
* indicate that this was a command that is not recognised by this game. * indicate that this was a command that is not recognised by this game.
*/ */
public Command(String firstWord, ArrayList<String> otherWords, String direction, String item, String enemy) { public Command(String firstWord, ArrayList<String> otherWords, String direction, String item, String enemy, String riddler) {
commandWord = firstWord; commandWord = firstWord;
this.otherWords = otherWords; this.otherWords = otherWords;
this.direction = direction; this.direction = direction;
@@ -53,6 +54,7 @@ class Command {
this.direction = "down"; this.direction = "down";
this.item = item; this.item = item;
this.enemy = enemy; this.enemy = enemy;
this.riddler = riddler;
} }
/** /**
@@ -104,6 +106,9 @@ class Command {
} }
public String getEnemy() { public String getEnemy() {
return enemy; return enemy;
}
public boolean hasRiddler() {
} }
public boolean hasEnemy() { public boolean hasEnemy() {
return !enemy.equals(""); return !enemy.equals("");

View File

@@ -16,8 +16,7 @@ import java.util.Scanner;
*/ */
class CommandWords { class CommandWords {
// a constant array that holds all valid command words // a constant array that holds all valid command words
private static HashMap<String, String> m_words = new HashMap<String, String>(); private static HashMap<String, String> m_words = new HashMap<String, String>();;
private static HashMap<String, String> m_synonyms = new HashMap<String, String>();
/** /**
* Constructor - initialise the command words. * Constructor - initialise the command words.
*/ */
@@ -34,18 +33,6 @@ class CommandWords {
}catch (Exception e) { }catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
try {
Scanner in = new Scanner(new File("data/synonyms.dat"));
while(in.hasNext()){
String text = in.nextLine();
String[] textarr = text.split(",");
m_synonyms.put(textarr[0], textarr[1].substring(1));
}
in.close();
}catch (Exception e) {
e.printStackTrace();
}
} }
/** /**
@@ -95,16 +82,4 @@ class CommandWords {
} }
System.out.println(); System.out.println();
} }
public static String replaceSynonym(String word) {
try {
String words = m_synonyms.get(word);
if(words == null)
throw new Exception();
else
return words;
} catch(Exception e) {
return word;
}
}
} }

View File

@@ -0,0 +1,27 @@
package com.bayviewglen.zork.Entities;
public class Riddle {
private String question;
private String answer;
public Riddle() {
this.question = "The quick brown fox jumped over the lazy dog";
this.answer = "Okay";
}
public Riddle(String question, String answer) {
this.question = question;
this.answer = answer;
}
public String getQuestion() {
return question;
}
public String getAnswer() {
return answer;
}
}

View File

@@ -0,0 +1,13 @@
package com.bayviewglen.zork.Entities;
public class Riddler extends Entity {
Riddle riddle;
String message;
public Riddler(double health, double hunger, Riddle riddle) {
super(health, hunger);
this.riddle = riddle;
this.message = "I can help you in your quest, but only if you answer my riddle.";
}
}

View File

@@ -7,6 +7,8 @@ import java.util.HashMap;
import java.util.Scanner; import java.util.Scanner;
import com.bayviewglen.zork.Entities.Player; import com.bayviewglen.zork.Entities.Player;
import com.bayviewglen.zork.Entities.Riddle;
import com.bayviewglen.zork.Entities.Riddler;
import com.bayviewglen.zork.Entities.Enemies.Enemy; import com.bayviewglen.zork.Entities.Enemies.Enemy;
import com.bayviewglen.zork.Items.*; import com.bayviewglen.zork.Items.*;
@@ -77,8 +79,9 @@ class Game {
try { try {
String question = riddle.split(",")[0].trim().substring(1, riddle.split(",")[0].length()-1).replaceAll("<comma>", ","); 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>", ","); String answer = riddle.split(",")[1].trim().substring(1, riddle.split(",")[1].length()-2).replaceAll("<comma>", ",");
Riddle r = new Riddle(question, answer); Riddle riddleObj = new Riddle(question, answer);
room.addRiddle(r); Riddler butler = new Riddler(100, 100, riddleObj);
room.addRiddler(butler);
}catch(Exception e) { }catch(Exception e) {
} }
@@ -329,6 +332,8 @@ class Game {
System.out.println("Eat what?"); System.out.println("Eat what?");
} }
break; break;
case "talk":
case "take": case "take":
boolean hasAll = false; boolean hasAll = false;
for(String a : command.getOtherWords()) { for(String a : command.getOtherWords()) {
@@ -480,9 +485,6 @@ class Game {
} }
} }
} }
break;
case "read":
break; break;
default: default:
return false; return false;

View File

@@ -1,28 +0,0 @@
package com.bayviewglen.zork.Items;
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

@@ -36,6 +36,7 @@ class Parser {
String direction = ""; String direction = "";
String item = ""; String item = "";
String enemy = ""; String enemy = "";
String
boolean open = false; boolean open = false;
//String word2; //String word2;
ArrayList<String> words = new ArrayList<String>(); ArrayList<String> words = new ArrayList<String>();

View File

@@ -18,6 +18,8 @@ import java.util.Set;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
import com.bayviewglen.zork.Entities.*;
import com.bayviewglen.zork.Items.*; import com.bayviewglen.zork.Items.*;
class Room { class Room {
@@ -25,7 +27,7 @@ class Room {
private String description; private String description;
private HashMap<String, Room> exits; // stores exits of this room. private HashMap<String, Room> exits; // stores exits of this room.
private ArrayList<Item> items; private ArrayList<Item> items;
private Riddle riddle; private Riddler riddler;
private boolean locked; private boolean locked;
/** /**
@@ -86,8 +88,8 @@ class Room {
/* /*
* Assigns a Riddle object to the Room * Assigns a Riddle object to the Room
*/ */
public void addRiddle(Riddle riddle) { public void addRiddler(Riddler riddler) {
this.riddle = riddle; this.riddler = riddler;
} }
/* /*