synonyms, and take all command
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
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.
|
||||
Locked: false
|
||||
Items:Lockpick,Milk,
|
||||
Items:Lockpick,Milk,Sword,Sword,Sword,Sword,Sword,Sword,Sword,Sword,Sword,Sword,Sword,Sword,Sword,Sword,Sword,Sword,Sword,Sword,Sword,Sword,Sword,Sword,Sword,Sword,Sword,Sword,Sword
|
||||
Riddle: "Who is never hungry during Christmas?", "The turkey because he is always stuffed."
|
||||
Exit Rooms: W-Apple Hallway
|
||||
|
||||
|
||||
@@ -1 +1,41 @@
|
||||
This is for the synonyms for the parser
|
||||
suicide, die
|
||||
grab, take
|
||||
destroy, attack
|
||||
kill, attack
|
||||
?, help
|
||||
leave, quit
|
||||
drive, go
|
||||
move, go
|
||||
glance, look
|
||||
glimpse, look
|
||||
peek, look
|
||||
gander, look
|
||||
charge, attack
|
||||
raid, attack
|
||||
strike, attack
|
||||
drown, die
|
||||
expire, die
|
||||
perish, die
|
||||
bounce, jump
|
||||
dive, jump
|
||||
fall, jump
|
||||
rise, jump
|
||||
free, unlock
|
||||
release, unlock
|
||||
leave, drop
|
||||
raid, attack
|
||||
bite, eat
|
||||
chew, eat
|
||||
devour, eat
|
||||
dine, eat
|
||||
feed, eat
|
||||
ingest, eat
|
||||
inhale, eat
|
||||
nibble, eat
|
||||
swallow, eat
|
||||
absorb, eat
|
||||
advice, help
|
||||
aid, help
|
||||
benefit, help
|
||||
scram, go
|
||||
hightail, go
|
||||
@@ -16,7 +16,8 @@ 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_words = new HashMap<String, String>();
|
||||
private static HashMap<String, String> m_synonyms = new HashMap<String, String>();
|
||||
/**
|
||||
* Constructor - initialise the command words.
|
||||
*/
|
||||
@@ -33,6 +34,18 @@ 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();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -82,4 +95,16 @@ 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -16,6 +16,7 @@ public class Player extends Entity{
|
||||
|
||||
public boolean addToInventory(Item item){
|
||||
if(currentInventoryWeight + item.getWeight() < INVENTORY_CAPACITY){
|
||||
currentInventoryWeight+= item.getWeight();
|
||||
inventory.add(item);
|
||||
return true;
|
||||
}
|
||||
@@ -26,6 +27,7 @@ public class Player extends Entity{
|
||||
for(int i =0; i<inventory.size(); i++) {
|
||||
if(item.equals(inventory.get(i))) {
|
||||
inventory.remove(i);
|
||||
currentInventoryWeight-= item.getWeight();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -330,7 +330,24 @@ class Game {
|
||||
}
|
||||
break;
|
||||
case "take":
|
||||
if(command.hasItem()) {
|
||||
boolean hasAll = false;
|
||||
for(String a : command.getOtherWords()) {
|
||||
if(a.equals("all"))
|
||||
hasAll = true;
|
||||
}
|
||||
if(hasAll){
|
||||
for(int i =0; i<currentRoom.getItems().size(); i++) {
|
||||
if(player.addToInventory(currentRoom.getItem(i))) {
|
||||
currentRoom.removeItem(i);
|
||||
i--;
|
||||
}else {
|
||||
System.out.println("You can't carry any more!");
|
||||
break;
|
||||
}
|
||||
System.out.println("Taken");
|
||||
}
|
||||
}
|
||||
else if(command.hasItem()) {
|
||||
Class<?> clazz;
|
||||
Item object;
|
||||
try {
|
||||
@@ -445,11 +462,9 @@ class Game {
|
||||
}else {
|
||||
System.out.println("That enemy is not in this room!");
|
||||
}
|
||||
|
||||
}else {
|
||||
System.out.println("Attack what?");
|
||||
}
|
||||
|
||||
} else {
|
||||
if(command.hasItem()) {
|
||||
boolean has = false;
|
||||
@@ -468,6 +483,7 @@ class Game {
|
||||
break;
|
||||
case "read":
|
||||
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -52,6 +52,7 @@ class Parser {
|
||||
words.add(tokenizer.nextToken());
|
||||
}
|
||||
for(int i=0; i<words.size(); i++) {
|
||||
words.set(i, CommandWords.replaceSynonym(words.get(i)));
|
||||
if(words.get(i).equals("open") || words.get(i).equals("unlock")) {
|
||||
open = true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user