# RPG STAGE 3 # Simple battle between the player and an enemy. # Very simple input validation. import random import math # dummy values, change as desired for testing name, strength, skill, vitality = ("Bob",8,10,20) enemyType, enemyStrength, enemySkill, enemyVitality = ("kobold",6,9,12) # player can attack or run away prompt = "Out of the darkness steps a fierce "+enemyType+". Do you attack [Y/N]? " action = input(prompt) while not (action == "Y" or action == "N"): action = input("That's not a valid option. Please enter Y or N: ") # player chooses to attack if action == "Y": while vitality > 0 and enemyVitality > 0: # display player/enemy stats print(name, "has the following stats: ") print("STRENGTH", strength, "SKILL", skill, "VITALITY", vitality) print("The", enemyType, "has the following stats: ") print("STRENGTH", enemyStrength, "SKILL", enemySkill, "VITALITY", enemyVitality) # generate random values to determine who hits who playerDie1 = random.randint(1,6) playerDie2 = random.randint(1,6) playerRoll = playerDie1 + playerDie2 playerAttack = playerRoll + skill enemyDie1 = random.randint(1,6) enemyDie2 = random.randint(1,6) enemyRoll = enemyDie1 + enemyDie2 enemyAttack = enemyRoll + enemySkill # Uncomment this block for debugging purposes print("Player rolled a", playerDie1, "and a", playerDie2, "for a sum of", playerRoll) print("The", enemyType, "rolled a", enemyDie1, "and a", enemyDie2, "for a sum of", enemyRoll) print(name, "has an attack value of", playerAttack) print("The", enemyType, "has an attack value of", enemyAttack) # special cases (critical hits, fatalities, fumbles) if playerRoll == 12 and enemyRoll == 12: damage = 4 enemyVitality -= damage vitality -= damage print("There is a flurry of sparks and fangs... both", name, "and the", enemyType, "hit each other for", damage, "points of damage.") elif playerRoll == 12 and enemyRoll == 2: enemyVitality = 0 print(name, "deals the", enemyType, "a FATAL BLOW!") elif playerRoll == 2 and enemyRoll == 12: vitality = 0 print("The", enemyType, "deals", name, "a FATAL BLOW!") elif playerRoll == 2 and enemyRoll == 2: damage = 2 enemyVitality -= damage vitality -= damage print("Both", name, "and the", enemyType, "fumble, grazing each other for", damage, "points of damage.") elif playerRoll == 12: damage = 2*math.ceil(strength/3) enemyVitality -= damage print(name, "makes a CRITICAL HIT for", damage, "points of damage!") elif enemyRoll == 12: damage = 2*math.ceil(strength/3) vitality -= damage print("The", enemyType, "makes a CRITICAL HIT for", damage, "points of damage!") elif playerRoll == 2: damage = math.ceil(strength/3)+1 vitality -= damage print(name, "fumbles. The", enemyType, "strikes for", damage, "points of damage.") elif enemyRoll == 2: damage = math.ceil(strength/3)+1 enemyVitality -= damage print("The", enemyType, "fumbles.", name, "strikes for", damage, "points of damage.") # standard damage else: if playerAttack > enemyAttack: damage = math.ceil(strength/3) print(name, "strikes the", enemyType, "for", damage, "points of damage.") enemyVitality -= damage elif playerAttack < enemyAttack: damage = math.ceil(strength/3) print("The", enemyType, "hits the player for", damage, "points of damage.") vitality -= damage else: print("You and the", enemyType, "parry each other's blows. No damage!") # someone dies if vitality <= 0 and enemyVitality <= 0: print("Both", name, "and the", enemyType, "have died in battle.") elif vitality <= 0: print("Alas!", name, "has been slain by the", enemyType+".") else: print("You have slain the", enemyType+", brave warrior.") # player didn't fight else: print(name, "cowardly runs away to live another day.")