#include #include "AttributeT.h" #include "SpellT.h" #include "DoubleSpellT.h" using namespace std; void UseSpell(SpellT s); void UseDoubleSpell(DoubleSpellT s); int main() { SpellT spell1("heal", "a heal spell", "A blue haze surrounds you and you feel better."); spell1.AddEffect(AttributeT::HEALTH, 5); spell1.SetDuration(5); cout << "Using the first spell" << endl; UseSpell(spell1); cout << endl << endl; SpellT spell2("buff", "buff", "I Pump You UP"); spell2.AddEffect(AttributeT::HEALTH, 2); spell2.AddEffect(AttributeT::DEFEND, 3); spell2.AddEffect(AttributeT::ATTACK, 4); spell2.SetDuration(3); cout << "Using the second spell " << endl; UseSpell(spell2); cout << endl << endl; DoubleSpellT spell3("buff", "buff", "I Pump you UP Twice"); spell3.AddEffect(AttributeT::HEALTH, 2); spell3.SetDuration(3); cout << "Using the double spell " << endl; UseDoubleSpell(spell3); cout << endl << endl; cout << "Using the double spell as a single spell" << endl; UseSpell(spell3); cout << endl << endl; SpellT * spell4 = new SpellT("pain", "pain", "Ouch"); spell4->AddEffect(AttributeT::HEALTH, -2); spell4->SetDuration(3); cout << "Using Spell 4" << endl; UseSpell(*spell4); cout << endl << endl; delete spell4; cout << "Using Spell 4" << endl; spell4 = new DoubleSpellT("PAIN", "PAIN", "Ouch"); spell4->AddEffect(AttributeT::HEALTH, -2); spell4->SetDuration(3); UseSpell(*spell4); cout << endl << endl; delete spell4; cout << "Spell 5" << endl; DoubleSpellT * spell5 = new DoubleSpellT("strong","strong", "Strenght"); spell5->AddEffect(AttributeT::ATTACK, 10); spell5->SetDuration(3); UseSpell(*spell5); cout << endl; UseDoubleSpell(*spell5); cout << endl << endl; //spell5 = (DoubleSpellT *)(spell4); cout << "Assigning the DoubleSpell to SpellT" << endl; spell4 = spell5; UseSpell(*spell4); cout << endl << endl; delete spell5; return 0; } void UseSpell(SpellT spell){ AttributeT i; while (spell.Active()) { cout << "The active " << spell.GetSpellName() << " spell takes effect." << endl; cout << "\t" << spell.GetResult() << endl; for (i = AttributeT::HEALTH; i!=AttributeT::NONE; i = NextAttribute(i)) { if (spell.GetEffect(i) != 0) { cout <<"\t" << i << " changed by " << spell.GetEffect(i) << endl; } } spell.Tick(); } } void UseDoubleSpell(DoubleSpellT spell){ AttributeT i; while (spell.Active()) { cout << "The active " << spell.GetSpellName() << " spell takes effect." << endl; cout << "\t" << spell.GetResult() << endl; for (i = AttributeT::HEALTH; i!=AttributeT::NONE; i = NextAttribute(i)) { if (spell.GetEffect(i) != 0) { cout <<"\t" << i << " changed by " << spell.GetEffect(i) << endl; } } spell.Tick(); } }