From 188c1be7bf307693f208aecea6aef3ca8b3a49a7 Mon Sep 17 00:00:00 2001 From: Toasterkitten Date: Thu, 25 Jun 2026 16:32:40 -0400 Subject: [PATCH] inventory and feed --- tests/test_persistence.py | 3 ++- untitled/content.py | 2 ++ untitled/rules.py | 9 ++++++--- untitled/screens/house.py | 23 +++++++++++++++++++---- 4 files changed, 29 insertions(+), 8 deletions(-) diff --git a/tests/test_persistence.py b/tests/test_persistence.py index 1e49221..da66c18 100644 --- a/tests/test_persistence.py +++ b/tests/test_persistence.py @@ -62,10 +62,11 @@ def test_decay_and_replenish(): last_updated=0, ), ) + cat.player.inventory["food"] = 1 rules.reconcile(cat.cat, 3600 * 2) assert cat.cat.happiness < 98 assert cat.cat.fullness < 98 - rules.feed(cat.cat) + rules.feed(cat.player, cat.cat) assert cat.cat.fullness == pytest.approx(100) rules.reconcile(cat.cat, 7200 + 20 * 3600) assert cat.cat.happiness < 96 - (content.BASE_HAPPINESS_DECAY_PER_HOUR * 20) diff --git a/untitled/content.py b/untitled/content.py index 303be50..b660e6c 100644 --- a/untitled/content.py +++ b/untitled/content.py @@ -15,6 +15,8 @@ BASE_INVENTORY = {item: 0 for item in ITEMS} WORK_START_LETTERS = 2 WORK_EARN_PER_ROUND = 3 +FOOD_RESTORE = 30 + CAT_COLORS = [ "orange tabby", "black", diff --git a/untitled/rules.py b/untitled/rules.py index ebf92cd..5adeecf 100644 --- a/untitled/rules.py +++ b/untitled/rules.py @@ -44,9 +44,12 @@ def reconcile(cat: model.Cat, now): cat.last_updated = now -def feed(cat, amount=100): - cat.fullness += amount - cat.fullness = _clamp(cat.fullness) +def feed(player, cat, amount=content.FOOD_RESTORE): + if player.inventory["food"] <= 0: + return False + player.inventory["food"] -= 1 + cat.fullness = _clamp(cat.fullness + amount) + return True def excite(cat, amount=100): diff --git a/untitled/screens/house.py b/untitled/screens/house.py index 25f586a..6f19300 100644 --- a/untitled/screens/house.py +++ b/untitled/screens/house.py @@ -9,17 +9,32 @@ 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", "Go to...", "Menu"], + [ + "Check on your cat", + "View your inventory", + "Feed your cat", + "Pet your cat", + "Go to...", + "Menu", + ], ): 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)}\nMoney: {save.player.money}" + f"{save.cat.name}, {generation.generate_trait_sentence(save.cat.traits).lower()}.\nFullness: {round(save.cat.fullness,1)}\nHappiness: {round(save.cat.happiness,1)}" + ) + case "View your inventory": + print( + f"Money: {save.player.money}\n\n{"\n".join(f'{item.capitalize()}: {amount}' for item,amount in save.player.inventory.items() if amount>0)}" ) case "Feed your cat": rules.reconcile(save.cat, time.time()) - rules.feed(save.cat) - print(f"You feed {save.cat.name}, {save.cat.name} is now full.") + if rules.feed(save.player, save.cat): + print( + f"You feed {save.cat.name}, {save.cat.name} now is {save.cat.fullness}% full." + ) + else: + print("You don't have any food!") case "Pet your cat": rules.reconcile(save.cat, time.time()) rules.excite(save.cat)