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 1
Create an array to store the player's dice rolled, i.e. the five dice values. For example:
int player_dice [5]={0}
Add code to simulate the rolling of five dice, i.e the damage the player will do. That is, you should generate five random numbers, each in the range of 1 through 6(inclusive) and assign each number to an array element. Use the rand() function (i.e.1+ rand()%6) 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 (i.e. the randomly generated dice roli) to the screen, e.g.: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 2
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 die_count [7]={0};
die count
\table[[0,0,0,0,0,0,0],[0,1,2,3,4,5,6]]
Given that die face values are 1-6 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, die_count[1] should contain the number of 1s that were rolled, die_count[2] the number of 2s rolled, etc.
For example: In the example provided in stage 1, the player's rolled dice is assigned the following dice values: 5,2,1,1,6. In light of this, the die_count should be as follows:
die count
\table[[0,2,1,0,0,1,1],[0,1,2,3,4,5,6]]
To access and update the appropriate array element (using the value of the die as an index):
int die_value = player_roll 0;
die_count [die_value]= die_count die_value +1;
Stage 3
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 die_count array from the prior step, loop through the array to determine if a number was rolled 3 or more times.
If 1 was rolled 3+ times, the attack misses and the damage should reset to 0.
Console output: Swing and a miss!
If any other value was rolled 3+ times, the attack scores a critical hit and multiplies the damage by 2.
Console output: A Critical Hit!
Stage 4
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 hp(health points) variable for them both at the start of your program. By default have the player start at 200 health and slime at 100 health.
Consider who the damage is being dealt to and subtract the damage dealt from their health. If they have no health remaining (0 or less than 0), modify the console message.
Example console outputs:
Slime has taken 56 damage and has 44 health remaining.
** Slime has taken 18 damage and has fallen!
Stage 5
Add code to simulate the slime's damage (i.e. computer). That is, repeat steps 1-4 to do this for the slime.
Note: Make sure the damage is dealt to the player instead of the slime.
Stage 6
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 7
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 text-based 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 8
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 'n'(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.
Stage 1 Create an array to store the player's

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!