add accidental exit protection
This commit is contained in:
parent
ae6cc86bd4
commit
066c7f3305
94
assistant.py
94
assistant.py
|
@ -302,49 +302,65 @@ def game_loop():
|
||||||
print("Basic commands are:")
|
print("Basic commands are:")
|
||||||
print("(S)tart, (N)ext, (H)elp, (C)heck, (E)xit")
|
print("(S)tart, (N)ext, (H)elp, (C)heck, (E)xit")
|
||||||
while True:
|
while True:
|
||||||
print("Waiting for your input:")
|
try:
|
||||||
command = input()
|
print("Waiting for your input:")
|
||||||
command = command.lower()
|
command = input()
|
||||||
if command in ("a", "abort", "(a)bort"):
|
command = command.lower()
|
||||||
abort_game(game, hint_giver, flag_checker)
|
if command in ("a", "abort", "(a)bort"):
|
||||||
elif command in ("e", "exit"):
|
abort_game(game, hint_giver, flag_checker)
|
||||||
abort_game(game, hint_giver, flag_checker)
|
elif command in ("e", "exit"):
|
||||||
print("Exiting...")
|
abort_game(game, hint_giver, flag_checker)
|
||||||
return
|
print("Exiting...")
|
||||||
elif command in ("s", "start", "(s)tart"):
|
return
|
||||||
start_game(game, level_selector)
|
elif command in ("s", "start", "(s)tart"):
|
||||||
elif command in ("n", "next", "(n)ext"):
|
start_game(game, level_selector)
|
||||||
try:
|
elif command in ("n", "next", "(n)ext"):
|
||||||
if game.level == 0:
|
try:
|
||||||
print("Can't continue, (S)tart the game first!")
|
if game.level == 0:
|
||||||
elif game.level == 5:
|
print("Can't continue, (S)tart the game first!")
|
||||||
print("Can't continue, you are on the last level!")
|
elif game.level == 5:
|
||||||
print("Make sure to run (F)inish and (L)og your progress before exiting.")
|
print("Can't continue, you are on the last level!")
|
||||||
|
print("Make sure to run (F)inish and (L)og your progress before exiting.")
|
||||||
|
else:
|
||||||
|
if check_flag(game.level, flag_checker):
|
||||||
|
try_next_level(game, level_selector)
|
||||||
|
except NoLevelFoundError as err:
|
||||||
|
print("Error encountered: {}".format(err))
|
||||||
|
elif command in ("f", "finish", "(f)inish"):
|
||||||
|
if (not game.game_in_progress and not game.game_finished):
|
||||||
|
print("Can't finish game, game was not started yet.")
|
||||||
|
elif (not game.game_in_progress and game.game_finished):
|
||||||
|
print("Can't finish game, game was already finished earlier.")
|
||||||
else:
|
else:
|
||||||
if check_flag(game.level, flag_checker):
|
if check_flag(game.level, flag_checker):
|
||||||
try_next_level(game, level_selector)
|
finish_game(game)
|
||||||
except NoLevelFoundError as err:
|
elif command in ("i", "info", "information", "(i)nfo", "(i)nformation"):
|
||||||
print("Error encountered: {}".format(err))
|
game.print_info()
|
||||||
elif command in ("f", "finish", "(f)inish"):
|
elif command in ("h", "help", "(h)elp"):
|
||||||
if (not game.game_in_progress and not game.game_finished):
|
print_help()
|
||||||
print("Can't finish game, game was not started yet.")
|
elif command in ("c", "check", "(c)heck"):
|
||||||
elif (not game.game_in_progress and game.game_finished):
|
check_prerequisites()
|
||||||
print("Can't finish game, game was already finished earlier.")
|
elif command in ("l", "log", "(l)og"):
|
||||||
|
player_logging(game, hint_giver, flag_checker)
|
||||||
|
elif command in ("t", "hint", "hin(t)"):
|
||||||
|
give_hint(game, hint_giver)
|
||||||
else:
|
else:
|
||||||
if check_flag(game.level, flag_checker):
|
print("Unknown command. Enter another command or try (H)elp.")
|
||||||
finish_game(game)
|
except EOFError:
|
||||||
elif command in ("i", "info", "information", "(i)nfo", "(i)nformation"):
|
|
||||||
game.print_info()
|
|
||||||
elif command in ("h", "help", "(h)elp"):
|
|
||||||
print_help()
|
|
||||||
elif command in ("c", "check", "(c)heck"):
|
|
||||||
check_prerequisites()
|
|
||||||
elif command in ("l", "log", "(l)og"):
|
|
||||||
player_logging(game, hint_giver, flag_checker)
|
|
||||||
elif command in ("t", "hint", "hin(t)"):
|
|
||||||
give_hint(game, hint_giver)
|
|
||||||
else:
|
|
||||||
print("Unknown command. Enter another command or try (H)elp.")
|
print("Unknown command. Enter another command or try (H)elp.")
|
||||||
|
print("If you want to exit the assistant, please use the `exit` command.")
|
||||||
|
except KeyboardInterrupt:
|
||||||
|
print("You sent a keyboard interrupt to the program.")
|
||||||
|
print("Would you like to exit? yes/no")
|
||||||
|
confirmation = input()
|
||||||
|
confirmation = confirmation.lower()
|
||||||
|
if confirmation in ("y", "yes"):
|
||||||
|
abort_game(game, hint_giver, flag_checker)
|
||||||
|
print("Exiting...")
|
||||||
|
return
|
||||||
|
else:
|
||||||
|
print("Not exiting. Continuing normal operation.")
|
||||||
|
print("Next time, please use the `exit` command to exit.")
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
Reference in New Issue