From d15a7f0aa985a2d688d04a8f4acd56fe3fc4b807 Mon Sep 17 00:00:00 2001 From: Owen Feldman Date: Fri, 17 Apr 2026 19:03:00 -0400 Subject: [PATCH] Food and bugfix --- data/cat.py | 3 +-- game.py | 9 +++++---- systems/items.py | 11 +++++++++-- systems/world.py | 33 +++++++++++++++------------------ 4 files changed, 30 insertions(+), 26 deletions(-) diff --git a/data/cat.py b/data/cat.py index 9911187..0dfb7f3 100644 --- a/data/cat.py +++ b/data/cat.py @@ -1,8 +1,7 @@ class Cat: - def __init__(self, name, traits, food=0, money=25, inventory={}): + def __init__(self, name, traits, money=25, inventory={}): self.name = name self.traits = traits - self.food = food self.money = money self.inventory = inventory diff --git a/game.py b/game.py index 6af6c38..b24ec32 100644 --- a/game.py +++ b/game.py @@ -6,6 +6,7 @@ import data.save import data.text import os import json +import traceback class Game: @@ -40,8 +41,8 @@ class Game: options[0:0] = [ # AI came up with this, what the heck is [0:0] "Save", "Save and quit", - "Settings", "Quit", + "Settings", ] else: print( @@ -76,7 +77,7 @@ class Game: print("Save complete.") self.game_loop() - # TODO: Add shop, make food buyable and add money system + # TODO: Add money system def game_loop(self): ui.current_cat = self.cat while True: @@ -155,9 +156,9 @@ if __name__ == "__main__": try: game = Game() game.run() - except Exception as e: # horrible coding right here + except: # horrible coding right here print("Developer stuff incoming, if you can, tell me what this says:") - print(e) + traceback.print_exc() print( "Welp, seems that the game crashed, idk why. A common cause of this is pressing CTRL+C, which will cancel some UI stuff and just break the game. If you're on the desktop version, reopen it, if you're on the web version, reload, and don't use CTRL+C.\nOtherwise, great job! You found an issue in the game! If you can, please tell me." ) diff --git a/systems/items.py b/systems/items.py index d05f31e..5e94f4d 100644 --- a/systems/items.py +++ b/systems/items.py @@ -1,8 +1,15 @@ import data.cat +import systems.world +import systems.ui as ui -def handle_item(cat: data.cat.Cat, item): +def item_menu(cat: data.cat.Cat, item): match item: + case "Food": + match ui.select("Please choose an option", [f"Feed your cat", "Back"]): + case "Feed your cat": + systems.world.feed(cat) + case "Back": + pass case _: pass - # TODO: MAKE THIS! diff --git a/systems/world.py b/systems/world.py index 86eb5e5..d03b7fa 100644 --- a/systems/world.py +++ b/systems/world.py @@ -99,7 +99,6 @@ def shop(cat: Cat): else: print("Cancelled.") - # TODO: idea, each item, when selected in house storage menu, call a item menu thing thats specific for each item # TODO: make toy mouse that increases happyness (so also add emotions and sicknesses maybe) but has a 25% chance of getting lost under the couch and makes the cat tired possibly case "Leave the shop": print("Goodbye!") @@ -146,28 +145,27 @@ def pet(cat: Cat): print(f"You pet {cat.name} a lot. {cat.name} is very happy.") -def feed(cat): - # TODO: Make this use inventory["Food"] instead! - if cat.food <= 0: +def feed(cat: Cat): + if cat.inventory.get("Food", 0) <= 0: print(f"You don't have any food. {cat.name} is sad.") return - cat.food -= 1 + cat.inventory["Food"] -= 1 print(f"You feed {cat.name}, {cat.name} is happy") def storage(cat: Cat): - while True: - item = ui.select( - "Please choose an item", - [ - ui.Choice(title=f"{name}: {amount}", value=name) - for name, amount in cat.inventory.items() - ] - + ["Back"], - ) - if item == "Back": - break - systems.items.item_menu(cat, item) + item = ui.select( + "Please choose an item", + [ + ui.Choice(title=f"{name}: {amount}", value=name) + for name, amount in cat.inventory.items() + if amount > 0 + ] + + ["Back"], + ) + if item == "Back": + return + systems.items.item_menu(cat, item) def house(cat: Cat): @@ -187,7 +185,6 @@ def house(cat: Cat): print( f"{cat.name} - a {cat.traits["size"]} {cat.traits["color"]} with {cat.traits["eyes"]} eyes" ) - print(f"Food: {cat.food}") case "Pet your cat": pet(cat) case "Feed your cat":