• API
• FAQ
• Tools
• Archive
SHARE
TWEET

# Project 3: Oregon Trail

a guest May 15th, 2019 140 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. from random import choice
2.
3. # Globals
4. health = 5
5. food_pounds = 500
6. miles_to_go = 2000
7. cur_month = 3
8. cur_day = 1
9. game_over = False
10.
11. months_with_31_days = [3, 5, 7, 8, 10, 12]
12.
14.     global cur_month, cur_day, miles_to_go, food_pounds, health
15.     if cur_day == 31 or (cur_day == 30 and cur_month not in months_with_31_days):
16.         cur_month += 1
17.         cur_day = 1
18.     else:
19.         cur_day += 1
20.
21.     food_pounds -= 5
22.     if food_pounds < 0:
23.         print('GAME OVER')
24.         print('You lost! You had nothing to eat and starved to death!')
25.         status()
26.         exit()
27.     print('You ate 5 lbs of food. Food remaining: ' + str(food_pounds))
28.
29.     if choice(range(14)) == 0:
30.         health -= 1
31.         print('You got sick and lost one health! Your health is now: ' + str(health) + 'hp')
32.     if health <= 0:
33.         print('GAME OVER')
34.         print('You lost! Your health dropped below 1!')
35.         status()
36.         exit()
37.     print('It is now %d/%d' % (cur_month, cur_day))
38.
39.
40.     if (cur_month, cur_day) == (12, 31):
41.         print('GAME OVER')
42.         if miles_to_go > 0:
43.             print('You lost! You did not make it before 12/31!')
44.         else:
45.             print('You won! You survived the Oregon Trail!')
46.             miles_to_go = 0
47.         status()
48.         exit()
49.
50. def travel():
51.     global miles_to_go
52.     miles_to_go -= choice(range(30, 61))
53.     for i in range(choice(range(3, 8))):
55.
56.     if miles_to_go <= 0:
57.         print('You won! You survived the Oregon Trail!')
58.         miles_to_go = 0
59.     status()
60.
61.     if miles_to_go <= 0:
62.         exit()
63.
64. def rest():
65.     global health
66.     if health < 5:
67.         for i in range(choice(range(2, 6))):
69.         health += 1
70.         print('Your health increases by 1 up to ' + str(health))
71.     else:
72.         print('Your health is already maxed out and there is no time to waste!')
73.
74. def hunt():
75.     global food_pounds
76.     food_pounds += 100
77.     for i in range(choice(range(2, 6))):
79.     print('You had a good hunt and your food stores increase by 100 up to ' + str(food_pounds))
80.
81. def status():
82.     print(name + ', your current status is:')
83.     print('-Today is ' + str(cur_month) + '/' + str(cur_day))
84.     print('-Food: ' + str(food_pounds) + ' pounds')
85.     print('-Health: ' + str(health))
86.     print('-Distance traveled: ' + str(2000 - miles_to_go) + ' miles')
87.     print(' You still have ' + str(miles_to_go) + ' miles to go before you reach Oregon.')
88.
89. def help():
90.     print('Commands: travel, rest, hunt, status, help, quit')
91.
92. def quit():
93.     print('You gave up on your dreams to make it to Oregon!')
94.     status()
95.     exit()
96.
97. def take_action(command):
98.     if command == 'travel':
99.         travel()
100.     elif command == 'rest':
101.         rest()
102.     elif command == 'hunt':
103.         hunt()
104.     elif command == 'status':
105.         status()
106.     elif command == 'help':
107.         help()
108.     elif command == 'quit':
109.         quit()
110.
111. name = input('What is your name? ')
112. while True:
113.     print('\nWhat do you want to do? (Type "help" to list commands)')
114.     command = input('>')
115.     take_action(command)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy.

Top