basic-rpg-fight-or-flee

basic-rpg-fight-or-flee @ github

In a role playing game setting, the user fights a bandit. Both sides have a health bar that will decrease, and a custom message printed depending on who is successful in the fight.

import random

print('RPG Fighter v1.1\n')

def Intro():
    print('Your exploring the lost woods of Fantasy Land.\n')

def Health():
    health = 18
    return health
    
def EnemyHealth():
    health = 15
    return health
        
def EnemyLow(danger, creature, weapon):
    print('Suddenly, you face a ' + danger + ' ' +  creature + 
    ' with a ' + weapon + '\n')

def Fight():
    health = Health()
    enemy_health = EnemyHealth()
    while health > 0:
        action = input('(F)ight or (R)un Away?\n')
        if action == 'f' or action == 'F':
            health -=  random.randint(1,3)
            enemy_health -= random.randint(1,3)
            if health <= 0:
                print('You strike one last time, before falling' +
                        ' to the floor, being quite dead.')
                break
            elif enemy_health <= 0:
                print('You killed the enemy! You take a nice helping' +
                    ' of treasure.')
                break
            else:
                print('\nYou strike a mighty blow!')
                print('Your health ' + str(health))
                print('Enemy health ' + str(enemy_health))
        elif action == 'r' or action == 'R':
                print('You run away to live to fight another day. A bit'
                ' pathetic for a fighter though dont you think?')
                break

playAgain = 'y'
while playAgain == 'y' or playAgain == 'Y':        
    
    Intro()
    EnemyLow('worthless','bandit', 'sword!')
    Fight()

    print('\nPlay again or quit? Y or N')
    playAgain = input()