#include #include "SuperHero.h" //=============================================================== // Superhero base class methods void SuperHero::addLife() { m_numberOfLives++; return ; } bool SuperHero::isAlive() { return m_numberOfLives > 0 ; } bool SuperHero::canFight() { return true ; } void SuperHero::fightResult( bool result ) { //std::cout << " SuperHero base fightResult() " << std::endl ; if (! result ) m_numberOfLives-- ; return ; } int SuperHero::power() { //std::cout << " SuperHero base power( ) " << std::endl ; return m_strength+m_weaponStrength ; } SuperHero::SuperHero( std::string name, int strength, int numberOfLives, int weaponStrength ) { m_name = name ; m_strength = strength ; m_numberOfLives = numberOfLives ; m_weaponStrength = weaponStrength ; } std::string SuperHero::name() { return m_name ; } std::string SuperHero::announce() { std::string msg ; msg = this->name()+" (a poor ordinary SuperHero) " ; return msg ; } //============================================================= // Invisible superhero // New methods void InvisibleSuperHero::disappear() { m_isInvisible = true ; } void InvisibleSuperHero::appear() { m_isInvisible = false ; } // Overridden method: Increase strenghth is invisible int InvisibleSuperHero::power() { //std::cout << " InvisibleSuperHero class power( ) " << std::endl ; float strength = SuperHero::power() ; if( m_isInvisible ) strength+=10 ; return strength; } // Constructor InvisibleSuperHero::InvisibleSuperHero( std::string name, int strength, int numberOfLives, int weaponStrength ) : SuperHero( name, strength, numberOfLives, weaponStrength ) { m_isInvisible = false ; } std::string InvisibleSuperHero::announce() { std::string msg ; if( m_isInvisible ) msg = this->name()+" ( invisible at the time ) " ; else msg = this->name()+" ( but fully visible ) " ; return msg ; } //============================================================= // Flying superhero // New methods void FlyingSuperHero::fly() { m_inAir = true ; } void FlyingSuperHero::land() { m_inAir = false ; } // Overridden method: Increase strenghth hugely bool FlyingSuperHero::canFight() { return ! m_inAir ; } // Constructor FlyingSuperHero::FlyingSuperHero( std::string name, int strength, int numberOfLives, int weaponStrength ) : SuperHero( name, strength, numberOfLives, weaponStrength ) { m_inAir = false ; } std::string FlyingSuperHero::announce() { std::string msg ; if( m_inAir ) msg = this->name()+" ( currently flying ) " ; else msg = this->name()+" ( resting on the ground ) " ; return msg ; } //============================================================= // Life sucking superhero // Overridden method void LifeSuckingSuperHero::fightResult( bool result) { if( result ) SuperHero::addLife() ; else SuperHero::fightResult( result); return ; } // Constructor LifeSuckingSuperHero::LifeSuckingSuperHero( std::string name, int strength, int numberOfLives, int weaponStrength ) : SuperHero( name, strength, numberOfLives, weaponStrength ) { } std::string LifeSuckingSuperHero::announce() { std::string msg ; msg = this->name()+" ( a lifesucking creature ) " ; return msg ; }