This is my first text-based game I made. It's very small because I just learned Python and wanted to start small and then code bigger programs. Please comment on this.
import random
import time
import sys
def fight_enemy(enemy_name, min_enemy_damage, max_enemy_damage, min_player_damage, max_player_damage):
enemy_damage_dealt = random.randint(min_enemy_damage, max_enemy_damage)
player_damage_dealt = random.randint(min_player_damage, max_player_damage)
if enemy_damage_dealt > player_damage_dealt:
print("Uh-oh! You died!")
game_over()
elif enemy_damage_dealt < player_damage_dealt:
print("You killed the {enemy_name}".format(enemy_name=enemy_name))
its_getting_late()
else:
print("You walk away unscathed, but the {enemy_name} still lives.".format(enemy_name=enemy_name))
its_getting_late()
def fight_enemy_2(enemy_name, min_enemy_damage, max_enemy_damage, min_player_damage, max_player_damage):
enemy_damage_dealt = random.randint(min_enemy_damage, max_enemy_damage)
player_damage_dealt = random.randint(min_player_damage, max_player_damage)
if enemy_damage_dealt > player_damage_dealt:
print("Uh-oh! You died!")
game_over()
elif enemy_damage_dealt < player_damage_dealt:
print("You killed the {enemy_name}".format(enemy_name=enemy_name))
game_end()
else:
print("You walk away unscathed, but the {enemy_name} still lives.".format(enemy_name=enemy_name))
game_end()
def intro():
name = input("Enter you name: ")
print("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~")
print("Welcome to the Wildlife %s" %(name))
print("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~")
time.sleep(1)
desert()
def desert():
print("You are in the middle of a Desert in Africa")
time.sleep(2)
print("All you see is Sand. EVERYWHERE!!!")
time.sleep(2)
print("You start walking")
time.sleep(2)
print("You see a Snake")
ch1 = str(input("Do you wanna attck the Snake? [y/n]: "))
if ch1 in ['y', 'Y', 'YES', 'Yes', 'yes']:
time.sleep(2)
fight_enemy('Snake', 1, 7, 1, 7)
elif ch1 in ['n', 'N', 'No', 'NO', 'no']:
print("You slowly back away")
time.sleep(1)
print("You managed to get away from the Snake")
print("But you fell in a sinkhole and died")
game_over()
def game_end():
print("Congratulations you won!!!")
ch4 = str(input("Do you wanna play again? [y/n] "))
if ch4 in ['y', 'Y', 'YES', 'Yes', 'yes']:
intro()
elif ch4 in ['n', 'N', 'No', 'NO', 'no']:
print("Thank you for playing")
def its_getting_late():
time.sleep(1)
print("Its starting to get late")
ch2 = str(input("Do you wanna go to sleep? [y/n]: "))
if ch2 in ['y', 'Y', 'YES', 'Yes', 'yes']:
print("You were shot dead last Night")
elif ch2 in ['n', 'N', 'No', 'NO', 'no']:
print("You stay up")
print("You see a person")
ch3 = str(input("Do you wanna attack the person? [y/n]: "))
if ch3 in ['y', 'Y', 'YES', 'Yes', 'yes']:
time.sleep(1)
fight_enemy_2('Enemy', 4, 9, 1, 7)
elif ch3 in ['n', 'N', 'No', 'NO', 'no']:
print("You try to run away")
print("But the Enemy is faster than you and stabs you")
game_over()
def game_over():
print("You lost")
ch5 = str(input("Do you wanna play again? [y/n] "))
if ch5 in ['y', 'Y', 'YES', 'Yes', 'yes']:
intro()
elif ch5 in ['n', 'N', 'No', 'NO', 'no']:
print("Thank you for playing")
intro()