From 339c803cfa8a29987efeaf4c1c44a2fa46c98d61 Mon Sep 17 00:00:00 2001 From: Marco Celon <20218924+nolecram@users.noreply.github.com> Date: Thu, 5 Dec 2024 18:34:14 +0000 Subject: [PATCH] Add simple fruit trading game implementation --- test.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/test.py b/test.py index 42645a9..6de8307 100644 --- a/test.py +++ b/test.py @@ -45,9 +45,30 @@ def sell_fruit(gold, inventory): inventory[fruit] -= quantity return gold, inventory +# Function to handle special events +def special_event(gold, inventory): + event = random.choice(["none", "find_gold", "fruit_spoil", "bonus_fruit"]) + if event == "find_gold": + found_gold = random.randint(5, 15) + gold += found_gold + print(f"Special Event: You found {found_gold} gold!") + elif event == "fruit_spoil": + fruit = random.choice(list(inventory.keys())) + if inventory[fruit] > 0: + spoiled_quantity = random.randint(1, inventory[fruit]) + inventory[fruit] -= spoiled_quantity + print(f"Special Event: {spoiled_quantity} {fruit}(s) spoiled!") + elif event == "bonus_fruit": + fruit = random.choice(list(inventory.keys())) + bonus_quantity = random.randint(1, 5) + inventory[fruit] += bonus_quantity + print(f"Special Event: You received {bonus_quantity} bonus {fruit}(s)!") + return gold, inventory + # Main game loop for day in range(1, days + 1): display_status(day, gold, inventory) + gold, inventory = special_event(gold, inventory) action = input("Do you want to buy or sell fruit? (buy/sell): ").lower() if action == "buy": gold, inventory = buy_fruit(gold, inventory)