-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRefrigerator.cpp
More file actions
180 lines (170 loc) · 5.98 KB
/
Refrigerator.cpp
File metadata and controls
180 lines (170 loc) · 5.98 KB
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
173
174
175
176
177
178
179
/**************************************************************************
* Program Name:Refrigerator.cpp
* Name: Manda Jensen
* Date: 08 JUN 2019
* Description: This file contains the definition of the functions included
* in the class Refrigerator.
* Refrigerator is a child class of and inherits from Space.
* Variables:
* no additional variables than the ones in Space.
*
* Functions:
* Refrigerator() - default constructor
* Parameters: none
* Return Type: n/a
* Purpose: default constructor for Refrigerator, sets
* the type of the space appropriately and sets
* all Space* variables to nullptr, and fills
* the items of the refrigerator to start the
* game
* ~Refrigerator() - default destructor
* Parameters: none
* Return Type: n/a
* Purpose: default destructor for Refrigator, sets all
* Space* variables to nullptr
* spaceMenu() - overriden function
* Parameters: none
* Return Type: int
* Purpose: prints the space menu displaying the possible
* actions in that space and returns the integer
* for the user's choice
* play() - overriden function
* Parameters: Ingredient vector by reference
* Return Type: bool
* Purpose: goes through the actions to play out a turn
* when the player is on this space, will
* manipulate the ingredient vector provided
* as an argument as needed, calls spaceMenu()
* to determine the user's choice for action
* returns true if game objective completed,
* false if not
* printType() - overriden function
* Parameters: none
* Return Type: string
* Prupose: returns a string that contains the type of
* the space centered within 18 characters with
* white space on either side
**************************************************************************/
#include "Refrigerator.hpp"
#include "Space.hpp"
#include "spaceType.hpp"
#include "ingredients.hpp"
#include "getLimitedInteger.hpp"
#include <string>
#include <vector>
#include <iomanip>
#include <iostream>
/**************************************************************************
*Refrigerator() - default constructor
* Parameters: none
* Return Type: n/a
* Purpose: default constructor for Refrigerator, sets the type of the
* space appropriately and sets all Space* variables to nullptr
* and adds the appropriate ingredients to the items vector
* to start the game
**************************************************************************/
Refrigerator::Refrigerator()
{ top = nullptr;
right = nullptr;
bottom = nullptr;
left = nullptr;
type = refrigerator;
items.push_back(butter);
items.push_back(eggs);
}
/**************************************************************************
*~Refrigerator() - default destructor
* Parameters: none
* Return Type: n/a
* Purpose: default destructor for Refrigator, sets all Space* variables
* to nullptr
**************************************************************************/
Refrigerator::~Refrigerator()
{ top = nullptr;
right = nullptr;
bottom = nullptr;
left = nullptr;
}
/**************************************************************************
*spaceMenu() - overriden function
* Parameters: none
* Return Type: int
* Purpose: prints the space menu displaying the possible actions in
* that space and returns the integer for the user's choice
* The possible options at the refrigerator are to pick up
* an item or to do nothing
**************************************************************************/
int Refrigerator::spaceMenu()
{
int userChoice = 0;
int lowLim = 1;
int highLim = 2;
int num = lowLim-1;
//menu text that will be sent to the user
for(int i=0; i<80; i++)
{ std::cout <<"-";
}
std::cout << "\n";
std::cout << "-" << std::setw(43) << std::right << "Refrigerator Menu" << std::setw(36) << "-" << "\n";
for(int i=0; i<80; i++)
{ std::cout <<"-";
}
std::cout << "\n";
std::cout << "- " << std::setw(78) << std:: left << "Select an action to take from the list below"
<< "-\n";
std::cout << "- " << std::setw(2) << std::right << ++num << ". " << std::setw(73) << std::left
<< "Pick up an item from the refrigerator" << "-\n";
std::cout << "- " << std::setw(2) << std::right << ++num << ". " << std::setw(73) << std::left
<< "Do nothing" << "-\n";
for(int i=0; i<80; i++)
{ std::cout <<"-";
}
std::cout << "\n";
std::cout << "Please enter the integer of your choice:" << std::endl;
//user choice is validated and set to the variable that is returned
getLimitedInteger(&userChoice, lowLim, highLim);
return userChoice;
}
/**************************************************************************
*play() - overriden function
* Parameters: Ingredient vector by reference
* Return Type: bool
* Purpose: goes through the actions to play out a turm when the player
* is on this space, will manipulate the ingredient vector
* provided as an argument as needed, calls spaceMenu() to
* determine the user's choice for action
**************************************************************************/
bool Refrigerator::play(std::vector<ingredients> &basket)
{ printItems();
int userChoice = spaceMenu();
switch(userChoice)
{ case 1:
//if there is space in the basket for another item
//call the itemMenu and add the choice to the
//user's basket, else print an error message
if(basket.size()<3)
{ userChoice = itemMenu();
basket.push_back(items[userChoice-1]);
}
else
{ std::cout << "You have reached the "
<< "capacity of your basket.\n"
<< "Remove an item at the trash "
<< "to free up space.\n";
}
break;
default:
break;
}
return false;
}
/**************************************************************************
*printType() - overriden function
* Parameters: none
* Return Type: string
* Prupose: returns a string that contains the type of the space centered
* within 18 characters with white space on either side
**************************************************************************/
std::string Refrigerator::printType()
{ return " Refrigerator ";
}