-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadventure.cpp
126 lines (113 loc) · 2.67 KB
/
adventure.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
#include "adventure.h"
World::World()
{
exists = true;
Library();
// Moody();
// RecCenter();
// CampusCenter();
// MBB();
// BarretHall();
}
World::~World()
{
}
void Player::move(string userinput)
{
string places[6] = {"Library", "Moody", "RecCenter", "CampusCenter", "MBB", "BarretHall"};
bool excepted = true;
for(int i = 0;i < 6; i++)
{
if(userinput == places[i] )
{
Library().enter();
excepted = false;
}
if(excepted == true )
throw invalidMove();
}
}
Library::Library()
{
location = 1;
hasBeenVisited = false;
isLocked = false;
}
Library::~Library()
{
isLocked = false;
}
void Library::getCoffee()
{
cout << "You stopped by the Starbucks and spent $5.60 on a cup of bad coffee." << endl;
cout << "You don't have a lot of time left to look around." << endl;
string userInput;
cin >> userInput;
bool tryWorked = false;
while (tryWorked == false)
{
try{
tryWorked = true;
Library::doThis(userInput);
}
catch(Library::tryagain){
cout << "That's not a valid command. For a list of valid commands type 'help'." << endl;
Library::doThis(userInput);
}
}
}
void Library::enter()
{
Library::hasBeenVisited = true;
string userInput;
cout << "You have entered the library, you think you have left your textbook here. You may search for items by entering in 'Search'. You may leave by entering 'Exit'." << endl;
cin >> userInput;
bool tryWorked = false;
while (tryWorked == false)
{
try{
tryWorked = true;
Library::doThis(userInput);
}
catch(Library::tryagain){
cout << "That's not a valid command. For a list of valid commands type 'help'." << endl;
Library::doThis(userInput);
}
}
}
void Library::exit()
{
string userInput;
cout << "You've exited the Library. What building do you want to look in next?" << endl;
cin >> userInput;
bool tryWorked = false;
while (tryWorked == false)
{
try {
// test inputs
tryWorked = true;
Player::move(userInput);
}
catch(Player::invalidMove){
cout << "It's not a good idea to go there, you didn't leave any supplies for class there." << endl;
}
}
}
void Library::search()
{
string userInput;
cout << "You've found your textbook! " << endl << "You're one step closer to getting to that test!" << endl;
cout << "You should keep looking for the rest of your supplies." << endl;
Library::exit();
}
void Library::doThis(string userInput)
{
if(userInput == "Exit")
Library::exit();
else if (userInput == "Search")
Library::search();
else if(userInput == "getCoffee")
Library::getCoffee();
else
throw tryagain();
}