Skip to content

Commit

Permalink
Merge pull request #2 from labermt/master
Browse files Browse the repository at this point in the history
Updated elephant0.cpp to loxodonta.cpp.
  • Loading branch information
TheJonBovi authored Feb 23, 2018
2 parents b6240c8 + 761d0d1 commit d2c5d2b
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 10 deletions.
2 changes: 1 addition & 1 deletion CST126SRS03/CST126SRS03.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@
</ItemGroup>
<ItemGroup>
<ClCompile Include="elephant.cpp" />
<ClCompile Include="elephant0.cpp" />
<ClCompile Include="loxodonta.cpp" />
<ClCompile Include="gps.cpp" />
<ClCompile Include="main.cpp" />
<ClCompile Include="preserve.cpp" />
Expand Down
2 changes: 1 addition & 1 deletion CST126SRS03/CST126SRS03.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
<ClCompile Include="preserve.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="elephant0.cpp">
<ClCompile Include="loxodonta.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
Expand Down
15 changes: 12 additions & 3 deletions CST126SRS03/elephant.h
Original file line number Diff line number Diff line change
Expand Up @@ -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_)
Expand All @@ -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;
Expand All @@ -50,6 +59,6 @@ class Elephant
void move();

public: // To be implemented methods.
void tag(const GPS& gps);
void tag(GPS& gps);
void findHerd();
};
81 changes: 76 additions & 5 deletions CST126SRS03/elephant0.cpp → CST126SRS03/loxodonta.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) };
Expand Down Expand Up @@ -103,13 +172,15 @@ int Elephant::listen() const

void Elephant::sleep()
{
incrementTime(120);
awake_ = 0;
}

void Elephant::drink()
{
const auto feature{ look() };

incrementTime(5);
if (feature == Preserve::Feature::kWater)
{
water_ = kMaxWater;
Expand All @@ -118,6 +189,7 @@ void Elephant::drink()

void Elephant::eat()
{
incrementTime(15);
if (gps_ != nullptr)
{
const auto feature{ look() };
Expand All @@ -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);
}
}
Binary file modified CST126SRS03/main.cpp
Binary file not shown.

0 comments on commit d2c5d2b

Please sign in to comment.