-
Notifications
You must be signed in to change notification settings - Fork 0
/
Pantry.cpp
181 lines (171 loc) · 5.83 KB
/
Pantry.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
173
174
175
176
177
178
179
180
/**************************************************************************
* Program Name:Pantry.cpp
* Name: Manda Jensen
* Date: 08 JUN 2019
* Description: This file contains the definition of the functions included
* in the class Pantry.
* Pantry is a child class of and inherits from Space.
* Variables:
* no additional variables than the ones in Space.
*
* Functions:
* Pantry() - default constructor
* Parameters: none
* Return Type: n/a
* Purpose: default constructor for Pantry, sets
* the type of the space appropriately and sets
* all Space* variables to nullptr, and fills
* the items of the pantry to start the
* game
* ~Pantry() - default destructor
* Parameters: none
* Return Type: n/a
* Purpose: default destructor for Pantry, 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 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
**************************************************************************/
#include "Pantry.hpp"
#include "Space.hpp"
#include "spaceType.hpp"
#include "ingredients.hpp"
#include "getLimitedInteger.hpp"
#include <string>
#include <vector>
#include <iomanip>
#include <iostream>
/**************************************************************************
*Pantry() - default constructor
* Parameters: none
* Return Type: n/a
* Purpose: default constructor for Pantry, 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
**************************************************************************/
Pantry::Pantry()
{ top = nullptr;
right = nullptr;
bottom = nullptr;
left = nullptr;
type = pantry;
items.push_back(sugar);
items.push_back(flour);
items.push_back(bakingSoda);
items.push_back(cocoaPowder);
}
/**************************************************************************
*~Pantry() - default destructor
* Parameters: none
* Return Type: n/a
* Purpose: default destructor for Pantry, sets all Space* variables
* to nullptr
**************************************************************************/
Pantry::~Pantry()
{ 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 pantry are to pick up
* an item or to do nothing
**************************************************************************/
int Pantry::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 << "Pantry 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 pantry" << "-\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;
//store and validate the user's choice
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, returns false
**************************************************************************/
bool Pantry::play(std::vector<ingredients> &basket)
{ printItems();
int userChoice = spaceMenu();
switch(userChoice)
{ case 1:
//if the user's basket has space, call the itemMenu
//and add the item 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 Pantry::printType()
{ return " Pantry ";
}