Merge remote-tracking branch 'origin/master'
This commit is contained in:
@@ -108,4 +108,6 @@ class Command {
|
||||
public boolean hasEnemy() {
|
||||
return !enemy.equals("");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -60,6 +60,9 @@ class Game {
|
||||
// Read the locked state
|
||||
boolean locked = Boolean.parseBoolean(roomScanner.nextLine().split(":")[1].replaceAll("<br>", "\n").trim());
|
||||
room.setLocked(locked);
|
||||
// Read the boarded state
|
||||
boolean boarded = Boolean.parseBoolean(roomScanner.nextLine().split(":")[1].replaceAll("<br>", "\n").trim());
|
||||
room.setBoarded(boarded);
|
||||
// Read the Items
|
||||
String items = roomScanner.nextLine();
|
||||
try {
|
||||
@@ -276,6 +279,31 @@ class Game {
|
||||
System.out.println("In what direction do you want to go in?");
|
||||
}else {
|
||||
System.out.println("What do you want to open the door with?");
|
||||
}
|
||||
boolean hasCrowbar = false;
|
||||
for(int i =0; i<player.getInventory().size(); i++) {
|
||||
if(player.getInventory().get(i).equals(new Crowbar())) {
|
||||
hasCrowbar = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(command.hasDirection() && hasCrowbar) {
|
||||
Room nextRoom = currentRoom.nextRoom(command.getDirection());
|
||||
try {
|
||||
if(nextRoom.getBoarded()) {
|
||||
nextRoom.setBoarded(false);
|
||||
player.removeFromInventory(new Crowbar());
|
||||
System.out.println("With great effort, you pry the boards off the door with the crowbar! However, it breaks and is no longer useable.");
|
||||
}else{
|
||||
System.out.println("That door is already unlocked!");
|
||||
}
|
||||
}catch(Exception e) {
|
||||
System.out.println("There is no door there!");
|
||||
}
|
||||
}else if(!command.hasDirection()){
|
||||
|
||||
}else {
|
||||
|
||||
}
|
||||
break;
|
||||
case "go": case "n": case "s": case "e": case "w": case "north": case "south": case "west": case "east": case "up": case "down": case "d": case "u":
|
||||
@@ -330,7 +358,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 +490,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 +511,7 @@ class Game {
|
||||
break;
|
||||
case "read":
|
||||
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
@@ -499,8 +543,11 @@ class Game {
|
||||
Room nextRoom = currentRoom.nextRoom(direction);
|
||||
if (nextRoom == null)
|
||||
System.out.println("There is no door!");
|
||||
else if(nextRoom.getLocked() && nextRoom.getBoarded()) {
|
||||
System.out.println("The door is locked and boarded shut. You need to find a key and crowbar to open it.");
|
||||
}
|
||||
else if(nextRoom.getLocked()) {
|
||||
System.out.println("The door is locked. You need to find a key to open it.");
|
||||
System.out.println("The door is locked. You need a key to open it.");
|
||||
}
|
||||
else {
|
||||
currentRoom = nextRoom;
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -27,6 +27,7 @@ class Room {
|
||||
private ArrayList<Item> items;
|
||||
private Riddle riddle;
|
||||
private boolean locked;
|
||||
private boolean boarded;
|
||||
|
||||
/**
|
||||
* Create a room described "description". Initially, it has no exits.
|
||||
@@ -49,10 +50,16 @@ class Room {
|
||||
public void setLocked(boolean b) {
|
||||
locked = b;
|
||||
}
|
||||
public void setBoarded(boolean b) {
|
||||
boarded = b;
|
||||
}
|
||||
|
||||
public boolean getLocked() {
|
||||
return locked;
|
||||
}
|
||||
public boolean getBoarded() {
|
||||
return boarded;
|
||||
}
|
||||
|
||||
public void setExit(char direction, Room r) throws Exception {
|
||||
String dir = "";
|
||||
|
||||
Reference in New Issue
Block a user