diff --git a/include/pet.hpp b/include/pet.hpp new file mode 100644 index 0000000..a753f41 --- /dev/null +++ b/include/pet.hpp @@ -0,0 +1,21 @@ +#pragma once +#include +#define MAXIMUM_STAT 100 + +class Pet { + public: + Pet(); + bool isAlive; + + void updateHunger(int8_t delta); + void updateJoy(int8_t delta); + void updateEnergy(int8_t delta); + void updateCleanliness(int8_t delta); + String getReasonForDeath() const; + private: + int8_t hunger; + int8_t joy; + int8_t energy; + int8_t cleanliness; + String reasonForDeath; +}; diff --git a/src/pet.cpp b/src/pet.cpp new file mode 100644 index 0000000..c370523 --- /dev/null +++ b/src/pet.cpp @@ -0,0 +1,68 @@ +#include "pet.hpp" + +Pet::Pet() + : isAlive(true), hunger(0), joy(100), energy(100), cleanliness(100), reasonForDeath("") {} + +void Pet::updateHunger(int8_t delta) { + hunger += delta; + + if (hunger < 0) { + isAlive = false; + reasonForDeath = "starvation"; + return; + } + + if (hunger > MAXIMUM_STAT) { + isAlive = false; + reasonForDeath = "overfeeding"; + } +} + +void Pet::updateJoy(int8_t delta) { + joy += delta; + + if (joy < 0) { + isAlive = false; + reasonForDeath = "depression"; + return; + } + + if (joy > MAXIMUM_STAT) { + isAlive = false; + reasonForDeath = "overstimulation"; + } +} + +void Pet::updateEnergy(int8_t delta) { + energy += delta; + + if (energy < 0) { + isAlive = false; + reasonForDeath = "exhaustion"; + return; + } + + if (energy > MAXIMUM_STAT) { + isAlive = false; + reasonForDeath = "overresting"; + } +} + +void Pet::updateCleanliness(int8_t delta) { + cleanliness += delta; + + if (cleanliness < 0) { + isAlive = false; + reasonForDeath = "disease"; + return; + } + + if (cleanliness > MAXIMUM_STAT) { + isAlive = false; + reasonForDeath = "overcleaning"; + } +} + +String Pet::getReasonForDeath() const { + return reasonForDeath; +}