Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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

Modern Database Management

Authors: Jeffrey A. Hoffer Fred R. McFadden

4th Edition

0805360476, 978-0805360479

More Books

Students also viewed these Databases questions

Question

Describe the bureaucratic perspective on organization design.

Answered: 1 week ago

Question

LO3.2 Describe demand and explain how it can change.

Answered: 1 week ago

Question

LO3.3 Describe supply and explain how it can change.

Answered: 1 week ago