Certainly! Below is a basic text-based Oregon Trail game with as many features as possible for a simple console application. This game includes decision-making, random events, resource management, and multiple endings.
import random
import time
class Player:
def __init__(self):
self.health = 100
self.food = 200 # pounds
self.ammo = 20 # bullets
self.money = $50
self.distance_traveled = 0
self.days_traveled = 0
self.party_size = 5
self.wagon_condition = 100
def status(self):
print(f"Health: {self.health}")
print(f"Food: {self.food} lbs")
print(f"Ammo: {self.ammo} bullets")
print(f"Money: ${self.money}")
print(f"Distance Traveled: {self.distance_traveled} miles")
print(f"Days Traveled: {self.days_traveled} days")
print(f"Party Size: {self.party_size}")
print(f"Wagon Condition: {self.wagon_condition}%\n")
def hunt(player):
print("You decide to hunt for food.")
time.sleep(1)
success = random.choices([True, False], weights=[60, 40])[0]
if success:
food_gained = random.randint(20, 50)
player.food += food_gained
print(f"Hunting was successful! You gained {food_gained} lbs of food.\n")
else:
print("Hunting was unsuccessful. You return empty-handed.\n")
player.ammo -= 1
if player.ammo < 0:
player.ammo = 0
def rest(player):
print("You decide to rest for the day.")
time.sleep(1)
player.health += random.randint(5, 15)
if player.health > 100:
player.health = 100
player.days_traveled += 1
player.food -= player.party_size * 2
print("You feel rested and ready to continue.\n")
def travel(player):
distance = random.randint(10, 20)
player.distance_traveled += distance
player.days_traveled += 1
player.food -= player.party_size * 2
player.wagon_condition -= random.randint(1, 5)
if player.wagon_condition < 0:
player.wagon_condition = 0
print(f"You traveled {distance} miles.\n")
def random_event(player):
event = random.choice([
"storm",
"bandit_attack",
"illness",
"found_supplies",
"wagon_breakdown",
"river_crossing"
])
if event == "storm":
print("A terrible storm hits! Your wagon takes damage.")
player.wagon_condition -= random.randint(10, 20)
if player.wagon_condition < 0:
player.wagon_condition = 0
elif event == "bandit_attack":
print("Bandits attack your party!")
if player.ammo > 0:
fight_or_flee = input("Do you want to (f)ight or (f)lee? ").lower()
if fight_or_flee == "f" and player.ammo > 0:
player.ammo -= 1
if random.random() < 0.7:
print("You successfully fought off the bandits!\n")
else:
print("The bandits overwhelmed you. You lost some supplies.")
player.food -= random.randint(10, 30)
player.money -= random.randint(5, 15)
else:
print("You fled from the bandits, but lost some supplies.")
player.food -= random.randint(5, 15)
else:
print("You have no ammo! You fled from the bandits, but lost some supplies.")
player.food -= random.randint(5, 15)
elif event == "illness":
print("Someone in your party fell ill.")
player.health -= random.randint(5, 15)
if player.health < 0:
player.health = 0
elif event == "found_supplies":
print("You found abandoned supplies!")
player.food += random.randint(20, 50)
player.ammo += random.randint(1, 5)
elif event == "wagon_breakdown":
print("Your wagon broke down!")
player.wagon_condition = 0
repair_cost = random.randint(10, 30)
if player.money >= repair_cost:
print(f"You have enough money to repair the wagon for ${repair_cost}.")
player.money -= repair_cost
player.wagon_condition = 100
else:
print(f"You don't have enough money to repair the wagon. It remains broken.")
elif event == "river_crossing":
print("You need to cross a river.")
cross_choice = input("Do you want to (f)ord the river or (b)uild a raft? ").lower()
if cross_choice == "f":
if random.random() < 0.7:
print("You successfully forded the river.\n")
else:
print("The river was too strong. You lost some supplies.")
player.food -= random.randint(10, 20)
player.ammo -= random.randint(1, 3)
elif cross_choice == "b":
if player.ammo >= 3:
player.ammo -= 3
print("You built a raft and successfully crossed the river.\n")
else:
print("You don't have enough ammo to build a raft. You'll have to ford the river.")
if random.random() < 0.7:
print("You successfully forded the river.\n")
else:
print("The river was too strong. You lost some supplies.")
player.food -= random.randint(10, 20)
player.ammo -= random.randint(1, 3)
def trade_post(player):
print("You've reached a trade post!")
time.sleep(1)
print("What would you like to do?")
print("1. Buy food")
print("2. Buy ammo")
print("3. Sell food")
print("4. Sell ammo")
print("5. Leave")
choice = input("Enter your choice: ")
if choice == "1":
amount = int(input("How many pounds of food would you like to buy? (1 lb = $1) "))
if player.money >= amount:
player.food += amount
player.money -= amount
print(f"You bought {amount} lbs of food.\n")
else:
print("You don't have enough money.\n")
elif choice == "2":
amount = int(input("How many bullets would you like to buy? (1 bullet = $2) "))
if player.money >= amount * 2:
player.ammo += amount
player.money -= amount * 2
print(f"You bought {amount} bullets.\n")
else:
print("You don't have enough money.\n")
elif choice == "3":
amount = int(input("How many pounds of food would you like to sell? (1 lb = $0.50) "))
if player.food >= amount:
player.food -= amount
player.money += amount // 2
print(f"You sold {amount} lbs of food.\n")
else:
print("You don't have enough food to sell.\n")
elif choice == "4":
amount = int(input("How many bullets would you like to sell? (1 bullet = $1) "))
if player.ammo >= amount:
player.ammo -= amount
player.money += amount
print(f"You sold {amount} bullets.\n")
else:
print("You don't have enough ammo to sell.\n")
elif choice == "5":
print("You leave the trade post.\n")
else:
print("Invalid choice.\n")
def check_status(player):
if player.health <= 0:
print("Your party's health has deteriorated too much. You've all perished. Game Over.")
return True
if player.food <= 0:
print("You've run out of food. Your party starves. Game Over.")
return True
if player.wagon_condition <= 0:
print("Your wagon is too broken to continue. You are forced to settle where you are. Game Over.")
return True
if player.distance_traveled >= 2000:
print("Congratulations! You've successfully reached Oregon!")
return True
return False
def main():
player = Player()
print("Welcome to the Oregon Trail!")
time.sleep(1)
print("Your journey begins now. Good luck!\n")
while True:
player.status()
print("What would you like to do?")
print("1. Hunt for food")
print("2. Rest for the day")
print("3. Travel")
print("4. Visit a trade post")
print("5. Check status")
choice = input("Enter your choice: ")
if choice == "1":
hunt(player)
elif choice == "2":
rest(player)
elif choice == "3":
travel(player)
if random.random() < 0.3: # 30% chance of a random event
random_event(player)
elif choice == "4":
trade_post(player)
elif choice == "5":
player.status()
else:
print("Invalid choice. Please try again.\n")
if check_status(player):
break
if __name__ == "__main__":
main()
Features Included:
-
Player Status:
- Health
- Food
- Ammo
- Money
- Distance Traveled
- Days Traveled
- Party Size
- Wagon Condition
-
Actions:
- Hunt for Food: Attempt to hunt for food, which consumes ammo. There's a 60% success rate.
- Rest for the Day: Restore health but consume food.
- Travel: Move a random distance between 10-20 miles, consume food, and reduce wagon condition.
- Visit a Trade Post: Buy or sell food and ammo.
- Check Status: View the current status of the player.
-
Random Events:
- Storm: Reduces wagon condition.
- Bandit Attack: Option to fight (if you have ammo) or flee. Fighting has a 70% success rate.
- Illness: Reduces party health.
- Found Supplies: Increases food and ammo.
- Wagon Breakdown: Wagon condition drops to 0. You can repair it if you have enough money.
- River Crossing: Choose to ford the river (70% success rate) or build a raft (requires 3 bullets).
-
Game Over Conditions:
- Health reaches 0 or below.
- Food reaches 0 or below.
- Wagon condition reaches 0 or below.
- Successfully travel 2000 miles to reach Oregon.
This game can be further expanded with more events, items, and complex decision-making.