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 pathEventManager.cpp
More file actions
251 lines (190 loc) · 7.1 KB
/
Copy pathEventManager.cpp
File metadata and controls
251 lines (190 loc) · 7.1 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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
//EventManager (.cpp)
//It is possible to add and call events to a certain time and occasion
#include "CEventManager.h"
using namespace std;
//Constructor
CEventManager::CEventManager()
{
m_next = NULL; //Set next not to NULL
m_numEvents = 0;
}
//Set a kew knot/ a new Event
void CEventManager::set(char* chEventType, void(CEventManager::*func)(CGame* game, char* chIdentify))
{
CFunctions F; //Provides various functions (here: allocate)
F.allocate(m_chEventType, chEventType); //Assigne eventtype
m_func = func; //Assign function of the event
}
//Add a new event to the eventmanager
void CEventManager::add_listener(char* chEventType, void(CEventManager::*func)(CGame* game, char* chIdentify))
{
m_numEvents++;
//If there is a next node, call "add_listener" with next node
if(m_next)
m_next->add_listener(chEventType, func);
//If there is no next node, create new node and call "set" from this node
else
{
m_next = new CEventManager;
m_next->set(chEventType, func);
}
return;
}
//Call event
void CEventManager::throw_event(char* chEventType, CGame* game, char* chIdentify)
{
//Check for empty list
if(!m_next)
return;
CFunctions F; //Provides various functions (here: compare)
CEventManager* temp = this->m_next; //Create temp
//Check whether given event matches the current knot
if(F.compare(temp->m_chEventType, chEventType) == true)
(this->*m_next->m_func)(game, chIdentify); //Call function
//Check, whether there is a next knot
if(temp->m_next)
temp->throw_event(chEventType, game, chIdentify); //Call function via next knot
}
//delete event
void CEventManager::delete_event(int eventNum)
{
//Check for empty list
if(!m_next)
return;
CEventManager* temp = this->m_next; //temp node
m_numEvents--; //Reduse number of elements in the list
//Check whether number of current node matches given number
if(temp->m_numEvents == eventNum)
{
m_next = temp->m_next; //Relink
delete temp; //Delete
}
//if not, then check, whether there is a next node and call delete via next node
else if (temp->m_next)
m_next->delete_event(eventNum);
}
//*********Events***************//
//---Basic functions---//
//Basic function to show all Doors in the current room
void CEventManager::echo_funcShowDoors(CGame* game, char* chIdentify)
{
//Output
cout << game->getPlayer()->getName() << " looks around for futher ways to go. \n";
cout << "He finds following exits: \n";
//Print list of all doors
game->getPlayer()->getCurRoom()->getDoors()->out();
}
//Basic function to show all people in the current room
void CEventManager::echo_funcShowPeople(CGame* game, char* chIdentify)
{
//Output
cout << game->getPlayer()->getName() << " sees the following people: \n";
//Print list of all people
game->getPlayer()->getCurRoom()->getPeople()->out();
}
//Basic function to show all attributes of the player
void CEventManager::echo_funcShowAttributes(CGame* game, char* chIdentify)
{
//Call matching Player function
game->getPlayer()->showAttributes();
}
//Basic function to show all items in the player's inventory
void CEventManager::echo_funcShowInventory(CGame* game, char* chIdentify)
{
//Output
cout << game->getPlayer()->getName() << "'s inventory: \n";
//Print inventory
game->getPlayer()->getInventory()->printInventory();
}
//Basic function to leave a door to a next room
void CEventManager::echo_funcGoTo(CGame* game, char* chIdentify)
{
CFunctions F; //Provides various function. Here: "error"-function
//Create selected door
CDoor *selectedDoor = game->getPlayer()->getCurRoom()->getDoors()->getElementByNameContains(chIdentify);
//Door found: the change current room of player and call description of new room
if(selectedDoor != NULL)
{
game->getPlayer()->setCurRoom(selectedDoor->getLinkedRoom());
game->getPlayer()->printMainAtts();
selectedDoor->callDesc();
}
//Door not found: print error and jump back to input
else
F.error("Room not found!\n");
}
//Basic function to talk to a selected person
void CEventManager::echo_funcTalkTo(CGame* game, char* chIdentify)
{
CFunctions F; //Provides various function. Here: "error"-function
//Create selected person
CPerson* selectedPerson = game->getPlayer()->getCurRoom()->getPeople()->getElementByNameContains(chIdentify);
//Person found: start dialog
if(selectedPerson != NULL)
{
game->getEventManager()->throw_event((char*)"person_interact", game,
selectedPerson->getName());
selectedPerson->callDialog();
}
//Person not found: print eroor and jump back to input
else
F.error("Person not found!\n");
}
//Basic function to use an item from players inventory
void CEventManager::echo_funcUseItem(CGame* game, char* chIdentify)
{
//Call "useItem"-function from class "Inventory
game->getPlayer()->getInventory()->useItem(chIdentify);
}
//basic function to show all of the players active quests
void CEventManager::echo_funcShowActiveQuests(CGame* game, char* chIdentify)
{
//Call "showActiveQuests" from CPlayer
game->getPlayer()->showActiveQuests();
}
//Basic functions showing possible user commands
void CEventManager::echo_funcHelp(CGame* game, char* chIdentify)
{
cout << "\"show doors\", \"show people\", \"show attributes\", \"inventory\"\n";
cout << "\"show inventory\", \"use\", \"go to\", \"talk to\", \"help\"\n";
cout << endl;
}
//---Basic Events---//
//Basic event for picked up items
void CEventManager::echo_item(CGame* game, char* chIdentify)
{
cout << "Hallo boy, you picked up ";
cout << game->getItemList()->getElement(chIdentify)->getName() << ".\n";
}
//Basic event for interacting with a person
void CEventManager::echo_person(CGame* game, char* chIdentify)
{
cout << "You aproach ";
cout << game->getPeopleList()->getElement(chIdentify)->getName() << ".\n";
}
//Basic event for entering a room or place
void CEventManager::echo_room(CGame* game, char* chIdentify)
{
cout << "You enter ";
cout << game->getRoomList()->getElement(chIdentify)->getName() << ".\n";
}
//Basic event for approaching a door
void CEventManager::echo_door(CGame* game, char* chIdentify)
{
}
//---Special events---//
//Quest: Karl Marx nr.1 -> talk to the dog
void CEventManager::echo_qMarx_TalkToDog(CGame* game, char* chIdentify)
{
CFunctions F; //provides various functions (here: compare)
//Create selected person
CPerson* selP = game->getPlayer()->getCurRoom()->getPeople()->getElement(chIdentify);
if (F.compare(selP->getName(), (char*)"a dog") == true)
{
cout << "Quest successful\n";
game->getPerson((char*)"Karl Marx")->getQuest(11)->getStep(1)->setStatus(true);
game->getPerson((char*)"Karl Marx")->getQuest(11)->getStep(2)->startQueststep();
//Delete Event
game->getEventManager()->delete_event(m_numEvents);
}
}