From 988ddf1ebf47d62ed83ae59166b18228fbb01605 Mon Sep 17 00:00:00 2001 From: Toasterkitten Date: Thu, 25 Jun 2026 15:40:40 -0400 Subject: [PATCH] shop --- untitled/content.py | 4 +++- untitled/rules.py | 8 ++++++++ untitled/screens/common.py | 7 +++++++ untitled/screens/house.py | 6 ++++-- untitled/screens/shop.py | 29 +++++++++++++++++++++++++++++ 5 files changed, 51 insertions(+), 3 deletions(-) create mode 100644 untitled/screens/shop.py diff --git a/untitled/content.py b/untitled/content.py index 5e39f38..13f89b6 100644 --- a/untitled/content.py +++ b/untitled/content.py @@ -8,7 +8,9 @@ BASE_HAPPINESS_DECAY_PER_HOUR = 2 HUNGER_SADNESS_THRESHOLD = 30 HUNGER_SADNESS_PENALTY_PER_HOUR = 5 -BASE_INVENTORY = {"food": 0, "medicine": 0, "catnip": 0} +ITEMS = {"food": 3, "medicine": 5, "catnip": 5} + +BASE_INVENTORY = {item: 0 for item in ITEMS.keys()} CAT_COLORS = [ "orange tabby", diff --git a/untitled/rules.py b/untitled/rules.py index 153cbba..8b0745b 100644 --- a/untitled/rules.py +++ b/untitled/rules.py @@ -52,3 +52,11 @@ def feed(cat, amount=100): def excite(cat, amount=100): cat.happiness += amount cat.happiness = _clamp(cat.happiness) + + +def buy(player, item, price): + if price > player.money: + return False + player.money -= price + player.inventory[item] += 1 + return True diff --git a/untitled/screens/common.py b/untitled/screens/common.py index cf63d48..7973fa7 100644 --- a/untitled/screens/common.py +++ b/untitled/screens/common.py @@ -1,4 +1,5 @@ from untitled import ui +from untitled.screens import shop def options(): @@ -10,3 +11,9 @@ def options(): return "save" case "Save and quit": return "savequit" + + +def go_to(save): + match ui.select("Where do you want to go?", ["The shop", "Back"]): + case "The shop": + shop.shop(save) diff --git a/untitled/screens/house.py b/untitled/screens/house.py index 1061be5..3042d11 100644 --- a/untitled/screens/house.py +++ b/untitled/screens/house.py @@ -1,7 +1,7 @@ import time from untitled import generation, model, persistence, rules, ui -from untitled.screens.common import options +from untitled.screens.common import options, go_to def house(save: model.Save): @@ -9,7 +9,7 @@ def house(save: model.Save): while True: match ui.select( "What do you want to do?", - ["Check on your cat", "Feed your cat", "Pet your cat", "Menu"], + ["Check on your cat", "Feed your cat", "Pet your cat", "Go to...", "Menu"], ): case "Check on your cat": rules.reconcile(save.cat, time.time()) @@ -24,6 +24,8 @@ def house(save: model.Save): rules.reconcile(save.cat, time.time()) rules.excite(save.cat) print(f"You pet {save.cat.name}, {save.cat.name} is now happy.") + case "Go to...": + go_to(save) case "Menu": result = options() match result: diff --git a/untitled/screens/shop.py b/untitled/screens/shop.py new file mode 100644 index 0000000..82048bd --- /dev/null +++ b/untitled/screens/shop.py @@ -0,0 +1,29 @@ +from untitled import ui, content, model, rules + + +def shop(save: model.Save): + print("Welcome to the shop!") + while True: + match ui.select("What do you want to do?", ["Buy items", "Leave"]): + case "Buy items": + while True: + print(f"You have ${save.player.money}.") + item = ui.select( + "Please choose an item to buy:", + [ + ui.Choice(f"{item.capitalize()}: ${price}", (item, price)) + for item, price in content.ITEMS.items() + ] + + ["Back"], + ) + if item == "Back": + break + if ui.confirm( + f"Are you sure you want to buy {item[0]} for ${item[1]}?" + ): + if rules.buy(save.player, item[0], item[1]): + print("Done!") + else: + print("You don't have enough money!") + case "Leave": + break