-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhouse.cpp
127 lines (102 loc) · 4.27 KB
/
house.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
/*******************************************************************************
** Program Name: Birthday Adventure Game
** Authors: Kelly von Borstel
** Date: 3/19/2018
** Description: This is implemenation file for house class, which is derived
** from space class. In addition to the member variable and function it
** inherits, it also has a member variable to keep track of whether the user
** has said goodbye to Ms. Whiskers. It overrides the virtual function that
** looks around to include a description and menu options specific to this
** space. It has two additional function, one to take an item from the space,
** and the other to say goodbye to Ms. Whiskers.
*******************************************************************************/
#include "house.hpp"
/*******************************************************************************
** Description: The constructor has one parameter, a string for the name of the
** space. In additon to setting name, it sets saidGoodbye initially to false.
*******************************************************************************/
House::House(string name) : Space(name)
{
saidGoodbye = false;
}
/*******************************************************************************
** Description: The lookAround function has two parameters, a reference to
** an integer of the user's funds and a reference to a vector of strings of
** the names of items in their shopping bag. After describing the space, the
** function gets the user's choice from a menu of options and calls other
** functions based on their choice. It returns nothing.
*******************************************************************************/
void House::lookAround(int& funds, vector<string>& bag)
{
cout << string(55, '-') << endl;
cout << "\nIn your house, there is a small table by the door"
<< "\nwith a set of Keys and your ID Card. Ms. Whiskers"
<< "\nis watching you from her favorite chair." << endl;
vector<string> spaceMenuOptions = {"Take Keys",
"Take ID Card",
"Say goodbye to Ms. Whiskers",
"Go back to Main Menu"};
Menu spaceMenu(spaceMenuOptions);
int choice = 0;
while (choice != 4)
{
cout << "\nWhat would you like to do?" << endl;
choice = spaceMenu.run();
if (choice == 1)
{
takeItem("Keys", bag);
}
else if (choice == 2)
{
takeItem("ID Card", bag);
}
else if (choice == 3)
{
sayGoodbye();
}
}
}
/*******************************************************************************
** Description: The takeItem function has two parameters, a string of the name
** of the item and a reference to a vector os strings of the names of the items
** in the user's bag. It checks if they have space for the items and checks
** that they don't already have the item, and then adds the item to bag. If
** they already have it, a message is printed. The function returns nothing.
*******************************************************************************/
void House::takeItem(string item, vector<string>& bag)
{
if (haveSpace(bag) && !haveItem(item, bag))
{
addItem(item, bag);
}
else
{
cout << string(55, '-') << endl;
cout << "\nYou already have " << item << " in your bag." << endl;
}
}
/*******************************************************************************
** Description: The sayGoodbye function prints a response from Ms. Whiskers
** based on whether you have said goodbye already or not, then sets saidGoodbye
** to true. It has no parameters and returns nothing.
*******************************************************************************/
void House::sayGoodbye()
{
cout << string(55, '-') << endl;
if (saidGoodbye)
{
cout << "\nMs. Whiskers repeats, ";
}
else
{
cout << "\nMs. Whiskers says, ";
}
cout << "\"Hurry home, but don't return until"
<< "\nyou have everything on the list. I won't let you"
<< "\nback in the house unless you have all the supplies"
<< "\nfor my birthday party!\"" << endl;
saidGoodbye = true;
}
House::~House()
{
}