import random import matplotlib.pyplot as plt from colorama import Fore, Style, init init(autoreset=True) import os os.system('cls' if os.name == 'nt' else 'clear') cryptos = { "Bitcoin": {"price": 1427.3, "sensitivity": 0.4, "volatility": 0.19, "price_history": [100.0]}, "Ethereum": {"price": 690.1, "sensitivity": 0.6, "volatility": 0.24, "price_history": [50.0]}, "Dodge": {"price": 42.9, "sensitivity": 0.9, "volatility": 0.4, "price_history": [50.0]}, } users = {} def save_graph(coin): plt.clf() plt.plot(cryptos[coin]["price_history"], label=f"{coin} Price") plt.title(f"{coin} Price Over Time") plt.xlabel("Turn") plt.ylabel("Price") plt.legend() plt.grid(True) filename = f"{coin.lower()}_price.png" plt.savefig(filename) print(Fore.MAGENTA + f"šŸ“Š Graph saved as '{filename}'") def total_value(user): return user["cash"] + sum(user["coins"].get(c, 0.0) * cryptos[c]["price"] for c in cryptos) # Intro print(Fore.YELLOW + Style.BRIGHT + "šŸ’° Welcome to Crypto Kids Multiplayer — Multi-Coin Edition!") print(Style.DIM + "šŸŽ® Register users, then trade Bitcoin, Ethereum, or Dodge in turn-based rounds.\n") # Register Users while True: user_input = input(Fore.CYAN + "Enter username to register/login (or type 'start' to begin): ").strip() if user_input.lower() == "start": if not users: print(Fore.RED + "āš ļø Add at least one user to begin.") continue break if user_input not in users: users[user_input] = {"cash": 1000.0, "coins": {coin: 0.0 for coin in cryptos}} print(Fore.GREEN + f"šŸ†• User '{user_input}' registered with $1000 cash.") else: print(Fore.BLUE + f"šŸ‘‹ Welcome back, {user_input}!") print(Fore.YELLOW + "\nšŸŽ¬ Game started! Trade using +amount to buy or -amount to sell. Type 'done' to end your turn, or 'exit' to quit.\n") # Main Game Loop while True: print(Fore.LIGHTMAGENTA_EX + "\nšŸ”€ NEW ROUND — Set the trading order") print(Fore.CYAN + f"Registered players: {', '.join(users.keys())}") while True: turn_input = input(Fore.YELLOW + "Enter usernames in desired order (space-separated): ").strip().split() if set(turn_input) == set(users.keys()): turn_order = turn_input break else: print(Fore.RED + "āš ļø Invalid order. Must include all registered users.") for username in turn_order: user = users[username] print(Fore.LIGHTWHITE_EX + "\nšŸ“Š CURRENT STANDINGS") print("="*40) for uname, data in users.items(): print(Fore.LIGHTCYAN_EX + f"šŸ‘¤ {uname}:") print(f" šŸ’¼ Cash: {Fore.GREEN}${data['cash']:.2f}") for c in cryptos: print(f" šŸŖ™ {c}: {data['coins'][c]:.2f}") print(f" šŸ“ˆ Total Value: {Fore.CYAN}${total_value(data):.2f}\n") print(Fore.LIGHTWHITE_EX + "\n" + "="*40) print(Fore.CYAN + f"šŸ” {username.upper()}'S TURN") print(Fore.LIGHTWHITE_EX + "="*40) coin_trades = [] while True: print(f"šŸ’¼ Cash: {Fore.GREEN}${user['cash']:.2f}") print("šŸŖ™ Your Holdings:") for coin in cryptos: print(f" - {Fore.YELLOW}{coin}: {user['coins'][coin]:.2f}") coin = input(Fore.CYAN + f"\nSelect a coin to trade {list(cryptos.keys())} (or type 'done' to finish turn): ").strip() if coin.lower() == "done": break if coin.lower() == "exit": print(Fore.YELLOW + "\nšŸ“‰ GAME OVER — FINAL BALANCES:\n") for uname, data in users.items(): print(Fore.LIGHTWHITE_EX + f"šŸ‘¤ {uname}:") print(f" šŸ’¼ Cash: {Fore.GREEN}${data['cash']:.2f}") for c in cryptos: print(f" šŸŖ™ {c}: {Fore.YELLOW}{data['coins'][c]:.2f}") print(f" šŸ“ˆ Total Value: {Fore.CYAN}${total_value(data):.2f}\n") exit() if coin not in cryptos: print(Fore.RED + "āš ļø Invalid coin selection.") continue price = cryptos[coin]["price"] print(Fore.LIGHTBLUE_EX + f"\nšŸ“ˆ {coin} Price: ${price:.2f}") user_input = input(Fore.CYAN + f"Enter trade amount for {coin} (e.g., +10 or -5): ").strip() try: trade_amount = int(user_input) except ValueError: print(Fore.RED + "āš ļø Invalid input format. Use +10 or -5.") continue if trade_amount > 0: cost = trade_amount * price if user["cash"] >= cost: user["cash"] -= cost user["coins"][coin] += trade_amount print(Fore.GREEN + f"āœ… Bought {trade_amount} {coin} for ${cost:.2f}") coin_trades.append((coin, trade_amount)) else: print(Fore.RED + "āŒ Not enough cash.") continue elif trade_amount < 0: sell_amt = -trade_amount if user["coins"][coin] >= sell_amt: user["coins"][coin] -= sell_amt user["cash"] += sell_amt * price print(Fore.GREEN + f"āœ… Sold {sell_amt} {coin} for ${sell_amt * price:.2f}") coin_trades.append((coin, trade_amount)) else: print(Fore.RED + "āŒ Not enough coins.") continue # Update price for each coin traded this turn updated_coins = set() for coin, trade_amount in coin_trades: if coin in updated_coins: continue # Avoid multiple updates per coin per turn crypto = cryptos[coin] price_change = trade_amount * crypto["sensitivity"] randomness = random.uniform(-crypto["volatility"], crypto["volatility"]) * crypto["price"] new_price = crypto["price"] + price_change + randomness crypto["price"] = max(1.0, new_price) crypto["price_history"].append(crypto["price"]) save_graph(coin) updated_coins.add(coin)