Untitled
unknown
plain_text
2 months ago
3.0 kB
3
Indexable
import random import time # Define the Fish class class Fish: def __init__(self, name, attitude, color): self.name = name self.attitude = attitude self.color = color def __repr__(self): return f"{self.name} (Attitude: {self.attitude}, Color: {self.color})" # Define possible attitudes and colors attitudes = ["Sassy", "Shy", "Cool", "Grumpy"] colors = ["Blue", "Red", "Green", "Yellow"] # Function to breed two fish def breed(fish1, fish2): # Randomly inherit traits from both parents attitude = random.choice([fish1.attitude, fish2.attitude]) color = random.choice([fish1.color, fish2.color]) # Create a new fish from the breeding baby_name = f"Baby {fish1.name} & {fish2.name}" baby_fish = Fish(baby_name, attitude, color) return baby_fish # Function to create a new fish def create_fish(): name = input("Enter your fish's name: ") attitude = random.choice(attitudes) color = random.choice(colors) return Fish(name, attitude, color) # Game setup fish_tank = [] def print_tank(): if not fish_tank: print("\nYour fish tank is empty! Let's create some fish.") else: print("\nFish in your tank:") for fish in fish_tank: print(fish) def main(): print("Welcome to the Fish with Attitude game!") time.sleep(1) while True: print("\nMenu:") print("1. Create a new fish") print("2. Breed two fish") print("3. View your fish tank") print("4. Exit the game") choice = input("Enter your choice (1/2/3/4): ") if choice == '1': # Create a new fish fish = create_fish() fish_tank.append(fish) print(f"\nYou've created a new fish: {fish}") elif choice == '2': # Breed two fish if len(fish_tank) < 2: print("\nYou need at least two fish to breed!") else: print("\nChoose the first fish by number:") for i, fish in enumerate(fish_tank): print(f"{i + 1}. {fish}") first_choice = int(input()) - 1 print("\nChoose the second fish by number:") for i, fish in enumerate(fish_tank): if i != first_choice: print(f"{i + 1}. {fish}") second_choice = int(input()) - 1 fish1 = fish_tank[first_choice] fish2 = fish_tank[second_choice] baby_fish = breed(fish1, fish2) fish_tank.append(baby_fish) print(f"\nYou've bred a new fish: {baby_fish}") elif choice == '3': # View the fish tank print_tank() elif choice == '4': # Exit the game print("\nThanks for playing Fish with Attitude!") break else: print("\nInvalid choice. Please try again.") if __name__ == "__main__": main()
Editor is loading...
Leave a Comment