Skip to content

Commit

Permalink
📝 Added & changed some comments (#70)
Browse files Browse the repository at this point in the history
* 📝 Added some comments

* ✨ Added a comment in heal unit
  • Loading branch information
AhmedSobhy01 authored May 16, 2024
1 parent 46c460e commit 255544d
Show file tree
Hide file tree
Showing 11 changed files with 19 additions and 18 deletions.
8 changes: 4 additions & 4 deletions ArmyClasses/AlienArmy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ void AlienArmy::addUnit(Unit* unit)
else
drones.enqueueFront(unit);

dronesAddingToggler = !dronesAddingToggler;
dronesAddingToggler = !dronesAddingToggler; // Toggle the adding toggler to add the drones in a once front, once back order
break;
}
}
Expand All @@ -44,7 +44,7 @@ Unit* AlienArmy::removeUnit(UnitType unitType)

case UnitType::AM:
if (!monsters.isEmpty())
monsters.remove((rand() % monsters.getCount()), unit);
monsters.remove((rand() % monsters.getCount()), unit); // Remove a random monster
break;

case UnitType::AD:
Expand All @@ -53,7 +53,7 @@ Unit* AlienArmy::removeUnit(UnitType unitType)
else
drones.dequeueBack(unit);

dronesRemovingToggler = !dronesRemovingToggler;
dronesRemovingToggler = !dronesRemovingToggler; // Toggle the removing toggler to remove the drones in a once front, once back order
break;
}

Expand Down Expand Up @@ -81,7 +81,7 @@ Unit* AlienArmy::pickAttacker(UnitType unitType)
else
drones.peekBack(unit);

dronesPickingToggler = !dronesPickingToggler;
dronesPickingToggler = !dronesPickingToggler; // Toggle the picking toggler to pick the drones in a once front, once back order
break;
}

Expand Down
4 changes: 2 additions & 2 deletions ArmyClasses/EarthArmy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ void EarthArmy::addUnit(Unit* unit)
{
case UnitType::ES:
soldiers.enqueue(unit);
if (dynamic_cast<EarthSoldier*>(unit)->isInfected())
if (dynamic_cast<EarthSoldier*>(unit)->isInfected()) // If the soldier is infected, increment the infected count
infectedSoldiersCount++;
break;

Expand All @@ -48,7 +48,7 @@ Unit* EarthArmy::removeUnit(UnitType unitType)
{
case UnitType::ES:
soldiers.dequeue(unit);
if (unit && dynamic_cast<EarthSoldier*>(unit)->isInfected())
if (unit && dynamic_cast<EarthSoldier*>(unit)->isInfected()) // If the soldier is infected, decrement the infected count
infectedSoldiersCount--;
break;

Expand Down
4 changes: 2 additions & 2 deletions RandomGenerator/RandomGenerator.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ class RandomGenerator
int getRandomNumber(int, int) const; // Generate a random number between the given range

// Setters
void setN(int);
void setProb(int);
void setN(int); // Set the number of units to generate
void setProb(int); // Set the probability of generating a unit

void setEarthParameters(int, int, int, int, Range, Range, Range); // Sets earth parameters loaded by game class
void setAlienParameters(int, int, int, Range, Range, Range); // Sets alien parameters loaded by game class
Expand Down
2 changes: 1 addition & 1 deletion UnitClasses/AlienDrone.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ bool AlienDrone::attack()
// Store the IDs of the fought units to be printed later
foughtUnits.enqueue(enemyUnit->getId());

// Nullify the pointer to avoid duplication
// Nullify the pointer
enemyUnit = nullptr;

// If this line is reached, at least one unit was attacked
Expand Down
6 changes: 3 additions & 3 deletions UnitClasses/AlienMonster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ bool AlienMonster::attack()
int x = rand() % 100 + 1;
if (enemyUnit->getUnitType() == UnitType::ES && x <= infectingProbability)
{
dynamic_cast<EarthSoldier*>(enemyUnit)->getInfection();
gamePtr->addUnit(enemyUnit);
dynamic_cast<EarthSoldier*>(enemyUnit)->getInfection(); // The soldier will get infected if not infected already and not immune
gamePtr->addUnit(enemyUnit); // The soldier will be re-enqueued to the list & infected soldiers counter will be incremented
continue;
}

Expand All @@ -68,7 +68,7 @@ bool AlienMonster::attack()
// Store the IDs of the fought units to be printed later
foughtUnits.enqueue(enemyUnit->getId());

// Nullify the pointer to avoid duplication
// Nullify the pointer
enemyUnit = nullptr;

// If this line is reached, at least one unit was attacked
Expand Down
2 changes: 1 addition & 1 deletion UnitClasses/AlienSoldier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ bool AlienSoldier::attack()
// Store the IDs of the fought units to be printed later
foughtUnits.enqueue(enemyUnit->getId());

// Nullify the pointer to avoid duplication
// Nullify the pointer
enemyUnit = nullptr;

// If this line is reached, at least one unit was attacked
Expand Down
2 changes: 1 addition & 1 deletion UnitClasses/EarthGunnery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ bool EarthGunnery::attack()
// Store the IDs of the fought units to be printed later
foughtUnits.enqueue(enemyUnit->getId());

// Nullify the pointer to avoid duplication
// Nullify the pointer
enemyUnit = nullptr;

// If this line is reached, at least one unit was attacked
Expand Down
2 changes: 1 addition & 1 deletion UnitClasses/EarthSoldier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ bool EarthSoldier::attack()
// Store the IDs of the fought units to be printed later
foughtUnits.enqueue(enemyUnit->getId());

// Nullify the pointer to avoid duplication
// Nullify the pointer
enemyUnit = nullptr;

// If this line is reached, at least one unit was attacked
Expand Down
2 changes: 1 addition & 1 deletion UnitClasses/EarthTank.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ bool EarthTank::attack()
// Store the IDs of the fought units to be printed later
foughtUnits.enqueue(enemyUnit->getId());

// Nullify the pointer to avoid duplication
// Nullify the pointer
enemyUnit = nullptr;

// Set attack check to true if one unit at least was attacked successfully
Expand Down
3 changes: 2 additions & 1 deletion UnitClasses/HealUnit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ bool HealUnit::attack()
}

// Heal each unit with the appropriate heal power
// Inside receiveHeal, if unit is infected, it would apply only half of UAP so it would take as twice as long to heal
unitToHeal->receiveHeal(calcUAP(unitToHeal));

// Add the unit back to its list if completely healed, otherwise re-add to the UML
Expand All @@ -57,7 +58,7 @@ bool HealUnit::attack()
// Store the IDs of the units that received heal to be printed later
foughtUnits.enqueue(unitToHeal->getId());

// Nullify the pointer to avoid duplication
// Nullify the pointer
unitToHeal = nullptr;

// If this line was reached, at least one heal was successful
Expand Down
2 changes: 1 addition & 1 deletion UnitClasses/SaverUnit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ bool SaverUnit::attack()
// Store the IDs of the fought units to be printed later
foughtUnits.enqueue(enemyUnit->getId());

// Nullify the pointer to avoid duplication
// Nullify the pointer
enemyUnit = nullptr;

// If this line is reached, at least one unit was attacked
Expand Down

0 comments on commit 255544d

Please sign in to comment.