@DuncanVaughan5/

Oregon Trail

Python

The Oregon Trail Game

fork
loading
Files
  • main.py
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
import random

monthKey = "mon"
dayKey = "d"
milesKey = "mil"
foodKey = "f"
healthKey = "h"
sickDaysListKey = "sd"
gameStateDict = { monthKey: 3, dayKey: 1, milesKey: 1750, foodKey: 2500, healthKey: 5, sickDaysListKey: [0, 0]}
maxMonth = 12
daysPerMonth = [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
milesToGo = 1750
lbsOfFood = 2500
maxHealthIndex = 5
healthIndex = maxHealthIndex
commandString = ""

def set_sick_days():
  if gameStateDict [monthKey] <= maxMonth:
    sickDay1 = random.randrange(1, daysPerMonth [gameStateDict[monthKey]] + 1, 1)
    sickDay2 = sickDay1
    while sickDay2 == sickDay1:
      sickDay1 = random.randrange(1, daysPerMonth [gameStateDict[monthKey]] + 1, 1)
    if sickDay1 < sickDay2:
      gameStateDict[sickDaysListKey][0] = sickDay1
      gameStateDict[sickDaysListKey][1] = sickDay2
    else:
      gameStateDict[sickDaysListKey][0] = sickDay2
      gameStateDict[sickDaysListKey][1] = sickDay1


def add_days(numDays):
  while numDays > 0:
    if gameStateDict[monthKey] <= maxMonth: 
      nextDay = gameStateDict[dayKey] + 1
      if nextDay > daysPerMonth[gameStateDict[monthKey]]:
        nextDay = 1
        gameStateDict[monthKey] = gameStateDict[monthKey] + 1
        set_sick_days()
      sickDay1 = gameStateDict[sickDaysListKey][0]
      sickDay2 = gameStateDict[sickDaysListKey][1]
      if nextDay == sickDay1 or nextDay == sickDay2:
        gameStateDict[healthKey] = gameStateDict[healthKey] - 1
      gameStateDict[dayKey] = nextDay
    gameStateDict[foodKey] = gameStateDict[foodKey] - 10
    numDays = numDays - 1
  return

def status():
  statusString = "date: " + str(gameStateDict[monthKey]) + "/" + str(gameStateDict[dayKey])
  statusString += ", milesToGo: " + str(gameStateDict[milesKey]) + ", food: " + str(gameStateDict[foodKey]) + ", health: " + str(gameStateDict[healthKey])
  statusString += ", sickDays: " + str(gameStateDict[sickDaysListKey])
  print(statusString)
  return

def help():
  print("Commands: travel, rest, hunt, status, help, quit")
  return

def travel():
  distanceTraveled = random.randrange(30, 61, 1)
  gameStateDict[milesKey] = gameStateDict[milesKey] - distanceTraveled
  travelDays = random.randrange(3, 8, 1)
  add_days(travelDays)
  return

def rest():
  if gameStateDict[healthKey] < maxHealthIndex:
    gameStateDict[healthKey] = gameStateDict[healthKey] + 1
  restDays = random.randrange(2, 6, 1)
  add_days(restDays)
  return

def hunt():
  gameStateDict[foodKey] = gameStateDict[foodKey] + 100
  huntDays = random.randrange(2, 6, 1)
  add_days(huntDays)
  return

set_sick_days()
print("Oregon Trail")
status()
help()
while commandString != "quit":
  commandString = input("Command: ")
  if commandString == "travel":
    travel()
    status()
  elif commandString == "rest":
    rest()
    status()
  elif commandString == "hunt":
    hunt()
    status()
  elif commandString == "status":
    status()
  elif commandString == "help":
    help()
  else:
    help()
  if gameStateDict[milesKey] <= 0:
    print("YOU WON!")
  if gameStateDict[monthKey] > maxMonth:
    print("Sorry, but you lost.")