food
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
from untitled import model, persistence
|
||||
from untitled import content, model, persistence
|
||||
|
||||
|
||||
def test_save_load_roundtrip(tmp_path):
|
||||
original = model.Save(
|
||||
version=1,
|
||||
version=content.SAVE_VERSION,
|
||||
cat=model.Cat(
|
||||
"Fry",
|
||||
{
|
||||
@@ -23,7 +23,7 @@ def test_save_load_roundtrip(tmp_path):
|
||||
"eyes": "blue",
|
||||
"personality": "judges you silently",
|
||||
}
|
||||
assert loaded.version == 1
|
||||
assert loaded.version == content.SAVE_VERSION
|
||||
|
||||
|
||||
def test_list_saves(tmp_path):
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
STUDIO_NAME = "Untitled Randomness Studios" # Titled Randomness Studios
|
||||
GAME_NAME = "Untitled Cat Game" # Titled Cat Game
|
||||
|
||||
SAVE_VERSION = 1
|
||||
SAVE_VERSION = 2
|
||||
|
||||
HUNGER_DECAY_PER_HOUR = 5
|
||||
|
||||
CAT_COLORS = [
|
||||
"orange tabby",
|
||||
|
||||
@@ -1,5 +1,14 @@
|
||||
import time
|
||||
|
||||
_MIGRATIONS = {} # TODO: ADD HUNGER AND LAST PLAYED MIGRATION
|
||||
|
||||
def _v1_to_v2(data):
|
||||
data["cat"]["hunger"] = 100
|
||||
data["cat"]["last_updated"] = time.time()
|
||||
data["version"] = 2
|
||||
return data
|
||||
|
||||
|
||||
_MIGRATIONS = {1: _v1_to_v2} # TODO: ADD HUNGER AND LAST PLAYED MIGRATION
|
||||
|
||||
|
||||
def migrate(data):
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
import string
|
||||
|
||||
from untitled import content
|
||||
|
||||
|
||||
def validate_cat_name(name, auto_gen=False):
|
||||
ALLOWED = set(string.ascii_letters + string.digits)
|
||||
@@ -13,3 +15,19 @@ def validate_cat_name(name, auto_gen=False):
|
||||
return "Your cat's name can only have letters and numbers."
|
||||
if not any(c in string.ascii_letters for c in name):
|
||||
return "Your cat's name needs at least 1 letter."
|
||||
|
||||
|
||||
def reconcile(cat, now):
|
||||
elapsed_hours = (now - cat.last_updated) / 3600
|
||||
if elapsed_hours <= 0:
|
||||
return
|
||||
cat.hunger -= content.HUNGER_DECAY_PER_HOUR * elapsed_hours
|
||||
if cat.hunger < 0:
|
||||
cat.hunger = 0
|
||||
cat.last_updated = now
|
||||
|
||||
|
||||
def feed(cat, amount=100):
|
||||
cat.hunger += amount
|
||||
if cat.hunger > 100:
|
||||
cat.hunger = 100
|
||||
|
||||
@@ -1,13 +1,23 @@
|
||||
from untitled import model, persistence, ui
|
||||
import time
|
||||
|
||||
from untitled import generation, model, persistence, rules, ui
|
||||
from untitled.screens.common import options
|
||||
|
||||
|
||||
def house(save: model.Save):
|
||||
print("Welcome to your house!")
|
||||
while True:
|
||||
match ui.select("What do you want to do?", ["Check on your cat", "Menu"]):
|
||||
match ui.select(
|
||||
"What do you want to do?", ["Check on your cat", "Feed your cat", "Menu"]
|
||||
):
|
||||
case "Check on your cat":
|
||||
print(save.cat.name)
|
||||
rules.reconcile(save.cat, time.time())
|
||||
print(
|
||||
f"{save.cat.name}, {generation.generate_trait_sentence(save.cat.traits).lower()}\nFullness: {round(save.cat.hunger,1)}"
|
||||
)
|
||||
case "Feed your cat":
|
||||
rules.feed(save.cat)
|
||||
print(f"You feed {save.cat.name}, {save.cat.name} is now full.")
|
||||
case "Menu":
|
||||
result = options()
|
||||
match result:
|
||||
|
||||
Reference in New Issue
Block a user