Skip to content

Commit

Permalink
Add simple fruit trading game implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
nolecram committed Dec 5, 2024
1 parent 1878001 commit 339c803
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 339c803

Please sign in to comment.