beursspel-sjo/crypto.py
2025-06-22 22:53:28 +02:00

52 lines
1.4 KiB
Python

import random
import matplotlib.pyplot as plt
# Game parameters
# Start price of coin
coin_price = 100.0
price_sensitivity = 0.5
volatility = 0.3
price_history = [coin_price]
def save_graph():
plt.clf()
plt.plot(price_history, label="Coin Price")
plt.title("Coin Price Over Time")
plt.xlabel("Turn")
plt.ylabel("Price")
plt.legend()
plt.grid(True)
plt.savefig("coin_price.png")
print("📊 Graph saved as 'coin_price.png'")
print("💰 Welcome to Crypto Kids! Type +10 to buy or -10 to sell.")
print("Type 'exit' to stop the game.\n")
while True:
print(f"\nCurrent Coin Price: {round(coin_price, 2)}")
user_input = input("Enter buy/sell amount (e.g., +10 or -10): ").strip()
if user_input.lower() == "exit":
print("👋 Game Over. Thanks for playing!")
break
try:
trade_amount = int(user_input)
except ValueError:
print("⚠️ Please enter a valid number like +10 or -5.")
continue
user_intput = 10
buys = trade_amount if trade_amount > 0 else 0
sells = -trade_amount if trade_amount < 0 else 0
net_demand = buys - sells
price_change_from_demand = net_demand * price_sensitivity
random_factor = random.uniform(-volatility, volatility) * coin_price
coin_price += price_change_from_demand + random_factor
coin_price = max(1, coin_price)
price_history.append(coin_price)
save_graph()