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...
Card Shuffling and Dealing (C++) All in one file with comments explaining please! Create a program...
Card Shuffling and Dealing (C++) All in one file with comments explaining please! Create a program to shuffle and deal a deck of cards. The program should consist of a class Card, class DeckOfCards and a driver program. Class Card should provide: a)      Data members face and suit of type int. b)      A constructor that receives two ints representing the face and suit and uses them to initialize the data members. c)      Two static arrays of strings representing the faces...
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...
Please code in C# - (C - Sharp) Assignment Description Write out a program that will...
Please code in C# - (C - Sharp) Assignment Description Write out a program that will ask the user for their name; the length and width of a rectangle; and the length of a square. The program will then output the input name; the area and perimeter of a rectangle with the dimensions they input; and the area and perimeter of a square with the length they input. Tasks The program needs to contain the following A comment header containing...
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...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT