-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathanExitList.cpp
79 lines (71 loc) · 2.53 KB
/
anExitList.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
#include <iostream>
#include "anExitList.h"
//------------------------------------------------------
// constructor
//------------------------------------------------------
// the number of items in a new list is zero
anExitList::anExitList() { numExits = 0; }
//------------------------------------------------------
// get methods
//------------------------------------------------------
int anExitList::getNumExits() { return numExits; }
anExit anExitList::getExit(int ndx) {
if (ndx < 0 || ndx >= numExits) {
cout << "anExitList::getExit: invalid index = " << ndx << endl;
anExit emptyExit;
return emptyExit;
}
return exit[ndx];
} // getExit()
//-----------------------------------------------------
// addExit (2 overloaded)
//------------------------------------------------------
void anExitList::addExit(anExit newExit) {
if (numExits < MAX_EXITS)
exit[numExits++] = newExit;
else {
cout << "anExitList::addExit: MAX_EXITS EXCEEDED: " <<
" toRoom=" << newExit.getToRoom() <<
" direction=" << newExit.getDirection() << endl;
}
} // addExit()
void anExitList::addExit(string dir, int to_room) {
anExit newExit;
newExit.setToRoom(to_room);
newExit.setDirection(dir);
addExit(newExit);
} // addExit()
//------------------------------------------------------
// findExit
//------------------------------------------------------
// search the list by direction.
// returns toRoom of found exit, or NOT_FOUND
int anExitList::findExit(string srchDir) {
for (int i = 0; i < numExits; i++)
if (srchDir == exit[i].getDirection()) {
return exit[i].getToRoom();
}
return EXIT_NOT_FOUND;
} // findExit()
//------------------------------------------------------
// displayExits
//------------------------------------------------------
// print a list of exits in this list for the player
void anExitList::displayExits() {
if (numExits == 0) {
cout << "There are no exits.\n";
return;
}
cout << "Exits: " << exit[0].getDirection();
for (int i = 1; i < numExits; i++)
cout << ", " << exit[i].getDirection();
cout << ".\n";
} // displayExits()
//------------------------------------------------------
// print
//------------------------------------------------------
void anExitList::print() {
cout << "EXITLIST: numExits = " << numExits << endl;
for (int i = 0; i < numExits; i++)
exit[i].print();
} // printList()