-
Notifications
You must be signed in to change notification settings - Fork 1
/
spend.py
172 lines (123 loc) · 3.92 KB
/
spend.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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
'''
Handels Spend phase
'''
import hud as h
import random as r
def feed_crew(food, crew):
'''
Feed crew
'''
# set food_consumed equal to number of crew
food_consumed = crew
# remove the food consumed from the supply and display results
food -= food_consumed
# if the player has food remaining after feeding the crew display food consumed
# otherwise skip to loss on food end of game message
if food > 0:
print(f"Your crew consumes {food_consumed} units of food.")
print("")
return food
def crystal_burn(power):
'''
Check for crystal burnout
'''
# create variables good, burned, and burn_rate
good = 0
burned = 0
burn_rate = 20
# for each power crystal roll d100
for b in range(0, int(power)):
roll = r.randint(1, 100)
# if result is equal or less than burn_rate add +1 burned
if roll <= burn_rate:
burned += 1
# if not add +1 good
elif roll > burn_rate:
good += 1
# set power equal to good
power = good
# print and return results
print(f"{str(burned)} of your power crystals have burned out!")
print('')
return power
def spend_fuel(fuel):
'''
Spend fuel and move ship
'''
# begin fueling loop
fueling = True
while fueling:
# get user input
print("How much fuel will you spend?")
print('')
print("Spend 1 fuel to move 1 distance.")
print("Spent 3 fuel to move 2 distance.")
print("Spend 6 fuel to move 3 distance.")
print("Spent 10 fuel to move 4 distance.")
print("Spend 15 fuel to move 5 distance.")
print('')
amount = input()
# if user input is valid set fule_spent and distance_traveled amounts
if amount == '1':
fuel_spent = 1
distance_traveled = 1
elif amount == '3':
fuel_spent = 3
distance_traveled = 2
elif amount == '6':
fuel_spent = 6
distance_traveled = 3
elif amount == '10':
fuel_spent = 10
distance_traveled = 4
elif amount == '15':
fuel_spent = 15
distance_traveled = 5
# if input is not valid print error message and restart loop
else:
print("command is invalid please input 1, 3, 6, 10, or 15.")
print("")
continue
# if fuel spent is greater than fuel restart loop
if fuel_spent > fuel:
print("You do not have that much fuel.")
print('')
continue
# if fuel spent is not greater than fuel restart break loop
else:
break
# adjust fule and distance totals
fuel -= fuel_spent
# print user's choice
print("")
print(f"You have spent {fuel_spent} fuel.")
print(f"You will travel {distance_traveled} during the travel phase.")
print("")
return fuel, distance_traveled
def spend_phase(fuel, food, power, hull, crew, morale, g_dist, distance):
'''
Spends resources during the spend phase
'''
# phase intro message
print("Press ENTER to begin the Spend Phase!")
input()
# spend food
food = feed_crew(food, crew)
if food > 0:
# check for crystal burnout
power = crystal_burn(power)
if (food > 0) and (power > 0) and (fuel > 0):
# display HUD
h.hud(fuel, food, power, hull, crew, morale)
# display distance
h.status(distance, g_dist)
# spend fuel
fuel, distance_traveled = spend_fuel(fuel)
# if player has fuel set distance traveled to 1 to avoid out of fuel loss message
# if player has no fuel
else:
if fuel > 0:
distance_traveled = 1
else:
distance_traveled = 0
return fuel, food, power, hull, crew, morale, distance_traveled