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 shop(cat: Cat): print("Welcome to the shop") while True: print(f"You have ${cat.money}") match ui.select("Please choose an option", ["Buy something", "Leave the shop"]): case "Buy something": item = ui.select( "Please choose something to buy", [ ui.Choice(title=f"{name} - ${price}", value=name) for name, price in data.text.SHOP_ITEMS.items() ], ) item_price = data.text.SHOP_ITEMS[item] if item_price > cat.money: print( f"You don't have enough money to buy this! You need {item_price-cat.money} more dollars." ) else: if ui.confirm( f"Are you sure you want to buy {item} for ${item_price}? You will have ${cat.money-item_price} left over." ): cat.money -= item_price cat.inventory[item] = cat.inventory.get(item, 0) + 1 print(f"You bought {item}.") else: print("Cancelled.") # TODO: idea, each item, when selected in house storage menu, call a item menu thing thats specific for each item # TODO: make toy mouse that increases happyness (so also add emotions and sicknesses maybe) but has a 25% chance of getting lost under the couch and makes the cat tired possibly pass case "Leave the shop": print("Goodbye!") break 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 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): print("Welcome to your house!") while True: match ui.select( "Please choose an option", ["Check on your cat", "Pet your cat", "Feed 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" ) print(f"Food: {cat.food}") case "Pet your cat": pet(cat) case "Feed your cat": feed(cat) case "Leave your house": break