-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPokemonCenter.cpp
More file actions
126 lines (107 loc) · 2.91 KB
/
PokemonCenter.cpp
File metadata and controls
126 lines (107 loc) · 2.91 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
#include "PokemonCenter.h"
PokemonCenter::PokemonCenter()
:Building()
{
display_code = 'C';
potion_capacity = 100;
num_potions_remaining = potion_capacity;
pokedollar_cost_per_potion = 5;
state = POTIONS_AVAILABLE;
}
PokemonCenter::PokemonCenter(int in_id, double potion_cost, unsigned int potion_cap, Point2D in_loc)
:Building(in_loc, in_id, 'C')
{
id_num = in_id;
location = in_loc;
pokedollar_cost_per_potion = potion_cost;
potion_capacity = potion_cap;
num_potions_remaining = potion_cap;
state = POTIONS_AVAILABLE;
}
//returns true if the PokemonCenter has potions
bool PokemonCenter::HasPotions()
{
if (num_potions_remaining >= 1)
{
state = POTIONS_AVAILABLE;
return true;
}
else
{
state = NO_POTIONS_AVAILABLE;
return false;
}
}
//returns number of potions that the PokemonCenter has
unsigned int PokemonCenter::GetNumPotionRemaining()
{
return num_potions_remaining;
}
//returns true if budget > potion cost
bool PokemonCenter::CanAffordPotion(unsigned int potion, double budget)
{
if (budget >= pokedollar_cost_per_potion*potion)
{
return true;
}
else
{
return false;
}
}
//returns cost for specified number of potions
double PokemonCenter::GetPokeDollarCost(unsigned int potion)
{
cout << "POKEDOLLAR_COST_PER_POTION IS: " << pokedollar_cost_per_potion << endl;
cout << "POTION NUMBER IS: " << potion << endl;
return pokedollar_cost_per_potion*potion;
}
//distributes potions based on how many are needed and how many are in the PokemonCenter
unsigned int PokemonCenter::DistributePotion(unsigned int potion_needed)
{
if (num_potions_remaining >= potion_needed)
{
num_potions_remaining = num_potions_remaining - potion_needed;
state = POTIONS_AVAILABLE;
return potion_needed;
}
else
{
unsigned int return_amount = num_potions_remaining;
num_potions_remaining = 0;
state = NO_POTIONS_AVAILABLE;
return return_amount;
}
}
//changes state the first time the PokemonCenter runs out of potions
bool PokemonCenter::Update()
{
char initial_state = state;
if (num_potions_remaining == 0)
{
state = NO_POTIONS_AVAILABLE;
display_code = 'c';
cout << "PokemonCenter " << id_num << " has run out of potions." << endl;
}
if ((initial_state == POTIONS_AVAILABLE) && (state == NO_POTIONS_AVAILABLE))
{
return true;
}
else
{
return false;
}
}
int PokemonCenter::GetCenterID()
{
return id_num;
}
void PokemonCenter::ShowStatus()
{
cout << "**********************************************************" << endl;
cout << "PokemonCenterStatus: " << endl;
Building::ShowStatus();
cout << "PokeDollars per potion: (" << pokedollar_cost_per_potion << ")" << endl;
cout << "has (" << num_potions_remaining << ") potion(s) remaining." << endl;
cout << "**********************************************************" << endl;
}