Question

In: Computer Science

Hello, I need some assistance on completing this program in Pseudocode and in C++ Program 2:...

Hello, I need some assistance on completing this program in Pseudocode and in C++

Program 2: Buh-RING IT! For this assignment, you’re going to simulate a text-based Role-Playing Game (RPG). Design (pseudocode) and implement (source) for a program that reads in 1) the hero’s Hit Points (HP – or health), 2) the maximum damage the hero does per attack, 3) the monster’s HP and 4) the maximum monster’s damage per attack. When the player attacks, it will pick a random number between 0 and up to the maximum damage the player does, and then subtract that from the monster. The same thing happens when the monster attacks the hero, but damage is to the hero. The program should display rounds and the HP of the hero and monster each round. If the hero or monster dies, it should print that this happened and should NOT continue (i.e. no extra text). To learn how to create random numbers, see the appendix.

Sample run 1: Enter the hero's starting hit points: 50

Enter the damage the hero’s weapon does per strike: 20

Enter the monster's starting hit points: 40

Enter the monster's damage per strike: 15

====== ROUND 1 ======

Hero attacks for: 10

Monster has 30 HP left

Monster attacks you for: 1

You have 49 HP left

====== ROUND 2 ======

Hero attacks for: 18

Monster has 12 HP left

Monster attacks you for: 7

You have 42 HP left

====== ROUND 3 ======

Hero attacks for: 0

Monster has 12 HP left

Monster attacks you for: 14

You have 28 HP left

====== ROUND 4 ======

Hero attacks for: 18

Monster has -6 HP left

The monster dies and you earn 5 XP Battle ends...

Sample run 2:

Enter the hero's starting hit points: 50

Enter the damage the hero’s weapon does per strike: 10

Enter the monster's starting hit points: 40

Enter the monster's damage per strike: 20

====== ROUND 1 ======

Hero attacks for: 1

Monster has 39 HP left

Monster attacks you for: 6

You have 44 HP left

====== ROUND 2 ======

Hero attacks for: 5

Monster has 34 HP left

Monster attacks you for: 1

You have 43 HP left

====== ROUND 3 ======

Hero attacks for: 8

Monster has 26 HP left

Monster attacks you for: 8

You have 35 HP left

====== ROUND 4 ======

Hero attacks for: 4

Monster has 22 HP left

Monster attacks you for: 5

You have 30 HP left

====== ROUND 5 ======

Hero attacks for: 7

Monster has 15 HP left

Monster attacks you for: 1

You have 29 HP left

====== ROUND 6 ======

Hero attacks for: 7

Monster has 8 HP left

Monster attacks you for: 9

You have 20 HP left

====== ROUND 7 ======

Hero attacks for: 0

Monster has 8 HP left

Monster attacks you for: 14

You have 6 HP left

====== ROUND 8 ======

Hero attacks for: 4

Monster has 4 HP left

Monster attacks you for: 11

You have -5 HP left

You are killed by the monster and lose 10 gold.

Battle ends...

his assignment is about Repetition Structures.

For Pseudocode, here are key words to use

: · DO … WHILE – A loop that will always run at least once ·

FOR … ENDFOR – A loop that runs until certain criteria is met ·

WHILE … ENDWHILE – A loop that runs only while certain criteria is met ·

FOREACH … ENDFOREACH – A loop that runs over elements in a data structure · BREAK - "break out" of the current loop (or other structure) you're in and start immediately after the loop

CONTINUE - skip over the current iteration of the loop and move on to the next one

Solutions

Expert Solution

Below is the C++ code I hope that i have provided sufficient comments for your better understanding Note that I have done proper indentation but this code is automatically left alligned on this interface

#include<bits/stdc++.h>
using namespace std;
using namespace std;

int main()
{
    int hp_hero, hp_monster;
    int damage_hero, damage_monster;
    int round_count;
    int random; //To store random damage

    srand(time(0)); //To generate different random numbers every time

    cout<<"Using do while loop"<<endl;
    //Take users input
    cout<<"Enter the hero's starting hit points: ";
    cin>>hp_hero;

    cout<<"Enter the damage the hero’s weapon does per strike: ";
    cin>>damage_hero;

    cout<<"Enter the monster's starting hit points: ";
    cin>>hp_monster;

    cout<<"Enter the monster's damage per strike: ";
    cin>>damage_monster;

    //using do while loop
    round_count = 1;
    do
    {
        cout<<"====== ROUND "<<round_count<<" ======"<<endl;
        random = rand()%(damage_hero+1);
        cout<<"Hero attacks for: "<<random<<endl;
        hp_monster-=random;
        cout<<"Monster has "<<hp_monster<<" HP left"<<endl;
        if(hp_monster<=0)
        {
            cout<<"The monster dies and you earn 5 XP Battle ends..."<<endl;
            break; //exit from the loop
        }
        random = rand()%damage_hero+1;
        cout<<"Monster attacks you for: "<<random<<endl;
        hp_hero-=random;
        cout<<"You have"<<hp_hero<<" HP left"<<endl;
        if(hp_hero<=0)
        {
            cout<<"You are killed by the monster and lose 10 gold."<<endl;
            break; //exit from the loop
        }
        round_count++;
    }while(true);

    cout<<"Using for loop"<<endl;
    //Take users input
    cout<<"Enter the hero's starting hit points: ";
    cin>>hp_hero;

    cout<<"Enter the damage the hero’s weapon does per strike: ";
    cin>>damage_hero;

    cout<<"Enter the monster's starting hit points: ";
    cin>>hp_monster;

    cout<<"Enter the monster's damage per strike: ";
    cin>>damage_monster;

    //using for loop
    round_count = 1;
    for( ;true; ) //Apply the specified condition
    {
        cout<<"====== ROUND "<<round_count<<" ======"<<endl;
        random = rand()%(damage_hero+1);
        cout<<"Hero attacks for: "<<random<<endl;
        hp_monster-=random;
        cout<<"Monster has "<<hp_monster<<" HP left"<<endl;
        if(hp_monster<=0)
        {
            cout<<"The monster dies and you earn 5 XP Battle ends..."<<endl;
            break; //exit from the loop
        }
        random = rand()%damage_hero+1;
        cout<<"Monster attacks you for: "<<random<<endl;
        hp_hero-=random;
        cout<<"You have"<<hp_hero<<" HP left"<<endl;
        if(hp_hero<=0)
        {
            cout<<"You are killed by the monster and lose 10 gold."<<endl;
            break; //exit from the loop
        }
        round_count++;
    }

    cout<<"Using while loop"<<endl;
    //Take users input
    //Take users input
    cout<<"Enter the hero's starting hit points: ";
    cin>>hp_hero;

    cout<<"Enter the damage the hero’s weapon does per strike: ";
    cin>>damage_hero;

    cout<<"Enter the monster's starting hit points: ";
    cin>>hp_monster;

    cout<<"Enter the monster's damage per strike: ";
    cin>>damage_monster;
    //using while loop
    round_count = 1;
    while(true)
    {
        cout<<"====== ROUND "<<round_count<<" ======"<<endl;
        random = rand()%(damage_hero+1);
        cout<<"Hero attacks for: "<<random<<endl;
        hp_monster-=random;
        cout<<"Monster has "<<hp_monster<<" HP left"<<endl;
        if(hp_monster<=0)
        {
            cout<<"The monster dies and you earn 5 XP Battle ends..."<<endl;
            break; //exit from the loop
        }
        random = rand()%damage_hero+1;
        cout<<"Monster attacks you for: "<<random<<endl;
        hp_hero-=random;
        cout<<"You have"<<hp_hero<<" HP left"<<endl;
        if(hp_hero<=0)
        {
            cout<<"You are killed by the monster and lose 10 gold."<<endl;
            break; //exit from the loop
        }
        round_count++;
    }
}

Below is the screenshot of output

I have tried to explain it in very simple language and I hope that i have answered your question satisfactorily.Leave doubts in comment section if any


Related Solutions

I need assistance on this problem in Pseudocode and in C++ Program Program 3: Give a...
I need assistance on this problem in Pseudocode and in C++ Program Program 3: Give a baby $5,000! Did you know that, over the last century, the stock market has returned an average of 10%? You may not care, but you’d better pay attention to this one. If you were to give a newborn baby $5000, put that money in the stock market and NOT add any additional money per year, that money would grow to over $2.9 million by...
I need assistance on this problem in Pseudocode and in C++ Program 1: Stay on the...
I need assistance on this problem in Pseudocode and in C++ Program 1: Stay on the Screen! Animation in video games is just like animation in movies – it’s drawn image by image (called “frames”). Before the game can draw a frame, it needs to update the position of the objects based on their velocities (among other things). To do that is relatively simple: add the velocity to the position of the object each frame. For this program, imagine we...
Hello I need some assistance with these questions I need not so long answers but not...
Hello I need some assistance with these questions I need not so long answers but not too short please Give some examples of How much decisions. What are the implicit costs of having an Airbnb in your neighborhood? What is marginal analysis? What is marginal cost? Under what conditions do marginal costs increase?
Hello, I am in need of some assistance in interpreting the data for the two variables...
Hello, I am in need of some assistance in interpreting the data for the two variables I did in a t-test for in Excel. Variable 1 is Relationship with Direct Supervisor and Variable 2 is the Workplace Happiness Rating. I am supposed to write a 125- to 175-word summary of my interpretation of the results of the t test. t-Test: Two-Sample Assuming Equal Variances Variable 1 Variable 2 Mean 2.5 7.4 Variance 1.030612245 2 Observations 50 50 Pooled Variance 1.515306122...
Hello I have these questions, Can I please get some assistance, I need not so long...
Hello I have these questions, Can I please get some assistance, I need not so long or short answers please How to decide what job to take. Is that a marginal decision? What is an explicit cost? What is an implicit cost? How is accounting profit calculated? How is economic profit calculated?
I need assistance translating a custom C++ program to MIPS. My C++ code is the following:...
I need assistance translating a custom C++ program to MIPS. My C++ code is the following: I have made numerous attempts on my own to no avail, any assistance is appreciated. Also, template code for this solution is provided below: #include int moveRobots(int *, int *, int, int ); int getNew(int, int); int main() { int x[4], y[4], i, j, myX = 25, myY = 25, move, status = 1; // initialize positions of four robots x[0] = 0; y[0]...
Hello, I need some advice on the case below. I need to know some arguments for...
Hello, I need some advice on the case below. I need to know some arguments for how Kant's ethics applies to this case, and why other people who believe in the Kantean theory of ethics would also support the arguments. I need to use Kants theory to determine if this is morally correct or incorrect. Casino Gambling on Wall Street Case 4.5 Casino Gambling on Wall Street CDO stands for “ collateralized debt obligation,” and before the financial meltdown of...
i need a pseudocode for a program in java that will convert dollars into euros and...
i need a pseudocode for a program in java that will convert dollars into euros and japanese yen using the print and prinln methods an if, if -else, statement a switch statement a while statement utilizes the file class uses the random class and random number generator and uses at least three methods other than main
Hello, I need assistance with writing a "Financial Action Plan" regarding the actions that would be...
Hello, I need assistance with writing a "Financial Action Plan" regarding the actions that would be appropriate to secure your financial future. The paper should demonstrate your understanding of the following concepts: Time Value of Money Taxation Credit Life Insurance Investing Your paper should reflect upon the importance of each of the above concepts, your financial goals, and the actions you can take to increase the probability that you will reach the desired outcomes in detail.
I NEED THIS IN PSEUDOCODE: SWITCH/CASE 2 - Complete the pseudocode below by including a SWITCH...
I NEED THIS IN PSEUDOCODE: SWITCH/CASE 2 - Complete the pseudocode below by including a SWITCH statement that takes the user input (an integer between 26-30) and prints out a count up in its English equivalent. For example: if the user inputs “26”, the code will print “twenty-six”, “twenty-seven” on the next line, and so on up to “thirty”. If the user inputs “30”, the code will print “thirty” and finish. CREATE inputNum PRINT ("Please enter a number between 26-30...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT