diff --git a/clean_input.py b/clean_input.py index b2c8062..a07b5c4 100644 --- a/clean_input.py +++ b/clean_input.py @@ -5,6 +5,7 @@ __credits__ = "" __email__ = "" import sys +import quartett def io_str(message: str, options: list) -> str: @@ -30,13 +31,9 @@ def io_str(message: str, options: list) -> str: else: if i == "q": - print( - "---------------------\nSpiel wird beendet...\n---------------------") - sys.exit() + end() elif i == "r": - print( - "---------------------\nSpiel wird neu gestartet...\n---------------------") - quartett.main() + restart() else: print('Noch nicht ganz richtig. Hast du deine Auswahl auch richtig geschrieben?') @@ -54,12 +51,9 @@ def io_int(message: str) -> int: unfiltered_input = input(message) if unfiltered_input == "q": - print("---------------------\nSpiel wird beendet...\n---------------------") - sys.exit() + end() elif unfiltered_input == "r": - print( - "---------------------\nSpiel wird neu gestartet...\n---------------------") - #quartett.main() + restart() try: i = int(unfiltered_input) @@ -72,43 +66,72 @@ def io_int(message: str) -> int: except (ValueError, NameError): print("Eingabe nicht gültig, bitte wiederhole deine Eingabe.") -def io_list(message: str, options: list): + +def io_card_selection(message: str): """ check card selection - :param message: 1a - :param options: [{'id': 3, 'number': 0, 'letter': 'd'}, {'id': 9, 'number': 1, 'letter': 'b'}] + :param message: Select something... :return: """ + card_stack = define_card_stack() + while True: - try: - i = str(input(message)) + user_input = input(message) - except (ValueError, NameError): - i = 0 - print("Eingabe nicht gültig, bitte wiederhole deine Eingabe.") + if user_input[0] in "0123" and user_input[1] in "abcdefgh": + for c in card_stack: + if c["number"] == user_input[0] and c["letter"] == user_input[1]: + card = c + return card - if i in options: - return i + elif user_input == "q": + end() + + elif user_input == "r": + restart() else: - if i == "q": - print( - "---------------------\nSpiel wird beendet...\n---------------------") - sys.exit() - elif i == "r": - print( - "---------------------\nSpiel wird neu gestartet...\n---------------------") - quartett.main() - else: - print('Noch nicht ganz richtig. Hast du deine Auswahl auch richtig geschrieben?') + print("Eingabe nicht gültig, bitte wiederhole deine Eingabe.") + def define_card_stack(): """ :return: """ + card_stack = [] + x = 0 for i in range(4): for l in "abcdefgh": - d = {"id": x, "number": i, "letter": l} + d = {"id": str(x), "number": str(i), "letter": l} card_stack.append(d) - x += 1 \ No newline at end of file + x += 1 + + return card_stack + + +def end(): + """ + + :return: + """ + print( + "---------------------\nSpiel wird beendet...\n---------------------") + sys.exit() + + +def restart(): + """ + + :return: + """ + print( + "---------------------\nSpiel wird neu gestartet...\n---------------------") + quartett.central_function() + + + + + + +