Question: Using Python and lists: I already have the code, but something's missing and i can't figure it out. ************************************************************************************ #Code Listing partyNames = ['Krogg', 'Glinda',

Using Python and lists:

I already have the code, but something's missing and i can't figure it out.

************************************************************************************

#Code Listing

partyNames = ['Krogg', 'Glinda', 'Geoffrey'] partyHP = [180, 120, 150] partyAttack = [20, 5, 15] partyDefense = [20, 20, 15] partyDead = [False, False, False] bossAttack = 25 bossDefense = 15 bossHP = 500

while (bossHP >= 0):

print 'Round', round

# Krogg Attack if partyDead[0] == False: bossDamage = partyAttack[0] - bossDefense bossHP -= bossDamage print 'Krogg does ',bossDamage ,'points of damage to Boss' else: print 'Krogg cannot attack because he is dead'

# Geoffrey Attack if partyDead[2] == False: bossDamage = partyAttack[2] - bossDefense bossHP -= bossDamage print 'Geoffrey does ',bossDamage ,'points of damage to Boss' else: print 'Geoffrey cannot attack because he is dead'

# Glinda Heal if partyDead[1] == False: for i in range(len(partyHP)): if partyDead[i] == False: partyHP[i] = partyHP[i] + 5 else: print 'Glinda cannot heal, because',partyNames[i] ,'is dead' else: print 'Glinda cannot heal, because she is dead'

# Boss Attack for i in range(len(partyHP)): if partyDead[i] == False: partyDamage = bossAttack - partyDefense[i]] partyHP[i] = partyHP[i] - partyDamage print 'The Boss cannot attack, because',partyNames[i] ,'is dead' else: print 'The Party is dead, you lose.'

round += 1

**************************************************************

For this lab, you will experiment with lists, while simulating a battle between a party of characters and an enemy character.

The code that follows sets up some basic information about the party and the boss:

 Code Listing 1  
 partyNames = ['Krogg', 'Glinda', 'Geoffrey'] partyHP = [180, 120, 150] partyAttack = [20, 5, 15] partyDefense = [20, 20, 15] 
 partyDead = [False, False, False] 
 bossAttack = 25 bossDefense = 15 bossHP = 500 

Your code will be similar to the previous lab, where you will create a loop simulating rounds of battle. This loop will exit when either the boss is dead. During each loop, the following events will take place:

Krogg will attack the boss

Geo rey will attack the boss

Glinda will heal the entire party by 5 points each

The boss will attack all party members simultaneously

The rules for battle are exactly the same as for the previous labs. The damage taken is equal to the attack power of the attacker minus the defense power of the target.

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 Boss does 5 points of damage to Krogg Boss does 5 points of damage to Glinda Boss does 10 points of damage to Geoffrey 
 ... lots of rounds ... 

Course: Lab: Topic:

CSCI 1030U: Introduction to Computer Science #4 Lists

Round 101 Krogg does 5 points of damage to Boss Geoffrey cannot attack because he is dead Boss does 5 points of damage to Krogg Boss does 5 points of damage to Glinda Boss: 5 Krogg: 180 Glinda: 120 Geoffrey: 0 

You should test your program with other values, to ensure that all of your logic works properly. Make sure you are able to identify what happens when the following initial data is used:

 Code Listing 2  
 partyNames = ['Krogg', 'Glinda', 'Geoffrey'] partyHP = [180, 120, 150] partyAttack = [20, 5, 15] partyDefense = [20, 20, 15] 
 partyDead = [False, False, False] 
 bossAttack = 25 bossDefense = 25 bossHP = 500 

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!