Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

please code in python b.) If the second fighter survives the attack (call is_alive), he then attacks the first. ii.) This function returns nothing. 3.)

please code in python

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed
b.) If the second fighter survives the attack (call is_alive), he then attacks the first. ii.) This function returns nothing. 3.) In main: i.) Create two instances of the Fighter class. The name of the first fighter must be Death_Mongrel; the second must be Hurt_then_Pain. ii.) Next repeat the following process until one (or both) fighters have been slain (remember, a Fighter is dead when it has less than I hit point): a.) Print the combat round number (start with 1) as shown in the following example: ROUND 1 NOTE: There are 19 equal signs on each side b.) Print each Fighter's information (remember how the _ repr_ method works). E.g.: Bonzo (HP : 4) Chubs (HP : 7)Combat rounds will continue until one (or both) combatants are dead. Create a new file called "rpg. py". In the file: 1.) Write a class called Fighter. Inside the class: A.) Write an initializer method called_init_that takes 2 parameters: self (all of your methods will have this as the first parameter), and name (a string, the name of a fighter). The initializer method will: . set a name attribute to the value of the name parameter. . set a hit_points attribute to 10 (i.e. all fighters begin life with 10 hit points.) B.) Write a method called_repr_that takes one parameter: self. The method returns a string showing the name and hit points of the instance in the following format: Bonzo (HP : 9) . In this example "Bonzo" is the Fighter's name and he currently has 9 hit points. C.) Write a method called take_damage that takes two parameters: self (the Fighter instance that calls the method), and damage_amount (an integer representing the number of hit points of damage that have just been inflicted on this Fighteri:this Fighter): i.) The method should first decrease the hit_points attribute by the damage_amount. ii.) It should next check to see if the Fighter has died from the damage: . A hit_points value that is zero or less indicates death. In that case print a message as shown in the following example: \\tAlas, Bonzo has fallen! - In this example the Fighter's name is "Bonzo" . Otherwise print a message as shown in the following example: AtBonzo has 5 hit points remaining. - In this example the Fighter's name is "Bonzo" and he has 5 hit points left over after the damage. iii.) This method returns nothing. D.) Write a method called attack that takes two parameters: self (the Fighterrpg_main_out_correcttxt - Notepad File Edit Format View Help ROUND 1 Death_Mongrel (HP: 10) Hurt_then_Pain (HP: 10) Hurt_then_Pain attacks Death_Mongrel! Hits for 4 hit points! Death_Mongrel has 6 hit points remaining. Death_Mongrel attacks Hurt_then_Pain! Misses ! Death_Mongrel (HP: 6) Hurt_then_Pain (HP: 10) Death_Mongrel attacks Hurt_then_Pain! Hits for 3 hit points! Hurt_then_Pain has 7 hit points remaining. Hurt_then_Pain attacks Death_Mongrel! Hits for 2 hit points! Death_Mongrel has 4 hit points remaining. BEEPERS ROUND 3 =EEEE= Death_Mongrel (HP: 4) Hurt_then_Pain (HP: 7) Death_Mongrel attacks Hurt_then_Pain! Hits for 5 hit points! Hurt_then_Pain has 2 hit points remaining. Hurt_then_Pain attacks Death_Mongrel! Misses! ==== ROUND 4 ====: Death_Mongrel (HP: 4) Hurt_then_Pain (HP: 2) Death_Mongrel attacks Hurt_then_Pain! Hits for 5 hit points! Alas, Hurt_then_Pain has fallen! The battle is over! Death_Mongrel (HP: 4) Hurt_then_Pain (HP: -3)D.) Write a method called attack that takes two parameters: self (the Fighter instance that calls the method), and other (another Fighter instance being attacked by self) i.) The method will print the name of the attacker and attacked in the following format: Bonzo attacks Chubs! ii.) Next determine whether the attack hits by generating a random integer between 1 and 20. Use the randrange function from the random module to get this number. A number that is 12 or higher indicates a hit*: . For an attack that hits: a.) Generate a random integer between 1 and 6 (use random. randrange) to represent the amount of damage inflicted by the attack. Do not use the from random import randrange syntax. randrange works like range, not like randint (think about the upper bounds you choose). b.) Print the amount of damage inflicted as in the following example: \\tHits for 4 hit points! c.) Invoke the take_damage method on the victim (i.e. on other), passing it the amount of damage inflicted. . For an attack that misses, just print the following message:\\tMisses ! iii.) This method returns nothing E.) Write a method called is_alive that takes one parameter: self (the Fighter instance that calls the method). i.) The method returns True if self has a positive number of points, False otherwise. 2.) Outside of the class write a function called combat_round that takes two parameters. The first is an instance of Fighter. The second is another instance of Fighter. i.) The function determines which of the two fighters attacks first for the round by generating a random integer (use randrange) between 1 and 6 for each fighter: . If the numbers are equal: a.) Print the following message: Simultaneous! b.) Have each fighter instance call his attack method on the other fighter (the first fighter in the argument list must attack first to make the test work correctly) . If one number is larger: a.) The fighter with the larger roll attacks first (by calling his attack method and passing it the fighter being attacked)Chubs (HP : 7) c.) Use the input function to pause the program (like we did in our turtle graphics programs) until the user presses enter. Prompt the user with the following message: Enter to Fight! d.) Use your combat_round function to simulate a single round of combat. *For the curious: The numbers are from Advanced Dungeons & Dragons in which you roll a 20 sided die to determine a hit. They assume the attacker is a Ist level Fighter swinging a club and the defender is wearing leather armor. iii.) Finally print a message indicating the battle has ended, followed by the information for each of the Fighters, as shown in the following example: The battle is over! Bonzo (HP : 3) Chubs (HP: -2) 4.) Adjust all of your output so that it looks pretty. See the example output below. 5.) Verify that your documentation makes sense and that you've added documentation to each of your functions.1.0) RPG COMBAT (100 POINTS) 1.1) DETAILS In this assignment you will write a program to simulate combat for a simple Role Playing Game (RPG). The game will have a single type of character, the Fighter. Each individual Fighter will have an integer value called "hit points" that represents his/her current health (the amount of damage he/she can sustain before death). The program will simulate combat between two Fighters. Combat will be divided into rounds. During each round each combatant will make one attempt to strike the other. Determining which Fighter attacks first in a round is important because the first attacker might kill his opponent before the opponent has a chance to attack him. In table top RPG's, the order of attacks is often determined by rolling dice. For example, each combatant rolls a six-sided die. The higher roller attacks first. The lower roller attacks second if he is still alive. We'll use random numbers to simulate the rolling of dice. In the event of a tie, we'll consider the attacks to occur simultaneously (i.e. the Fighters attempt to strike each other at the exact same moment). During a simultaneous attack both Fighters will get to attack even if one (or both) is (are) killed during that round We'll use a random number to determine whether an attack attempt is successful or not. Each successful attack will inflict damage on the opponent. To simulate damage, we'll reduce the opponent's hit points by another random number. When a Fighter's hit points are reduced to 0 (or less than () he is considered to be dead

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Financial management theory and practice

Authors: Eugene F. Brigham and Michael C. Ehrhardt

12th Edition

978-0030243998, 30243998, 324422695, 978-0324422696

Students also viewed these Programming questions