# RPG STAGE 4 # Simple Boss Battle. Uses functions to separate tasks. # Better input validation. import random import rpg_functions as rpg # DUMMY VALUES, CHANGE AS DESIRED FOR TESTING PURPOSES name, strength, skill, vitality, luck = ("Bob",8,10,20,7) superAttacks = ("SLASH","FLYING KICK") bossType, bossStrength, bossSkill, bossVitality, bossLuck = ("wyvern",10,7,40,3) bossAttacks = ("FIREY BLAST","TAIL WHIP") # see who starts first: hero has 75% chance of starting heroTurn = True start = rpg.rollDice(1,4) if start == 1: heroTurn = False # start the battle: keep playing until the hero/boss dies, or the hero flees print("The boss of this lair, a fierce", bossType+", steps out of the darkness and attacks!") skillPenalty = False while vitality > 0 and bossVitality > 0: # Display stats print(name, "has", vitality, "vitality points.") print("The", bossType, "has", bossVitality, "vitality points.") # HERO'S TURN? if heroTurn: action = rpg.getBattleAction() if action in "Aa": # standard attack if rpg.playerWinsRound(skill, bossSkill): damage = rpg.getDamage(strength, luck) print(name, "attacks, and hits the", bossType, "for", damage, "damage.") bossVitality -= damage else: print(name, "attacks, but misses!") elif action in "Ss": # super attack: double damage if success, skill decrease if not attackType = random.choice(superAttacks) if rpg.playerWinsRound(skill, bossSkill): damage = rpg.getDamage(strength, luck, "super") print(name, "uses a", attackType, "on the", bossType, "for", damage, "damage!") bossVitality -= damage else: print(name, "tries a", attackType+", but misses!", name+"'s skill temporarily decreases by 1.") skillPenalty = True skill -= 1 # flee else: fleeAttempt = rpg.rollDice(6, 3) if fleeAttempt < luck: # get away print("You are fortunate, and escape the battle.") break else: # unsuccessful: take token damage damage = rpg.rollDice(1,3) print("You cannot escape. In your attempt to flee, you take", damage, "damage.") vitality -= damage # BOSS'S TURN? Boss has 80% chance of a standard attack, 20% of boss attack, does not flee else: attack = rpg.rollDice(1,5) if attack == 1: # boss attack: triple damage if success attackType = random.choice(bossAttacks) if rpg.playerWinsRound(skill, bossSkill): print("The", bossType, "uses a fearsome", attackType+", but misses!") else: damage = rpg.getDamage(bossStrength, bossLuck, "super") print("The", bossType, "uses a fearsome", attackType, "for", damage, "damage!") vitality -= damage else: # standard attack if rpg.playerWinsRound(skill, bossSkill): print("The", bossType, "attacks, but misses!") else: damage = rpg.getDamage(bossStrength, bossLuck) print("The", bossType, "attacks, and hits", name, "for", damage, "damage.") vitality -= damage # restore player's skill penalty, if necessary if skillPenalty: print(name+"'s skill penalty is over.") skillPenalty = False skill += 1 # swap hero/boss turns if heroTurn: heroTurn = False else: heroTurn = True if vitality <= 0: print("Alas! Poor", name, "has died in battle!") elif bossVitality <= 0: print("Hooray!", name, "is victorious in battle!") else: print(name, "has run away to fight another day.")