68 lines
2.2 KiB
Python
68 lines
2.2 KiB
Python
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 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 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
|
|
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)
|