-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEntranceHall.cpp
More file actions
131 lines (118 loc) · 4.85 KB
/
EntranceHall.cpp
File metadata and controls
131 lines (118 loc) · 4.85 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
/****************************
**Program: Final Project
**Name: Kirsten Carter
**Date: 6/3/2019
**Description: EntranceHall 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 "EntranceHall.hpp"
#include <iostream>
#include "itemsHelper.hpp"
EntranceHall::EntranceHall()
{
}
void EntranceHall::play(People * player, std::vector<std::string>& inventory, int &steps)
{
std::cout << "You slowly open the door into the Entrance Hall. You both quickly and quietly enter, trying very hard to not slam the door or make the hinges squeak. You both look around and breath a sigh of relief, no one is here." << std::endl;
int playerChoice;
int choiceInv;
int choiceInvB;
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! 1=Yes, 2=No: \n";
std::cin.clear();
std::cin.ignore(256, '\n');
std::cin >> playerChoice;
}
if (playerChoice == 1)
{
int sizeI = inventory.size();
std::cout << "You found a small collection of Galleons! 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, "3 Galleons");
}
else
{
itemSwitch(inventory, "3 Galleons");
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 sizeI = inventory.size();
std::cout << "You also found a Dead Ferret! 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 >> choiceInvB;
}
switch (choiceInvB)
{
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, Snape just rounded the corner from the dungeons and is coming this way!" << 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 << "Snape (*ehem* Professor Snape) has found you, takes 20 points from Gryffindor (EACH), and takes you to Professor Dumbledoor to determine your fit and just punishment. You've lost." << std::endl;
player->setStrength(0);
}
else
{
std::cout << "Quick Harry, through the doorway on your right!" << std::endl;
std::cout << "Snape passes you by and in a swirl of cloak ascends the stairs to the upper an level of the Castle." << std::endl;
}
}
}
++steps;
} else if (player->getStrength() > 0)
{
std::cout << "Ok, lets move on then." << std::endl;
}
++steps;
}
EntranceHall::~EntranceHall()
{
}