Repository navigation
Expand file tree
/
Copy pathKey.cpp
More file actions
118 lines (109 loc) · 2.02 KB
/
Copy pathKey.cpp
File metadata and controls
118 lines (109 loc) · 2.02 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
#include <string>
#include <iostream>
#include <string>
#include <map>
#include "User.h"
#include "InteractObject.h"
#include "Door.h"
#include "Key.h"
using namespace std;
Key::Key(string d, string l):InteractObject(true,false,d,l,"key")
{
behindPainting = true;
}
void Key::beCalled(string v, User& b)
{
if(sameLoc(b)||getInventoryState())
{
if(v == "use")
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 key."<<endl;
};
void Key::beCalled2(string v, User& b, InteractObject* p)
{
if(p->sameLoc(b))
{
if(p->getName() == "door" && getInventoryState() && (v == "unlock"|| v == "use"))
{
dynamic_cast<Door*>(p)->unlock();
}
else if(p->getName() == "door" && getInventoryState() && v == "open")
{
cout<<"That doesn't make any sense."<<endl;
}
else if(!(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 Key::beUsed()
{
if(getInventoryState())
{
cout<<"You spin the key on your finger, but achieve nothing."<<endl;
}
else
cout<<"You don't have a key."<<endl;
};
void Key::bePickedUp(User& b)
{
if(!behindPainting)
{
if(getInventoryState())
{
cout<<"The key is already in your inventory."<<endl;
}
else
{
cout<<"Picked up key"<<endl;
changeInventoryState("Key", b);
}
}
else
{
cout<<"I don't see a key."<<endl;
}
};
void Key::beDropped(User& b)
{
if(!behindPainting)
{
if(getInventoryState())
{
cout<<"Key dropped"<<endl;
changeLocation(b.getLocation());
changeInventoryState("Key", b);
}
else
cout<<"You don't have a key"<<endl;
}
else
{
cout<<"I don't see a key."<<endl;
}
};
void Key::beLooked()
{
cout<<getDescription()<<endl;
};
void Key::fall()
{
behindPainting = false;
};