I am having an issue adding in the following strenght and defense criteria. *Mob, *charm, *Hogwarts. Can you help please?
Requirements
In this project, you will create a simple class hierarchy as the basis for a fantasy combat game. Your ‘universe’ contains Vampires, Barbarians, Blue Men, Medusa and Harry Potter. Each has characteristics for attack, defense, armor, and strength points as follows.
Type |
Attack |
Defense |
Armor |
Strength Points |
Vampire1 |
1d12 |
1d6* Charm |
1 |
18 |
Barbarian2 |
2d6 |
2d6 |
0 |
12 |
Blue Men3 |
2d10 |
3d6 |
3 |
12 *Mob |
Medusa4 |
2d6* Glare |
1d6 |
3 |
8 |
Harry Potter5 |
2d6 |
2d6 |
0 |
10/20*Hogwarts |
“3d6” is rolling three 6-sided dice, “2d10” is rolling two 10-sided dice, etc.
*Charm: Vampires can charm an opponent into not attacking. For a given attack there is a 50% chance that their opponent does not actually attack them.
*Glare: If a Medusa rolls a 12 in attack, then the target has looked her in the eyes and is turned to stone. The Medusa wins! If Medusa uses Glare on Harry Potter on his first life, then Harry Potter get back to life. If the Vampire's Charm ability activates versus Medusa's Glare, the Vampire's Charm trump the Glare.
*Mob: The Blue Men are actually a swarm of small individuals. For every 4 points of damage (round down), they lose one defense die. For example, when they reach strength of 8 they only have 2d6 for defense.
*Hogwarts: If Harry dies (i.e. strength <=0), he immediately recovers and his total strength becomes 20. If he were to die again, then he’s dead.
//Blue Men //mob
class BlueMen : public Character
{
public:
BlueMen() : Character( 3, 12, "Blue Men" ){};
BlueMen(string tm) : Character( 3, 12, "Blue Men" )
{
this->team = tm;
};
void defend( Dice* die, int attackDamage, string attacker );
};
//-------------------------------------------------------------------------------------------------
//blue men defintions //mob?
void BlueMen::defend( Dice* die, int attackDamage, string attacker )
{
//3 dice for defense
int defense = die->rollDice() + die->rollDice() + die->rollDice();
//cout << this->getName() << " rolled " << defense << " for defense.\n";
int damage = attackDamage - defense;
if ( damage > 0)
{
damage -= this->armor;
if ( damage > 0 )
{
this->setStrength( this->getStrength() - damage );
}
}
}
//-----------------------------------------------------------------------------------------------------------
//Vampire declarations
class Vampire : public Character
{
public:
Vampire() : Character( 1, 18, "Vampire" ){};
Vampire(string tm) : Character( 1, 18, "Vampire" )
{
this->team = tm;
};
int attack( Dice* die);
void defend( Dice* die, int attackDamage, string attacker );
};
//---------------------------------------------------------------------------------------------------------
//vampire charm?
//Vampire definitions
int Vampire::attack( Dice* die )
{
//roll 3 die
int roll1 = die->rollDice();
int roll2 = die->rollDice();
int roll3 = die->rollDice();
//cout << this->getName() << " rolled a " << roll1 + roll2 + roll3 << " for attack.\n";
return roll1 + roll2 + roll3;
}
void Vampire::defend( Dice* die, int attackDamage, string attacker )
{
//only one die for defense
int defense = die->rollDice();
//cout << this->getName() << " rolled " << defense << " for defense.\n";
int damage = attackDamage - defense;
if ( damage > 0)
{
damage -= this->armor;
if ( damage > 0 )
{
this->setStrength( this->getStrength() - damage );
}
}
}
//-----------------------------------------------------------------------------------------------------------------
//Harry Potter class //Hogwarts?
class HarryPotter : public Character
{
public:
HarryPotter() : Character( 0, 10, "Harry Potter" ){};
HarryPotter(string tm) : Character( 0, 10, "HarryPotter" )
{
this->team = tm;
};
void defend( Dice* die, int attackDamage, string attacker );
};
//-------------------------------------------------------------------
//Harry Potter defense
void HarryPotter::defend( Dice* die, int attackDamage, string attacker )
{
//only two dice for defense
int defense = die->rollDice() + die->rollDice();
//cout << this->getName() << " rolled " << defense << " for defense.\n";
int damage = attackDamage - defense;
//only takes damage half of the time
if ( rand() % 2 )
{
if ( damage > 0)
{
damage -= this->armor;
if ( damage > 0 )
{
this->setStrength( this->getStrength() - damage );
}
}
}
else
{
cout << this->getName() << "avoided all damage through manipulation!\n";
}
}
//------------------------------------------------------------------------------------
//
//functions.cpp
//* Assignment
//*
//* Purpose: Functions for the main program
//*******************************************************************************/
//#include "functions.h"
//function that has two oppenents battle with 10-sided dice for attack and 6-sided for defense
string battle( Character* p1, Character* p2, Dice* d10, Dice* d6)
{
//change name if players are named the same
if( p1->getName() == p2->getName() )
{
p2->setName( p2->getName() + "2" );
}
while( p1->getStrength() > 0 && p2->getStrength()> 0 )
{
//first player attacks first
//check if player one is a character that uses d10 for attack
if( p1->getName() == "Blue Men" || p1->getName() == "Harry Potter")
{
p2->defend( d6, p1->attack( d10 ), p1->getName() );
}
else
{
//attack with regular d6 die
p2->defend( d6, p1->attack( d6 ), p1->getName() );
}
//no longer reporting rolls and damage
//cout << p2->getName() << ": Strength points = "<< p2->getStrength() << ".\n";
//make some room
//cout << "\n";
if( p2->getStrength() < 1 )
{
return p1->getName();
}
//second player attacks, again checking for creature's appropriate sided dice
if( p2->getName() == "Blue Men" || p2->getName() == "Harry Potter" || p2->getName() == "Harry Potter2" || p2->getName() == "Harry Potter2")
{
p1->defend( d6, p2->attack( d10 ), p2->getName() );
}
else
{
//attack with regular dice
p1->defend( d6, p2->attack( d6 ), p2->getName() );
}
//cout << p1->getName() << ": Strength points = "<< p1->getStrength() << ".\n";
//make some room
//cout << "\n";
if( p1->getStrength() < 1 )
{
return p2->getName();
}
}
//control should not reach here
cout << "ERROR" << endl;
exit(-1);
}
//controls whether the player would like to replay
bool askToReplay()
{
char response;
do
{
cout << "Would you like to run another battle? (y to continue)\n";
}
while( !(cin >> response) );
if( response == 'y' )
{
return true;
}
else
{
return false;
}
}
I am having an issue adding in the following strenght and defense criteria. *Mob, *charm, *Hogwarts....