diff --git a/untitled/content.py b/untitled/content.py index 5c95f5b..303be50 100644 --- a/untitled/content.py +++ b/untitled/content.py @@ -12,6 +12,9 @@ ITEMS = {"food": 3, "medicine": 5, "catnip": 5} BASE_INVENTORY = {item: 0 for item in ITEMS} +WORK_START_LETTERS = 2 +WORK_EARN_PER_ROUND = 3 + CAT_COLORS = [ "orange tabby", "black", diff --git a/untitled/rules.py b/untitled/rules.py index 8b0745b..ebf92cd 100644 --- a/untitled/rules.py +++ b/untitled/rules.py @@ -60,3 +60,7 @@ def buy(player, item, price): player.money -= price player.inventory[item] += 1 return True + + +def earn(player, amount): + player.money += amount diff --git a/untitled/screens/common.py b/untitled/screens/common.py index 7973fa7..5c63f24 100644 --- a/untitled/screens/common.py +++ b/untitled/screens/common.py @@ -1,5 +1,5 @@ from untitled import ui -from untitled.screens import shop +from untitled.screens import shop, work def options(): @@ -14,6 +14,8 @@ def options(): def go_to(save): - match ui.select("Where do you want to go?", ["The shop", "Back"]): + match ui.select("Where do you want to go?", ["The shop", "Work", "Back"]): case "The shop": shop.shop(save) + case "Work": + work.work(save) diff --git a/untitled/screens/house.py b/untitled/screens/house.py index 642c7ce..25f586a 100644 --- a/untitled/screens/house.py +++ b/untitled/screens/house.py @@ -14,7 +14,7 @@ def house(save: model.Save): case "Check on your cat": rules.reconcile(save.cat, time.time()) print( - f"{save.cat.name}, {generation.generate_trait_sentence(save.cat.traits).lower()}\nFullness: {round(save.cat.fullness,1)}\nHappiness: {round(save.cat.happiness,1)}" + f"{save.cat.name}, {generation.generate_trait_sentence(save.cat.traits).lower()}\nFullness: {round(save.cat.fullness,1)}\nHappiness: {round(save.cat.happiness,1)}\nMoney: {save.player.money}" ) case "Feed your cat": rules.reconcile(save.cat, time.time()) diff --git a/untitled/screens/work.py b/untitled/screens/work.py new file mode 100644 index 0000000..4a8c934 --- /dev/null +++ b/untitled/screens/work.py @@ -0,0 +1,51 @@ +import random +import string +import time + +from untitled import content, rules, ui + + +def work(save): + length = content.WORK_START_LETTERS + total_earned = 0 + lost = False + print("Welcome to work!") + print("The rules:") + print( + "Each round, a string of letters will appear, when it says go, type them from memory. If you miss one, you lose, each round gets more money." + ) + if not ui.confirm("Would you like to start?"): + return + for i in range(3, 0, -1): + print(i) + time.sleep(1) + ui.clear() + print("Start!") + while not lost: + seconds = 1 + (length * 0.5) + letters = random.choices(string.ascii_lowercase, k=length) + print(f"Round {len(letters)-1}") + print("Memorize:", " ".join(letters)) + for i in range(round(seconds), 0, -1): + print(i) + time.sleep(1) + ui.clear() + print(f"Round {len(letters)-1}") + print("Type!") + for letter in letters: + key = ui.getch().lower() + print(key, end=" ", flush=True) + if key != letter: + print(f"\nThe correct key was: {letter}") + lost = True + break + if not lost: + total_earned += content.WORK_EARN_PER_ROUND + print("\nCorrect!") + time.sleep(1) + ui.clear() + length += 1 + rules.earn(save.player, total_earned) + print( + f"Game finished! You earned ${total_earned}, you now have ${save.player.money}!" + ) diff --git a/untitled/ui.py b/untitled/ui.py index fe87f71..fdbb351 100644 --- a/untitled/ui.py +++ b/untitled/ui.py @@ -1,3 +1,4 @@ +import sys import time import questionary @@ -46,3 +47,21 @@ def text(title, default): def confirm(title): return questionary.confirm(title).ask() + + +def getch(): + if sys.platform == "win32": + import msvcrt + + return msvcrt.getwch() + else: + import termios + import tty + + fd = sys.stdin.fileno() + old = termios.tcgetattr(fd) + try: + tty.setcbreak(fd) + return sys.stdin.read(1) + finally: + termios.tcsetattr(fd, termios.TCSADRAIN, old)