-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHagridHut.cpp
More file actions
160 lines (146 loc) · 5.88 KB
/
HagridHut.cpp
File metadata and controls
160 lines (146 loc) · 5.88 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
/****************************
**Program: Final Project
**Name: Kirsten Carter
**Date: 6/3/2019
**Description: HagridHut Class - Holds play function. Takes a pointer to the player, a reference to the vector named Inventory, and a reference to Steps. Inventory and Steps can be altered in this function.
*****************************/
#include "HagridHut.hpp"
#include <iostream>
#include "itemsHelper.hpp"
HagridHut::HagridHut()
{
}
void HagridHut::play(People * player, std::vector<std::string>& inventory, int &steps)
{
std::cout << "After making it down the path you arrive at Hagrid's Hut where you can hear some not so quiet sobbing drifting out the open window. The Pumpkin Patch is directly to your right where you can see Buckbeak is tied up and napping in the evening Scottish sun." << std::endl;
int playerChoice;
std::cout << "Do you want to search the area for items? (1=Yes 2=No)" << std::endl;
std::cin >> playerChoice;
while (playerChoice < 1 || playerChoice > 2 || std::cin.fail() || std::cin.get() != '\n') //adapted use of cin from: https://www.hackerearth.com/practice/notes/validating-user-input-in-c/ and http://www.cplusplus.com/reference/limits/numeric_limits/ and last answer here: https://stackoverflow.com/questions/40119366/how-to-check-if-the-input-number-integer-not-float
{
std::cout << "ERROR - Invalid input! Please choose 1 for Harry or 2 for Hermione: \n";
std::cin.clear();
std::cin.ignore(256, '\n');
std::cin >> playerChoice;
}
if (playerChoice == 1)
{
int choiceInv;
int sizeI = inventory.size();
std::cout << "You found a dead ferret! Would you like to add it to the inventory? (1=Yes 2=No)" << std::endl;
std::cin >> choiceInv;
while (choiceInv < 1 || choiceInv > 2 || std::cin.fail() || std::cin.get() != '\n') //adapted use of cin from: https://www.hackerearth.com/practice/notes/validating-user-input-in-c/ and http://www.cplusplus.com/reference/limits/numeric_limits/ and last answer here: https://stackoverflow.com/questions/40119366/how-to-check-if-the-input-number-integer-not-float
{
std::cout << "ERROR - Invalid input! Please choose 1 for yes or 2 for no: \n";
std::cin.clear();
std::cin.ignore(256, '\n');
std::cin >> choiceInv;
}
switch (choiceInv)
{
case 1:
{
if (sizeI < 7)
{
itemAdd(inventory, "Dead Ferret");
}
else
{
itemSwitch(inventory, "Dead Ferret");
std::cout << "You currently have " << inventory.size() << " items in your bag." << std::endl;
}
}
break;
case 2:
default: std::cout << "You have chosen to not add this item to your inventory. You currently have " << inventory.size() << " items in your bag." << std::endl;
break;
}
int choiceInvA;
std::cout << "It's a rock... No, wait, it's one of Hagrid's Rock Cookies. Would you like to add it to the inventory? (1=Yes 2=No)" << std::endl;
std::cin >> choiceInvA;
while (choiceInvA < 1 || choiceInvA > 2 || std::cin.fail() || std::cin.get() != '\n') //adapted use of cin from: https://www.hackerearth.com/practice/notes/validating-user-input-in-c/ and http://www.cplusplus.com/reference/limits/numeric_limits/ and last answer here: https://stackoverflow.com/questions/40119366/how-to-check-if-the-input-number-integer-not-float
{
std::cout << "ERROR - Invalid input! Please choose 1 for yes or 2 for no: \n";
std::cin.clear();
std::cin.ignore(256, '\n');
std::cin >> choiceInvA;
}
switch (choiceInvA)
{
case 1:
{
if (sizeI < 7)
{
itemAdd(inventory, "Rock Cookie");
}
else
{
itemSwitch(inventory, "Rock Cookie");
std::cout << "You currently have " << inventory.size() << " items in your bag." << std::endl;
}
}
break;
case 2:
default: std::cout << "You have chosen to not add this item to your inventory. You currently have " << inventory.size() << " items in your bag." << std::endl;
break;
}
int choiceInvB;
std::cout << "It's another dead ferret, what luck! Would you like to add it to the inventory? (1=Yes 2=No)" << std::endl;
std::cin >> choiceInvB;
while (choiceInvB < 1 || choiceInvB > 2 || std::cin.fail() || std::cin.get() != '\n') //adapted use of cin from: https://www.hackerearth.com/practice/notes/validating-user-input-in-c/ and http://www.cplusplus.com/reference/limits/numeric_limits/ and last answer here: https://stackoverflow.com/questions/40119366/how-to-check-if-the-input-number-integer-not-float
{
std::cout << "ERROR - Invalid input! Please choose 1 for yes or 2 for no: \n";
std::cin.clear();
std::cin.ignore(256, '\n');
std::cin >> choiceInvA;
}
switch (choiceInvA)
{
case 1:
{
if (sizeI < 7)
{
itemAdd(inventory, "Dead Ferret");
}
else
{
itemSwitch(inventory, "Dead Ferret");
std::cout << "You currently have " << inventory.size() << " items in your bag." << std::endl;
}
}
break;
case 2:
default: std::cout << "You have chosen to not add this item to your inventory. You currently have " << inventory.size() << " items in your bag." << std::endl;
break;
}
if ((rand() % (6 + 1)) > 3)
{
std::cout << "Oh no, Professor Dumbledoor and The Ministry officials are making their way towards the Hut!" << std::endl;
if (inventory[1] == "Invisibility Cloak")
{
std::cout << "Quick Hermione, get under the Cloak." << std::endl;
}
else
{
if ((rand() % (4 + 1)) == 1)
{
std::cout << "Professor Dumbledoor finds you and thanks you for wanting to comfort Hagrid during this difficult time but you must return to the Castle. You've lost." << std::endl;
player->setStrength(0);
}
else
{
std::cout << "Quick Harry, behind the stone wall!" << std::endl;
}
}
}
++steps;
}
else if (player->getStrength() < 0)
{
std::cout << "Ok, lets move on then." << std::endl;
}
++steps;
}
HagridHut::~HagridHut()
{
}