diff options
author | Loek Le Blansch <loek@pipeframe.xyz> | 2024-10-30 16:34:29 +0100 |
---|---|---|
committer | Loek Le Blansch <loek@pipeframe.xyz> | 2024-10-30 16:34:29 +0100 |
commit | 71380426426dffe787d1704a8fd639c4b1bbfad3 (patch) | |
tree | f550cc1dfa100e208712e20b4442687cc2a7f157 /backend | |
parent | a3c1ba7b49e4c5901d7c9dd917049744ad20fc96 (diff) |
cmd_get complete
Diffstat (limited to 'backend')
-rw-r--r-- | backend/GoldObject.cpp | 5 | ||||
-rw-r--r-- | backend/GoldObject.h | 3 | ||||
-rw-r--r-- | backend/List.h | 3 | ||||
-rw-r--r-- | backend/List.hpp | 16 | ||||
-rw-r--r-- | backend/Location.cpp | 3 | ||||
-rw-r--r-- | backend/Location.h | 1 |
6 files changed, 27 insertions, 4 deletions
diff --git a/backend/GoldObject.cpp b/backend/GoldObject.cpp index 624fdf9..cf97b2e 100644 --- a/backend/GoldObject.cpp +++ b/backend/GoldObject.cpp @@ -1,6 +1,9 @@ #include "GoldObject.h" -void GoldObject::set_count(int count) { +void GoldObject::set_count(const int & count) { this->count = count; } +int GoldObject::get_count() const { + return this->count; +} diff --git a/backend/GoldObject.h b/backend/GoldObject.h index ea473d4..03a074e 100644 --- a/backend/GoldObject.h +++ b/backend/GoldObject.h @@ -6,7 +6,8 @@ class GoldObject : public Object { using Object::Object; public: - void set_count(int count); + void set_count(const int & count); + int get_count() const; private: int count = 0; diff --git a/backend/List.h b/backend/List.h index 2d3d6b1..1d8893e 100644 --- a/backend/List.h +++ b/backend/List.h @@ -20,7 +20,8 @@ class List { public: size_t size(); - void push_back(T el); + void push_back(T & el); + void remove(const T & val); void pop_back(); diff --git a/backend/List.hpp b/backend/List.hpp index df075f9..a0d9289 100644 --- a/backend/List.hpp +++ b/backend/List.hpp @@ -8,7 +8,7 @@ size_t List<T>::size() { } template <typename T> -void List<T>::push_back(T el) { +void List<T>::push_back(T & el) { ListLink<T> * link = static_cast<ListLink<T> *>(malloc(sizeof(ListLink<T>))); link->prev = this->head; link->next = nullptr; @@ -20,6 +20,20 @@ void List<T>::push_back(T el) { } template <typename T> +void List<T>::remove(const T & target) { + ListLink<T> * link = nullptr; + for (link = this->tail; link != nullptr; link = link->next) { + if (link->value == target) break; + } + if (link == nullptr) return; // target not in list + + if (link->next != nullptr) link->next->prev = link->prev; + if (link->prev != nullptr) link->prev->next = link->next; + free(link); + this->length--; +} + +template <typename T> void List<T>::pop_back() { if (this->head == nullptr) return; // empty list diff --git a/backend/Location.cpp b/backend/Location.cpp index a26d530..9add524 100644 --- a/backend/Location.cpp +++ b/backend/Location.cpp @@ -40,6 +40,9 @@ Location * Location::get_exit(Direction dir) { void Location::add_object(Object * object) { this->objects.push_back(object); } +void Location::remove_object(Object * object) { + this->objects.remove(object); +} ListRange<Object *> Location::get_objects() { return this->objects.range(); } diff --git a/backend/Location.h b/backend/Location.h index 59a531f..fb0abfc 100644 --- a/backend/Location.h +++ b/backend/Location.h @@ -23,6 +23,7 @@ public: void set_exit(Direction dir, Location * location = nullptr); Location * get_exit(Direction dir); void add_object(Object *); + void remove_object(Object *); ListRange<Object *> get_objects(); void add_enemy(Enemy *); ListRange<Enemy *> get_enemies(); |