Created
December 5, 2022 17:57
-
-
Save matthewdeanmartin/95f2ccfc09eea9c36d135f49afee5b80 to your computer and use it in GitHub Desktop.
ChatGPT oregon trail clone
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Define a function that represents the game | |
| def play_oregon_trail(): | |
| # Initialize the game variables | |
| distance_traveled = 0 | |
| supplies = 100 | |
| health = 100 | |
| weather = "sunny" | |
| # Print the game introduction | |
| print("Welcome to the Oregon Trail! You are a pioneer traveling west in search of a new life.\n") | |
| # Loop until the player has reached the end of the trail | |
| while distance_traveled < 2000: | |
| # Print the current game status | |
| print("Distance traveled: {} miles".format(distance_traveled)) | |
| print("Supplies: {}".format(supplies)) | |
| print("Health: {}".format(health)) | |
| print("Weather: {}\n".format(weather)) | |
| # Get the player's next action | |
| action = input("What would you like to do? (Travel, Rest, Hunt)\n") | |
| # Handle the player's action | |
| if action.lower() == "travel": | |
| # Travel 10 miles | |
| distance_traveled += 10 | |
| # Decrease supplies and health based on the weather | |
| if weather == "sunny": | |
| supplies -= 5 | |
| health -= 5 | |
| elif weather == "rainy": | |
| supplies -= 10 | |
| health -= 10 | |
| elif weather == "snowy": | |
| supplies -= 15 | |
| health -= 15 | |
| elif action.lower() == "rest": | |
| # Increase health | |
| health += 20 | |
| # Decrease supplies | |
| supplies -= 10 | |
| elif action.lower() == "hunt": | |
| # Hunt for food | |
| food = 30 | |
| # Increase supplies | |
| supplies += food | |
| # Decrease health | |
| health -= 10 | |
| # Check if the player has died | |
| if health <= 0 or supplies <= 0: | |
| print("You have died on the trail. Better luck next time!") | |
| return | |
| # Randomly generate the weather for the next turn | |
| weather_options = ["sunny", "rainy", "snowy"] | |
| weather = random.choice(weather_options) | |
| # If the player reaches the end of the trail, they win the game | |
| print("Congratulations, you won!") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment