-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRoom.cpp
More file actions
45 lines (36 loc) · 1 KB
/
Room.cpp
File metadata and controls
45 lines (36 loc) · 1 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
#include "Room.h"
#include <iostream>
Room::Room(const std::string& desc)
: desc(desc), roomBuff(nullptr) {}
void Room::setBuff(const Buff& buff) {
roomBuff = new Buff(buff);
}
bool Room::hasBuff() const {
return roomBuff != nullptr;
}
void Room::giveBuff(Player& player) {
if (roomBuff) {
roomBuff->applyTo(player); // Apply the buff to the player
delete roomBuff; // Remove the buff from the room (applied once)
roomBuff = nullptr;
}
}
void Room::setEncounter(std::unique_ptr<Encounter> encounter) {
this->encounter = std::move(encounter); // Transfer ownership
}
void Room::triggerEncounter(Player& player) {
if (encounter) {
encounter->trigger(player);
} else {
std::cout << "No encounter in this room.\n";
}
}
void Room::addEdge(Room* room, int weight) {
edges.emplace_back(room, weight);
}
std::vector<std::pair<Room*, int>> Room::getEdges() const {
return edges;
}
std::string Room::getDesc() const {
return desc;
}