Question: Programming on Python (add comments) Requirements - Player Class The requirements for the Player class are given below. Please ensure that your methods have the


Programming on Python (add comments)
Requirements - Player Class The requirements for the Player class are given below. Please ensure that your methods have the EXACT naming as specified! Failure to do so will result in lost marks. Note: you must include a try and except statement in at least one function in your code. 1. Create an __init__(name) method that takes the following arguments: name: A string representing the name of the player. The variable is assigned to an instance variable. If name is an empty string, the instance variable is set to the string "Default". The method also initializes the following instance variables: a. An int representing the player's health. The player's health is initially set to 100 b. An int representing the player's level. The player's initial level is 0. c. An int representing the player's current score. The player's initial score is 0. d. An int representing the score required to reach the next level. The initial value is 50. e. A list of lists representing the current set of attacks. Each sub-list has a length of 2. The first element is a string that represents the name of the attack and the second element is an int representing the strength of the attack. A player has 3 different attacks. The player's initial attacks are provided below: [["Fast attack",5],["Slow attack", 15],["Default Special Attack",20]] 2. Create the following accessor methods: a. get_name: Returns the player's name. b. get_health: Returns the player's health. C. get_level: Returns the player's level. d.get_score: Returns the player's current score e. get_next_lvl_score: Returns the score required to reach the next level. f. get_attacks: Returns the player's attack set. 3. Create the mutator method raise_health(val). val: An int. Method description: The method does not return anything, but increases the player's health by val. If the val is negative, the method does nothing. The player's health cannot exceed 100 so if the sum of their current health and val exceeds 100, then set health to 100. 4. Create the mutator method replace_attack(i, name, strength). I: An int representing an index (either 0, 1, or 2). name: A string representing the name of an attack. strength: An int representing the strength of the attack associated with name. Method description: The method replaces the list at index i in the attack list instance variable with a list of length 2 where the first element is name and the second element is strength. 5. Create the mutator method take_damage(quantity). quantity: An int. Method description: The method deducts quantity from the instance variable that stores the players health. The player's health is set to 0 if quantity is greater than or equal to the player's current health 6. Create the mutator method perform_attack(i, player_2). I: An int representing an index. Assume that the value must be either 0,1, or 2. player_2: A Player object. Method description: The method simulates a user attack on player_2 using the attack at index i from the attack instance variable list of lists. The method performs the following actions: player_2's health is calculated and stored in a variable. The object calling the method uses the attack associated with index i from the current set of attacks to inflict damage on player_2 (i.e player_2 will take damage equal to attack i's strength). The difference between player_2's current health and player_2's health before the attack is calculated and stored in the variable damage_given. The value of damage_given is added to the player's current score if the sum of damage_given and current score will result in a value less than the instance variable containing the score required to reach the next level. . If the sum of damage_given and player score results in a value equal to or higher than the score required to reach the next level, then the following actions are performed o a. The player's level is increased by 1. o b. The player's current score is set to 0. oc. The score required to reach the next level is increased by 20. od. Each of the player's attack strengths are increased by 5. Requirements - Battle Simulation In addition to the Player class, you are required to implement a function to simulate a battle. The function definition is given below: 1. Create the function simulate_battle(player_1, player_2, player_1_moves, player_2_moves). player_1: A Player object. player_2: A Player object. player_1_moves: A list of integers where each element is between 0 and 2 (inclusive) player_2_moves: A list of integers where each element is between 0 and 2 (inclusive) Method Description: The function performs the following algorithm: . For each elementi in player_1_moves, player_1 attacks player_2 using the perform_attack method with attack i. If player_2's health becomes 0 at any point, player_1 wins the battle. . Then, for each elementi in player_2_moves, player_2 attacks player_1 using the perform_attack method with attack i. If player_1's health becomes 0 at any point, player_2 wins the battle. Note: All Player 1 attacks should occur first before all Player 2 attacks Return: A string representing the name of the player object that won the battle. If there is no winner, an empty string is provided
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
