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...
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...
MBA 5010 Week 4 Integrative Assignment This week, you’re going to build on the knowledge you...
MBA 5010 Week 4 Integrative Assignment This week, you’re going to build on the knowledge you gained. Your assignment is to deconstruct the economics underlying Airbnb. Specifically, I want you to answer the following questions: • Does Airbnb capture a sufficient amount of any value generated to remain a viable business? The purpose of this question is to provide you an opportunity to demonstrate your understanding of the economics of value creation. So, emphasize this aspect of your answer. Try...
Suppose you’re playing a game where you consecutively roll 3 dice. After each roll you may...
Suppose you’re playing a game where you consecutively roll 3 dice. After each roll you may choose to either roll the next dice or sacrifice one die to reroll any number of the previous dice. If you get a number greater than 5 you win, but if you roll doubles or a number less than 6 you lose. Considering each roll a separate state what is the approximate branching factor? Justify. Draw the full state space considering only the number...
You’re working on a team-based homework assignment with a partner, Deidre, that consists of an essay...
You’re working on a team-based homework assignment with a partner, Deidre, that consists of an essay and graphing questions. You can write an essay answer in 15 minutes while Deidre takes 20 minutes to write an essay of similar quality. You can answer a graphing question in 30 minutes and it also takes Deidre 30 minutes. What are you and your partner’s opportunity cost of answering essay questions and of finishing graphing questions? Use the opportunity cost principle to determine...
JAVA 1) You are provided an implementation of a text-based adventure game. Currently the game responds...
JAVA 1) You are provided an implementation of a text-based adventure game. Currently the game responds to directional movements that allow you to move your adventurer around a maze (that is read from a text file). Add the ability to save (and load) the game using object serialization. Write the serialization of the file out to a default filename SavedGame.dat. Make sure that you take care of any exceptions that may occur when reading or writing to a file (for...
Question 2 A text-based adventure game has several types of player. The code for the game...
Question 2 A text-based adventure game has several types of player. The code for the game uses the following class, Character to define all the shared elements for different types of player characters (Warrior, Wizard etc). 1. public class Character { 2. private String name; 3. private int life; 4. protected int hitPoints; 5. public Character(String name, int life, int hitPoints) { 6. this.name = name; 7. this.life = life; 8. this.hitPoints = hitPoints; 9. } 10. public void setHitPoints(int...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT