Battle/Battle.cpp
bool Battle::CastSpell(Hero& hero, Monster& monster) 
{
    unsigned int totalDamage;
    unsigned int slotNumber;
    unsigned int typeOfSpell;
    Spell* chosenSpell;

    if (hero.DisplaySpells(chosenSpell , slotNumber , typeOfSpell) == false)
        return false;

    // Checks if the hero has enough magic power
    if (hero.UseSpell(*chosenSpell) == true) { 
        hero.ReduceMagicPower(chosenSpell->GetReqEnergy()); // Reduces the hero's magic power
        totalDamage = chosenSpell->HeroDamage(hero);        // Gets the total damage that will be caused
        monster.ChangeHealth(floor((double)(totalDamage * totalDamage) / (totalDamage + monster.MonsterGetDefence())));
        monster.HitBySpell(chosenSpell);                    // Applies the after attack effects of the spell
        hero.SpellUsed(slotNumber , typeOfSpell);           // Deletes the spell
        
        if (monster.Fainted()) {
            cout << "The hero " << hero.GetName() << " defeated the monster " << monster.GetName() << endl;
            return true;
        }
    }
    return true;
}
// displays the spells and lets the user choose one. After the spell is chosen it is cast
displays the spells and lets the user choose one. After the spell is chosen it is cast
displays the spells and lets the user choose one . After the spell is chosen it is cast
bool Battle::CastSpell(Hero& hero, Monster& monster) 
{
    unsigned int totalDamage;
    unsigned int slotNumber;
    unsigned int typeOfSpell;
    Spell* chosenSpell;
    if (hero.DisplaySpells(chosenSpell , slotNumber , typeOfSpell) == false)
        return false;
    if (hero.UseSpell(*chosenSpell) == true) { 
        hero.ReduceMagicPower(chosenSpell->GetReqEnergy()); 
        totalDamage = chosenSpell->HeroDamage(hero);        
        monster.ChangeHealth(floor((double)(totalDamage * totalDamage) / (totalDamage + monster.MonsterGetDefence())));
        monster.HitBySpell(chosenSpell);                    
        hero.SpellUsed(slotNumber , typeOfSpell);           
        if (monster.Fainted()) {
            cout << "The hero " << hero.GetName() << " defeated the monster " << monster.GetName() << endl;
            return true;
        }
    }
    return true;
}
bool Battle :: CastSpell ( Hero & hero , Monster & monster ) { unsigned int totalDamage ; unsigned int slotNumber ; unsigned int typeOfSpell ; Spell * chosenSpell ; if ( hero . DisplaySpells ( chosenSpell , slotNumber , typeOfSpell ) == false ) return false ; if ( hero . UseSpell ( * chosenSpell ) == true ) { hero . ReduceMagicPower ( chosenSpell -> GetReqEnergy ( ) ) ; totalDamage = chosenSpell -> HeroDamage ( hero ) ; monster . ChangeHealth ( floor ( ( double ) ( totalDamage * totalDamage ) / ( totalDamage + monster . MonsterGetDefence ( ) ) ) ) ; monster . HitBySpell ( chosenSpell ) ; hero . SpellUsed ( slotNumber , typeOfSpell ) ; if ( monster . Fainted ( ) ) { cout << " " << hero . GetName ( ) << " " << monster . GetName ( ) << endl ; return true ; } } return true ; }
displays the spells and lets the user choose one.
displays the spells and lets the user choose one .
// Checks if the hero has enough magic power // Reduces the hero's magic power // Gets the total damage that will be caused // Applies the after attack effects of the spell // Deletes the spell