This repository was archived by the owner on May 13, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCommandParser.cpp
More file actions
85 lines (69 loc) · 2.66 KB
/
Copy pathCommandParser.cpp
File metadata and controls
85 lines (69 loc) · 2.66 KB
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
// *** CommandParser *** //
#include "CCommandParser.hpp"
/**
* parseCommand: parse a command the player enter into an event. The event contains an event type
* what does the player want to do. F.e. "changeRoom" in case the player wants to go somewhere and
* an identifier providing additional information, in our example where the player wants to go to.
* Assuming the player entered "go to kitchen" the string will be parsed into an event with event
* type "changeRoom" and identifier "kitchen".
* @parameter string (player input)
* @return CEvent* (Pointer to event created)
*/
CEvent* CCommandParser::parseCommand(std::string sInput)
{
//Create regular expressions for different command the player might have choosen
std::regex showExits("((Z|z)eige).*Ausgänge");
std::regex goTo("(G|g)(ehe) (.*)");
std::regex showcharacters("(Z|z)eige.*(P|p)ersonen.*");
std::regex talkTo1("(S|s)(preche )(.*) an");
std::regex talkTo2("(R|r)(ede mit )(.*)");
std::regex showActive("(((Z|z)eig(e?) )?.*((A|a)ktive(n?))? (Q|q)uests)");
std::regex showSolved("(((Z|z)eig(e?) )?.*(G|g)elöste(n?) (Q|q)uests)");
std::regex end("((V|v)erlasse|(B|b)eende).*(S|s)piel");
std::regex end_direct(":q");
//Create an instans of smatch
std::smatch m;
//Check which regular expression the players input matches. Create and return event if match
//Show exits:
if(std::regex_match(sInput, showExits)) {
CEvent* event = new CEvent("showExits", "");
return event;
}
//Change room
if(std::regex_search(sInput, m, goTo)) {
CEvent* event = new CEvent("changeRoom", m[3]);
return event;
}
//Show characters in room:
if(std::regex_match(sInput, m, showcharacters)) {
CEvent* event = new CEvent("showChars", "");
return event;
}
//Talk to character:
if(std::regex_match(sInput, m, talkTo1) || std::regex_match(sInput, m, talkTo2)) {
CEvent* event = new CEvent("talkTo", m[3]);
return event;
}
//Show active quests
if(std::regex_match(sInput, m, showActive)) {
CEvent* event = new CEvent("showQuests", "");
return event;
}
//Show solved quests
if(std::regex_match(sInput, m, showSolved)) {
CEvent* event = new CEvent("showQuests", "");
return event;
}
//End game
if(std::regex_match(sInput, m, end)) {
CEvent* event = new CEvent("endGame", "");
return event;
}
//End game directly
if(std::regex_match(sInput, m, end_direct)) {
CEvent* event = new CEvent("endGameDirectly", "");
return event;
}
CEvent* event = new CEvent("falseInput", "");
return event;
}