Advertisement
LordJesusChrist

Tamagotchi game expansion on original.

May 4th, 2025
21
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 13.11 KB | Gaming | 0 0
  1. import json
  2. import time
  3. import random
  4. import os
  5.  
  6. # Create directories if they don't exist
  7. os.makedirs("friends", exist_ok=True)
  8. os.makedirs("tamagotchis", exist_ok=True)
  9.  
  10. # Tamagotchi Data Structure
  11. TAMAGOTCHI_TYPES = {
  12.     "cat": {"name": "Whiskers", "hunger_rate": 3, "cleanliness_rate": 2},
  13.     "dinosaur": {"name": "Tyranno", "hunger_rate": 5, "cleanliness_rate": 4},
  14.     "dolphin": {"name": "Flipper", "hunger_rate": 4, "cleanliness_rate": 1},
  15.     "ant": {"name": "Tiny", "hunger_rate": 1, "cleanliness_rate": 1},
  16.     "robot": {"name": "Bolt", "hunger_rate": 2, "cleanliness_rate": 3},
  17.     "pegasus": {"name": "Cloud", "hunger_rate": 4, "cleanliness_rate": 2},
  18.     "alien": {"name": "Zyborg", "hunger_rate": 6, "cleanliness_rate": 5},
  19.     "dragon": {"name": "Ember", "hunger_rate": 7, "cleanliness_rate": 3},
  20.     "fox": {"name": "Rusty", "hunger_rate": 3, "cleanliness_rate": 2},
  21.     "owl": {"name": "Hoot", "hunger_rate": 2, "cleanliness_rate": 1},
  22.     "panda": {"name": "Bamboo", "hunger_rate": 4, "cleanliness_rate": 2},
  23.     "penguin": {"name": "Waddle", "hunger_rate": 3, "cleanliness_rate": 1},
  24.     "unicorn": {"name": "Sparkle", "hunger_rate": 2, "cleanliness_rate": 2},
  25.     "wolf": {"name": "Howler", "hunger_rate": 5, "cleanliness_rate": 3},
  26.     "dragonfly": {"name": "Zephyr", "hunger_rate": 1, "cleanliness_rate": 1}
  27. }
  28.  
  29. # Toy Inventory System
  30. TOYS = {
  31.     "ball": {"effect": lambda t: (t.update({"happiness": min(100, t["happiness"] + 15)}), "You played with the ball! 🎾")},
  32.     "frisbee": {"effect": lambda t: (t.update({"happiness": min(100, t["happiness"] + 20), "energy": max(0, t["energy"] - 10)}), "You threw the frisbee! πŸ₯")},
  33.     "doll": {"effect": lambda t: (t.update({"happiness": min(100, t["happiness"] + 10)}), "You hugged your doll! 🧸")},
  34.     "remote": {"effect": lambda t: (t.update({"happiness": min(100, t["happiness"] + 5), "cleanliness": max(0, t["cleanliness"] - 5)}), "You smashed the remote! πŸ“Ί")},
  35.     "bath_toy": {"effect": lambda t: (t.update({"cleanliness": min(100, t["cleanliness"] + 15)}), "You played in the bath! πŸ›")},
  36.     "feather": {"effect": lambda t: (t.update({"happiness": min(100, t["happiness"] + 10), "energy": max(0, t["energy"] - 5)}), "You chased the feather! πŸͺΆ")},
  37.     "tunnel": {"effect": lambda t: (t.update({"happiness": min(100, t["happiness"] + 8), "energy": max(0, t["energy"] - 3)}), "You ran through the tunnel! πŸ‡")},
  38.     "laser": {"effect": lambda t: (t.update({"happiness": min(100, t["happiness"] + 12), "energy": max(0, t["energy"] - 5)}), "You chased the laser dot! πŸ”΅")},
  39.     "chew_toy": {"effect": lambda t: (t.update({"happiness": min(100, t["happiness"] + 10), "hunger": max(0, t["hunger"] - 5)}), "You chewed your toy! 🦷")},
  40.     "tug_rope": {"effect": lambda t: (t.update({"happiness": min(100, t["happiness"] + 15), "energy": max(0, t["energy"] - 10)}), "You played tug-of-war! πŸͺ’")},
  41.     "puzzle": {"effect": lambda t: (t.update({"happiness": min(100, t["happiness"] + 10), "hunger": max(0, t["hunger"] - 5)}), "You solved a puzzle! 🧩")},
  42.     "music_box": {"effect": lambda t: (t.update({"happiness": min(100, t["happiness"] + 8)}), "You danced to music! 🎡")},
  43.     "treat_toy": {"effect": lambda t: (t.update({"happiness": min(100, t["happiness"] + 10), "hunger": max(0, t["hunger"] - 10)}), "You got a treat! πŸͺ")},
  44.     "catnip": {"effect": lambda t: (t.update({"happiness": min(100, t["happiness"] + 25), "energy": max(0, t["energy"] - 15)}), "You're high on catnip! 🌿")},
  45.     "robot_dog": {"effect": lambda t: (t.update({"happiness": min(100, t["happiness"] + 20), "sick": False}), "Your robot dog cured you! πŸ€–")}
  46. }
  47.  
  48. # Tamagotchi Base Structure
  49. def create_tamagotchi(ttype="cat", name=None):
  50.     return {
  51.         "id": f"TAMA{random.randint(100, 999)}",
  52.         "name": name or TAMAGOTCHI_TYPES[ttype]["name"],
  53.         "type": ttype,
  54.         "age": 0,
  55.         "hunger": 50,
  56.         "happiness": 50,
  57.         "health": 100,
  58.         "cleanliness": 75,
  59.         "energy": 100,
  60.         "thirst": 30,
  61.         "sick": False,
  62.         "stage": "egg",
  63.         "alive": True,
  64.         "last_interacted": time.time(),
  65.         "inventory": [],
  66.         "friends": []
  67.     }
  68.  
  69. # Save/Load Functions
  70. def save_tamagotchi(data, folder="tamagotchis"):
  71.     with open(f"{folder}/{data['id']}.json", "w") as f:
  72.         json.dump(data, f, indent=2)
  73.  
  74. def load_tamagotchi(id, folder="tamagotchis"):
  75.     try:
  76.         with open(f"{folder}/{id}.json", "r") as f:
  77.             data = json.load(f)
  78.             for key in create_tamagotchi():
  79.                 if key not in data:
  80.                     data[key] = create_tamagotchi()[key]
  81.             return data
  82.     except FileNotFoundError:
  83.         print("No saved Tamagotchi found!")
  84.         return create_tamagotchi()
  85.  
  86. # Game Mechanics
  87. def update_stats():
  88.     global tamagotchi
  89.     time_passed = time.time() - tamagotchi["last_interacted"]
  90.    
  91.     if time_passed > 10:
  92.         # Base stat decay
  93.         tamagotchi["hunger"] = min(100, tamagotchi["hunger"] + TAMAGOTCHI_TYPES[tamagotchi["type"]]["hunger_rate"])
  94.         tamagotchi["thirst"] = min(100, tamagotchi["thirst"] + 2)
  95.         tamagotchi["cleanliness"] = max(0, tamagotchi["cleanliness"] - TAMAGOTCHI_TYPES[tamagotchi["type"]]["cleanliness_rate"])
  96.         tamagotchi["happiness"] = max(0, tamagotchi["happiness"] - 2)
  97.         tamagotchi["energy"] = max(0, tamagotchi["energy"] - 3)
  98.  
  99.         # Aging
  100.         tamagotchi["age"] += 0.1
  101.         update_stage()
  102.  
  103.         # Sickness Risk
  104.         if tamagotchi["cleanliness"] < 20 or tamagotchi["hunger"] > 80:
  105.             if random.random() < 0.1:
  106.                 tamagotchi["sick"] = True
  107.  
  108.         # Health Decay
  109.         if tamagotchi["sick"]:
  110.             tamagotchi["health"] = max(0, tamagotchi["health"] - 5)
  111.         else:
  112.             tamagotchi["health"] = min(100, tamagotchi["health"] + 1)
  113.  
  114.         tamagotchi["last_interacted"] = time.time()
  115.         check_status()
  116.         random_event()
  117.  
  118. def update_stage():
  119.     global tamagotchi
  120.     if tamagotchi["age"] >= 5 and tamagotchi["stage"] == "egg":
  121.         print("🐣 It's hatching!")
  122.         tamagotchi["stage"] = "baby"
  123.     elif tamagotchi["age"] >= 10 and tamagotchi["stage"] == "baby":
  124.         print("πŸ‘Ά Your Tamagotchi is growing up!")
  125.         tamagotchi["stage"] = "adult"
  126.  
  127. def check_status():
  128.     global tamagotchi
  129.     if tamagotchi["health"] <= 0:
  130.         print("\nπŸ’” Your Tamagotchi has died!")
  131.         tamagotchi["alive"] = False
  132.  
  133. # Player Actions
  134. def feed():
  135.     global tamagotchi
  136.     tamagotchi["hunger"] = max(0, tamagotchi["hunger"] - 15)
  137.     tamagotchi["thirst"] = max(0, tamagotchi["thirst"] - 10)
  138.     print("\n🍴 You fed your Tamagotchi!")
  139.  
  140. def play():
  141.     global tamagotchi
  142.     tamagotchi["happiness"] = min(100, tamagotchi["happiness"] + 10)
  143.     tamagotchi["energy"] = max(0, tamagotchi["energy"] - 15)
  144.     print("\n🎈 You played with your Tamagotchi!")
  145.  
  146. def clean():
  147.     global tamagotchi
  148.     tamagotchi["cleanliness"] = min(100, tamagotchi["cleanliness"] + 20)
  149.     print("\n🧼 You cleaned your Tamagotchi!")
  150.  
  151. def sleep():
  152.     global tamagotchi
  153.     if tamagotchi["energy"] < 50:
  154.         tamagotchi["energy"] = min(100, tamagotchi["energy"] + 50)
  155.         print("\nπŸ’€ Your Tamagotchi took a nap!")
  156.     else:
  157.         print("\n⚠️ Your Tamagotchi isn’t tired yet!")
  158.  
  159. def give_medicine():
  160.     global tamagotchi
  161.     if tamagotchi["sick"]:
  162.         tamagotchi["sick"] = False
  163.         print("\nπŸ’Š You gave your Tamagotchi medicine!")
  164.     else:
  165.         print("\n⚠️ Your Tamagotchi isn’t sick!")
  166.  
  167. def use_toy():
  168.     global tamagotchi
  169.     if not tamagotchi["inventory"]:
  170.         print("\n⚠️ No toys in inventory!")
  171.         return
  172.    
  173.     print("\nToys available:")
  174.     for i, toy in enumerate(tamagotchi["inventory"], 1):
  175.         print(f"{i}. {toy}")
  176.    
  177.     choice = input("Which toy to use? (Enter number or BACK): ")
  178.     if choice.lower() == "back":
  179.         return
  180.    
  181.     try:
  182.         idx = int(choice) - 1
  183.         toy = tamagotchi["inventory"][idx]
  184.         msg = TOYS[toy]["effect"](tamagotchi)
  185.         print(msg)
  186.         tamagotchi["inventory"].pop(idx)
  187.     except (IndexError, ValueError):
  188.         print("\nInvalid choice!")
  189.  
  190. def visit_park():
  191.     global tamagotchi
  192.     if random.random() < 0.1:  # 10% chance
  193.         friend_type = random.choice(list(TAMAGOTCHI_TYPES.keys()))
  194.         friend = create_tamagotchi(friend_type)
  195.         print(f"\nπŸ‘₯ You met a new friend! It's a {friend_type} named {friend['name']}!")
  196.         tamagotchi["friends"].append(friend["id"])
  197.         save_tamagotchi(friend, "friends")
  198.     else:
  199.         print("\nNo new friends today.")
  200.  
  201. # Cheats
  202. def cheat_full():
  203.     global tamagotchi
  204.     for stat in ["hunger", "thirst", "cleanliness", "happiness", "energy"]:
  205.         tamagotchi[stat] = 100
  206.     tamagotchi["sick"] = False
  207.     print("\nβœ… All stats maxed out!")
  208.  
  209. def cheat_all_toys():
  210.     global tamagotchi
  211.     tamagotchi["inventory"].extend(TOYS.keys())
  212.     print("\n🎁 You got all toys!")
  213.  
  214. # Random Events (10 types)
  215. def random_event():
  216.     global tamagotchi
  217.     event = random.choice([
  218.         "lost_toys", "found_toy", "bad_weather", "good_weather",
  219.         "dream", "sick_friend", "party", "injury", "treasure", "runaway"
  220.     ])
  221.    
  222.     if event == "lost_toys":
  223.         if tamagotchi["inventory"]:
  224.             lost = random.choice(tamagotchi["inventory"])
  225.             tamagotchi["inventory"].remove(lost)
  226.             print(f"\n🚫 You lost your {lost}!")
  227.    
  228.     elif event == "found_toy":
  229.         toy = random.choice(list(TOYS.keys()))
  230.         tamagotchi["inventory"].append(toy)
  231.         print(f"\n🎁 You found a {toy}!")
  232.    
  233.     elif event == "bad_weather":
  234.         tamagotchi["happiness"] = max(0, tamagotchi["happiness"] - 20)
  235.         tamagotchi["cleanliness"] = max(0, tamagotchi["cleanliness"] - 10)
  236.         print("\n🌧️ Stormy weather made your Tamagotchi sad!")
  237.    
  238.     elif event == "good_weather":
  239.         tamagotchi["happiness"] = min(100, tamagotchi["happiness"] + 20)
  240.         print("\nβ˜€οΈ Sunny weather made your Tamagotchi happy!")
  241.    
  242.     elif event == "dream":
  243.         print("\nπŸ’­ Your Tamagotchi had a wonderful dream!")
  244.         tamagotchi["happiness"] = min(100, tamagotchi["happiness"] + 10)
  245.    
  246.     elif event == "sick_friend":
  247.         if tamagotchi["friends"]:
  248.             friend_id = random.choice(tamagotchi["friends"])
  249.             print(f"\n⚠️ Your friend {friend_id} is sick!")
  250.             if random.random() < 0.3:
  251.                 tamagotchi["sick"] = True
  252.    
  253.     elif event == "party":
  254.         print("\nπŸŽ‰ Surprise party! Everyone's happy!")
  255.         tamagotchi["happiness"] = min(100, tamagotchi["happiness"] + 30)
  256.         tamagotchi["energy"] = max(0, tamagotchi["energy"] - 20)
  257.    
  258.     elif event == "injury":
  259.         print("\n🩹 Your Tamagotchi got a minor injury!")
  260.         tamagotchi["health"] = max(0, tamagotchi["health"] - 10)
  261.    
  262.     elif event == "treasure":
  263.         print("\nπŸ’Ž You found a treasure chest!")
  264.         cheat_all_toys()
  265.    
  266.     elif event == "runaway":
  267.         print("\nπŸƒ Your Tamagotchi almost ran away!")
  268.         tamagotchi["happiness"] = max(0, tamagotchi["happiness"] - 30)
  269.         tamagotchi["energy"] = max(0, tamagotchi["energy"] - 20)
  270.  
  271. # Game Loop
  272. def game_loop():
  273.     global tamagotchi
  274.     print(f"\n{tamagotchi['name']} the {tamagotchi['type']} is ready to play!")
  275.    
  276.     while tamagotchi["alive"]:
  277.         update_stats()
  278.        
  279.         # Mood Indicator
  280.         mood = "sad"
  281.         if tamagotchi["sick"]:
  282.             mood = "sick"
  283.         elif tamagotchi["energy"] < 20:
  284.             mood = "tired"
  285.         elif tamagotchi["happiness"] > 70:
  286.             mood = "happy"
  287.        
  288.         print(f"\nCurrent Mood: {mood.capitalize()} | Age: {int(tamagotchi['age'])}")
  289.         print(f"Stats: 😊{tamagotchi['happiness']} | 🍽️{tamagotchi['hunger']} | πŸ’§{tamagotchi['thirst']}")
  290.         print("1. Feed  2. Play  3. Clean  4. Sleep  5. Meds  6. Toys  7. Park  8. Status  9. Save  10. Exit")
  291.        
  292.         choice = input("What do you want to do? ")
  293.        
  294.         if choice == "1":
  295.             feed()
  296.         elif choice == "2":
  297.             play()
  298.         elif choice == "3":
  299.             clean()
  300.         elif choice == "4":
  301.             sleep()
  302.         elif choice == "5":
  303.             give_medicine()
  304.         elif choice == "6":
  305.             use_toy()
  306.         elif choice == "7":
  307.             visit_park()
  308.         elif choice == "8":
  309.             print(f"\nName: {tamagotchi['name']} | Type: {tamagotchi['type'].capitalize()}")
  310.             print(f"Friends ({len(tamagotchi['friends'])}) | Inventory ({len(tamagotchi['inventory'])})")
  311.         elif choice == "9":
  312.             save_tamagotchi(tamagotchi)
  313.             print("\nπŸ’Ύ Game saved!")
  314.         elif choice == "10":
  315.             print("πŸ‘‹ See you next time!")
  316.             break
  317.         elif choice.lower() == "full":
  318.             cheat_full()
  319.         elif choice.lower() == "alltoys":
  320.             cheat_all_toys()
  321.        
  322.         time.sleep(2)  # Simulate time passing
  323.  
  324. # Start Game
  325. if __name__ == "__main__":
  326.     tamagotchi = load_tamagotchi("TAMA123")
  327.     game_loop()
Advertisement
Comments
  • LordJesusChrist
    38 days
    # text 0.22 KB | 0 0
    1. For lines 157 and 165, please change the apostrophe in "isn't" to the normal one. Apparently some compilers freeze at this simple mistake. If it runs, then ignore this message. If it does not, that is the sole reason why.
Add Comment
Please, Sign In to add comment
Advertisement