import random # Game variables health = 100 food = 100 money = 50 location = "Town 1" days_travelled = 0 # Possible random events events = [ "You encounter a wild animal. Lose 10 health.", "You found a hidden stash of food. Gain 20 food.", "A storm delays your travel. Lose 1 day.", "You suffer from illness. Lose 20 health.", "A kind stranger gives you 20 money.", ] # Function to display current stats def display_stats(): print(f"Location: {location}") print(f"Health: {health}") print(f"Food: {food}") print(f"Money: {money}") print(f"Days Travelled: {days_travelled}") print() # Function to handle travel def travel(): global location, health, food, money, days_travelled location = "Town " + str(int(location.split()[-1]) + 1) days_travelled += 1 food -= 10 # Each day consumes 10 food event = random.choice(events) print(f"Event: {event}") # Apply the event effects if "Lose" in event: if "health" in event: health -= int(event.split()[3]) elif "food" in event: food -= int(event.split()[3]) elif "day" in event: days_travelled += 1 elif "Gain" in event: if "food" in event: food += int(event.split()[3]) elif "money" in event: money += int(event.split()[3]) # Function to check if the game is over def check_game_over(): if health <= 0: print("You have died from illness or injury!") return True if food <= 0: print("You have run out of food and perished!") return True if days_travelled >= 50: # Example: you win if you survive 50 days print("Congratulations! You made it to the destination!") return True return False # Main game loop def main(): global health, food, money, days_travelled print("Welcome to the Oregon Trail!") while True: display_stats() action = input("What would you like to do? (travel / rest / quit): ").lower() if action == "travel": travel() if check_game_over(): break elif action == "rest": food += 20 # Rest to regain food health += 10 # Rest to regain health print("You rested and regained some health and food.") elif action == "quit": print("Thanks for playing!") break else: print("Invalid choice! Please choose 'travel', 'rest', or 'quit'.") # Run the game if __name__ == "__main__": main()