-
Notifications
You must be signed in to change notification settings - Fork 69
Expand file tree
/
Copy pathCard.cpp
More file actions
91 lines (74 loc) · 1.96 KB
/
Card.cpp
File metadata and controls
91 lines (74 loc) · 1.96 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
#include "Card.h"
static const bool WIN = true;
static const bool LOSS = false;
Card::Card(CardType type, const CardStats &stats) : m_effect(type), m_stats(stats)
{
if (type == CardType::Battle)
{
this->m_stats.loot=stats.loot;
this->m_stats.force=stats.force;
this->m_stats.hpLossOnDefeat=stats.hpLossOnDefeat;
}
if (type == CardType::Buff)
{
this->m_stats.cost=stats.cost;
this->m_stats.buff=stats.buff;
}
if (type == CardType::Treasure)
{
this->m_stats.loot=stats.loot;
}
if (type == CardType::Heal)
{
this->m_stats.cost=stats.cost;
this->m_stats.heal=stats.heal;
}
}
void Card::applyEncounter(Player& player) const
{
if (this->m_effect== CardType::Battle)
{
if (player.getAttackStrength() >= this->m_stats.force)
{
player.levelUp();
player.addCoins(this->m_stats.loot) ;
printBattleResult(WIN);
}
else
{
player.damage(this->m_stats.hpLossOnDefeat);
printBattleResult(LOSS);
}
}
if (this->m_effect== CardType::Heal && player.pay(this->m_stats.cost))
{
player.heal(this->m_stats.heal);
}
if (this->m_effect== CardType::Buff && player.pay(this->m_stats.cost))
{
player.buff(this->m_stats.buff);
}
if (this->m_effect== CardType::Treasure)
{
player.addCoins(this->m_stats.loot);
}
}
void Card:: printInfo() const
{
if (this->m_effect== CardType::Treasure)
{
printTreasureCardInfo(this->m_stats);
}
if (this->m_effect== CardType::Battle)
{
printBattleCardInfo(this->m_stats);
}
if (this->m_effect== CardType::Buff)
{
printBuffCardInfo(this->m_stats);
}
if (this->m_effect== CardType::Heal)
{
printHealCardInfo(this->m_stats);
}
}