-
Notifications
You must be signed in to change notification settings - Fork 2
/
Player.cpp
71 lines (52 loc) · 1.04 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
#include "Player.h"
Player::Player()
{
_x = 0;
_y = 0;
}
void Player::init(int level, int health, int attack, int defense, int experience) {
_level = level;
_health = health;
_attack = attack;
_defense = defense;
_experience = experience;
}
void Player::setPosition(int x, int y) {
_x = x;
_y = y;
}
void Player::getPosition(int &x, int &y){
x = _x;
y = _y;
}
int Player::attack() {
static default_random_engine randomEngine(time(NULL));
uniform_int_distribution<int> attackRoll(0, _attack);
return attackRoll(randomEngine);
}
void Player::addExperience(int experience) {
_experience += experience;
//Level up
while (_experience > 50) {
printf("Leveled up!\n");
_experience -= 50;
_attack += 10;
_defense += 5;
_health += 10;
_level++;
//Bad habit. Real bad. Neva use system pause
system("PAUSE");
}
}
int Player::takeDamage(int attack) {
attack -= _defense;
//Cjecl of the attack does damage
if (attack > 0) {
_health -= attack;
//Check if he died
if (_health <= 0) {
return 1;
}
}
return 0;
}