Skip to content

Commit

Permalink
⚡ Added condition to check first UMLjointTime (#73)
Browse files Browse the repository at this point in the history
* ⚡ Added condition to check first UMLjointTime

* 🎨 Auto formatted files

---------

Co-authored-by: AhmedSobhy01 <[email protected]>
  • Loading branch information
HelanaNady and AhmedSobhy01 authored May 16, 2024
1 parent 19a3f75 commit 701db5b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
13 changes: 10 additions & 3 deletions UnitClasses/HealableUnit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#include "../Game.h"

HealableUnit::HealableUnit(Game* gamePtr, UnitType unitType, double health, int power, int attackCapacity)
: Unit(gamePtr, unitType, health, power, attackCapacity), UMLjoinTime(0)
: Unit(gamePtr, unitType, health, power, attackCapacity), UMLjoinTime(-1)
{}

bool HealableUnit::needsHeal() const
Expand All @@ -22,6 +22,11 @@ bool HealableUnit::isHealed() const
return health > initialHealth * 0.2;
}

bool HealableUnit::hasBeenInUMLbefore() const
{
return UMLjoinTime != -1;
}

void HealableUnit::receiveHeal(double UHP)
{
// Infected units get twice the time to get healed
Expand All @@ -33,5 +38,7 @@ void HealableUnit::receiveHeal(double UHP)

void HealableUnit::setUMLjoinTime(int UMLjoinTime)
{
this->UMLjoinTime = UMLjoinTime;
}
// Check if it's the unit first time to join uml
if (!hasBeenInUMLbefore())
this->UMLjoinTime = UMLjoinTime;
}
1 change: 1 addition & 0 deletions UnitClasses/HealableUnit.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class HealableUnit: public Unit
bool needsHeal() const; // Check if the unit is eligible for healing
bool hasWaitedForTooLong() const; // Decides whether to kill or heal the unit based on its wait time
bool isHealed() const; // Checks if the unit's health has increased enough
bool hasBeenInUMLbefore() const; // Check if it has been inside uml before or not

void receiveHeal(double); // Increase the health of the unit by "UHP"

Expand Down

0 comments on commit 701db5b

Please sign in to comment.