-
Notifications
You must be signed in to change notification settings - Fork 1
/
production.py
293 lines (209 loc) · 8.14 KB
/
production.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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
'''
Handels Production phase
'''
import hud as h
import random as r
def assign_crew():
'''
Prompt user for crew assignment and take input
'''
# get input for crew assigned to fuel
print("How many crew members will you assign to fuel?")
fuel_crew = input()
# get imput for crew assigned to food
print("")
print("How many crew members will you assign to food?")
food_crew = input()
# get imput for crew assigned to power
print("")
print("How many crew members will you assign to power crystals?")
power_crew = input()
# get imput for crew assigned to hull
print("")
print("How many crew members will you assign to hull?")
hull_crew = input()
# get imput for crew assigned to morale
print("")
print("How many crew members will you assign to morale?")
morale_crew = input()
# print space between next block of text
print('')
return fuel_crew, food_crew, power_crew, hull_crew, morale_crew
def check_crew_assignment(fuel_crew, food_crew, power_crew, hull_crew, morale_crew, crew):
'''
Check that crew is assigned properly
'''
# Check for non-numeric input
if not (fuel_crew.isdigit() and food_crew.isdigit() and power_crew.isdigit() and hull_crew.isdigit() and morale_crew.isdigit()):
# if non-numeric input is found propt user and return false
print("Input is incorrect. Please input only numbers")
print("")
return False
# get total of assigned crew
assigned = int(fuel_crew) + int(food_crew) + int(power_crew) + int(hull_crew) + int(morale_crew)
# if assigned crew > crew prompt user and return false
if assigned > crew:
print("You assigned too many crew members.")
print("")
return False
# if assigned crew <= crew
else:
# display crew assignments
print(f"You have assigned {fuel_crew} crew to fuel.")
print(f"You have assigned {food_crew} crew to food.")
print(f"You have assigned {power_crew} crew to power.")
print(f"You have assigned {hull_crew} crew to hull.")
print(f"You have assigned {morale_crew} crew to morale.")
print('')
# if assigned crew < crew display warning
if assigned < crew:
print("You have not assigned all of your crew members!!!")
print('')
# create loop to ask if user wishes to proceed with the current selection
crew_check = True
while crew_check:
# prompt user for verification and get input
print("Proceed with the current assignment? (y/n)")
acknowledge = input()
print('')
# if input is not valid restart the loop
if acknowledge not in('y', 'n'):
print("Invalid command please type 'y' or 'n")
print('')
continue
# if y return True
if acknowledge == 'y':
return True
# if n return False
elif acknowledge == 'n':
return False
def generate(fuel_crew, food_crew, power_crew, hull_crew, morale_crew, fuel_chance, food_chance, power_chance, hull_chance, morale_chance, fuel_prod, food_prod, power_prod, hull_prod, morale_prod):
'''
Generate resources based on crew assignment
'''
# define resources generated
fuel_gen = 0
food_gen = 0
power_gen = 0
hull_gen = 0
morale_gen = 0
# calculate resorces generated this turn
# for each crew assigned to a resource roll a 100 sided die
# if that die rolls at or below resource_chance add resource_prod to resorce_gen
# Fuel
for c in range(0, int(fuel_crew)):
if r.randint(1,100) <= fuel_chance:
fuel_gen += fuel_prod
# Food
for c in range(0, int(food_crew)):
if r.randint(1,100) <= food_chance:
food_gen += food_prod
# Power
for c in range(0, int(power_crew)):
if r.randint(1,100) <= power_chance:
power_gen += power_prod
# Hull
for c in range(0, int(hull_crew)):
if r.randint(1,100) <= hull_chance:
hull_gen += hull_prod
# Morale
for c in range(0, int(morale_crew)):
if r.randint(1,100) <= morale_chance:
morale_gen += morale_prod
# display generated resources
print("")
print(f"Fuel generated: {fuel_gen} ")
print(f"Food generated: {food_gen}")
print(f"Power Crystals generated: {power_gen}")
print(f"Hull repaired: {hull_gen}")
print(f"Morale generated: {morale_gen}")
print('')
return fuel_gen, food_gen, power_gen, hull_gen, morale_gen
def is_capped(fuel, food, hull, power, morale):
'''
Check that each resource is under its resource cap if it is not set the value of that resource to its resource cap
'''
if fuel > 40:
print("You can only store up to 40 fuel")
print('')
fuel = 40
if food > 50:
print("You can only store up to 50 food")
print('')
food = 50
if hull > 6:
print("Hull cannot exceed 5")
print('')
hull = 6
if power > 15:
print("You can only store up to 15 power crystals")
print('')
power = 15
if morale > 100:
print("morale cannot exceed 100")
print('')
morale = 100
return fuel, food, hull, power, morale
def production_phase(fuel, food, power, hull, crew, morale):
'''
Main function for production phase
'''
# number of crew assigned to each resource
fuel_crew = 0
food_crew = 0
power_crew = 0
hull_crew = 0
morale_crew = 0
# set additional amount subtracted from morale during prodiction test
fuel_pen = 15
food_pen = 0
power_pen = 10
hull_pen = 20
morale_pen = 0
# chance to produce each reasorce
fuel_chance = (morale - fuel_pen)
food_chance = (morale - food_pen)
power_chance = (morale - power_pen)
hull_chance = (morale - hull_pen)
morale_chance = (morale - morale_pen)
# number of resorces produced on success
fuel_prod = 3
food_prod = 5
power_prod = 3
hull_prod = 1
morale_prod = 4
# display information for the beginning of the production phase
print("Press ENTER to begin the Production Phase!")
input()
# display resourse table
h.hud(fuel, food, power, hull, crew, morale)
# display chance for success when attempting to produce each resource type
print(f"You may assign {crew} crew members to produce resources")
print('')
print(f"Each crew assigned to fuel has a {fuel_chance}% chance to produce {fuel_prod} fuel.")
print(f"Each crew assigned to food has a {food_chance}% chance to produce {food_prod} food.")
print(f"Each crew assigned to power has a {power_chance}% chance to produce {power_prod} power crystals.")
print(f"Each crew assigned to hull has a {hull_chance}% chance to repair {hull_prod} damage to the hull.")
print(f"Each crew assigned to morale has a {morale_chance}% chance to improve the crew's morale by {morale_prod}%.")
print('')
# create loop for assigning crew
giving_orders = True
while giving_orders:
# assign crew to resources
fuel_crew, food_crew, power_crew, hull_crew, morale_crew = assign_crew()
# Check for valid input and user validation
# If input is valid and validated break loop
# otherwise restart loop and reassign crew
if check_crew_assignment(fuel_crew, food_crew, power_crew, hull_crew, morale_crew, crew):
break
# get generated resources and display them
fuel_gen, food_gen, power_gen, hull_gen, morale_gen = generate(fuel_crew, food_crew, power_crew, hull_crew, morale_crew, fuel_chance, food_chance, power_chance, hull_chance, morale_chance, fuel_prod, food_prod, power_prod, hull_prod, morale_prod)
# add generated resources to total resource
fuel += fuel_gen
food += food_gen
power += power_gen
hull += hull_gen
morale += morale_gen
# check for capped resources
fuel, food, hull, power, morale = is_capped(fuel, food, hull, power, morale)
return fuel, food, power, hull, crew, morale