made riddler for rooms, etc...
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
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
|
||||
Items:Lockpick,Milk
|
||||
Riddle: "Who is never hungry during Christmas?", "The turkey because he is always stuffed."
|
||||
|
||||
@@ -29,13 +29,14 @@ class Command {
|
||||
private ArrayList<String> otherWords;
|
||||
private String item;
|
||||
private String enemy;
|
||||
private String riddler;
|
||||
|
||||
/**
|
||||
* 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
|
||||
* 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;
|
||||
this.otherWords = otherWords;
|
||||
this.direction = direction;
|
||||
@@ -53,6 +54,7 @@ class Command {
|
||||
this.direction = "down";
|
||||
this.item = item;
|
||||
this.enemy = enemy;
|
||||
this.riddler = riddler;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -104,6 +106,9 @@ class Command {
|
||||
}
|
||||
public String getEnemy() {
|
||||
return enemy;
|
||||
}
|
||||
public boolean hasRiddler() {
|
||||
|
||||
}
|
||||
public boolean hasEnemy() {
|
||||
return !enemy.equals("");
|
||||
|
||||
@@ -16,8 +16,7 @@ import java.util.Scanner;
|
||||
*/
|
||||
class CommandWords {
|
||||
// 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_synonyms = new HashMap<String, String>();
|
||||
private static HashMap<String, String> m_words = new HashMap<String, String>();;
|
||||
/**
|
||||
* Constructor - initialise the command words.
|
||||
*/
|
||||
@@ -34,18 +33,6 @@ class CommandWords {
|
||||
}catch (Exception e) {
|
||||
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();
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
27
src/com/bayviewglen/zork/Entities/Riddle.java
Normal file
27
src/com/bayviewglen/zork/Entities/Riddle.java
Normal 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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
13
src/com/bayviewglen/zork/Entities/Riddler.java
Normal file
13
src/com/bayviewglen/zork/Entities/Riddler.java
Normal 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.";
|
||||
}
|
||||
|
||||
}
|
||||
@@ -7,6 +7,8 @@ import java.util.HashMap;
|
||||
import java.util.Scanner;
|
||||
|
||||
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.Items.*;
|
||||
|
||||
@@ -77,8 +79,9 @@ class Game {
|
||||
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);
|
||||
Riddle riddleObj = new Riddle(question, answer);
|
||||
Riddler butler = new Riddler(100, 100, riddleObj);
|
||||
room.addRiddler(butler);
|
||||
}catch(Exception e) {
|
||||
}
|
||||
|
||||
@@ -329,6 +332,8 @@ class Game {
|
||||
System.out.println("Eat what?");
|
||||
}
|
||||
break;
|
||||
case "talk":
|
||||
|
||||
case "take":
|
||||
boolean hasAll = false;
|
||||
for(String a : command.getOtherWords()) {
|
||||
@@ -480,9 +485,6 @@ class Game {
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "read":
|
||||
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -36,6 +36,7 @@ class Parser {
|
||||
String direction = "";
|
||||
String item = "";
|
||||
String enemy = "";
|
||||
String
|
||||
boolean open = false;
|
||||
//String word2;
|
||||
ArrayList<String> words = new ArrayList<String>();
|
||||
|
||||
@@ -18,6 +18,8 @@ import java.util.Set;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
|
||||
import com.bayviewglen.zork.Entities.*;
|
||||
import com.bayviewglen.zork.Items.*;
|
||||
|
||||
class Room {
|
||||
@@ -25,7 +27,7 @@ class Room {
|
||||
private String description;
|
||||
private HashMap<String, Room> exits; // stores exits of this room.
|
||||
private ArrayList<Item> items;
|
||||
private Riddle riddle;
|
||||
private Riddler riddler;
|
||||
private boolean locked;
|
||||
|
||||
/**
|
||||
@@ -86,8 +88,8 @@ class Room {
|
||||
/*
|
||||
* Assigns a Riddle object to the Room
|
||||
*/
|
||||
public void addRiddle(Riddle riddle) {
|
||||
this.riddle = riddle;
|
||||
public void addRiddler(Riddler riddler) {
|
||||
this.riddler = riddler;
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
Reference in New Issue
Block a user