Used ClangFormat style guide I'm happy with.
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2019-11-28 12:55:22 +01:00
parent 3b685ae782
commit a8730d983f
91 changed files with 946 additions and 1121 deletions

View File

@@ -4,15 +4,13 @@
#include <exception>
#include <string>
class CreatureException : std::exception{
class CreatureException : std::exception {
std::string _error;
public:
CreatureException(std::string error){}
const char *what() const noexcept override {
return _error.c_str();
}
public:
CreatureException(std::string error) {}
const char* what() const noexcept override { return _error.c_str(); }
};
#endif //CREATURELIB_CREATUREEXCEPTION_HPP
#endif // CREATURELIB_CREATUREEXCEPTION_HPP

View File

@@ -3,10 +3,10 @@
#include "CreatureException.hpp"
class NotImplementedException : CreatureException{
class NotImplementedException : CreatureException {
public:
NotImplementedException(std::string error) : CreatureException(error){}
NotImplementedException() : CreatureException("Not Implemented"){}
NotImplementedException(std::string error) : CreatureException(error) {}
NotImplementedException() : CreatureException("Not Implemented") {}
};
#endif //CREATURELIB_NOTIMPLEMENTEDEXCEPTION_HPP
#endif // CREATURELIB_NOTIMPLEMENTEDEXCEPTION_HPP

View File

@@ -3,9 +3,9 @@
#include "CreatureException.hpp"
class NotReachableException : CreatureException{
class NotReachableException : CreatureException {
public:
NotReachableException() : CreatureException("Not Reachable"){};
};
#endif //CREATURELIB_NOTREACHABLEEXCEPTION_HPP
#endif // CREATURELIB_NOTREACHABLEEXCEPTION_HPP

View File

@@ -2,7 +2,8 @@
#include <limits>
// Seed parameterless constructor with current milliseconds since epoch.
CreatureLib::Core::Random::Random() : _rng(std::mt19937(duration_cast<milliseconds>(system_clock::now().time_since_epoch()).count())){}
CreatureLib::Core::Random::Random()
: _rng(std::mt19937(duration_cast<milliseconds>(system_clock::now().time_since_epoch()).count())) {}
float CreatureLib::Core::Random::GetFloat() {
return static_cast<float>(_rng()) / (static_cast<float>(std::mt19937::max() - std::mt19937::min()) - 0.5f);
@@ -13,18 +14,13 @@ double CreatureLib::Core::Random::GetDouble() {
}
int32_t CreatureLib::Core::Random::Get() {
return static_cast<int32_t >(GetDouble() * static_cast<float>(std::numeric_limits<int32_t >::max()));
return static_cast<int32_t>(GetDouble() * static_cast<float>(std::numeric_limits<int32_t>::max()));
}
int32_t CreatureLib::Core::Random::Get(int32_t max) {
return static_cast<int32_t >(GetDouble() * static_cast<float>(max));
return static_cast<int32_t>(GetDouble() * static_cast<float>(max));
}
int32_t CreatureLib::Core::Random::Get(int32_t min, int32_t max) {
return static_cast<int32_t >(GetDouble() * static_cast<float>(max - min) + min);
return static_cast<int32_t>(GetDouble() * static_cast<float>(max - min) + min);
}

View File

@@ -1,13 +1,14 @@
#ifndef CREATURELIB_RANDOM_HPP
#define CREATURELIB_RANDOM_HPP
#include <cstdint>
#include <chrono>
#include <cstdint>
#include <random>
using namespace std::chrono;
namespace CreatureLib::Core {
class Random {
private:
std::mt19937 _rng;
public:
Random();
explicit Random(int32_t seed) : _rng(seed){};
@@ -20,4 +21,4 @@ namespace CreatureLib::Core {
};
}
#endif //CREATURELIB_RANDOM_HPP
#endif // CREATURELIB_RANDOM_HPP

View File

@@ -3,7 +3,7 @@
#include <cstdint>
namespace CreatureLib::Core{
namespace CreatureLib::Core {
enum Statistic : uint8_t {
Health,
PhysicalAttack,
@@ -14,4 +14,4 @@ namespace CreatureLib::Core{
};
}
#endif //CREATURELIB_STATISTIC_HPP
#endif // CREATURELIB_STATISTIC_HPP

View File

@@ -1,12 +1,12 @@
#ifndef CREATURELIB_STATISTICSET_HPP
#define CREATURELIB_STATISTICSET_HPP
#include <stdint.h>
#include <exception>
#include "Statistic.hpp"
#include <stdint.h>
#include "../GenericTemplates.cpp"
#include "Exceptions/NotReachableException.hpp"
#include "Statistic.hpp"
namespace CreatureLib::Core{
namespace CreatureLib::Core {
template <class T>
class StatisticSet {
protected:
@@ -16,25 +16,23 @@ namespace CreatureLib::Core{
T _magicalAttack;
T _magicalDefense;
T _speed;
public:
StatisticSet(T health, T physicalAttack, T physicalDefense, T magicalAttack, T magicalDefense, T speed)
: _health(health), _physicalAttack(physicalAttack),
_physicalDefense(physicalDefense), _magicalAttack(magicalAttack),
_magicalDefense(magicalDefense), _speed(speed){}
: _health(health), _physicalAttack(physicalAttack), _physicalDefense(physicalDefense),
_magicalAttack(magicalAttack), _magicalDefense(magicalDefense), _speed(speed) {}
StatisticSet()
: _health(0), _physicalAttack(0), _physicalDefense(0), _magicalAttack(0), _magicalDefense(0), _speed(0)
{}
: _health(0), _physicalAttack(0), _physicalDefense(0), _magicalAttack(0), _magicalDefense(0), _speed(0) {}
inline T GetHealth() const{ return _health; }
inline T GetPhysicalAttack() const{ return _physicalAttack; }
inline T GetPhysicalDefense() const{ return _physicalDefense; }
inline T GetMagicalAttack() const{ return _magicalAttack; }
inline T GetMagicalDefense() const{ return _magicalDefense; }
inline T GetSpeed() const{ return _speed; }
inline T GetHealth() const { return _health; }
inline T GetPhysicalAttack() const { return _physicalAttack; }
inline T GetPhysicalDefense() const { return _physicalDefense; }
inline T GetMagicalAttack() const { return _magicalAttack; }
inline T GetMagicalDefense() const { return _magicalDefense; }
inline T GetSpeed() const { return _speed; }
[[nodiscard]] inline T GetStat(Statistic stat) const{
switch (stat){
[[nodiscard]] inline T GetStat(Statistic stat) const {
switch (stat) {
case Health: return _health;
case PhysicalAttack: return _physicalAttack;
case PhysicalDefense: return _physicalDefense;
@@ -45,8 +43,8 @@ namespace CreatureLib::Core{
throw NotReachableException();
}
inline void SetStat(Statistic stat, T value){
switch (stat){
inline void SetStat(Statistic stat, T value) {
switch (stat) {
case Health: _health = value;
case PhysicalAttack: _physicalAttack = value;
case PhysicalDefense: _physicalDefense = value;
@@ -57,8 +55,8 @@ namespace CreatureLib::Core{
throw NotReachableException();
}
inline void IncreaseStatBy(Statistic stat, T amount){
switch (stat){
inline void IncreaseStatBy(Statistic stat, T amount) {
switch (stat) {
case Health: _health += amount;
case PhysicalAttack: _physicalAttack += amount;
case PhysicalDefense: _physicalDefense += amount;
@@ -68,8 +66,8 @@ namespace CreatureLib::Core{
}
throw NotReachableException();
}
inline void DecreaseStatBy(Statistic stat, T amount){
switch (stat){
inline void DecreaseStatBy(Statistic stat, T amount) {
switch (stat) {
case Health: _health -= amount;
case PhysicalAttack: _physicalAttack -= amount;
case PhysicalDefense: _physicalDefense -= amount;
@@ -82,5 +80,4 @@ namespace CreatureLib::Core{
};
}
#endif //CREATURELIB_STATISTICSET_HPP