Initial commit
This commit is contained in:
		
							
								
								
									
										30
									
								
								src/Core/Random.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										30
									
								
								src/Core/Random.cpp
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,30 @@
 | 
			
		||||
#include "Random.hpp"
 | 
			
		||||
#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())){}
 | 
			
		||||
 | 
			
		||||
float CreatureLib::Core::Random::GetFloat() {
 | 
			
		||||
    return static_cast<float>(_rng()) / (static_cast<float>(std::mt19937::max() - std::mt19937::min()) - 0.5f);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
double CreatureLib::Core::Random::GetDouble() {
 | 
			
		||||
    return static_cast<double>(_rng()) / ((static_cast<double>(std::mt19937::max()) - std::mt19937::min()) - 0.5);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int32_t CreatureLib::Core::Random::Get() {
 | 
			
		||||
    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));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int32_t CreatureLib::Core::Random::Get(int32_t min, int32_t max) {
 | 
			
		||||
    return static_cast<int32_t >(GetDouble() * static_cast<float>(max - min) + min);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										23
									
								
								src/Core/Random.hpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										23
									
								
								src/Core/Random.hpp
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,23 @@
 | 
			
		||||
#ifndef CREATURELIB_RANDOM_HPP
 | 
			
		||||
#define CREATURELIB_RANDOM_HPP
 | 
			
		||||
#include <cstdint>
 | 
			
		||||
#include <chrono>
 | 
			
		||||
#include <random>
 | 
			
		||||
using namespace std::chrono;
 | 
			
		||||
namespace CreatureLib::Core {
 | 
			
		||||
    class Random {
 | 
			
		||||
    private:
 | 
			
		||||
        std::mt19937 _rng;
 | 
			
		||||
    public:
 | 
			
		||||
        Random();
 | 
			
		||||
        explicit Random(int32_t seed) : _rng(seed){};
 | 
			
		||||
 | 
			
		||||
        [[nodiscard]] float GetFloat();
 | 
			
		||||
        [[nodiscard]] double GetDouble();
 | 
			
		||||
        [[nodiscard]] int32_t Get();
 | 
			
		||||
        [[nodiscard]] int32_t Get(int32_t max);
 | 
			
		||||
        [[nodiscard]] int32_t Get(int32_t min, int32_t max);
 | 
			
		||||
    };
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#endif //CREATURELIB_RANDOM_HPP
 | 
			
		||||
							
								
								
									
										17
									
								
								src/Core/Statistic.hpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										17
									
								
								src/Core/Statistic.hpp
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,17 @@
 | 
			
		||||
#ifndef CREATURELIB_STATISTIC_HPP
 | 
			
		||||
#define CREATURELIB_STATISTIC_HPP
 | 
			
		||||
 | 
			
		||||
#include <cstdint>
 | 
			
		||||
 | 
			
		||||
namespace CreatureLib::Core{
 | 
			
		||||
    enum Statistic : uint8_t {
 | 
			
		||||
        Health,
 | 
			
		||||
        PhysicalAttack,
 | 
			
		||||
        PhysicalDefense,
 | 
			
		||||
        MagicalAttack,
 | 
			
		||||
        MagicalDefense,
 | 
			
		||||
        Speed
 | 
			
		||||
    };
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#endif //CREATURELIB_STATISTIC_HPP
 | 
			
		||||
							
								
								
									
										13
									
								
								src/Core/StatisticSet.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										13
									
								
								src/Core/StatisticSet.cpp
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,13 @@
 | 
			
		||||
#include <exception>
 | 
			
		||||
#include "StatisticSet.hpp"
 | 
			
		||||
 | 
			
		||||
CreatureLib::Core::StatisticSet::StatisticSet(uint32_t health, uint32_t physicalAttack, uint32_t physicalDefense,
 | 
			
		||||
                                              uint32_t magicalAttack, uint32_t magicalDefense, uint32_t speed)
 | 
			
		||||
                                              :
 | 
			
		||||
                                              __Health(health),
 | 
			
		||||
                                              __PhysicalAttack(physicalAttack),
 | 
			
		||||
                                              __PhysicalDefense(physicalDefense),
 | 
			
		||||
                                              __MagicalAttack(magicalAttack),
 | 
			
		||||
                                              __MagicalDefense(magicalDefense),
 | 
			
		||||
                                              __Speed(speed)
 | 
			
		||||
                                              {}
 | 
			
		||||
							
								
								
									
										35
									
								
								src/Core/StatisticSet.hpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										35
									
								
								src/Core/StatisticSet.hpp
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,35 @@
 | 
			
		||||
#ifndef CREATURELIB_STATISTICSET_HPP
 | 
			
		||||
#define CREATURELIB_STATISTICSET_HPP
 | 
			
		||||
#include <stdint.h>
 | 
			
		||||
#include "Statistic.hpp"
 | 
			
		||||
#include "../GenericTemplates.cpp"
 | 
			
		||||
 | 
			
		||||
namespace CreatureLib::Core{
 | 
			
		||||
    class StatisticSet {
 | 
			
		||||
    public:
 | 
			
		||||
        StatisticSet(uint32_t health, uint32_t physicalAttack, uint32_t physicalDefense, uint32_t magicalAttack,
 | 
			
		||||
                uint32_t magicalDefense, uint32_t speed);
 | 
			
		||||
 | 
			
		||||
        GetSetProperty(uint32_t, Health)
 | 
			
		||||
        GetSetProperty(uint32_t, PhysicalAttack)
 | 
			
		||||
        GetSetProperty(uint32_t, PhysicalDefense)
 | 
			
		||||
        GetSetProperty(uint32_t, MagicalAttack)
 | 
			
		||||
        GetSetProperty(uint32_t, MagicalDefense)
 | 
			
		||||
        GetSetProperty(uint32_t, Speed)
 | 
			
		||||
 | 
			
		||||
        [[nodiscard]] inline uint32_t GetStat(Statistic stat) const{
 | 
			
		||||
            switch (stat){
 | 
			
		||||
                case Health: return __Health;
 | 
			
		||||
                case PhysicalAttack: return __PhysicalAttack;
 | 
			
		||||
                case PhysicalDefense: return __PhysicalDefense;
 | 
			
		||||
                case MagicalAttack: return __MagicalAttack;
 | 
			
		||||
                case MagicalDefense: return __MagicalDefense;
 | 
			
		||||
                case Speed: return __Speed;
 | 
			
		||||
            }
 | 
			
		||||
            throw std::exception();
 | 
			
		||||
        }
 | 
			
		||||
    };
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
#endif //CREATURELIB_STATISTICSET_HPP
 | 
			
		||||
		Reference in New Issue
	
	Block a user