-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfixedobject.cpp
More file actions
103 lines (99 loc) · 3.35 KB
/
Copy pathfixedobject.cpp
File metadata and controls
103 lines (99 loc) · 3.35 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
//these are the header file below
#include "fixedobject.h"
#include"room.h"
#include"player.h"
using namespace std;
fixedobject::fixedobject(string nam, string des, string ke,object* hidden,bool stat, room* cur)
{
name=nam;
desc=des;
key=ke;
hidden_value=hidden;
state=stat;
cur->fixed_object.push_back(this);
}
fixedobject::fixedobject(string nam, string des, string ke,object* hidden,bool stat)
{
name=nam;
desc=des;
key=ke;
hidden_value=hidden;
state=stat;
}
//this is a function with return type bool and accept two parameters one is pointer and other one is bool
bool fixedobject::act(agent* plyr,bool flag)
{
if(flag)
{
if(this!=NULL)
{
if(key=="")
{
return true;
}
else
{
for(int i=0; i<2 ; i++)
{
if(plyr->holding[i]!=NULL && plyr->holding[i]->getname()==key)
{
cout<<"You can enter this room by typing the name of the required object.(Hey,you there.Just type "<<key<<".)"<<endl;
string str;
while(true)
{
cin>>str;
if(str==key)
{
cout<<"Now you can enter the room."<<endl;
//here when the str become equal to key and this block of code will execute and else part won`t be executed
break;
}
else
{
cout<<"It is not the required key \n or (enter the object name again)."<<endl<<endl;
}
}
return true;
}
}
cout<<"Seems like you don't have the required object to enter this room because of the "<<this->getname()<<"."<<"You need to get a "<<this->getkey()<<endl<<endl;
return false;
}
}
}
else
{
if(key=="")
{
return true;
}
else
{
for(int i=0; i<2 ; i++)
{
if(plyr->holding[i]!=NULL && plyr->holding[i]->getname()==key)
{
cout<<"You can use/open "<<this->getname()<<" by typing it's key name. \n (Hey,you there.Just type ( "<<key<<" .)"<<endl;
string str;
while(true)
{
cin>>str;
if(str==key)
{
cout<<"Now you can use/open the object."<<endl;
break;
}
else
{
cout<<"it is not the required key \n or (enter the object name again)."<<endl;
}
}
return true;
}
}
cout<<"Seems like you don't have the required object to use/open this object."<<endl;
return false;
}
}
return true;
}