Question

In: Computer Science

Source code with comments explaining your code in C# Program 2: Buh-RING IT! For this assignment,...

Source code with comments explaining your code 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 the maximum damage the player does, and then subtract that from the monster. A similar thing happens when the monster attacks 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) 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...

***no extra text after hero/monster dies!***

Solutions

Expert Solution

PSEUDOCODE:

Main() {
input heroHP,hPerStrikeDamage,monsterHP,mPerStrikeDamage,round=1;
Object of random class to generate random numbers
Random rnd <-- new Random();
Ask for hero's starting point
heroHP <-- Convert.ToInt32(Console.ReadLine());
Ask for hero's damage per strike
hPerStrikeDamage <-- Convert.ToInt32(Console.ReadLine());
Ask for monster's starting point
monsterHP <-- Convert.ToInt32(Console.ReadLine());
Ask for monster's damage per strike
mPerStrikeDamage=Convert.ToInt32(Console.ReadLine());
  
while(true){
hero's Damage to monster
heroDamage <-- rnd.Next(hPerStrikeDamage);
monster's updated HP
monsterHP <-- monsterHP-heroDamage;
monster's Damage to hero
monsterDamage=rnd.Next(mPerStrikeDamage);
hero's updated HP
heroHP <-- heroHP-monsterDamage;

if(monsterHP<=0){
print "The monster dies and you earn 5 XP Battle ends..."
break;
}   
//Displaing result of the game
if(heroHP<=0){
print "The Hero dies and the monster earns 5 XP Battle ends"
break;
}
round+=1;
}
  
}
}

CODE FOR THE GIVEN PROGRAM:

using System;
class HelloWorld {
static void Main() {
int heroHP,hPerStrikeDamage,monsterHP,mPerStrikeDamage,round=1;
//Object of random class to generate random numbers
Random rnd = new Random();
//Asking for hero's starting point
Console.WriteLine(" Enter the hero's starting hit points:");
heroHP = Convert.ToInt32(Console.ReadLine());
//Asking for hero's damage per strike
Console.WriteLine("Enter the damage the hero’s weapon does per strike:");
hPerStrikeDamage=Convert.ToInt32(Console.ReadLine());
//Asking for monster's starting point
Console.WriteLine(" Enter the monster's starting hit points:");
//Asking for monster's damage per strike
monsterHP = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Enter the monster's damage per strike:");
mPerStrikeDamage=Convert.ToInt32(Console.ReadLine());
  
while(true){
//hero's Damage to monster
int heroDamage= rnd.Next(hPerStrikeDamage);
//monster's updated HP
monsterHP=monsterHP-heroDamage;
//monster's Damage to hero
int monsterDamage=rnd.Next(mPerStrikeDamage);
//hero's updated HP
heroHP=heroHP-monsterDamage;
//Displaying HP's after each round
Console.WriteLine("=========ROUND"+round+"=========");
Console.WriteLine("Hero attacks for: "+heroDamage);
if(monsterHP<=0){
Console.WriteLine("The monster dies and you earn 5 XP Battle ends...");
break;
}
Console.WriteLine("Monster has "+ monsterHP +" HP left");
Console.WriteLine("Monster attacks you for: "+monsterDamage);
Console.WriteLine("You have "+ heroHP +" HP left");
round+=1;
//Displaing result of the game
if(heroHP<=0){
Console.WriteLine("The Hero dies and the monster earns 5 XP Battle ends");
break;
}
}
  
}
}

SCREENSHOT OF THE GIVEN PROGRAM AND SAMPLE OUTPUT:-

SAMPLE OUTPUT:-

HAPPY LEARNING


Related Solutions

This is a python program. Put comments explaining the code, please. Suppose you have been tasked...
This is a python program. Put comments explaining the code, please. Suppose you have been tasked with writing a Python program (using linked lists) to keep track of computer equipment. For each piece of equipment, we track its name, purchase date, purchase amount, and quantity on hand. Write a program that completes the following tasks: allow the user to add a piece of equipment to the front of the list; allow the user to update the quantity of a piece...
I need to complete this C++ program. The instructions are in the comments inside the code...
I need to complete this C++ program. The instructions are in the comments inside the code below: ------------------------------------------------------------------------- Original string is: this is a secret! Encypted string is: uijt!jt!b!tfdsfu" Decrypted string is: this is a secret! //Encoding program //Pre-_____? //other necessary stuff here int main() { //create a string to encrypt using a char array cout<< "Original string is: "<<string<<endl; encrypt(string); cout<< "Encrypted string is: "<<string<<endl; decrypt(string); cout<<"Decrypted string is: "<<string<<endl; return 0; } void encrypt(char e[]) { //Write implementation...
JAVA PROGRAM: INCLUDE COMMENTS EXPLAINING THE CODE PLEASE Given the following information: 13-inch MacBook Air, 1.6GHz...
JAVA PROGRAM: INCLUDE COMMENTS EXPLAINING THE CODE PLEASE Given the following information: 13-inch MacBook Air, 1.6GHz dual-core Intel Core i5 processor, Turbo Boost up to 2.7GHz, Intel HD Graphics 6000, 8GB memory, 128GB PCIe-based flash storage 13-inch MacBook Air, 1.6GHz dual-core Intel Core i5 processor, Turbo Boost up to 2.7GHz, Intel HD Graphics 6000, 8GB memory, 256GB PCIe-based flash storage 15.6-inch Dell i3552, 1.6GHz Processor, Intel Pentium N3700, HD Laptop, 4 GB memory, DDR3L SDRAM, Windows 10, Black Drive 3...
C++ program to read line comments. This assignment will give you a little bit of practice...
C++ program to read line comments. This assignment will give you a little bit of practice with string parsing. Your task is to write a program that reads in a .cpp file line-by-line, and prints out only the text that's after the // characters that indicate a single-line comment. You do not have to worry about /* multiline comments */ though there will be a small amount of extra credit for programs that correctly extract these comments as well.
This problem needs to be solved with source code. I need a C++ program that will...
This problem needs to be solved with source code. I need a C++ program that will help me solve this question. I need it in C++, please. Writing with comments so it maybe cleared. 1.2. We received the following ciphertext which was encoded with a shift cipher: xultpaajcxitltlxaarpjhtiwtgxktghidhipxciwtvgtpilpit ghlxiwiwtxgqadds. 1. Perform an attack against the cipher based on a letter frequency count: How many letters do you have to identify through a frequency count to recover the key? What is...
JAVA Please put detailed comments as well explaining your program. I'm in a beginning programming class,...
JAVA Please put detailed comments as well explaining your program. I'm in a beginning programming class, and so please use more basic techniques such as if else statements, switch operators, and for loops if needed. http://imgur.com/a/xx9Yc Pseudocode for the main method: Print the headings             Print the directions             Prompt for the month             If the month is an integer       (Hint: Use the Scanner class hasNextInt method.)                         Input the integer for the month                         Get the...
Explain your code with comments. Solve in C++. 1. Write a str2int() function that convers a...
Explain your code with comments. Solve in C++. 1. Write a str2int() function that convers a string to integer. The function will take the number as a string then will return it as integer. E.g. str2int(“123”) will return 123 str2int(“005”) will return 5 str2int(“102”) will return 102
Also please add comments on the code and complete in C and also please use your...
Also please add comments on the code and complete in C and also please use your last name as key. The primary objective of this project is to increase your understanding of the fundamental implementation of Vigenere Cipher based program to encrypt any given message based on the Vignere algorithm. Your last name must be used as the cipher key. You also have to skip the space between the words, while replicating the key to cover the entire message. Test...
Write a program that solves the Knapsack problem. Code to the following standards. Your source of...
Write a program that solves the Knapsack problem. Code to the following standards. Your source of items to put into the knapsack should consist of five randomly generated integers in the range of 1 to 20. Your knapsack can hold 20 lbs.
CS 400 Assignment 5 Recursive/Backtracking: Generating Permutations WRITE CODE IN C++ PROGRAMMING LANGUAGE WITH COMMENTS INCLUDED...
CS 400 Assignment 5 Recursive/Backtracking: Generating Permutations WRITE CODE IN C++ PROGRAMMING LANGUAGE WITH COMMENTS INCLUDED Description: Mimic the code for N-queen problem (https://introcs.cs.princeton.edu/java/23recursion/Queens.java.html), develop a program that generates all permutations for the set {1, 2, 3, 4, 5}. The output should contain all 5! = 120 permutations. Output Sample: P#1: 1 2 3 4 5 P#2: 1 2 3 5 4 P#3: 1 2 4 3 5 ... P#120: 5 4 3 2 1 Hint: - Thoroughly study the...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT