This commit is contained in:
2026-06-25 13:56:54 -04:00
parent 3f3913abee
commit 7bc6e2cb4d
5 changed files with 39 additions and 14 deletions

View File

@@ -1,4 +1,4 @@
import time
import pytest
from untitled import content, migration, model, persistence, rules
@@ -47,7 +47,7 @@ def test_migration():
assert "last_updated" in result["cat"]
def test_decay_and_feed():
def test_decay_and_replenish():
cat = model.Save(
version=content.SAVE_VERSION,
cat=model.Cat(
@@ -58,12 +58,16 @@ def test_decay_and_feed():
"eyes": "blue",
"personality": "judges you silently",
},
last_updated=0,
),
)
rules.reconcile(cat.cat, time.time() + 3600)
rules.reconcile(cat.cat, 3600 * 2)
assert cat.cat.happiness < 98
assert cat.cat.fullness < 98
rules.feed(cat.cat)
assert cat.cat.fullness > 98 and cat.cat.fullness <= 100
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)
def test_list_saves(tmp_path):

View File

@@ -4,8 +4,9 @@ GAME_NAME = "Untitled Cat Game" # Titled Cat Game
SAVE_VERSION = 2
HUNGER_DECAY_PER_HOUR = 5
BASE_HAPPINESS_DECAY_PER_HOUR = 5
BASE_HAPPINESS_DECAY_PER_HOUR = 2
HUNGER_SADNESS_THRESHOLD = 30
HUNGER_SADNESS_PENALTY_PER_HOUR = 5
CAT_COLORS = [
"orange tabby",
"black",

View File

@@ -3,6 +3,7 @@ import time
def _v1_to_v2(data):
data["cat"]["fullness"] = 100
data["cat"]["happiness"] = 100
data["cat"]["last_updated"] = time.time()
data["version"] = 2
return data

View File

@@ -17,20 +17,34 @@ def validate_cat_name(name, auto_gen=False):
return "Your cat's name needs at least 1 letter."
def _clamp(value, low=0, high=100):
if value < low:
return low
if value > high:
return high
return value
def reconcile(cat: model.Cat, now):
elapsed_hours = (now - cat.last_updated) / 3600
if elapsed_hours <= 0:
return
cat.fullness -= content.HUNGER_DECAY_PER_HOUR * elapsed_hours
if cat.fullness < 0:
cat.fullness = 0
cat.fullness = _clamp(cat.fullness)
cat.happiness -= content.BASE_HAPPINESS_DECAY_PER_HOUR * elapsed_hours
if cat.happiness < 0:
cat.happiness = 0
if cat.fullness < content.HUNGER_SADNESS_THRESHOLD:
cat.happiness -= content.HUNGER_SADNESS_PENALTY_PER_HOUR * elapsed_hours
cat.happiness = _clamp(cat.happiness)
cat.last_updated = now
def feed(cat, amount=100):
cat.fullness += amount
if cat.fullness > 100:
cat.fullness = 100
cat.fullness = _clamp(cat.fullness)
def excite(cat, amount=100):
cat.happiness += amount
cat.happiness = _clamp(cat.happiness)

View File

@@ -8,17 +8,22 @@ 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", "Feed your cat", "Menu"]
"What do you want to do?",
["Check on your cat", "Feed your cat", "Pet your cat", "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)}"
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 "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.")
case "Pet your cat":
rules.reconcile(save.cat, time.time())
rules.excite(save.cat)
print(f"You pet {save.cat.name}, {save.cat.name} is now happy.")
case "Menu":
result = options()
match result: