From 6b23548b26e41f1e44afea9658c5a96997c5494e Mon Sep 17 00:00:00 2001 From: Owen Feldman Date: Sat, 11 Apr 2026 17:40:34 -0400 Subject: [PATCH] Mainloop+house --- data/save.py | 5 ++++- game.py | 28 +++++++++++++++++++++++++--- systems/world.py | 14 ++++++++++++++ 3 files changed, 43 insertions(+), 4 deletions(-) diff --git a/data/save.py b/data/save.py index 4a40fda..24bfe12 100644 --- a/data/save.py +++ b/data/save.py @@ -1,5 +1,6 @@ import json from data.cat import Cat +import os class SaveData: @@ -9,7 +10,9 @@ class SaveData: def save(cat): - with open(f"{cat.name}.kitten", "w") as f: + if not os.path.exists("saves"): + os.mkdir("saves") + with open(f"saves/{cat.name}.kitten", "w") as f: json.dump(cat.to_dict(), f) diff --git a/game.py b/game.py index c32dff0..b300f99 100644 --- a/game.py +++ b/game.py @@ -1,6 +1,6 @@ from data.cat import Cat from systems.ui import clear, title -from systems.world import shelter +from systems.world import shelter, house import systems.ui as ui import data.save @@ -17,8 +17,30 @@ class Game: self.game_loop() def game_loop(self): - # TODO: make - pass + while True: + match ui.select("Please choose an option", ["Go to your house", "Options"]): + case "Go to your house": + house(self.cat) + case "Options": + while True: + match ui.select( + "Please choose an option", + ["Save", "Save and quit", "Quit", "Back"], + ): + case "Save": + data.save.save(self.cat) + case "Save and quit": + print("Goodbye!") + data.save.save(self.cat) + return + case "Quit": + if ui.confirm( + "Are you sure you want to quit without saving?" + ): + print("Goodbye!") + return + case "Back": + break def run(self): title() diff --git a/systems/world.py b/systems/world.py index 44dba46..27338c4 100644 --- a/systems/world.py +++ b/systems/world.py @@ -65,3 +65,17 @@ def shelter(include_welcome=True): return shelter(include_welcome=False) print(f"You pick up {name}, {name} is ready to leave the shelter.") return Cat(name, traits) + + +def house(cat: Cat): + print("Welcome to your house!") + while True: + match ui.select( + "Please choose an option", ["Check on your cat", "Leave your house"] + ): + case "Check on your cat": + print( + f"{cat.name} - a {cat.traits["size"]} {cat.traits["color"]} with {cat.traits["eyes"]} eyes" + ) + case "Leave your house": + break