shop
This commit is contained in:
@@ -8,7 +8,9 @@ BASE_HAPPINESS_DECAY_PER_HOUR = 2
|
|||||||
HUNGER_SADNESS_THRESHOLD = 30
|
HUNGER_SADNESS_THRESHOLD = 30
|
||||||
HUNGER_SADNESS_PENALTY_PER_HOUR = 5
|
HUNGER_SADNESS_PENALTY_PER_HOUR = 5
|
||||||
|
|
||||||
BASE_INVENTORY = {"food": 0, "medicine": 0, "catnip": 0}
|
ITEMS = {"food": 3, "medicine": 5, "catnip": 5}
|
||||||
|
|
||||||
|
BASE_INVENTORY = {item: 0 for item in ITEMS.keys()}
|
||||||
|
|
||||||
CAT_COLORS = [
|
CAT_COLORS = [
|
||||||
"orange tabby",
|
"orange tabby",
|
||||||
|
|||||||
@@ -52,3 +52,11 @@ def feed(cat, amount=100):
|
|||||||
def excite(cat, amount=100):
|
def excite(cat, amount=100):
|
||||||
cat.happiness += amount
|
cat.happiness += amount
|
||||||
cat.happiness = _clamp(cat.happiness)
|
cat.happiness = _clamp(cat.happiness)
|
||||||
|
|
||||||
|
|
||||||
|
def buy(player, item, price):
|
||||||
|
if price > player.money:
|
||||||
|
return False
|
||||||
|
player.money -= price
|
||||||
|
player.inventory[item] += 1
|
||||||
|
return True
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
from untitled import ui
|
from untitled import ui
|
||||||
|
from untitled.screens import shop
|
||||||
|
|
||||||
|
|
||||||
def options():
|
def options():
|
||||||
@@ -10,3 +11,9 @@ def options():
|
|||||||
return "save"
|
return "save"
|
||||||
case "Save and quit":
|
case "Save and quit":
|
||||||
return "savequit"
|
return "savequit"
|
||||||
|
|
||||||
|
|
||||||
|
def go_to(save):
|
||||||
|
match ui.select("Where do you want to go?", ["The shop", "Back"]):
|
||||||
|
case "The shop":
|
||||||
|
shop.shop(save)
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import time
|
import time
|
||||||
|
|
||||||
from untitled import generation, model, persistence, rules, ui
|
from untitled import generation, model, persistence, rules, ui
|
||||||
from untitled.screens.common import options
|
from untitled.screens.common import options, go_to
|
||||||
|
|
||||||
|
|
||||||
def house(save: model.Save):
|
def house(save: model.Save):
|
||||||
@@ -9,7 +9,7 @@ def house(save: model.Save):
|
|||||||
while True:
|
while True:
|
||||||
match ui.select(
|
match ui.select(
|
||||||
"What do you want to do?",
|
"What do you want to do?",
|
||||||
["Check on your cat", "Feed your cat", "Pet your cat", "Menu"],
|
["Check on your cat", "Feed your cat", "Pet your cat", "Go to...", "Menu"],
|
||||||
):
|
):
|
||||||
case "Check on your cat":
|
case "Check on your cat":
|
||||||
rules.reconcile(save.cat, time.time())
|
rules.reconcile(save.cat, time.time())
|
||||||
@@ -24,6 +24,8 @@ def house(save: model.Save):
|
|||||||
rules.reconcile(save.cat, time.time())
|
rules.reconcile(save.cat, time.time())
|
||||||
rules.excite(save.cat)
|
rules.excite(save.cat)
|
||||||
print(f"You pet {save.cat.name}, {save.cat.name} is now happy.")
|
print(f"You pet {save.cat.name}, {save.cat.name} is now happy.")
|
||||||
|
case "Go to...":
|
||||||
|
go_to(save)
|
||||||
case "Menu":
|
case "Menu":
|
||||||
result = options()
|
result = options()
|
||||||
match result:
|
match result:
|
||||||
|
|||||||
29
untitled/screens/shop.py
Normal file
29
untitled/screens/shop.py
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
from untitled import ui, content, model, rules
|
||||||
|
|
||||||
|
|
||||||
|
def shop(save: model.Save):
|
||||||
|
print("Welcome to the shop!")
|
||||||
|
while True:
|
||||||
|
match ui.select("What do you want to do?", ["Buy items", "Leave"]):
|
||||||
|
case "Buy items":
|
||||||
|
while True:
|
||||||
|
print(f"You have ${save.player.money}.")
|
||||||
|
item = ui.select(
|
||||||
|
"Please choose an item to buy:",
|
||||||
|
[
|
||||||
|
ui.Choice(f"{item.capitalize()}: ${price}", (item, price))
|
||||||
|
for item, price in content.ITEMS.items()
|
||||||
|
]
|
||||||
|
+ ["Back"],
|
||||||
|
)
|
||||||
|
if item == "Back":
|
||||||
|
break
|
||||||
|
if ui.confirm(
|
||||||
|
f"Are you sure you want to buy {item[0]} for ${item[1]}?"
|
||||||
|
):
|
||||||
|
if rules.buy(save.player, item[0], item[1]):
|
||||||
|
print("Done!")
|
||||||
|
else:
|
||||||
|
print("You don't have enough money!")
|
||||||
|
case "Leave":
|
||||||
|
break
|
||||||
Reference in New Issue
Block a user