-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathGrass.cpp
More file actions
82 lines (71 loc) · 2.09 KB
/
Copy pathGrass.cpp
File metadata and controls
82 lines (71 loc) · 2.09 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
/***************************************
Program Name: Final Project
Author: Robert Elsom
Date: 3/6/2019
Description: Grass class, allows character to build shelters
and fires, containes buildShelter, buildFire, and getShelter
which returns true if shelter is in the space
**************************************/
#include "Grass.hpp"
#include "validStr.hpp"
#include <iostream>
//enters grass space and gets user input to interact with space
int Grass::enterSpace( int wood) {
int woodUsed = 0;
//prompt to build shelter if not already build
if (!builtShelter) {
std::cout << "You entered a grassy clearing. Here you could build a shelter to spend the night\n"\
"and start a fire to reduce chances of hypothermia. You can only build a fire if you have\n"\
"a shelter already built." <<std::endl <<std::endl;
if (wood >= 10) {
std::string shelterOption = validStr("Would you like to build a shelter with 10 pieces of wood? (Y/N)");
if (shelterOption == "Y" || shelterOption == "y") {
buildShelter();
woodUsed -= 10;
}
}
else {
std::cout << "Sorry, you do not have enough wood to build a shelter." << std::endl;
}
}
else if (builtShelter) {
std::cout << "You have returned to a shelter you have built." <<std::endl;
}
return woodUsed;
}
//returns type of space
std::string Grass::getType() {
return "grass";
}
//returns true if there was a shelter previously built here
bool Grass::hasShelter() {
return builtShelter;
}
//builds a shelter on the space, dont forget to update wood container in game class
void Grass::buildShelter() {
builtShelter = true;
}
void Grass::buildFire() {
builtFire = true;
}
void Grass::extinguishFire() {
builtFire = false;
}
//calculates if someone got hypothermia with an 80% chance
bool Grass::gotHypothermia() {
if (!builtFire) {
//if got hypothermia
if (rand() % 100 < 80) {
std::cout << std::endl << "Oh no, you got hypothermia and died." << std::endl;
hypothermia = true;
return hypothermia;
}
}
return hypothermia;
}
bool Grass::getHypothermiaFlag() {
return hypothermia;
}
bool Grass::hasFire() {
return builtFire;
}