-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEncounter.cpp
More file actions
107 lines (89 loc) · 4.16 KB
/
Encounter.cpp
File metadata and controls
107 lines (89 loc) · 4.16 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
#include "Encounter.h"
#include <iostream>
// MonsterEncounter Implementation
MonsterEncounter::MonsterEncounter(std::unique_ptr<Monster> monster)
: monster(std::move(monster)) {}
void MonsterEncounter::trigger(Player& player) {
if (!player.isAlive()) {
std::cout << player.getName() << " is already dead and cannot fight!\n";
return;
}
std::cout << "A wild " << monster->getName() << " appears!\n";
int turnCounter = 0; // Track player turns for strong attack
while (player.isAlive() && monster->isAlive()) {
// Display stats
std::cout << "\n=====================================\n";
std::cout << "Player's Stats:\n";
std::cout << "Health: " << player.getHealth()
<< ", Damage: " << player.getDamage()
<< ", Defense: " << player.getDefense() << "\n";
std::cout << "Monster's Stats:\n";
std::cout << "Health: " << monster->getHealth()
<< ", Damage: " << monster->getDamage() << "\n";
std::cout << "=====================================\n";
// Ask the player for their action
std::cout << "\nYour turn! Choose an action:\n";
std::cout << "1. Attack\n";
std::cout << "2. Block\n";
if (turnCounter >= 3) {
std::cout << "3. Strong Attack (Available!)\n";
}
std::cout << "Enter your choice: ";
int choice;
std::cin >> choice;
if (choice == 1) {
// Player attacks the monster
int damageToMonster = player.getDamage();
std::cout << player.getName() << " attacks " << monster->getName()
<< " for " << damageToMonster << " damage.\n";
monster->takeDamage(damageToMonster);
} else if (choice == 2) {
// Player blocks, increasing defense temporarily
std::cout << player.getName() << " blocks the next attack!\n";
player.setDefense(player.getDefense() + 5);
} else if (choice == 3 && turnCounter >= 3) {
// Player performs a strong attack
int strongAttackDamage = player.getDamage() * 2; // Strong attack deals double damage
std::cout << player.getName() << " unleashes a powerful attack on " << monster->getName()
<< " for " << strongAttackDamage << " damage!\n";
monster->takeDamage(strongAttackDamage);
turnCounter = 0; // Reset turn counter after strong attack
} else {
std::cout << "Invalid choice or strong attack not available. You lose your turn.\n";
}
// Check if the monster is still alive for its turn
if (monster->isAlive()) {
// Monster attacks the player
int damageToPlayer = monster->getDamage() - player.getDefense();
if (damageToPlayer < 0) damageToPlayer = 0; // Ensure non-negative damage
std::cout << monster->getName() << " attacks " << player.getName()
<< " for " << damageToPlayer << " damage.\n";
player.takeDamage(damageToPlayer);
// Reset the player's temporary defense boost if they blocked
if (choice == 2) {
player.setDefense(player.getDefense() - 5);
}
}
// Check victory or defeat conditions
if (!monster->isAlive()) {
std::cout << "\n" << monster->getName() << " has been defeated!\n";
} else if (!player.isAlive()) {
std::cout << "\n" << player.getName() << " has fallen in battle...\n";
}
turnCounter++; // Increment turn counter at the end of each player turn
}
}
// BuffEncounter Implementation
BuffEncounter::BuffEncounter(const Buff& buff)
: buff(buff) {}
void BuffEncounter::trigger(Player& player) {
if (!player.isAlive()) {
std::cout << player.getName() << " is dead and cannot receive buffs.\n";
return;
}
std::cout << "You found a buff: " << buff.getDesc() << "!\n";
buff.applyTo(player);
std::cout << "Player's new stats - Health: " << player.getHealth()
<< ", Damage: " << player.getDamage()
<< ", Defense: " << player.getDefense() << "\n";
}