INTRO_MESSAGE = ('You are in a locked room.\n'
'You will need to OPEN DOOR to ecape this terrible trap.\n'
'What will you do?\n')
DOOR_MESSAGE = 'You need to OPEN DOOR to escape this insufferable imprisonment.\n'
PICK_UP_KEY_MESSAGE = 'With a determined display of digit dexterity you picked up the KEY!\n'
HAS_KEY_MESSAGE = 'You are currently holding a KEY, your mind is filled with all the possible uses you could have ' \
'for such an item! But for now you ponder if it could fit in the DOOR?\n'
LOCKED_DOOR_MESSAGE = 'The DOOR is currently locked, perhaps you can find a KEY?\n'
OPEN_DOOR_MESSAGE = 'The DOOR swings open and you make a grand escape, vowing to NEVER be outsmarted ' \
'by a strong breeze and automatically locking door ever again!\n'
OTHER_OPTION_MESSAGE = 'Try to stay focused, you need to OPEN DOOR.\n'
def play_the_game():
print(INTRO_MESSAGE)
has_key = False
is_door_unlocked = False
while not is_door_unlocked:
action = input()
match action:
case 'door':
print(DOOR_MESSAGE)
case 'key':
has_key = pick_up_key(has_key)
case 'open door':
is_door_unlocked = try_open_door(has_key)
case _:
print(OTHER_OPTION_MESSAGE)
def try_open_door(has_key):
if has_key:
print(OPEN_DOOR_MESSAGE)
else:
print(LOCKED_DOOR_MESSAGE)
return has_key
def pick_up_key(has_key):
if has_key:
print(HAS_KEY_MESSAGE)
else:
print(PICK_UP_KEY_MESSAGE)
return True
if __name__ == '__main__':
while True:
play_the_game()
print('Do you want to play again?')
if not input() == "yes":
break