Question

In: Computer Science

Buh-RING IT! For this assignment, you’re going to simulate a text-based Role-Playing Game (RPG). Design (pseudocode)...

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.

Solutions

Expert Solution

Source Code :

#include <iostream>
#include<random>

using namespace std;

int attack(int maxVal){
   //simulates an attack
   random_device d;
    mt19937 rng(d());
    uniform_int_distribution<mt19937::result_type> dist6(0,maxVal); // distribution in range [0, maxVal]
    return dist6(rng); //returns a random number between 0 and maxVal (both included)
}

int main() {
   int heroHp , monsterHp , heroDmg, monsterDmg;
   cout << "Enter hero's HP" << endl;
   cin >> heroHp;
   cout << "Enter hero's maximum damage" << endl;
   cin >> heroDmg;
   cout << "Enter monster's HP" << endl;
   cin >> monsterHp;
   cout << "Monster's maximum damage" << endl;
   cin >> monsterDmg;
   while(true){
       //RPG game start
       if(heroHp <= 0){
           cout << "Hero Died" << endl;
           break;
       }
          
       if(monsterHp <= 0){
           cout << "Monster Died" << endl;
           break;
       }
       cout << "Hero's HP = " << heroHp << endl;
       cout << "Monster's HP = " << monsterHp << endl;
       heroHp -= attack(monsterDmg); // subtract monster's damage from hero's Hp
       monsterHp -= attack(heroDmg); // subtract hero's damage from monster's Hp
          
   }
   return 0;
}

Input :

Output :

Source Code (with syntax highlighted) :

If you have trouble compiling, please switch to C++ 11.

If you liked this solution, please give a thumbs up rating. Feel free to comment for any explanation/clarification.


Related Solutions

I need this in pseudocode: Similar to the previous assignment, you’re going to read in the...
I need this in pseudocode: Similar to the previous assignment, you’re going to read in the number of years the player played and the starting year of that player – followed by the statistics for those years. This time, however, you’re going to print out the years from worst to best in sorted order. Hint: this will require a second array to store years. If you can sort one array, can you sort both? Sample Output #1: Enter the number...
pseudocode please! Assignment 5B: Moneyball: Part 2. Similar to the previous assignment, you’re going to read...
pseudocode please! Assignment 5B: Moneyball: Part 2. Similar to the previous assignment, you’re going to read in the number of years the player played and the starting year of that player – followed by the statistics for those years. This time, however, you’re going to print out the years from worst to best in sorted order. Hint: this will require a second array to store years. If you can sort one array, can you sort both? Sample Output #1: Enter...
2. You’re playing a game of Magic: The Gathering with a deck that consists of 60...
2. You’re playing a game of Magic: The Gathering with a deck that consists of 60 cards, 24 of which are land cards. You draw an opening hand of seven cards which contains exactly one land and six non-lands. (For this problem, you are welcome to read and use the tools of this article1, but your answers must include clear explanations of the mathematical reasoning you’re using!) (a) What is the probability of this event (that your hand of seven...
Design a text-based game. The game should involve starting from some point in the universe and...
Design a text-based game. The game should involve starting from some point in the universe and seeking or exploring. For example, you could start at the mouth of a cave and seek gold in the halls and caverns. Write out the logic in English and/or pseudocode. Write several lines of JavaScript code that will start the game going, containing control flow statement(s).
Overview For this assignment, write a program that uses functions to simulate a game of Craps....
Overview For this assignment, write a program that uses functions to simulate a game of Craps. Craps is a game of chance where a player (the shooter) will roll 2 six-sided dice. The sum of the dice will determine whether the player (and anyone that has placed a bet) wins immediately, loses immediately, or if the game continues. If the sum of the first roll of the dice (known as the come-out roll) is equal to 7 or 11, the...
For this assignment, write a program that uses functions to simulate a game of Craps. Craps...
For this assignment, write a program that uses functions to simulate a game of Craps. Craps is a game of chance where a player (the shooter) will roll 2 six-sided dice. The sum of the dice will determine whether the player (and anyone that has placed a bet) wins immediately, loses immediately, or if the game continues. If the sum of the first roll of the dice (known as the come-out roll) is equal to 7 or 11, the player...
For this assignment you will design a set of classes that work together to simulate a...
For this assignment you will design a set of classes that work together to simulate a police officer issuing a parking ticket. You should design the following classes: - The ParkedCar Class: This class should simulate a parked car. The class's responsibilities are as follows: - To know the car's make, model, color, license number, and the number of minutes that the car has been parked. - The ParkingMeter Class: This class should simulate a parking meter. The class's only...
Top-down design: Design a program called TeamGame to simulate a simple game of drafting players to...
Top-down design: Design a program called TeamGame to simulate a simple game of drafting players to teams. Rules of the game: • There are two teams: Team A and Team B. • There are 50 players, with numbers from 1 to 50. • Each team will get 10 of the players. The program should randomly select 10 players for each team. To accomplish this, you may select each player randomly, or you may shuffle the list of players before making...
In python please: You’re going to program a simulation of the following game. Like many probability...
In python please: You’re going to program a simulation of the following game. Like many probability games, this one involves an infinite supply of ping-pong balls. No, this game is "not quite beer pong." The balls are numbered 1 through N. There is also a group of N cups, labeled 1 through N, each of which can hold an unlimited number of ping-pong balls (a;ll numbered 1 through N). The game is played in rounds. A round is composed of...
In python 3.7: You’re going to program a simulation of the following game. Like many probability...
In python 3.7: You’re going to program a simulation of the following game. Like many probability games, this one involves an infinite supply of ping-pong balls. No, this game is "not quite beer pong." The balls are numbered 1 through N. There is also a group of N cups, labeled 1 through N, each of which can hold an unlimited number of ping-pong balls (all numbered 1 through N). The game is played in rounds. A round is composed of...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT