Simple food and debug bugfix
This commit is contained in:
@@ -2,6 +2,7 @@ class Cat:
|
|||||||
def __init__(self, name, traits):
|
def __init__(self, name, traits):
|
||||||
self.name = name
|
self.name = name
|
||||||
self.traits = traits
|
self.traits = traits
|
||||||
|
self.food = 3
|
||||||
|
|
||||||
def to_dict(self):
|
def to_dict(self):
|
||||||
return vars(self)
|
return vars(self)
|
||||||
|
|||||||
1
game.py
1
game.py
@@ -75,6 +75,7 @@ class Game:
|
|||||||
if os.path.exists("ENABLE DEBUG"):
|
if os.path.exists("ENABLE DEBUG"):
|
||||||
with open("ENABLE DEBUG", "r") as f:
|
with open("ENABLE DEBUG", "r") as f:
|
||||||
file = f.read().strip()
|
file = f.read().strip()
|
||||||
|
if file:
|
||||||
self.cat = data.save.load(file)
|
self.cat = data.save.load(file)
|
||||||
self.game_loop()
|
self.game_loop()
|
||||||
print(f"{self.cat.name} says bye")
|
print(f"{self.cat.name} says bye")
|
||||||
|
|||||||
@@ -107,18 +107,28 @@ def pet(cat: Cat):
|
|||||||
print(f"You pet {cat.name} a lot. {cat.name} is very happy.")
|
print(f"You pet {cat.name} a lot. {cat.name} is very happy.")
|
||||||
|
|
||||||
|
|
||||||
|
def feed(cat):
|
||||||
|
if cat.food <= 0:
|
||||||
|
print(f"You don't have any food. {cat.name} is sad.")
|
||||||
|
cat.food -= 1
|
||||||
|
print(f"You feed {cat.name}, {cat.name} is happy")
|
||||||
|
|
||||||
|
|
||||||
def house(cat: Cat):
|
def house(cat: Cat):
|
||||||
print("Welcome to your house!")
|
print("Welcome to your house!")
|
||||||
while True:
|
while True:
|
||||||
match ui.select(
|
match ui.select(
|
||||||
"Please choose an option",
|
"Please choose an option",
|
||||||
["Check on your cat", "Pet your cat", "Leave your house"],
|
["Check on your cat", "Pet your cat", "Feed your cat", "Leave your house"],
|
||||||
):
|
):
|
||||||
case "Check on your cat":
|
case "Check on your cat":
|
||||||
print(
|
print(
|
||||||
f"{cat.name} - a {cat.traits["size"]} {cat.traits["color"]} with {cat.traits["eyes"]} eyes"
|
f"{cat.name} - a {cat.traits["size"]} {cat.traits["color"]} with {cat.traits["eyes"]} eyes"
|
||||||
)
|
)
|
||||||
|
print(f"Food: {cat.food}")
|
||||||
case "Pet your cat":
|
case "Pet your cat":
|
||||||
pet(cat)
|
pet(cat)
|
||||||
|
case "Feed your cat":
|
||||||
|
feed(cat)
|
||||||
case "Leave your house":
|
case "Leave your house":
|
||||||
break
|
break
|
||||||
|
|||||||
Reference in New Issue
Block a user