-
Notifications
You must be signed in to change notification settings - Fork 2
/
player.cpp
172 lines (147 loc) · 4.06 KB
/
player.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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* *
* Copyright (C) 2015 Simon Stuerz <stuerz.simon@gmail.com> *
* *
* This file is part of Monster Wars. *
* *
* Monster Wars is free software: you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation, version 3 of the License. *
* *
* Monster Wars is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with Monster Wars. If not, see <http://www.gnu.org/licenses/>. *
* *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
#include "player.h"
Player::Player(int playerId, QObject *parent):
QObject(parent),
m_id(playerId)
{
m_colorString = "white";
m_playerType = PlayerTypeNone;
m_playerTypeString = "None";
m_strength = 0;
m_speed = 0;
m_defense = 0;
m_reproduction = 0;
m_percentage = 0;
m_pointCount = 0;
}
int Player::id() const
{
return m_id;
}
void Player::setColorString(const QString &colorString)
{
m_colorString = colorString;
}
QString Player::colorString() const
{
return m_colorString;
}
void Player::setPlayerType(const Player::PlayerType &playerType)
{
m_playerType = playerType;
m_playerTypeString = playerTypeToString(playerType);
}
void Player::setPlayerType(const QString &playerType)
{
if (playerType == "PlayerTypeHuman") {
m_playerType = PlayerTypeHuman;
} else if (playerType == "PlayerTypeAi") {
m_playerType = PlayerTypeAi;
} else {
qWarning() << "ERROR: unknown PlayerType. Please Check the level.json file";
}
m_playerTypeString = playerTypeToString(m_playerType);
}
Player::PlayerType Player::playerType() const
{
return m_playerType;
}
QString Player::playerTypeString()
{
return m_playerTypeString;
}
void Player::setStrength(const int &strength)
{
m_strength = strength;
}
int Player::strength() const
{
return m_strength;
}
void Player::setSpeed(const int &speed)
{
m_speed = speed;
}
int Player::speed() const
{
return m_speed;
}
void Player::setDefence(const int &defense)
{
m_defense = defense;
}
int Player::defense() const
{
return m_defense;
}
void Player::setReproduction(const int &reaction)
{
m_reproduction = reaction;
}
int Player::reproduction() const
{
return m_reproduction;
}
void Player::setReaction(const int &reaction)
{
m_reaction = reaction;
}
int Player::reaction() const
{
return m_reaction;
}
double Player::percentage() const
{
return m_percentage;
}
void Player::setPercentage(const double &percentage)
{
m_percentage = percentage;
emit percentageChanged();
}
void Player::setPointCount(const int &pointCount)
{
m_pointCount = pointCount;
emit pointCountChanged();
}
int Player::pointCount()
{
return m_pointCount;
}
void Player::addPoints(int points)
{
m_pointCount += points;
emit pointCountChanged();
}
QString Player::playerTypeToString(Player::PlayerType playerType)
{
switch (playerType) {
case PlayerTypeHuman:
return "PlayerTypeHuman";
break;
case PlayerTypeAi:
return "PlayerTypeAi";
break;
default:
qWarning() << "ERROR: unknown PlayerType!";
return QString();
}
}