-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlayer.cpp
More file actions
75 lines (65 loc) · 1.12 KB
/
Player.cpp
File metadata and controls
75 lines (65 loc) · 1.12 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
#include "Player.h"
#include <random>
#include <time.h>
#include <cstdio>
using namespace std;
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;
}
int
Player::attack()
{
static default_random_engine randomEngine( time( NULL ));
uniform_int_distribution <int> attackRoll( 0, _attack );
return attackRoll( randomEngine );
}
void
Player::addExperience(int xp)
{
_experience += xp;
//Level up
while (_experience > 50) {
printf( "Leveled up!\n" );
_experience -= 50;
_attack += 10;
_defense += 5;
_health += 10;
_level++;
system( "PAUSE" );
}
}
int
Player::takeDamage(int attack)
{
attack -= _defense;
if (attack > 0) {
_health -= attack;
if (_health <= 0) {
return 1;
}
}
return 0;
}
void
Player::setPosition(int x, int y)
{
_x = x;
_y = y;
}
void
Player::getPosition(int& x, int& y)
{
x = _x;
y = _y;
}