diff --git a/CST126SRS03/CST126SRS03.vcxproj b/CST126SRS03/CST126SRS03.vcxproj index 55747d4..2fda73b 100644 --- a/CST126SRS03/CST126SRS03.vcxproj +++ b/CST126SRS03/CST126SRS03.vcxproj @@ -157,7 +157,7 @@ - + diff --git a/CST126SRS03/CST126SRS03.vcxproj.filters b/CST126SRS03/CST126SRS03.vcxproj.filters index 6277a06..ed6dcd1 100644 --- a/CST126SRS03/CST126SRS03.vcxproj.filters +++ b/CST126SRS03/CST126SRS03.vcxproj.filters @@ -50,7 +50,7 @@ Source Files - + Source Files diff --git a/CST126SRS03/elephant.h b/CST126SRS03/elephant.h index d5f73b3..cfd0e42 100644 --- a/CST126SRS03/elephant.h +++ b/CST126SRS03/elephant.h @@ -18,8 +18,8 @@ class Elephant static constexpr unsigned kMaxWater{ 200 }; // liters/day static constexpr unsigned kMaxFood{ 200 }; // kg/day - unsigned clock_{}; // TODO: Make the clock run. - unsigned awake_{}; + unsigned elapsedTime_{}; // minutes + unsigned awake_{}; // minutes unsigned water_{}; // [0, kMaxWater) unsigned weight_; // [minWeight_,maxWeight_) @@ -34,9 +34,18 @@ class Elephant private: static Preserve::Feature look(const Elephant& elephant); + void incrementTime(const unsigned minutes); + void decrementWater(const unsigned liters); + void decrementWeight(const unsigned kg); + +private: + bool isSleepy() const; + bool isThirsty() const; + bool isHungry() const; public: GPS * getGps_() const; + unsigned getElapsedTime() const; private: // Available methods. Direction getHeading(const Turn turn) const; @@ -50,6 +59,6 @@ class Elephant void move(); public: // To be implemented methods. - void tag(const GPS& gps); + void tag(GPS& gps); void findHerd(); }; diff --git a/CST126SRS03/elephant0.cpp b/CST126SRS03/loxodonta.cpp similarity index 68% rename from CST126SRS03/elephant0.cpp rename to CST126SRS03/loxodonta.cpp index 622ff04..685259a 100644 --- a/CST126SRS03/elephant0.cpp +++ b/CST126SRS03/loxodonta.cpp @@ -20,6 +20,75 @@ GPS* Elephant::getGps_() const return gps_; } +unsigned Elephant::getElapsedTime() const +{ + return elapsedTime_; +} + +void Elephant::incrementTime(const unsigned minutes) +{ + auto min = minutes; + + if (isSleepy()) + { + min *= 2; + } + + if (isThirsty()) + { + min *= 2; + } + + if (isHungry()) + { + min *= 2; + } + + elapsedTime_ += minutes; + awake_ += minutes; +} + +void Elephant::decrementWater(const unsigned liters) +{ + int water = water_ - liters; + if (water < 0) + { + water = 0; + } + water_ -= water; +} + +void Elephant::decrementWeight(const unsigned kg) +{ + if (weight_ >= minWeight_) + { + int weight = weight_ - kg; + if (weight < 0) + { + weight = 0; + } + weight_ = weight; + } +} + +bool Elephant::isSleepy() const +{ + const auto result{ awake_ >= kMaxAwake }; + return result; +} + +bool Elephant::isThirsty() const +{ + const auto result{ water_ == 0 }; + return result; +} + +bool Elephant::isHungry() const +{ + const auto result{ weight_ < minWeight_ }; + return result; +} + Preserve::Feature Elephant::look() const { const auto result{ look(*this) }; @@ -103,6 +172,7 @@ int Elephant::listen() const void Elephant::sleep() { + incrementTime(120); awake_ = 0; } @@ -110,6 +180,7 @@ void Elephant::drink() { const auto feature{ look() }; + incrementTime(5); if (feature == Preserve::Feature::kWater) { water_ = kMaxWater; @@ -118,6 +189,7 @@ void Elephant::drink() void Elephant::eat() { + incrementTime(15); if (gps_ != nullptr) { const auto feature{ look() }; @@ -138,18 +210,17 @@ void Elephant::eat() void Elephant::turn(const Turn turn) { + incrementTime(1); heading_ = getHeading(turn); } void Elephant::move() { + incrementTime(60); + decrementWater(20); + decrementWeight(20); if (gps_ != nullptr) { - // TODO: Add awake time, lose water and weight. - // TODO: If awake too long, slow down. - // TODO: If dehydrated, slow down. - // TODO: If below weight, slow down. - // TODO: Move to the next GPS. gps_->move(heading_, 1); } } diff --git a/CST126SRS03/main.cpp b/CST126SRS03/main.cpp index 0b329b6..0812edf 100644 Binary files a/CST126SRS03/main.cpp and b/CST126SRS03/main.cpp differ