Skip to content

Commit

Permalink
♻️ Made printUnitsFighting function
Browse files Browse the repository at this point in the history
  • Loading branch information
AhmedSobhy01 committed May 16, 2024
1 parent d767b1c commit 9116331
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 14 deletions.
31 changes: 17 additions & 14 deletions Game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,21 @@ void Game::printUnitMaintenanceList() const
std::cout << "]" << std::endl;
}

void Game::printUnitsFighting()
{
Unit* currentAttacker = nullptr;
std::string currentFoughtUnits, currentAction;

while (attackers.dequeue(currentAttacker) && attackActions.dequeue(currentAction) && foughtUnits.dequeue(currentFoughtUnits))
{
currentAttacker->printUnit();
std::cout << " " << currentAction << " [" << currentFoughtUnits << "]" << std::endl;

// Nullify the pointers
currentAction = nullptr;
}
}

void Game::printAll()
{
std::cout << std::endl;
Expand All @@ -311,20 +326,8 @@ void Game::printAll()
std::cout << std::endl << "============== Earth Allied Army Alive Units ===================" << std::endl;
earthAlliedArmy.printArmy();

if (!attackers.isEmpty())
{
std::cout << std::endl << "============== Units fighting at current step =================" << std::endl;
Unit* currentAttacker = nullptr;
std::string currentFoughtUnits, currentAction;

while (attackers.dequeue(currentAttacker) && attackActions.dequeue(currentAction) && foughtUnits.dequeue(currentFoughtUnits))
{
currentAttacker->printUnit();
std::cout << " " << currentAction << " [" << currentFoughtUnits << "]" << std::endl;
}
}
else
std::cout << std::endl << "============== No units fighting at current step ==============" << std::endl;
std::cout << std::endl << (attackers.isEmpty() ? "============== No units fighting at current step ==============" : "============== Units fighting at current step =================") << std::endl;
printUnitsFighting();

std::cout << std::endl << "============== Maintenance List Units =========================" << std::endl;
printUnitMaintenanceList();
Expand Down
1 change: 1 addition & 0 deletions Game.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class Game

void printKilledList() const; // Prints the killed list with the console formats
void printUnitMaintenanceList() const; // Print the units at the maintence list
void printUnitsFighting(); // Print the units fighting in current timestep
void printAll(); // Prints all the armies and the killed list and units fighting at the current timestep

std::string battleResult() const; // Returns the result of the battle
Expand Down

0 comments on commit 9116331

Please sign in to comment.