Question: Stage 1 Create an array to store the player's dice rolled, i . e . the five dice values. For example: int player _ dice
Stage
Create an array to store the player's dice rolled, ie the five dice values. For example:
int playerdice
Add code to simulate the rolling of five dice, ie the damage the player will do That is you should generate five random numbers, each in the range of through inclusive and assign each number to an array element. Use the rand function ie rand to simulate the roll of a die. Hint: Use a loop in order to assign each random number die roll to an array element.
Display the player's dice ie the randomly generated dice roli to the screen, eg:Sample output this will look different given we are generating random values here:
Make sure the program runs correctly. Once you have that working, back up your program. Note: When developing software, you should always have fixed points in your development where you know your software is bug free and runs correctly.
Stage
To determine if a critical hit or miss occurs, add code to count how many times each die face value was rolled. Hint: Use an array in order to store this information.
To define an array in order to count how many times each die face value was rolled:
int diecount ;
die count
table
Given that die face values are inclusive, we create an array with seven elements but ignore the zero element of the array. This will make it easier to increment the appropriate array element. That is diecount should contain the number of that were rolled, diecount the number of rolled, etc.
For example: In the example provided in stage the player's rolled dice is assigned the following dice values: In light of this, the diecount should be as follows:
die count
table
To access and update the appropriate array element using the value of the die as an index:
int dievalue playerroll ;
diecount dievalue diecount dievalue ;
Stage
Now that we have counted the dice values rolled and totalled the damage, we can consider if a critical hit or miss occurs. Using the diecount array from the prior step, loop through the array to determine if a number was rolled or more times.
If was rolled times, the attack misses and the damage should reset to
Console output: Swing and a miss!
If any other value was rolled times, the attack scores a critical hit and multiplies the damage by
Console output: A Critical Hit!
Stage
Now that our final damage value has been calculated, it's time to start dealing damage! For this to work, we obviously require the player and slime to have health values. Create a health points variable for them both at the start of your program. By default have the player start at health and slime at health.
Consider who the damage is being dealt to and subtract the damage dealt from their health. If they have no health remaining or less than modify the console message.
Example console outputs:
Slime has taken damage and has health remaining.
Slime has taken damage and has fallen!
Stage
Add code to simulate the slime's damage ie computer That is repeat steps to do this for the slime.
Note: Make sure the damage is dealt to the player instead of the slime.
Stage
Now let's add code so there is more than one round of combat. Add a loop which loops until the player or slime is defeated. Think about where this code should go what needs to be repeated in our loop? What needs to be reset for each loop?
Note: The player will always attack first. Thus if the slime have no health remaining, it cannot attack!
Stage
You should now have a battle that loops until the player or slime is defeated. But the user does not get to interact during the combat, lets change that.
At the start of each round of combat, prompt the user if they would like to attack or run.
Attack: roll dice and deal damage to the slime, akin to the prior steps.
Run: The player will attempt to run... but as our game has an 'intentional' bug like many older textbased games, this will always result in failing to get away.
Console output:
Player attempts to run...
Failed to get away!
In both cases, the slime will still attack the player provided the slime had HP remaining after the player's attack.
Stage
Now... it's time to allow the player to battle more than one slime. Let's add a loop which loops until the user enters to stop playing the game Think about where this code should go what needs to be repeated, etc.
Note: The prompt should be different to the first slime battled.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
