-
Notifications
You must be signed in to change notification settings - Fork 0
/
archmage.cpp
45 lines (39 loc) · 1.08 KB
/
archmage.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include <string>
#include "parser.h"
#include "command.h"
#include "dictionary.h"
#include "io.h"
#include "exceptions.h"
#include "archmagedict.h"
#include "archmagelocations.h"
#include "archmageactors.h"
int main(){
Dictionary* dictionary = createArchMageDictionary();
Parser* parser = new Parser(dictionary);
std::string userInput;
buildLocations();
buildActors();
addActorsToDictionary(dictionary);
Actor* player = getActor("player");
Command command;
player->announceLocation();
while(true){
userInput = getInput();
try {
command = parser->parseSentence(userInput);
} catch(UnknownWord unknownWord) {
outputString("I do not know the word '" + unknownWord.word + "'");
continue;
} catch(InvalidSentenceStructure invalidSentenceStructure) {
outputString("I do not know how to interpret a phrase with the structure: " + invalidSentenceStructure.phraseStructure);
continue;
}
try {
player->getLocation()->processCommand(command,
player);
} catch(CannotDoThat cannotDoThat){
outputString(cannotDoThat.message);
}
}
return 0;
}