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) def pet(cat: Cat): print(f"Mash keys to pet {cat.name}, press enter when you're done.") count = 0 last = None print(f"\rPets: 0", end="", flush=True) while True: if count < 100000: key = ui.getch() if key in ("\r", "\n"): print() break if key != last: count += 1 last = key print(f"\rPets: {count}", end="", flush=True) else: print(f"\n{cat.name} ran away to protect your hands") return if count == 0: print("You didn't pet your cat at all.") elif count < 50: print(f"You didn't pet your cat enough, {cat.name} wants more pets.") elif count <= 200: print(f"You pet {cat.name} a lot, {cat.name} is happy.") elif count > 75000: print(f"{cat.name} is getting extremely worried about your hands.") elif count > 50000: print("Seriously. Stop.") elif count > 20000: print("You should probably stop now.") elif count > 10000: print(f"What are you even doing at this point?") elif count > 1000: print(f"{cat.name} has had enough pets.") elif count > 500: print(f"You pet {cat.name} an absurd amount of times.") else: print(f"You pet {cat.name} a lot. {cat.name} is very happy.") def house(cat: Cat): print("Welcome to your house!") while True: match ui.select( "Please choose an option", ["Check on your cat", "Pet your cat", "Leave your house"], ): case "Check on your cat": print( f"{cat.name} - a {cat.traits["size"]} {cat.traits["color"]} with {cat.traits["eyes"]} eyes" ) case "Pet your cat": pet(cat) case "Leave your house": break