This repository has been 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
/
Door.cpp
90 lines (71 loc) · 2.59 KB
/
Door.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
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
//Door
// @Author = Jan van Dick
#include "CDoor.h"
using namespace std;
//Constructor:
//chName (name of he door), linkedRoom (Room this door is leading to),
//localID (ID to clearly identify all doors in a room), ID (ID to clearly identify this door out of all doors)
CDoor::CDoor(char* chName, CRoom* linkedRoom, int localID, int ID,
std::vector<std::string> sDescriptions, void(CDoor::*callDescription)())
{
m_chName = chName;
m_localID = localID;
m_ID = ID;
m_linkedRoom = linkedRoom;
m_curDescription = 0;
for(unsigned int i=0; i<sDescriptions.size(); i++)
m_sDescriptions.push_back(sDescriptions[i]);
m_callDescription = callDescription;
}
//PrintDescription:
//Load current description, then print current description
void CDoor::printDescription()
{
//Vaiables
string sDescription; //String containing description
string sDescName = "/home/leonce/Documents/C++ Projects/Textadventure/DoorDescriptions/";
sDescName.append(m_sDescriptions[m_curDescription]);
//Read description-file
ifstream ifs(sDescName);
//Check, whether file has been open
if (!ifs)
cout << "File: \"" << sDescName << "\" could not be opended! \n\n";
//Load description form file "into sDescription"
else
sDescription.assign((istreambuf_iterator<char>(ifs)), (istreambuf_iterator<char>()));
//close file
ifs.close();
//Print description
cout << sDescription << endl;
}
//callDesc
//Calls m_callDescription which is a pointer to the wanted function
void CDoor::callDesc()
{
(this->*m_callDescription)();
}
//****************Description Calls *******************//
//DescCall_Standard:
//Simply calls the current description
void CDoor::DescCall_Standard()
{
//Print description
this->printDescription();
}
//DescCall_IncreaseCurDesc()
//Prints current description and increases current description
void CDoor::DescCall_Increase1CurDesc()
{
this->printDescription(); //Print description
this->m_curDescription++; //Increase curDescription by 1
this->setCallDescription(&CDoor::DescCall_Standard); //Change DescCall to standard
}
//DescCall_d_LeninsTomb3
//Prints current description, increases current description and changes door_name
void CDoor::DescCallLeninsTomb()
{
this->printDescription(); //Print description
this->m_curDescription++; //Change to next description
this->setCallDescription(&CDoor::DescCall_Standard); //Change DescCall to standard
this->setName((char*)"Stalins tomb"); //Change door name to "Stalins tomb"
}