-
Notifications
You must be signed in to change notification settings - Fork 0
/
shipobservationroom.cpp
158 lines (138 loc) · 4.53 KB
/
shipobservationroom.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
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
/*********************************************************************
** Author: Jose Cisneros
** Date: 3/21/2017
** Description: ShipObservationroom.cpp is the ShipObservationRoom class implementation file.
*********************************************************************/
#include "shipobservationroom.hpp"
/*********************************************************************
** Description: default constructor
*********************************************************************/
ShipObservationRoom::ShipObservationRoom()
{
roomName = "Observation Room";
roomInventory.push_back("Key");
isDoorLocked = false;
}
/*********************************************************************
** Description: Menu for space
** Returns: void
***********************************************************c*********/
void ShipObservationRoom::menu(Space* &l, int &h, int &e, int &o, vector<string> &i)
{
bool flag = true; // flag
int choice = 0; // user choice input
//Check if door si locked
if (isDoorLocked)
{
cout << "\nThe door is locked " << endl;
l = up;
return;
}
cout << endl;
// Print space info
displayArt("observation.txt");
cout << "Observation Deck" << endl;
cout << "\nThis room is leaking air." << endl;
// Menu
do
{
cout << "\nPlease make a selection" << endl;
cout << "1: Go back to the Gate Room" << endl;
cout << "2: Lock the door" << endl;
cout << "3: Search the room" << endl;
cout << "\nEnter: ";
cin >> choice;
validateInput(choice, 1, 3);
// Make selection based on input
switch (choice)
{
case 1:
{
l = up;
flag = false;
}
break;
case 2:
{
// Check if user has picked up key
if (!(roomInventory[0] == "empty"))
{
cout << "You don't have a key " << endl;
}
// Check if door is locked. If not, lock.
else if (!isDoorLocked)
{
cout << "The door was locked and the leak has been sealed" << endl << endl;
isDoorLocked = true;
flag = false;
l = up;
}
else
{
cout << "The door is already locked" << endl;
}
}
break;
case 3:
{
searchRoom(i);
}
break;
}
cin.get();
} while (flag);
}
/*********************************************************************
** Description: search room and add to inventory
** Returns: void
***********************************************************c*********/
void ShipObservationRoom::searchRoom(vector<string> &i)
{
bool flag = true; // flag
int choice = 0; // user choice input
cout << "Items found in room" << endl;
// Menu
do
{
cout << "\nPlease make a selection to add to bag" << endl;
cout << "1: Key" << endl;
cout << "2: Back to room menu"<< endl;
cout << "\nEnter: ";
cin >> choice;
validateInput(choice, 1, 2);
// Limit bag size
if (i.size() == 3)
{
cout << "There's no more room-" << endl;
return;
}
// Make selection based on input
switch (choice)
{
case 1:
// Check if user has picked up key. If not, add to inventory.
if (!(roomInventory[0] == "empty"))
{
i.push_back(roomInventory[0]);
cout << roomInventory[0] << " was added to the inventory" << endl;
roomInventory[0] = "empty";
}
else
{
cout << "The item was already added!" << endl;
}
break;
case 2:
flag = false;
break;
}
} while (flag);
}
/*********************************************************************
** Description: returns whether door is locked or not
** Returns: Bool
***********************************************************c*********/
bool ShipObservationRoom::getIsDoorLocked()
{
return isDoorLocked;
}