-
Notifications
You must be signed in to change notification settings - Fork 0
/
Pokemon.cpp
54 lines (47 loc) · 1.2 KB
/
Pokemon.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
#pragma once
#include "Pokemon.hpp"
#include "PokemonType.hpp"
#include <iostream>
using namespace std;
// Default constructor
Pokemon::Pokemon() {
name = "Unknown";
type = PokemonType::NORMAL;
health = 50;
maxHealth = 50;
attackPower = 10;
}
// Parameterized constructor
Pokemon::Pokemon(string p_name, PokemonType p_type, int p_health,
int p_attackPower) {
name = p_name;
type = p_type;
maxHealth = p_health;
health = p_health;
attackPower = p_attackPower;
}
// Copy constructor
Pokemon::Pokemon(const Pokemon& other) {
name = other.name;
type = other.type;
health = other.health;
maxHealth = other.maxHealth;
attackPower = other.attackPower;
}
// Reduce HP by the damage amount
void Pokemon::takeDamage(int damage) {
health -= damage;
if (health < 0) {
health = 0;
}
}
// Check if the Pokemon has fainted
bool Pokemon::isFainted() const { return health <= 0; }
// Restore health to full
void Pokemon::heal() { health = maxHealth; }
// Attack another Pokemon
void Pokemon::attack(Pokemon& target) {
cout << name << " attacks " << target.name << " for " << attackPower
<< " damage!\n";
target.takeDamage(attackPower);
}