-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPokemon.cpp
More file actions
113 lines (93 loc) · 2.26 KB
/
Pokemon.cpp
File metadata and controls
113 lines (93 loc) · 2.26 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
#include "Pokemon.h"
#include "Element.h"
#include <iostream>
#include <string>
#include <map>
#include <iterator>
constexpr int hpbase = 20;
constexpr int hplvl = 3;
constexpr int xplvl = 10;
Pokemon::Pokemon(const std::string& name, int level, Element type)
: m_name(name),
m_lvl(level),
m_type(type),
m_xp(0),
m_xpmax(m_lvl * xplvl),
m_atk(m_lvl),
m_hpmax(hpbase + m_lvl * hplvl),
m_hp(m_hpmax)
{
}
void Pokemon::Name()
{
std::cout << "O nome do Pokemon é: " << m_name << std::endl;
}
void Pokemon::Attack(Pokemon &enemy)
{
const float multiplier = Weakness(enemy)*Strength(enemy);
EmitSound();
std::cout << m_name << " causou " << static_cast<int>(m_atk * multiplier) << " de dano em " << enemy.m_name << std::endl;
enemy.HP(enemy.m_hp - static_cast<int>(m_atk * multiplier));
Pokemon::Level(static_cast<int>(m_atk * multiplier));
std::cout << std::endl;
}
void Pokemon::Cure(int life)
{
std::cout << m_name << " recebeu " << life << " pontos de vida" << std::endl;
m_hp += life;
if (m_hp > m_hpmax)
{
m_hp = m_hpmax;
}
Pokemon::HP();
}
void Pokemon::Level(const int exp)
{
m_xpmax = m_lvl * 10;
m_xp += exp;
if (m_xp >= m_xpmax)
{
++m_lvl;
std::cout << m_name << " subiu para nível " << m_lvl << std::endl;
m_atk = m_lvl;
m_hpmax = (20 + m_lvl * 3);
Pokemon::HP(m_hpmax);
}
}
void Pokemon::HP()
{
std::cout << m_name << " está com " << m_hp << " pontos de vida" << std::endl;
}
void Pokemon::HP(int life)
{
m_hp = life;
if (m_hp < 0)
{
m_hp = 0;
}
std::cout << m_name << " está com " << m_hp << " pontos de vida" << std::endl;
}
int Pokemon::Strength(Pokemon &enemy)
{
for (const auto &type : Weaknesses.at(enemy.m_type))
{
if (type == m_type)
{
std::cout << m_name << " é forte contra " << enemy.m_name << std::endl;
return 2;
}
}
return 1;
}
float Pokemon::Weakness(Pokemon &enemy)
{
for (const auto &type : Strengths.at(enemy.m_type))
{
if (type == m_type)
{
std::cout << m_name << " é fraco contra " << enemy.m_name << std::endl;
return 0.5;
}
}
return 1;
}