Question: Using Python: For this part of the assignment, we will add a level up system to our RPG characters. Use the code for the Character
Using Python:
For this part of the assignment, we will add a level up system to our RPG characters. Use the code for the Character class from the labs as a starting point.
Add an xpGained attribute to the Character class. This is how much XP would be gained by defeating this character in a battle. The value of xpGained will be passed into the constructor.
Add two more attributes, xp and level, to the Character class. The attribute xp is how much XP has been collected so far, and will be initialized to 0. The attribute level is the current level of the character, and will be initialized to 1.
Write a new function, gainXP, which will add some amount of experience to the character, possibly leveling them up as well. Adding the experience is simply a matter of adding it to the instance variable. To determine if the character levels up, however, we'll use a series of lists with values are described in the table below:

If the character's XP exceeds the minimum for a level, their level should be increased, along with their attack, defense, and magic power. All of these values should come from the tables, above.
Add code to the attack() function that will call gainXP with the appropriate arguments, when the attack results in defeating the other character.
Now, we'll simulate a huge battle. We're going to have a list of enemies to ght. Each enemy will ght your party one at a time, meaning only one enemy attacks per round (though your party can still all attack each round). You will need to modify the code of the battle loop to accommodate:
Move onto the next enemy when an enemy is defeated
Check to see if all enemies have been defeated to exit the loop (instead of just the boss)
This program will be challenging to debug. It is recommended that you implement a better __str__ function and output every character's stats at the end of each round. You should also display messages for everything that happens (e.g. a character gaining XP, a character leveling up).
The following code sets up a pretty close battle, and you should use it for testing:
krogg = Character('Krogg', 180, 0, 20, 20) glinda = Character('Glinda', 120, 0, 5, 20, 5) geoffrey = Character('Geoffrey', 150, 0, 15, 15) party = [krogg, glinda, geoffrey]
enemy1 = Character('Spider 1', 50, 100, 10, 1) enemy2 = Character('Spider 2', 50, 100, 10, 1) enemy3 = Character('Wolf 1', 100, 250, 15, 5) enemy4 = Character('Wolf 2', 100, 250, 15, 5) enemy5 = Character('Bear 1', 200, 350, 20, 10) enemy6 = Character('Bear 2', 200, 350, 20, 10) enemy7 = Character('Red Dragon', 300, 800, 30, 20) enemy8 = Character('Blue Dragon', 400, 1000, 35, 20) enemies = [enemy1, enemy2, enemy3, enemy4, enemy5, enemy6, enemy7, enemy8]
Here is some sample output (using the above character stats):
Round 1
Action: Krogg does 19 points of damage to Spider 1 Geoffrey does 14 points of damage to Spider 1 Glinda heals 5 hp for Krogg Glinda heals 5 hp for Glinda Glinda heals 5 hp for Geoffrey Spider 1 does 0 points of damage to Krogg Spider 1 does 0 points of damage to Glinda Spider 1 does 0 points of damage to Geoffrey
Character status: Krogg (HP:180, XP:0, Level:1, Attack:20, Defense:20) Glinda (HP:120, XP:0, Level:1, Attack:5, Defense:20) Geoffrey (HP:150, XP:0, Level:1, Attack:15, Defense:15) Spider 1 (HP:17, XP:0, Level:1, Attack:10, Defense:1) Spider 2 (HP:50, XP:0, Level:1, Attack:10, Defense:1) Wolf 1 (HP:100, XP:0, Level:1, Attack:15, Defense:5) Wolf 2 (HP:100, XP:0, Level:1, Attack:15, Defense:5) Bear 1 (HP:200, XP:0, Level:1, Attack:20, Defense:10) Bear 2 (HP:200, XP:0, Level:1, Attack:20, Defense:10) Red Dragon (HP:300, XP:0, Level:1, Attack:30, Defense:20) Blue Dragon (HP:400, XP:0, Level:1, Attack:35, Defense:20)
The enemies are dead. You are victorious! ... more rounds ... Round 59
Action: Krogg does 12.5 points of damage to Blue Dragon Geoffrey cannot attack because he/she is dead. Glinda cannot heal because he/she is dead.
Blue Dragon does 7.5 points of damage to Krogg Blue Dragon does 15 points of damage to Glinda Glinda has been defeated. Blue Dragon gained 0 XP.
Blue Dragon does 12.5 points of damage to Geoffrey Geoffrey has been defeated. Blue Dragon gained 0 XP.
Character status: Krogg [DEAD] Glinda [DEAD] Geoffrey [DEAD] Spider 1 [DEAD] Spider 2 [DEAD] Wolf 1 [DEAD] Wolf 2 [DEAD] Bear 1 [DEAD] Bear 2 [DEAD]
Red Dragon [DEAD] Blue Dragon (HP:5.0, XP:0, Level:1, Attack:35, Defense:20)
Your whole party is dead. You lose.
List Variable NameDescription levels levelMinXP levelAttackGain How much attack power is gained at this level [ 5 , 7 . 5 , 10, 12. 5, 15) level DefenseGain How much defense power is gained at this level [ 25, 5, 7 . 5, 10, 15) levelMagicGain How much magic power is gained at this level 2,3,5,8,10] Sample Values [2,3,4,5,61 [100,200,300,400,500] The level numbers nxP Minimum XP required to galn this level List Variable NameDescription levels levelMinXP levelAttackGain How much attack power is gained at this level [ 5 , 7 . 5 , 10, 12. 5, 15) level DefenseGain How much defense power is gained at this level [ 25, 5, 7 . 5, 10, 15) levelMagicGain How much magic power is gained at this level 2,3,5,8,10] Sample Values [2,3,4,5,61 [100,200,300,400,500] The level numbers nxP Minimum XP required to galn this level
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
