This commit is contained in:
2026-04-11 17:13:54 -04:00
parent 18a0fd249c
commit f38fd535fb
6 changed files with 111 additions and 11 deletions

View File

@@ -1,26 +1,67 @@
from data.cat import Cat
import systems.ui as ui
import re
import data.text
import random
def check_cat_name(name):
name = name.strip()
if not name:
return "Please choose a name:"
if len(name) > 4 or len(name) < 20:
return "Please choose a name greater than 4 charecters and less than 20:"
if len(name) < 4 or len(name) > 20:
return "Please choose a name greater than 4 characters and less than 20:"
if re.search(r"[^a-zA-Z \-']", name):
return "Please only use letters, spaces, hyphens and apostrophes:"
return "Ok"
def shelter():
# TODO: make
name = ui.text("Welcome to the shelter! Please choose a name for your cat:")
def generate_cat_choice(personality=None):
size = random.choice(data.text.CAT_SIZES)
color = random.choice(data.text.CAT_COLORS)
eyes = random.choice(data.text.CAT_EYE_COLORS)
personality = personality or random.choice(data.text.CAT_PERSONALITIES)
article = "An" if size[0] in "aeiou" else "A"
description = f"{article} {size} {color} kitten with {eyes} eyes who {personality}"
return description, {
"size": size,
"color": color,
"eyes": eyes,
"personality": personality,
}
def generate_cat_choices(n=5):
personalities = random.sample(data.text.CAT_PERSONALITIES, n)
return [generate_cat_choice(p) for p in personalities]
def shelter(include_welcome=True):
while True:
cat_choices = generate_cat_choices()
descriptions = []
for desc, _ in cat_choices:
descriptions.append(desc)
descriptions.append("Reroll")
kitten_description = ui.select(
f"{"Welcome to the shelter! " if include_welcome else ""}Please choose a kitten to adopt.",
descriptions,
)
if kitten_description != "Reroll":
break
for desc, traits in cat_choices:
if desc == kitten_description:
break
name = ui.text("Please choose a name for your kitten:")
while True:
check_result = check_cat_name(name)
if check_result != "Ok":
name = ui.text(check_result)
else:
break
return Cat(name)
if not ui.confirm(
f"Are you sure you want to adopt {name}, a{kitten_description[1:]}?"
):
return shelter(include_welcome=False)
print(f"You pick up {name}, {name} is ready to leave the shelter.")
return Cat(name, traits)