Hafta make a text based game for class and it’s due tmmrw but idk how to make it run properly… After the first choice is made it splits into two paths: one where the game ends and one where it continues. It prompts the user to ask to replay if you choose 1 in the first choice cause it ends the game there and then if they dont say yes it’s supposed to break but it just continues the while loop anyway and the game keeps going. I literally just need to figure out how to ask the user if they wanna restart when the game ends and have it actually stop when they say no. I also have the codeHS link if this is too long for here. Sorry if this is worded weirdly I’m in a rush lol.
import random
import time
name=input("Player name: ")
def display_intro():
print()
print('There is a monster lurking around, make the right choices or die...')
time.sleep(2)
print('Be aware that death is always looming aorund the corner...')
time.sleep(2)
print()
print('After falling asleep after a long day of work you abruptly wake up to the sound of'
+ ' knocking on your door. You begrudgingly pull yourself out of bed and slug towards the front'
+ ' door, as you walk closer the sound of the knocking only grows louder and more aggressive.'
+ ' Once you get close to the door and grab the handle the incessant banging suddenly stops.'
+ ' When you open the door there\'s no one there. Do you... ')
time.sleep(4)
print()
def prompt_replay():
replay=input('Would you like to play again? (yes or no): ')
def close_door():
door=''
while door!='1' and door!='2':
print("1 - Close the door and go back to sleep\n2- Walk outside to investigate")
door=input()
return door
def choice1(door):
cooked= random.randint(1,5)
if door=='1':
print()
print('You shut the door thinking it was just some kids playing a pranks and go back to'
+ ' bed...')
time.sleep(2)
if door==cooked:
print('Later in the night the knocking starts again and you get back up, exasperated,'
+ ' and quickly answer the door. This time a large dark shadow envelopes you as you stare'
+ ' in awe at the monstrosity standing at your door. ')
print()
time.sleep(3)
print("YOU DIED")
print()
prompt_replay()
else:
print('After a less than satisfactory night of sleep you wake up in a daze wondering'
+ ' what happened last night. Your thoughts are interrupted by the sound of your coworker'
+ ' calling you, and you move on like nothing happened.')
print()
time.sleep(3)
print("YOU LIVE")
print()
prompt_replay()
elif door=='2':
print()
print('You walk outside to look around your property...')
time.sleep(2)
print('Your front lawn is clear, so you go to the gate leading to the backyard and'
+ ' open it expecting nothing as well...')
time.sleep(2)
if door==cooked:
print('What you see is far from nothing, and befoee you can take in the monstrosity'
+ ' standing before you, everything turns black...')
time.sleep(3)
print("YOU DIED")
print()
prompt_replay()
else:
print()
print('As expected, the backyard is clear, aside from some dark patches in the grass.'
+ ' You walk closer to inspect the patches; they\'re small puddles of a black, oil-like'
+ ' substance that doesn\'t stick to your hand when you touch it. Confused but tired,'
+ ' you brush it off and start to head back into your house, but a shadowy figure catches'
+ ' your attention out of the corner of your eye...')
print()
time.sleep(2)
print('\"' + name + '~\"')
print()
time.sleep(2)
print("You snap your head to the direction of the voice but ")
while True:
display_intro()
choice1(close_door())
if replay!='yes':
break
print()
print("Thanks for playing :)")