-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlayer.cpp
122 lines (104 loc) · 2.48 KB
/
Player.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
#include "Player.h"
#include <iostream>
#include <iomanip>
using namespace std;
Player::Player()
{
_name = "";
_strength = 100;
_stamina = 100;
_wisdom = 100;
_pride_points = 0;
_age = 1;
}
Player::Player(string name, int age, int strength, int stamina, int wisdom, int pride_points)
{
_name = name;
_age = age;
_strength = constrainIntToRange(strength, 100, 1000);
_stamina = constrainIntToRange(stamina, 100, 1000);
_wisdom = constrainIntToRange(wisdom, 100, 1000);
_pride_points = pride_points;
}
string Player::getName()
{
return _name;
}
int Player::getStrength()
{
return _strength;
}
int Player::getStamina()
{
return _stamina;
}
int Player::getWisdom()
{
return _wisdom;
}
int Player::getPridePoints()
{
return _pride_points;
}
int Player::getAge()
{
return _age;
}
void Player::setName(string name)
{
_name = name;
}
void Player::addStrength(int strength)
{
_strength += strength;
}
void Player::addStamina(int stamina)
{
_stamina += stamina;
}
void Player::addWisdom(int wisdom)
{
_wisdom += wisdom;
}
void Player::addPridePoints(int pride_points)
{
_pride_points += pride_points;
}
void Player::addAge(int years)
{
_age += years;
}
void Player::trainCub(int strength, int stamina, int wisdom)
{
_strength = constrainIntToRange(strength, 100, 1000);
_stamina = constrainIntToRange(stamina, 100, 1000);
_wisdom = constrainIntToRange(wisdom, 100, 1000);
_pride_points -= 5000;
}
void Player::toPrideLands()
{
_pride_points += 5000;
_strength -= 2000;
_wisdom -= 2000;
_stamina -= 1000;
}
void Player::printStats()
{
cout << "##############################\n"
<< "# " << _name << ", age " << _age << fixed << setw(23 - static_cast<int>(_name.length() + (_age >= 10 ? 2 : 1))) << " #\n"
<< "# Strength: " << setw(16) << _strength << " #\n"
<< "# Stamina: " << setw(17) << _stamina << " #\n"
<< "# Wisdom: " << setw(18) << _wisdom << " #\n"
<< "# Pride Points: " << setw(12) << _pride_points << " #\n"
<< "##############################\n";
}
// Little utility function to make life easier
int Player::constrainIntToRange(int input, int min, int max)
{
if (input < min)
return min;
else if (input > max)
return max;
else
return input;
}