-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStable.cpp
172 lines (151 loc) · 6.77 KB
/
Stable.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
168
169
170
171
172
//
// Created by Justin Lin on 2019-06-06.
//
/*********************************************************************
** Program name: Stable.cpp
** Author: Justin Lin
** Date: 06/03/2019
** Description: This is the implementation file for the derived Stable class.
* The class has two member variables that are both bools
* that will represent if the player has satisfied a
* condition. The constructor that will call the base
* Space class constructor and set horseFed and carrotTaken
* to false. Lastly, there are 3 override methods. The name
* method returns the name of the class. The info method prints
* a description of the cell. Lastly, the interactions method
* will provide a menu of options based upon the bool member
* variables.
*********************************************************************/
#include "Stable.hpp"
#include "inBounds.hpp"
#include "integerValidation.hpp"
#include <iostream>
#include <string>
using std::cout;
using std::endl;
using std::string;
/*******************************************************************************
Name: Justin Lin
Called by: N/A
Calls: Space()
Passed: N/A
Returns: N/A
Description: This is the default constructor for the Stable class. It calls the
base class Space constructor, and sets horseFed and carrotTaken
to false using an initialization list.
*******************************************************************************/
Stable::Stable() : Space(), horseFed(false), carrotTaken(false) {};
/*******************************************************************************
Name: Justin Lin
Called by: interactions()
Calls: N/A
Passed: N/A
Returns: N/A
Description: This method simply returns the name of the Space. It is used when
a player enters a new space.
*******************************************************************************/
string Stable::name() {
return "[Stable Car]";
}
/*******************************************************************************
Name: Justin Lin
Called by: play()
Calls: N/A
Passed: N/A
Returns: N/A
Description: This is a polymorphic method which prints a unique train car
description.
*******************************************************************************/
void Stable::info() {
cout << "The smell of manure hits you instantly. Ah, that's what that\n"
"smell was. You see a large horse staring back at you. Why is\n"
"there a horse on this train!? There is a large stack of hay in\n"
"the corner of the Stable Car. Across from you, you see the door\n"
"to the next train car. Across the car from the stack of hay you\n"
"see a pile of carrots \'Yuck\' you think to yourself.\n" << endl;
}
/*******************************************************************************
Name: Justin Lin
Called by: play()
Calls: N/A
Passed: Character*
Returns: Space*
Description: This is a polymorphic method which prints a menu based upon
what actions the player has completed. It takes as an argument
a pointer to a Character representing the player character. The
menu changes based on whether the horse has been fed. The
interactions method presents a menu to the user indicating what
actions they can perform. The interactions method is an infinite
loop with the exit condition the player leaving the space. If
the player moves right/;eft, the method will use the respective
links to return the next space.
*******************************************************************************/
Space* Stable::interactions(Character *player) {
int choice = 0;
while (true) {
// If horse is not fed, provide option
if (!horseFed) {
cout << " 1. Look around\n 2. Move Right\n 3. Move Left\n"
" 4. Inventory\n 5. Stats\n 6. Take Carrot\n"
" 7. Feed horse hay\n" << endl;
do {
choice = integerValidation();
} while (!inBounds(choice, 1, 7));
// If horse has already been fed
} else {
cout << " 1. Look around\n 2. Move Right\n 3. Move Left\n"
" 4. Inventory\n 5. Stats\n 6. Take Carrot" << endl;
do {
choice = integerValidation();
} while (!inBounds(choice, 1, 6));
}
// Prints space info
if (choice == 1) {
info();
// Attempts to move right
} else if (choice == 2) {
cout << "You make your way through the carriageway forward into\n"
"the " << getRight()->name() << "\n" << endl;
player->setHP(player->getHP() - 1);
return this->getRight();
// Attempts to move left
} else if (choice == 3) {
cout << "You make your way back through the carriageway into\n"
"the " << getLeft()->name() << "\n" << endl;
player->setHP(player->getHP() - 1);
return this->getLeft();
// Prints player inventory
} else if (choice == 4) {
player->inventory();
// Prints player stats
} else if (choice == 5) {
player->stats();
// Take carrot
} else if (choice == 6) {
if (!carrotTaken) {
cout << "You grab a [Carrot] out of the pile and shove it in your"
" pockets.\n" << endl;
cout << "[Carrot] added to [Inventory]\n" << endl;
player->takeItem("Carrot");
player->checkItems();
carrotTaken = true;
} else {
cout << "You already took a [Carrot]. You only have so many\n"
"pockets. Best not to fill them all up with carrots.\n"
<< endl;
}
// Feed horse
} else if (choice == 7) {
cout << "You grab some hay out of the corner and place it infront of\n"
"the horse. He or maybe she...what do you know, you're no\n"
"horse expert. AHEM! The horse begins munching away happily\n"
"at the stack of hay. Looking back over at the haystack\n"
"you see something shiny poking out. You walk over and pick\n"
"it up\n" << endl;
cout << "[Crowbar] added to [Inventory]\n" << endl;
player->takeItem("Crowbar");
player->checkItems();
horseFed = true;
}
}
}