Kod:
main.cpp
monster rabbit("rabbit", 5, 1, 3, 2, 2, 1)
rabbit.stats();
rabbit.fight(gracz.yourDmg, gracz.strength, weaponDmg, gracz.agility, &gracz.hp, &gracz.gold, &gracz.exp, &gracz.allTimeExp, gracz.maxHP, questNr, &questProgress, questObjective, &gracz.lvl, &rabbit.hp, &rabbit.strength, &rabbit.agility, &rabbit.exp, &rabbit.gold);
deklaracja metody:
void monster::fight(int yourDmg, int yourStrength, int weaponDamage, int yourAgility, int* yourHP, int* yourGold, int*yourExp, int* yourAllTimeExp, int yourMaxHP, int questNo, int* qProgress, int qObjective, int* yourLvl, int* monsterHP, int* monsterStrength, int*monsterAgility, int* monsterExp, int* monsterGold)
{
system("cls");
do
{
yourDmg=(yourStrength)-(rand() % 2-1)+weaponDamage;
cout<<"Enemy hp: "<<hp<<endl;
cout<<"Your hp: "<<yourHP<<endl;
if(yourAgility>=agility)
{
Sleep(500);
hp-=yourDmg;
cout<<"You dealt "<<yourDmg<<" damage"<<endl;
Sleep(500);
yourHP-=monsterDmg;
cout<<"You recieved "<<monsterDmg<<" damage"<<endl;
}
else
{
Sleep(500);
yourHP-=monsterDmg;
cout<<"You recieved "<<monsterDmg<<" damage"<<endl;
Sleep(500);
hp-=yourDmg;
cout<<"You dealt "<<yourDmg<<" damage"<<endl;
}
}while((hp>0)&&(yourHP>0));
if(hp<=0)
{
cin.get();
cout<<"Congratulations! You defeated a rabbit!"<<endl;
cout<<"You found "<<gold<<" GC"<<endl;
yourGold+=gold;
yourExp+=2;
yourAllTimeExp+=2;
if(questNo==1)
{
qProgress++;
cout<<"Your progress in quest: "<<qProgress<<" of "<<qObjective<<endl;
}
}
else if(yourHP<=0)
{
cin.get();
cout<<"Random villager found you senseless bleeding in grass... All you remember is that you messed with wrong rabbit"<<endl;
cin.get();
yourHP=yourLvl+5;
}
}