Skip to content

Commit 30cfa7e

Browse files
committed
stats implementation
1 parent 4b541b5 commit 30cfa7e

2 files changed

Lines changed: 31 additions & 2 deletions

File tree

cpp-backend-new/include/combatants/stats/Stats.hpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,17 @@
99
struct Stats
1010
{
1111
public:
12-
double& getStat(StatRequest request);
12+
// Returns copy of the stat corresponding to the request
13+
[[nodiscard]] double getStat(StatRequest request) const;
14+
15+
// Adds the amount of the double to the stat corresponding with the request
16+
void changeStat(StatRequest request, double change);
17+
18+
// Merge another stat object into the called object
19+
// Sums together all stats effectively
20+
void mergeStats(const Stats& other);
1321
private:
14-
std::array<double, static_cast<size_t>(StatRequest::COUNT)> _data;
22+
std::array<double, static_cast<size_t>(StatRequest::COUNT)> data{};
1523
};
1624

1725
#endif
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#include "combatants/stats/Stats.hpp"
2+
3+
// type cast the request to an integral value then return double
4+
double Stats::getStat(const StatRequest request) const
5+
{
6+
return data[(static_cast<size_t>(request))];
7+
}
8+
9+
// type cast the request to integral than add change
10+
void Stats::changeStat(const StatRequest request, const double change)
11+
{
12+
data[static_cast<size_t>(request)] += change;
13+
}
14+
15+
void Stats::mergeStats(const Stats& other)
16+
{
17+
for (size_t i{}; i < data.size(); ++i)
18+
{
19+
data[i] += other.data[i];
20+
}
21+
}

0 commit comments

Comments
 (0)