diff options
author | Loek Le Blansch <loek@pipeframe.xyz> | 2024-10-30 01:29:58 +0100 |
---|---|---|
committer | Loek Le Blansch <loek@pipeframe.xyz> | 2024-10-30 01:29:58 +0100 |
commit | b9e738502260b8f448289c9888203971c7749c76 (patch) | |
tree | 09477251ba49307173a112e0cd5dbdd3633346ce /backend | |
parent | e4261302944303781c952943e3290c99e2cabc52 (diff) |
WIP SQL gedoe
Diffstat (limited to 'backend')
-rw-r--r-- | backend/ArmorObject.h | 2 | ||||
-rw-r--r-- | backend/ConsumableObject.h | 2 | ||||
-rw-r--r-- | backend/Enemy.h | 4 | ||||
-rw-r--r-- | backend/GoldObject.h | 2 | ||||
-rw-r--r-- | backend/Location.cpp | 10 | ||||
-rw-r--r-- | backend/Location.h | 5 | ||||
-rw-r--r-- | backend/LocationFactory.h | 2 | ||||
-rw-r--r-- | backend/ObjectFactory.cpp | 19 | ||||
-rw-r--r-- | backend/ObjectFactory.h | 10 | ||||
-rw-r--r-- | backend/WeaponObject.h | 2 |
10 files changed, 53 insertions, 5 deletions
diff --git a/backend/ArmorObject.h b/backend/ArmorObject.h index e9c02d2..112997b 100644 --- a/backend/ArmorObject.h +++ b/backend/ArmorObject.h @@ -3,6 +3,8 @@ #include "Object.h" class ArmorObject : public Object { + using Object::Object; + private: int protection = 0; diff --git a/backend/ConsumableObject.h b/backend/ConsumableObject.h index 0e98674..3b4a2ce 100644 --- a/backend/ConsumableObject.h +++ b/backend/ConsumableObject.h @@ -3,5 +3,7 @@ #include "Object.h" class ConsumableObject : public Object { + using Object::Object; + }; diff --git a/backend/Enemy.h b/backend/Enemy.h index dd33090..fb04472 100644 --- a/backend/Enemy.h +++ b/backend/Enemy.h @@ -1,5 +1,9 @@ #pragma once class Enemy { +private: + Enemy() = default; + virtual ~Enemy() = default; + friend class EnemyFactory; }; diff --git a/backend/GoldObject.h b/backend/GoldObject.h index f37b7d9..6f65c1d 100644 --- a/backend/GoldObject.h +++ b/backend/GoldObject.h @@ -3,6 +3,8 @@ #include "Object.h" class GoldObject : public Object { + using Object::Object; + private: int count = 0; }; diff --git a/backend/Location.cpp b/backend/Location.cpp index 96d06ca..a26d530 100644 --- a/backend/Location.cpp +++ b/backend/Location.cpp @@ -37,7 +37,17 @@ Location * Location::get_exit(Direction dir) { return this->edges[dir]; } +void Location::add_object(Object * object) { + this->objects.push_back(object); +} ListRange<Object *> Location::get_objects() { return this->objects.range(); } +void Location::add_enemy(Enemy * enemy) { + this->enemies.push_back(enemy); +} +ListRange<Enemy *> Location::get_enemies() { + return this->enemies.range(); +} + diff --git a/backend/Location.h b/backend/Location.h index 8b600bb..4ce2349 100644 --- a/backend/Location.h +++ b/backend/Location.h @@ -22,9 +22,12 @@ public: const char * get_description(); void set_exit(Direction dir, Location * location = nullptr); Location * get_exit(Direction dir); + void add_object(Object *); ListRange<Object *> get_objects(); + void add_enemy(Enemy *); + ListRange<Enemy *> get_enemies(); -protected: +private: Location(const char * name = "", const char * description = ""); virtual ~Location(); friend class LocationFactory; diff --git a/backend/LocationFactory.h b/backend/LocationFactory.h index a12bb0e..ba34ff3 100644 --- a/backend/LocationFactory.h +++ b/backend/LocationFactory.h @@ -4,6 +4,6 @@ class LocationFactory { public: - Location * create_location(const char * name, const char * description); + static Location * create_location(const char * name, const char * description); }; diff --git a/backend/ObjectFactory.cpp b/backend/ObjectFactory.cpp index efb7742..4a0642b 100644 --- a/backend/ObjectFactory.cpp +++ b/backend/ObjectFactory.cpp @@ -1,6 +1,21 @@ #include "ObjectFactory.h" -Object * ObjectFactory::create_object() { - return new Object(); +#include "ArmorObject.h" +#include "ConsumableObject.h" +#include "GoldObject.h" +#include "WeaponObject.h" + +Object * ObjectFactory::create_object(ObjectType type, const char * name, const char * description) { + switch (type) { + case ARMOR: return new ArmorObject(name, description); + case CONSUMABLE: return new ConsumableObject(name, description); + case GOLD: return new GoldObject(name, description); + case WEAPON: return new WeaponObject(name, description); + } + return ObjectFactory::create_object(name, description); +} + +Object * ObjectFactory::create_object(const char * name, const char * description) { + return new Object(name, description); } diff --git a/backend/ObjectFactory.h b/backend/ObjectFactory.h index f9a7301..adf960b 100644 --- a/backend/ObjectFactory.h +++ b/backend/ObjectFactory.h @@ -2,9 +2,17 @@ #include "Object.h" +enum ObjectType { + ARMOR, + CONSUMABLE, + GOLD, + WEAPON, +}; + class ObjectFactory { public: - static Object * create_object(); + static Object * create_object(ObjectType type, const char * name = "", const char * description = ""); + static Object * create_object(const char * name = "", const char * description = ""); private: ObjectFactory() = delete; diff --git a/backend/WeaponObject.h b/backend/WeaponObject.h index e9ce261..8b1bc58 100644 --- a/backend/WeaponObject.h +++ b/backend/WeaponObject.h @@ -3,6 +3,8 @@ #include "Object.h" class WeaponObject : public Object { + using Object::Object; + private: int damage_min; int damage_max; |