-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlayer.h
87 lines (67 loc) · 1.64 KB
/
Player.h
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
#pragma once
#include <string>
#include <vector>
#include "Entity.h"
#include "Item.h"
#include "Room.h"
#include "Sword.h"
class Room;
class Player : public Entity {
private:
using Items = std::vector<Item*>;
Items m_items;
Room::Pointer m_pCurrentRoom;
std::string m_name;
public:
Player() { }
Player(const Player& originalPlayer) {
m_pCurrentRoom = originalPlayer.m_pCurrentRoom;
m_name = originalPlayer.m_name;
}
Player& operator=(const Player& originalPlayer) {
m_pCurrentRoom = originalPlayer.m_pCurrentRoom;
m_name = originalPlayer.m_name;
return *this;
}
Player(Player&& tempPlayer) {
m_pCurrentRoom = tempPlayer.m_pCurrentRoom;
m_name = tempPlayer.m_name;
tempPlayer.m_pCurrentRoom = nullptr;
m_name.clear();
}
Player& operator=(Player&& tempPlayer) {
if (this != &tempPlayer) {
m_pCurrentRoom = tempPlayer.m_pCurrentRoom;
m_name = tempPlayer.m_name;
tempPlayer.m_pCurrentRoom = nullptr;
m_name.clear();
}
return *this;
}
void SetName(const std::string& name) {
m_name = name;
}
const std::string& GetName() const {
return m_name;
}
void SetCurrentRoom(Room::Pointer currentRoom) {
m_pCurrentRoom = currentRoom;
}
Room::Pointer GetCurrentRoom() const {
return m_pCurrentRoom;
}
void AddItem(const Item* item) {
m_items.push_back(const_cast<Item*>(item));
}
bool HasWeapon() {
bool hasWeapon = false;
for (const Item* item : m_items) {
const Sword* sword = dynamic_cast<const Sword*>(item);
if (sword != nullptr) {
hasWeapon = true;
break;
}
}
return hasWeapon;
}
};