gtg
This commit is contained in:
@@ -4,6 +4,7 @@ GAME_NAME = "Untitled Cat Game" # Titled Cat Game
|
||||
SAVE_VERSION = 2
|
||||
|
||||
HUNGER_DECAY_PER_HOUR = 5
|
||||
BASE_HAPPINESS_DECAY_PER_HOUR = 5
|
||||
|
||||
CAT_COLORS = [
|
||||
"orange tabby",
|
||||
|
||||
@@ -2,10 +2,11 @@ import time
|
||||
|
||||
|
||||
class Cat:
|
||||
def __init__(self, name, traits, fullness=100, last_updated=None):
|
||||
def __init__(self, name, traits, fullness=100, happiness=100, last_updated=None):
|
||||
self.name = name
|
||||
self.traits = traits
|
||||
self.fullness = fullness
|
||||
self.happiness = happiness
|
||||
self.last_updated = last_updated if last_updated is not None else time.time()
|
||||
|
||||
def to_dict(self):
|
||||
@@ -13,12 +14,19 @@ class Cat:
|
||||
"name": self.name,
|
||||
"traits": self.traits,
|
||||
"fullness": self.fullness,
|
||||
"happiness": self.happiness,
|
||||
"last_updated": self.last_updated,
|
||||
}
|
||||
|
||||
@staticmethod
|
||||
def from_dict(data):
|
||||
return Cat(data["name"], data["traits"], data["fullness"], data["last_updated"])
|
||||
return Cat(
|
||||
data["name"],
|
||||
data["traits"],
|
||||
data["fullness"],
|
||||
data["happiness"],
|
||||
data["last_updated"],
|
||||
)
|
||||
|
||||
|
||||
class Save:
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import string
|
||||
|
||||
from untitled import content
|
||||
from untitled import content, model
|
||||
|
||||
|
||||
def validate_cat_name(name, auto_gen=False):
|
||||
@@ -17,13 +17,16 @@ def validate_cat_name(name, auto_gen=False):
|
||||
return "Your cat's name needs at least 1 letter."
|
||||
|
||||
|
||||
def reconcile(cat, now):
|
||||
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.happiness -= content.BASE_HAPPINESS_DECAY_PER_HOUR * elapsed_hours
|
||||
if cat.happiness < 0:
|
||||
cat.happiness = 0
|
||||
cat.last_updated = now
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user