-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDoor.cpp
More file actions
114 lines (100 loc) · 1.83 KB
/
Door.cpp
File metadata and controls
114 lines (100 loc) · 1.83 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
#include <iostream>
#include <string>
#include <map>
#include "User.h"
#include "InteractObject.h"
#include "Key.h"
#include "Painting.h"
#include "Door.h"
using namespace std;
Door::Door(string d,string l):InteractObject(false,false,d,l,"door")
{
isOpen = false;
isLocked = true;
};
void Door::beCalled(string v, User& b)
{
B = &b;
if(sameLoc(b))
{
if(v == "use"||v == "open")
beUsed();
else if(v == "get")
bePickedUp(b);
else if(v == "drop")
beDropped(b);
else if(v == "look")
beLooked();
else
cout<<"I can't do that."<<endl;
}
else
cout<<"I don't see a door."<<endl;
}
void Door::beCalled2(string v, User& b, InteractObject* p)//if an indirect object is included
{
B = &b;
if(sameLoc(b))
{
if(p->getName() == "key" && p->getInventoryState() && (v == "unlock"|| v == "use"))
{
unlock();
}
else if(p->getName() == "key" && p->getInventoryState() && v == "open")
{
unlock();
open();
}
else if(p->getName() == "key" && !(p->getInventoryState()))
{
cout<<"You don't have a key"<<endl;
}
else
{
cout<<"I can't do that."<<endl;
}
}
else
cout<<"I can't do that."<<endl;
}
void Door::open()
{
if(!isOpen)
{
cout<<"Opening"<<endl;
isOpen = true;
B->unlock("Tiny Room");
}
else
{
cout<<"Closing"<<endl;
isOpen = false;
B->unlock("Tiny Room");
}
}
void Door::beUsed()
{
if(!isLocked)
open();
else
{
cout<<"The door is locked."<<endl;
}
}
void Door::bePickedUp(User& b)
{
cout<<"Who in their right mind would try to pick up a door?"<<endl;
}
void Door::beDropped(User& b)
{
cout<<"I can't do that."<<endl;
}
void Door::beLooked()
{
cout<<getDescription()<<endl;
}
void Door::unlock()
{
isLocked = false;
cout<<"You unlock the door"<<endl;
}