-
Notifications
You must be signed in to change notification settings - Fork 0
/
space.cpp
167 lines (146 loc) · 4.23 KB
/
space.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
159
160
161
162
163
164
165
166
167
/*********************************************************************
** Author: Jose Cisneros
** Date: 3/21/2017
** Description: space.cpp is the Space class implementation file.
*********************************************************************/
#include "space.hpp"
/*********************************************************************
** Description: default constructor
*********************************************************************/
Space::Space()
{
right = left = up = down = nullptr;
}
/*********************************************************************
** Description: default constructor
*********************************************************************/
Space::~Space()
{
}
/*********************************************************************
** Description: retrieve room
** Returns: Space*
*********************************************************************/
Space* Space::getRight()
{
return right;
}
/*********************************************************************
** Description: retrieve room
** Returns: Space*
*********************************************************************/
Space* Space::getLeft()
{
return left;
}
/*********************************************************************
** Description: retrieve room
** Returns: Space*
*********************************************************************/
Space* Space::getUp()
{
return up;
}
/*********************************************************************
** Description: retrieve room
** Returns: Space*
*********************************************************************/
Space* Space::getdown()
{
return down;
}
/*********************************************************************
** Description: retrieve room
** Returns: Space*
*********************************************************************/
void Space::displayArt(string fileName)
{
ifstream inputFile; // Create input file stream object
string lines = "";
//Open the input file
inputFile.open(fileName);
// Read input and store into Vector
if (inputFile)
{
// Read and add the numbers in file
while (inputFile)
{
string tempLine;
getline(inputFile, tempLine);
tempLine += "\n";
lines += tempLine;
}
cout << lines << endl;
}
else
{
// Display error message
cout << "could not access file" << endl;
}
// Close file
inputFile.close();
}
/*********************************************************************
** Description: retrieve room name
** Returns: string
***********************************************************c*********/
string Space::getRoomName()
{
return roomName;
}
/*********************************************************************
** Description: set location
** Returns: void
***********************************************************c*********/
void Space::setLocation(Space* location, char direction)
{
// Based on char input, set pointer
switch (direction)
{
case 'U':
up = location;
break;
case 'D':
down = location;
break;
case 'L':
left = location;
break;
case 'R':
right = location;
break;
default:
break;
}
}
/*********************************************************************
** Description: set location
** Returns: void
***********************************************************c*********/
int Space::searchBag(vector<string> &inv, string name)
{
int position = -1; // Position of search string
bool searchDone = false; // flag
int i = 0; // Starting position
// If empty, return
if (inv.size() == 0)
{
return position;
}
while (!searchDone)
{
// If element is equal to search string, set position and update flag
if (inv[i] == name)
{
position = i;
searchDone = true;
}
// If back is reached update flag
if (inv[i] == inv.back())
{
searchDone = true;
}
i++;
}
return position;
}