Question: The code that follows sets up some basic information about the party and the boss, then executes a battle simulation: Code Listing 1 krogg =

The code that follows sets up some basic information about the party and the boss, then executes a battle simulation: Code Listing 1 krogg = Character('Krogg', 180, 20, 20) glinda = Character('Glinda', 120, 5, 20, 5) geoffrey = Character('Geoffrey', 150, 15, 15) party = [krogg, glinda, geoffrey] boss = Character('Boss', 500, 25, 15) round = 1 while (not boss.isDead()) and (not isPartyDead(party)): print('Round', round) # krogg attacks krogg.attack(boss) # geoffrey attacks geoffrey.attack(boss) # glinda heals glinda.heal(party) # boss attacks for partyMember in party: boss.attack(partyMember) # show progress for partyMember in party: print(partyMember) print(boss) print('') round += 1 if isPartyDead(party): 2 print('Your whole party is dead. You lose.') elif boss.isDead(): print('The boss is dead. You are victorious!') The battle simulation, above, requires a class called Character. This class will have the following variables: name (string) hp (number) maxhp (number, initialized to the same value as hp) attackpower (number) defensepower (number) magic (number) The class will have the following methods/member functions: __init__(self, name, hp, attack, defense, magic) initializes the following instance variables: name (from argument name) hp (from argument hp) maxhp (from argument hp) attackpower (from argument attack) defensepower (from argument defense) magic (from argument magic) Note: Magic is an optional parameter, and should have a default value of 0 __str__(self) Returns a simple string representation of the character: e.g. Glinda has 120 HP. This method is invoked when calling print on an object of this class isDead(self) Returns True if this character has HP 0, False otherwise attack(self, otherCharacter) Reduces the other character's HP by damage damage is calculated by this character's attack power minus the other character's defense power Output's an appropriate message heal(self, party) Increases the entire party's HP by this character's magic level Output's an appropriate message Below is the sample output, using the values given in code listing 1: Sample Output 1 Round 1 Krogg does 5 points of damage to Boss Geoffrey does 0 points of damage to Boss Glinda heals 5 hp for Krogg Glinda heals 5 hp for Glinda Glinda heals 5 hp for Geoffrey Boss does 5 points of damage to Krogg Boss does 5 points of damage to Glinda Boss does 10 points of damage to Geoffrey Krogg has 175 HP. Glinda has 115 HP. 3 Geoffrey has 140 HP. Boss has 495 HP. lots of rounds Round 100 Krogg does 5 points of damage to Boss Geoffrey cannot attack because he/she is dead. Glinda heals 5 hp for Krogg Glinda heals 5 hp for Glinda Boss cannot attack because he/she is dead. Boss cannot attack because he/she is dead. Boss cannot attack because he/she is dead. Krogg has 180 HP. Glinda has 120 HP. Geoffrey has 0 HP. Boss has 0 HP. The boss is dead. You are victorious! You should test your program with other values, to ensure that all of your logic works properly.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!