-
Notifications
You must be signed in to change notification settings - Fork 0
/
backend.cpp
98 lines (78 loc) · 1.95 KB
/
backend.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
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
#include "backend.h"
using namespace std;
Backend::Backend(QObject* parent): QObject(parent) {
game = Game::getInstance(); // inizializzo il gioco
m_playerBar = game->getPlayerHealth();
m_monsterBar = game->getMonsterHealth();
m_gameOver = game->gameOver();
m_healEnabled = game->healEnabled();
m_winner = QString::fromStdString(game->getWinner());
}
// SLOTS
void Backend::attack(){
game->attackMonster();
setAllValues();
}
void Backend::heal(){
game->heal();
setAllValues();
}
void Backend::playAgain(){
game->restart();
setAllValues();
}
// GETTERS
int Backend::playerBar() const {
return m_playerBar;
}
int Backend::monsterBar() const {
return m_monsterBar;
}
bool Backend::gameOver() const {
return m_gameOver;
}
bool Backend::healEnabled() const{
return m_healEnabled;
}
QString Backend::winner() const{
return m_winner;
}
// SETTERS
void Backend::setPlayerBar(int value) {
if(m_playerBar != value) {
m_playerBar = value;
emit playerBarChanged(); // trigger signal of counter change
}
}
void Backend::setMonsterBar(int value) {
if(m_monsterBar != value) {
m_monsterBar = value;
emit monsterBarChanged(); // trigger signal of counter change
}
}
void Backend::setGameOver(bool value) {
if(m_gameOver != value) {
m_gameOver = value;
emit gameOverChanged(); // trigger signal of game changed
}
}
void Backend::setHealEnabled(bool value) {
if(m_healEnabled != value) {
m_healEnabled = value;
emit healEnabledChanged(); // trigger signal of game changed
}
}
void Backend::setWinner(QString value) {
if(m_winner != value) {
m_winner = value;
emit winnerChanged(); // trigger signal of game changed
}
}
// SETTERS FOR ALL
void Backend::setAllValues(){
setPlayerBar(game->getPlayerHealth());
setMonsterBar(game->getMonsterHealth());
setGameOver(game->gameOver());
setHealEnabled(game->healEnabled());
setWinner(QString::fromStdString(game->getWinner()));
}