transfer - locked rooms
This commit is contained in:
@@ -52,3 +52,6 @@ novel, item
|
|||||||
mop, item
|
mop, item
|
||||||
bucket, item
|
bucket, item
|
||||||
towels, item
|
towels, item
|
||||||
|
open, verb
|
||||||
|
i, verb
|
||||||
|
unlock, verb
|
||||||
@@ -23,7 +23,13 @@ public class Player extends Entity{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void removeFromInventory(Item item){
|
public void removeFromInventory(Item item){
|
||||||
inventory.remove(item);
|
for(int i =0; i<inventory.size(); i++) {
|
||||||
|
if(item.equals(inventory.get(i))) {
|
||||||
|
inventory.remove(i);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -54,8 +54,8 @@ class Game {
|
|||||||
// Read the Description
|
// Read the Description
|
||||||
String roomDescription = roomScanner.nextLine();
|
String roomDescription = roomScanner.nextLine();
|
||||||
room.setDescription(roomDescription.split(":")[1].replaceAll("<br>", "\n").trim());
|
room.setDescription(roomDescription.split(":")[1].replaceAll("<br>", "\n").trim());
|
||||||
// Read the Description
|
// Read the locked state
|
||||||
boolean locked = Boolean.parseBoolean(roomScanner.nextLine());
|
boolean locked = Boolean.parseBoolean(roomScanner.nextLine().split(":")[1].replaceAll("<br>", "\n").trim());
|
||||||
room.setLocked(locked);
|
room.setLocked(locked);
|
||||||
// Read the Items
|
// Read the Items
|
||||||
String items = roomScanner.nextLine();
|
String items = roomScanner.nextLine();
|
||||||
@@ -168,7 +168,31 @@ class Game {
|
|||||||
}
|
}
|
||||||
String commandWord = command.getCommandWord();
|
String commandWord = command.getCommandWord();
|
||||||
switch(commandWord) {
|
switch(commandWord) {
|
||||||
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":
|
case "open": case "unlock":
|
||||||
|
boolean hasLockPick = false;
|
||||||
|
for(int i =0; i<player.getInventory().size(); i++) {
|
||||||
|
if(player.getInventory().get(i).equals(new Lockpick())) {
|
||||||
|
hasLockPick = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(command.hasDirection() && hasLockPick) {
|
||||||
|
Room nextRoom = currentRoom.nextRoom(command.getDirection());
|
||||||
|
if(nextRoom.getLocked()) {
|
||||||
|
nextRoom.setLocked(false);
|
||||||
|
player.removeFromInventory(new Lockpick());
|
||||||
|
System.out.println("With great effort, you unlocked the door!");
|
||||||
|
}else{
|
||||||
|
System.out.println("That door is already unlocked!");
|
||||||
|
}
|
||||||
|
}else if(!command.hasDirection()){
|
||||||
|
System.out.println("You must specify a direction!");
|
||||||
|
}else {
|
||||||
|
System.out.println("You need a lockpick!");
|
||||||
|
}
|
||||||
|
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":
|
||||||
goRoom(command);
|
goRoom(command);
|
||||||
break;
|
break;
|
||||||
case "help":
|
case "help":
|
||||||
@@ -244,20 +268,6 @@ class Game {
|
|||||||
System.out.println("You have nothing on you. Try and find some items.");
|
System.out.println("You have nothing on you. Try and find some items.");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "open":
|
|
||||||
boolean hasLockpick = false;
|
|
||||||
for(int i =0; i<player.getInventory().size(); i++) {
|
|
||||||
if(player.getInventory().get(i).equals(new Lockpick())) {
|
|
||||||
hasLockpick = true;
|
|
||||||
player.removeFromInventory(new Lockpick());
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(command.hasDirection()) {
|
|
||||||
Room nextRoom = currentRoom.nextRoom(command.getDirection());
|
|
||||||
nextRoom.setLocked(false);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
default:
|
default:
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,6 +35,7 @@ class Parser {
|
|||||||
String verb = "";
|
String verb = "";
|
||||||
String direction = "";
|
String direction = "";
|
||||||
String item = "";
|
String item = "";
|
||||||
|
boolean open = false;
|
||||||
//String word2;
|
//String word2;
|
||||||
ArrayList<String> words = new ArrayList<String>();
|
ArrayList<String> words = new ArrayList<String>();
|
||||||
ArrayList<String> otherWords = new ArrayList<String>();
|
ArrayList<String> otherWords = new ArrayList<String>();
|
||||||
@@ -50,6 +51,9 @@ class Parser {
|
|||||||
words.add(tokenizer.nextToken());
|
words.add(tokenizer.nextToken());
|
||||||
}
|
}
|
||||||
for(int i=0; i<words.size(); i++) {
|
for(int i=0; i<words.size(); i++) {
|
||||||
|
if(words.get(i).equals("open") || words.get(i).equals("unlock")) {
|
||||||
|
open = true;
|
||||||
|
}
|
||||||
if(CommandWords.isCommand(words.get(i))) {
|
if(CommandWords.isCommand(words.get(i))) {
|
||||||
verb = words.get(i);
|
verb = words.get(i);
|
||||||
if(CommandWords.isDirection(words.get(i))) {
|
if(CommandWords.isDirection(words.get(i))) {
|
||||||
@@ -57,14 +61,16 @@ class Parser {
|
|||||||
}
|
}
|
||||||
}else if(CommandWords.isItem(words.get(i))){
|
}else if(CommandWords.isItem(words.get(i))){
|
||||||
item = words.get(i);
|
item = words.get(i);
|
||||||
}
|
}else{
|
||||||
else {
|
|
||||||
otherWords.add(words.get(i));
|
otherWords.add(words.get(i));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//System.out.println(verb);
|
//System.out.println(verb);
|
||||||
if (CommandWords.isCommand(verb))
|
if (CommandWords.isCommand(verb))
|
||||||
return new Command(verb, otherWords, direction, item);
|
if(!open)
|
||||||
|
return new Command(verb, otherWords, direction, item);
|
||||||
|
else
|
||||||
|
return new Command("open", otherWords, direction, item);
|
||||||
else
|
else
|
||||||
return new Command(null, otherWords, direction, item);
|
return new Command(null, otherWords, direction, item);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user