diff options
Diffstat (limited to 'backend')
-rw-r--r-- | backend/CMakeLists.txt | 1 | ||||
-rw-r--r-- | backend/Enemy.cpp | 31 | ||||
-rw-r--r-- | backend/Enemy.h | 15 | ||||
-rw-r--r-- | backend/EnemyFactory.cpp | 4 | ||||
-rw-r--r-- | backend/EnemyFactory.h | 2 | ||||
-rw-r--r-- | backend/Location.h | 3 | ||||
-rw-r--r-- | backend/LocationFactory.h | 2 | ||||
-rw-r--r-- | backend/Object.h | 3 | ||||
-rw-r--r-- | backend/RNG.cpp | 3 |
9 files changed, 55 insertions, 9 deletions
diff --git a/backend/CMakeLists.txt b/backend/CMakeLists.txt index 8797bca..6821388 100644 --- a/backend/CMakeLists.txt +++ b/backend/CMakeLists.txt @@ -11,5 +11,6 @@ target_sources(main PUBLIC ConsumableObject.cpp GoldObject.cpp WeaponObject.cpp + Enemy.cpp ) diff --git a/backend/Enemy.cpp b/backend/Enemy.cpp new file mode 100644 index 0000000..699a303 --- /dev/null +++ b/backend/Enemy.cpp @@ -0,0 +1,31 @@ +#include <string.h> + +#include "Enemy.h" +#include "util.h" + +Enemy::Enemy(const char * name, const char * description) { + this->set_name(name); + this->set_description(description); +} + +Enemy::~Enemy() { + safe_free(this->name); + safe_free(this->description); +} + +void Enemy::set_name(const char * name) { + safe_free(this->name); + this->name = strdup(name); +} +const char * Enemy::get_name() { + return this->name; +} + +void Enemy::set_description(const char * description) { + safe_free(this->description); + this->description = strdup(description); +} +const char * Enemy::get_description() { + return this->description; +} + diff --git a/backend/Enemy.h b/backend/Enemy.h index fb04472..fdc095e 100644 --- a/backend/Enemy.h +++ b/backend/Enemy.h @@ -1,9 +1,20 @@ #pragma once class Enemy { +public: + void set_name(const char * name); + const char * get_name(); + void set_description(const char * description); + const char * get_description(); + private: - Enemy() = default; - virtual ~Enemy() = default; friend class EnemyFactory; + Enemy(const char * name = "", const char * description = ""); +public: + virtual ~Enemy(); + +private: + const char * name = nullptr; + const char * description = nullptr; }; diff --git a/backend/EnemyFactory.cpp b/backend/EnemyFactory.cpp index 9c92c0b..42e35ae 100644 --- a/backend/EnemyFactory.cpp +++ b/backend/EnemyFactory.cpp @@ -1,6 +1,6 @@ #include "EnemyFactory.h" -Enemy * EnemyFactory::create_enemy() { - return new Enemy(); +Enemy * EnemyFactory::create_enemy(const char * name, const char * description) { + return new Enemy(name, description); } diff --git a/backend/EnemyFactory.h b/backend/EnemyFactory.h index ebb956b..6e8b6db 100644 --- a/backend/EnemyFactory.h +++ b/backend/EnemyFactory.h @@ -4,7 +4,7 @@ class EnemyFactory { public: - static Enemy * create_enemy(); + static Enemy * create_enemy(const char * name = "", const char * description = ""); private: EnemyFactory() = delete; diff --git a/backend/Location.h b/backend/Location.h index 4ce2349..59a531f 100644 --- a/backend/Location.h +++ b/backend/Location.h @@ -28,9 +28,10 @@ public: ListRange<Enemy *> get_enemies(); private: + friend class LocationFactory; Location(const char * name = "", const char * description = ""); +public: virtual ~Location(); - friend class LocationFactory; private: const char * name = nullptr; diff --git a/backend/LocationFactory.h b/backend/LocationFactory.h index 2da590e..178d5d3 100644 --- a/backend/LocationFactory.h +++ b/backend/LocationFactory.h @@ -4,7 +4,7 @@ class LocationFactory { public: - static Location * create_location(const char * name, const char * description); + static Location * create_location(const char * name = "", const char * description = ""); private: LocationFactory() = delete; diff --git a/backend/Object.h b/backend/Object.h index cb2c209..b98dc82 100644 --- a/backend/Object.h +++ b/backend/Object.h @@ -15,9 +15,10 @@ public: bool get_hidden(); protected: + friend class ObjectFactory; Object(const char * name = "", const char * description = ""); +public: virtual ~Object(); - friend class ObjectFactory; protected: bool hidden = false; diff --git a/backend/RNG.cpp b/backend/RNG.cpp index bc3e57b..2d7895b 100644 --- a/backend/RNG.cpp +++ b/backend/RNG.cpp @@ -14,7 +14,8 @@ int RNG::rand_int(const int upper) { return this->rand_int(0, upper); } int RNG::rand_int(const int lower, const int upper) { - uniform_int_distribution<int> random_dist(lower, upper); + // NOTE: random_dist's upper limit is inclusive + uniform_int_distribution<int> random_dist(lower, upper - 1); return random_dist(rng); } |