Untitled

 avatar
unknown
plain_text
a year ago
1.3 kB
10
Indexable
import random

player1hp = 100
enemy1hp = 120
gameisgoing = False

player_name = input("\nEnter the player's name: ")
print(player_name)

moveon = input("Hello hero, please help us fight the horrible enemy that curses this land. Type 'yes' to proceed: ")
if moveon.lower() == "yes":
    gameisgoing = True

while gameisgoing:
    attackonenemy = input("Type 'sword' to attack: ")
    if attackonenemy.lower() == "sword":
        rand_num = random.randrange(9, 21)
        print(f"You did {rand_num} damage to the monster.")
        enemy1hp -= rand_num
    else:
        print("This did not attack.")

    if enemy1hp <= 0:
        print("You have defeated the enemy!")
        break

    typee = input("Enemy's turn. Type 'defend' to proceed: ")
    if typee.lower() == "defend":
        rand_num = random.randrange(0, 22)
        print(f"Enemy attacked! Your HP is reduced by {rand_num}.")
        player1hp -= rand_num
        print(f"Your current HP: {player1hp}")
    else:
        print("You did not defend properly.")

    if player1hp <= 0:
        print("You have been defeated by the enemy.")
        gameisgoing = False
    elif enemy1hp <= 0:
        print("You have defeated the enemy!")
        gameisgoing = False
    else:
        print("The battle continues.")
Editor is loading...
Leave a Comment