Gladiator class is described briefly in the beginning. Using C++
#pragma once |
| #include |
| //Fighter in the ring |
| class Gladiator { |
| private: |
| int dmgMin,//The lowest amount of damage a gladiator can inflict with a successful attack |
| dmgRange,//The most damage ABOVE Minimum Damage that the gladiator can inflict with a single, non-critical hit |
| evasion, //The % chance (0-100) that the gladiator will completely avoid incoming damage when defending |
| critical,//The % chance (0-100) that the gladiator will inflict twice (2x) the rolled damage when attacking the opponent (known as a crit) |
| maxHealth,//The amount of HP a gladiator will start each fight with |
| curHealth;//The amount of HP a gladiator has left before they have died and lost the fight |
| public: |
| //How the gladiator is referenced to the user, provided somehow in the constructor |
| std::string name; |
| //make memeber fucntion to get each one of those values. accessors and mutators. indivuial memeeber values. | | | | Gladiator(); | | int getCurHealth(); | | int rollDamage(); | | bool takeDamage(int); | | void display(); | |
| //Called upon creation; prevent any uninitialized values from being available |
| Gladiator();//Constructor |
| //Use this to obtain all information on our gladiators, including their name. |
| //Confirmation of the created gladiator is permitted but NOT required. |
| |
| //Accessor for health |
| int getCurHealth(); |
| |
| //Calculates a damage roll based on dmgMin, dmgRange, and crit |
| //This would be a good place to display a crit notification |
| int rollDamage(); |
| |
| //Displays gladiator's stats, in one or two lines so it's pleasing in a list |
| void display();//you're responsible for defining this function |
| |
| //Hint: Evasion should be calculated here |
| bool takeDamage(int dmgAmt);//Returns whether the gladiator was killed by the damage or not |
| }; |
| |
| //Most simple function, so it's defined here to show syntax you'll be using |
| int Gladiator::getCurHealth() |
| { |
| return curHealth; |
| } |
Using Classes The following program is going to revolve around creating and using the "Gladiator" class, which is included in your github repository. You must use that class definition in your project. In addition to writing a main function that uses the class correctly, you will also be responsible for defining 4 member functions of the gladiator class Write a program that performs the following 1. Tell the user that they are going to be hosting a fight! But first, we need to 2. Declare your gladiator objects. This will call the constructor, which is where you will assign stats and assign, or ask for, a name a. Max Health should be 150, 200, or 250 b. Evasion and Crit should be two separate random values chosen from 5, 10, or 15% Minimum Damage should be in the range 8-14, with Damage Range in the range 16-22 C. 3. Display the names and stats of both fighters to the user, and inform them that the fight will begin 4. Your gladiators will alternatingly attack each other using the appropriate member functions (think about who is attacking, and who is taking *how much* damage) Each attack should display info about damage and/or remaining health b. a. This will continue until a gladiator loses all their health 5. Inform the user who was victorious. Ask if the user wants to run another fight (return to step 2) or not (end program) Min damage roll = min(8)+ rand() % range(6+1) Maximum Damage = Minimum Damage + Damage Range --Min 30, range 50 would result in damage between 30-80 To roll for a 10% chance, due to the % (per "cent" ie century) we will be taking rand() % 100 and comparing it to the chance, 10. If the random number generated is lower than the chance an 8 for example, that's considered a success ---End of Chapter 8 slides contain more help with random numbers. Use srand properly (ie once) Using Classes The following program is going to revolve around creating and using the "Gladiator" class, which is included in your github repository. You must use that class definition in your project. In addition to writing a main function that uses the class correctly, you will also be responsible for defining 4 member functions of the gladiator class Write a program that performs the following 1. Tell the user that they are going to be hosting a fight! But first, we need to 2. Declare your gladiator objects. This will call the constructor, which is where you will assign stats and assign, or ask for, a name a. Max Health should be 150, 200, or 250 b. Evasion and Crit should be two separate random values chosen from 5, 10, or 15% Minimum Damage should be in the range 8-14, with Damage Range in the range 16-22 C. 3. Display the names and stats of both fighters to the user, and inform them that the fight will begin 4. Your gladiators will alternatingly attack each other using the appropriate member functions (think about who is attacking, and who is taking *how much* damage) Each attack should display info about damage and/or remaining health b. a. This will continue until a gladiator loses all their health 5. Inform the user who was victorious. Ask if the user wants to run another fight (return to step 2) or not (end program) Min damage roll = min(8)+ rand() % range(6+1) Maximum Damage = Minimum Damage + Damage Range --Min 30, range 50 would result in damage between 30-80 To roll for a 10% chance, due to the % (per "cent" ie century) we will be taking rand() % 100 and comparing it to the chance, 10. If the random number generated is lower than the chance an 8 for example, that's considered a success ---End of Chapter 8 slides contain more help with random numbers. Use srand properly (ie once)