Skip to content

Instantly share code, notes, and snippets.

@Gertkeno
Last active February 27, 2023 22:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Gertkeno/cb8dd0d330aef3b12a7e26a1452c6c2e to your computer and use it in GitHub Desktop.
Save Gertkeno/cb8dd0d330aef3b12a7e26a1452c6c2e to your computer and use it in GitHub Desktop.
import random
import time
player_health = 100
player_experience = 0
player_name = input("Welcome to the land of the Ylsides, what is your name? ")
def start_fight(enemy_name, enemy_health, enemy_damage, experience_awarded):
# Global variables to be modified.
global player_health
global player_experience
# Using empty prints to add space.
print()
print(player_name, "encounters a", enemy_name + "!")
# Loop while the player and the enemy lives, if either dies the loop stops.
while player_health > 0 and enemy_health > 0:
print()
print("Player Health:", player_health, "Enemy Health:", enemy_health)
choice = input("What action to you take!? ").lower()
if choice == "run":
print("You run from the fight! no rewards! BOOOOOOOO!")
return # This keyword stops the current function immediately!
elif choice == "attack":
print("->", enemy_name, "takes 20 points of damage!")
enemy_health -= 20
# TODO: Replace 20 with a player_damage variable.
else:
print("What? are you crazy? you cannot", choice)
if enemy_health > 0:
print("->", player_name, "takes", enemy_damage, "points of damage!")
player_health -= enemy_damage
# Outside of the while loop, the player or the enemy must have died.
if player_health > 0:
# Our player lived, so we give rewards.
print("VICTORY!!", player_name, "gains", experience_awarded, "experience!")
player_experience += experience_awarded
# Function defined! Now to use it!
start_fight("Lil Goblin", 21, 1, 8)
start_fight("Wooden Barrel", 50, 0, 1)
start_fight("Dennis", 30, 9, 2)
if player_experience >= 10:
print("You level up! New Health: 110")
player_experience = 0
player_health = 110
start_fight("Epic Dragon", 39, 100, 10000)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment