This commit is contained in:
2025-02-18 13:53:59 +01:00
parent e64a127c34
commit a7344d4543
3 changed files with 23 additions and 2 deletions

View File

@@ -15,7 +15,7 @@ public class CommandWords
{
// a constant array that holds all valid command words
private static final String[] validCommands = {
"go", "quit", "help"
"go", "quit", "help", "look"
};
/**
@@ -40,4 +40,14 @@ public class CommandWords
// if we get here, the string was not found in the commands
return false;
}
public String showAll()
{
StringBuilder exitsInString = new StringBuilder();
for (String validCommands : validCommands){
exitsInString.append(validCommands).append(" ");
}
return exitsInString.toString().trim();
}
}

View File

@@ -145,6 +145,9 @@ public class Game
else if (commandWord.equals("quit")) {
wantToQuit = quit(command);
}
else if (commandWord.equals("look")) {
look(currentRoom);
}
return wantToQuit;
}
@@ -162,7 +165,7 @@ public class Game
System.out.println("through the jungle. At once there is a glade. On it there a buildings...");
System.out.println();
System.out.println("Your command words are:");
System.out.println(" go quit help");
System.out.println(parser.showCommands());
}
/**
@@ -213,4 +216,8 @@ public class Game
System.out.print(currentRoom.getLongDescription());
System.out.println();
}
private void look(Room currentRoom)
{
System.out.println(currentRoom.getLongDescription());
}
}

View File

@@ -64,4 +64,8 @@ public class Parser
return new Command(null, word2);
}
}
public String showCommands()
{
return commands.showAll();
}
}