-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgame_menu.py
More file actions
786 lines (660 loc) · 27.3 KB
/
Copy pathgame_menu.py
File metadata and controls
786 lines (660 loc) · 27.3 KB
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
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
'''
Daily game menu
'''
from math import (ceil, floor)
from game import (run_day, end_game)
from utils import (cyan, clear_terminal, gold, pink, green, print_go_back,
print_press_enter_to, red, orange, print_error_message,
print_current_balance,
validate_input, validate_yes_no, yellow)
from save_load import (save_data)
from shared import (cost_to_make, get_portions_available)
import constants
def daily_menu(stats):
'''
Daily player menu to purchase upgrades and make changes to recipes
'''
while True:
clear_terminal()
# Converts the .5 or .0 into text.
if (stats["day"] % 1) == 0:
text_time_of_day = "Morning"
else:
text_time_of_day = "Afternoon"
# Creates and prints game menu text
print(menu_string(stats, text_time_of_day))
# Get user input
user_choice = input(orange(f'\n{"Input choice (0-8) : "}'))
# Validation of user input
if not validate_input(user_choice, 8):
continue
# If user wishes to start trading, make sure sure user has all the
# required elements to do so, or show error.
if (not stats["location"]["1"]["purchased"]
and user_choice == '7'):
print_error_message("No locations purchased yet.")
continue
if (stats["location"]["1"]["cart_lvl"] == 0
and user_choice == '7'):
print_error_message("No carts purchased yet.")
continue
if (stats["location"]["1"]["staff_lvl"] == 0
and user_choice == '7'):
print_error_message("No staff purchased yet.")
continue
if (get_portions_available(stats) == 0
and user_choice == '7'):
# If both True
print_error_message("You have no stock to sell.")
continue
break
# Where to take user based on user input.
if user_choice == '1':
purchase_location(stats)
elif user_choice == '2':
purchase_cart_menu(stats)
elif user_choice == '3':
purchase_staff_menu(stats)
elif user_choice == '4':
purchase_stock_menu(stats)
elif user_choice == '5':
change_recipe_menu(stats)
elif user_choice == '6':
set_selling_price(stats)
elif user_choice == '7':
result, stats = run_day(stats)
if result:
end_game(stats)
else:
save_data(stats, False)
daily_menu(stats)
elif user_choice == '8':
help_menu(stats)
elif user_choice == '0':
clear_terminal()
print(f'\n{pink("IMPORTANT: ")} Make sure you write down your '
+ 'Game ID as you will need it to return to this game.')
print(f'\nGame ID: {gold(stats["user_id"])}')
# Save game.
save_data(stats, False)
# After enter user is taken back to main menu.
print_press_enter_to("\nPress Enter to go to main menu...")
def menu_string(stats, text_time_of_day):
'''
Doc string for daily game menu
'''
# Set variables.
selling_price = "Base price: £{:.2f}".format(stats["selling_price"])
recipe = "Cost: £{:.2f}".format(cost_to_make(stats))
cash = "£{:.2f}".format(stats["cash"])
stock = f"Stock: {get_portions_available(stats)}"
action_cart = ""
action_staff = ""
action_loc = ""
game_id = f'(Game ID : {cyan(stats["user_id"])})'
company_name = stats['name']
day = floor(stats["day"])
# If user has purchased location but no cart or staff, show warning.
for key in stats["location"]:
if (stats["location"][key]["purchased"]
and stats["location"][key]["cart_lvl"] == 0):
action_cart = "ACTION REQUIRED"
break
for key in stats["location"]:
if (stats["location"][key]["purchased"]
and stats["location"][key]["staff_lvl"] == 0):
action_staff = "ACTION REQUIRED"
break
# If user has not yet purchased location 1, show warning.
if not stats["location"]["1"]["purchased"]:
action_loc = "ACTION REQUIRED"
# Return string.
return f"""{gold(company_name)} - {game_id}
{constants.LINE}
Current balance {green(cash)}
Day: {pink(day)} / {constants.LAST_DAY}
Time of Day: {pink(text_time_of_day)}
Company reputation: {gold(stats['reputation'])} / 5
{cyan('Choose from the following options:')}
{constants.LINE}
{'1. Purchase location':<33}{red(action_loc):<10}
{'2. Purchase / upgrade cart(s)':<33}{red(action_cart):<10}
{'3. Hire / upgrade staff':<33}{red(action_staff):<10}
{'4. Purchase stock':<33}{green(stock):<10}
{'5. Change Recipe':<33}{green(recipe):<10}
{'6. Set selling prices':<33}{green(selling_price):<10}
{pink("7. Start trading")} - Day {day} - {text_time_of_day}
{gold("8. Help")}
{yellow('0. Save and quit')}"""
def purchase_location(stats):
'''
Purchase location menu for player
'''
# Set variables
loc_name = constants.LOCATION_NAMES
loc_cost = constants.LOCATION_COSTS
while True:
clear_terminal()
# Header
print(f'{cyan("Purchase hotdog pitch locations")}')
print(constants.LINE)
print(f'Current balance {green(print_current_balance(stats))}\n')
# Body
print('Each location purchase means more customers to sell to. '
+ 'The better the location \nthe more potential customers.\n')
print(f'{pink("TIP")}: Each location will need a cart and a staff '
+ 'member before they sell any \nhotdogs.\n')
# Create first part of string. Location number and name.
for count, key in enumerate(loc_name, start=1):
str_part_1 = f'{count}. {key}'
# Check to see if location before has been purchased.
# If not print "Not yet available".
# elif, print Available and location cost.
# else, print purchased.
if not purchase_loc_try(stats, count):
print(f'{str_part_1:<16}' + ' - '
+ f'{red("Not yet available"):<53}')
elif not stats['location'][str(count)]['purchased']:
text = f'PURCHASE for £{loc_cost[count - 1]}'
print(f'{str_part_1:<16}' + ' - ' + f'{green("Available"):<53}'
+ ' - ' f'{cyan(text):<30}')
else:
print(f'{str_part_1:<16}' + ' - '
+ f'{gold("Purchased"):<52}')
print_go_back()
# Get user input
user_choice = input(f'\n{orange("Input choice: ")}')
# Validate user input
if not validate_input(user_choice, 5):
continue
# If user input is 0 go back to game menu.
if int(user_choice) == 0:
break
# If location Available then check have cash to purchase.
# elif location not available, display error.
# else, display error.
if (not stats['location'][str(user_choice)]['purchased']
and purchase_loc_try(stats, int(user_choice))):
remaining_cash = stats["cash"] - loc_cost[int(user_choice)-1]
elif not purchase_loc_try(stats, int(user_choice)):
print_error_message('Can not make this purchase yet.')
continue
else:
print_error_message('Already Purchased.')
continue
# Check if remaining cash will remain >= 0
# If enough, purchase and show success message.
# else, display error.
if remaining_cash >= 0:
stats['location'][str(user_choice)]['purchased'] = True
var_1 = loc_name[int(user_choice)-1]
var_2 = loc_cost[int(user_choice)-1]
print(green(f'Your purchased {var_1} for £{var_2}'))
stats["cash"] = remaining_cash
print(cyan(f'Remaining balance {print_current_balance(stats)}'))
print_press_enter_to("Press Enter to continue...")
else:
print_error_message("Not enough funds")
daily_menu(stats)
def purchase_loc_try(stats, count):
'''
Check to see if location before has been purchased.
Returns True or False.
'''
try:
stats['location'][str(count - 1)]['purchased']
except KeyError:
return True
else:
return stats['location'][str(count-1)]['purchased']
def purchase_cart_menu(stats):
'''
Purchase cart menu for player
'''
# Set variables.
loc_name = constants.LOCATION_NAMES
cart_price = constants.CART_COSTS
while True:
clear_terminal()
# Header
print(f'{cyan("Purchase or upgrade carts at your hotdog pitch ")}'
+ f'{cyan("locations")}')
print(constants.LINE)
print(f'Current balance {green(print_current_balance(stats))}\n')
# Heading text
print('Each upgrade on a cart will produce better quality hotdogs.'
+ f' So you will sell {constants.CART_SELLING_INCREASE}% more'
+ ' for each level on top the base selling price without any'
+ ' penalties at that \nlocation.')
print(f'\n{pink("TIP")}: Each location will need a staff member'
+ ' before they sell any hotdogs.\n')
# Body
# Print carts, levels, costs, or if available.
for count, key in enumerate(loc_name, start=1):
cart_level = stats['location'][str(count)]['cart_lvl']
# Create first part of string, index and location.
str_part_1 = f'{count}. {key}'
# Shows cart level, if 0 then cart not yet purchased.
if cart_level == 0:
str_part_2 = red('Not currently owned')
else:
str_part_2 = cyan(f'Current level is {cart_level}')
# Check to see if location for cart has been purchased yet.
# If not, str_part_3 = purchase location first.
# If cart level 0, str_part_3 = purchase cart.
# If cart > 0 , show str_part_3 = cart
# If cart = 5. str_part_3 = no further upgrades.
if not stats['location'][str(count)]['purchased']:
str_part_3 = red('Purchase location first')
elif cart_level == 0:
str_part_3 = green(f'PURCHASE for £ {cart_price[cart_level]}')
elif cart_level == 5:
str_part_3 = gold('No further upgrades')
else:
str_part_3 = green(f'UPGRADE for £{cart_price[cart_level]}')
# Print string based on above.
print(
f'{str_part_1:<16}' + ' - ' +
f'{str_part_2:<23}' + ' - ' +
f'{str_part_3:<18}'
)
print_go_back()
# Get user input.
result = input(f'\n{orange("Input choice (0-5): ")}')
# Validate user input.
if not validate_input(result, 5):
continue
# if user input = 0 go back to game menu.
if int(result) == 0:
break
# Make sure location has been purchased first.
if not stats['location'][str(result)]['purchased']:
print_error_message("Purchase Land")
continue
# Check if cart is not already at max level.
cart_level = stats['location'][str(result)]['cart_lvl']
if cart_level == 5:
print_error_message("Already at max level.")
continue
# Check if remaining cash will above 0 after purchase, if so
# continue, else loop.
remaining_cash = stats["cash"] - cart_price[cart_level]
if remaining_cash >= 0:
new_cart_lvl = cart_level + 1
stats['location'][str(result)]['cart_lvl'] = new_cart_lvl
stats["cash"] = remaining_cash
loc = int(result) - 1
# Print success message.
print(green(f'Cart level {new_cart_lvl} purchased for ')
+ green(f'{loc_name[loc]} for £{cart_price[cart_level]}.'))
print(cyan(f'Remaining balance {print_current_balance(stats)}'))
print_press_enter_to("Press Enter to continue...")
continue
print_error_message("Not enough funds")
continue
daily_menu(stats)
def purchase_staff_menu(stats):
'''
Hire and train staff menu
'''
# Set variables.
loc_name = constants.LOCATION_NAMES
staff_price = constants.STAFF_COSTS
while True:
clear_terminal()
# Header
print(cyan("Hire and train staff for your hotdog pitch")
+ cyan("locations."))
print(constants.LINE)
# Heading text
print(f'Current balance {green(print_current_balance(stats))}\n')
print('Better trained staff encourage returning customers meaning more'
+ ' footfall.\n')
print(f'{pink("TIP")}: Each location will need a cart before they sell'
+ ' any hotdogs.\n')
# Body
# Print staff, levels, costs, or if available.
for count, key in enumerate(loc_name, start=1):
staff_level = stats['location'][str(count)]['staff_lvl']
# Create first part of string, index and location.
text1 = f'{count}. {key}'
# Shows staff level, if 0 then staff not yet purchased.
if staff_level == 0:
text2 = red('Vacant position')
else:
text2 = cyan(f'Current level is {staff_level}')
# Check to see if location for staff has been purchased yet.
# If not, str_part_3 = purchase location first.
# If staff level 0, str_part_3 = purchase staff.
# If staff > 0 , show str_part_3 = staff
# If staff = 5. str_part_3 = no further upgrades.
if not stats['location'][str(count)]['purchased']:
text3 = red('Purchase location first')
elif staff_level == 0:
text3 = green(f'PURCHASE for £ {staff_price[staff_level]}')
elif staff_level == 5:
text3 = gold('No training required')
else:
text3 = green(f'TRAIN for £{staff_price[staff_level]}')
# Print string based on above.
print(f'{text1:<16}' + ' - ' + f'{text2:<23}'
+ ' - ' f'{text3:<18}')
print_go_back()
# Get user input
user_choice = input(f'\n{orange("Input choice (0-5): ")}')
# Validate user input
if not validate_input(user_choice, 5):
continue
# if user input = 0 go back to game manu.
if int(user_choice) == 0:
break
# Make sure location has been purchased first
if not stats['location'][str(user_choice)]['purchased']:
print_error_message("Purchase Land")
continue
# Check if staff is not already at max level.
staff_level = stats['location'][str(user_choice)]['staff_lvl']
if staff_level == 5:
print_error_message("Already at max level.")
continue
# Check if remaining cash < 0 after purchase, if
# so continue, else pass
remaining_cash = stats["cash"] - staff_price[staff_level]
if remaining_cash >= 0:
new_staff_lvl = staff_level + 1
stats['location'][str(user_choice)]['staff_lvl'] = new_staff_lvl
stats["cash"] = remaining_cash
loc = int(user_choice) - 1
# Print success message.
print(green(f'Staff level {new_staff_lvl} purchased for')
+ f'{loc_name[loc]} for £{staff_price[staff_level]}.')
text = f'Remaining balance {print_current_balance(stats)}'
print(cyan(text))
print_press_enter_to("Press Enter to continue...")
continue
print_error_message("Not enough funds")
continue
daily_menu(stats)
def purchase_stock_menu(stats):
'''
Purchase stock menu
'''
while True:
clear_terminal()
# Header
print(f'{cyan("Purchase consumable stock")}')
print(constants.LINE)
print(f'Current balance {green(print_current_balance(stats))}')
print('You have enough ingredients to sell '
+ f'{gold(get_portions_available(stats))} hotdogs.\n')
# Show current ingredients in stock
print(f'{cyan("Current stock:")}')
print(constants.LINE)
print(f'{stats["bun"]:<5} x {"Hotdog bun(s)":<20}'
+ f'| {stats["sausage"]:<5} x Sausage(s)')
print(f'{stats["onion"]:<5} x {"Onion(s)":<20}'
+ f'| {stats["sauce"]:<5} x Special sauce(s)')
# Show price list for ingredients
print(constants.PURCHASE_STOCK_OPTIONS)
# Tip to show.
print(f"\n{pink('TIP: ')}This will purchase the amount of "
+ "ingredients you \nneed for the amount of hotdogs "
+ "you want to stock. All sales are final")
print_go_back()
# Get user input
user_choice = input(orange('\nHow many hotdogs would you like to '
+ 'have in stock? '))
# Validation checks
if not validate_input(user_choice, 99999):
continue
if int(user_choice) == 0:
break
# Setting up variables
cost = 0
basket = { # Create empty basket
"stock": [],
"recipe": [],
"portions": [],
"cost": [],
"total_qty_r": [], # Total Qty Required
"total_qty_c": [] # Total cost for item
}
# Calculate how many ingredients need to be purchased and thee
# costs including total cost.
for count, key in enumerate(constants.STOCK_OPTIONS):
basket["stock"].append(stats[key])
basket["recipe"].append(stats['recipe'][key])
basket["portions"].append(constants.STOCK_COSTS[key][1])
basket["cost"].append(constants.STOCK_COSTS[key][2])
basket["total_qty_r"].append(
ceil(
(
int(user_choice)
- (
basket["stock"][count]
/ basket["recipe"][count]
)
)
/ basket["portions"][count]
* basket["recipe"][count]
)
)
if basket["total_qty_r"][count] < 0:
basket["total_qty_r"][count] = 0
basket["total_qty_c"].append(
basket["total_qty_r"][count]
* basket["cost"][count]
)
cost += basket["total_qty_c"][count]
# If cost is 0 then no ingredients required to be purchased
# Show error to user then go back to beginning of loop.
if cost == 0:
print_error_message("\nYou already have this many hotdogs in "
+ "stock.")
continue
# Displaying checkout to the user
while True:
clear_terminal()
# Header
print(f'\n{cyan("Checkout:")}')
print(constants.LINE)
print(f'{"Item:":<23}{"Qty:":<10}{"Portions:":<12}'
+ f'{"Sub total:":<10}')
print(constants.LINE)
# Basket
for count, key in enumerate(constants.STOCK_COSTS):
text = (basket["portions"][count]
* basket["total_qty_r"][count])
text2 = basket["total_qty_c"][count]
print(f'{constants.STOCK_COSTS[key][0]:<23}'
+ f'{basket["total_qty_r"][count]:<12}'
+ f'{text:<10}'
+ f'£{"{:.2f}".format(text2):<10}')
print(constants.LINE)
# Basket total
print('TOTAL COST: ' + green(f"£{'{:.2f}'.format(cost)}"))
# User input required
user_choice = input(f'\n{orange("Would you like to make this")}'
+ f'{orange(" purchase? (yes / no) ")}')
# Validate user input
if not validate_yes_no(user_choice):
continue
if user_choice.lower() in ['y', 'ye', 'yes']:
# Check if remaining cash will above 0 after purchase,
# if so continue, else loop
remaining_cash = stats["cash"] - cost
if remaining_cash < 0:
print_error_message("Not enough funds")
break
# Update player stock with purchased items
for count, i in enumerate(constants.STOCK_OPTIONS):
stats[i] += (basket["portions"][count]
* basket["total_qty_r"][count])
# Purchase successful, update user cash balance.
print(green('Purchase Successful'))
stats["cash"] = remaining_cash
print(cyan('Remaining balance '
+ f'{print_current_balance(stats)}'))
print_press_enter_to("Press Enter to continue...")
break
# Purchaser unsuccessful
print(red('Purchase Aborted'))
print_press_enter_to("Press Enter to continue...")
break
daily_menu(stats)
def change_recipe_menu(stats):
'''
Player is able to change recipe menu
'''
def validate_recipe_change(data):
'''
Check user input for recipe change is valid
'''
if len(data) == 1 and data[0] == str(0):
return True
if len(data) != 2:
print(f'{red("Check instructions and try again.")}')
print_press_enter_to("Press Enter to continue...")
else:
if validate_input(data[0], 999) and validate_input(data[1], 999):
return True
return False
# def validate_recipe_change() end here
# Main function thread starts here
while True:
clear_terminal()
# Set variables
bun = green(stats['recipe']['bun'])
sausage = green(stats['recipe']['sausage'])
onion = green(stats['recipe']['onion'])
sauce = green(stats['recipe']['sauce'])
# Display current recipe to user
print(f'{cyan("Make changes to your recipe")}')
print(constants.LINE)
print(cyan("\nCurrent Recipe:"))
print(constants.LINE)
print(f'{cyan("Ingredient "):<12}{"|":<2}'
+ f'{cyan("Portions per serving"):<0}')
print(constants.LINE)
print(f'{"1. Buns":<12}{"|":<2}{f"{bun}":<4} (Min 1 - Max 1)')
print(f'{"2. Sausages":<12}{"|":<2}{f"{sausage}":<4} (Min 1 - Max 2)')
print(f'{"3. Onions":<12}{"|":<2}{f"{onion}":<4} (Min 0 - Max 5)')
print(f'{"4. Sauce":<12}{"|":<2}{f"{sauce}":<4} (Min 0 - Max 5)')
# Display cost to make each hotdog
prod_cost = cost_to_make(stats)
markup = constants.PRODUCT_VALUE_MAX_INCREASE
text = green(f'£{str("{:.2f}".format(prod_cost))}')
print(f'\nCost to make each hotdog you sell: {text}')
# Display recommended retail cost to user
prod_cost *= markup
text = gold(f'£{str("{:.2f}".format(prod_cost + .50))}')
print(f'Recommended retail price: {text}')
print(f'\n{pink("TIP:")} Use this to guide your selling price.')
print_go_back()
# Show tip to user
print(f'\n{pink("HOW: ")}To update your recipe type the ingredient'
+ ' and amount i.e. "3 4".')
# Get user input to change recipe
result = input(f'\n{orange("Enter change i.e. 3 4: ")}')
# Split string into a list
result = result.split()
# Validate user input
if not validate_recipe_change(result):
continue
if int(result[0]) == 0:
break
if int(result[0]) > 4:
print_error_message("Invalid choice.")
continue
if ((int(result[0]) == 1 and int(result[1]) > 1)
or (int(result[0]) == 2 and int(result[1]) > 2)
or (int(result[0]) == 3 and int(result[1]) > 5)
or (int(result[0]) == 4 and int(result[1]) > 5)):
print_error_message("Check maximum amounts.")
continue
if ((int(result[0]) == 1 and int(result[1]) < 1)
or (int(result[0]) == 2 and int(result[1]) < 1)
or (int(result[0]) == 3 and int(result[1]) < 0)
or (int(result[0]) == 4 and int(result[1]) < 0)):
print_error_message("Check minimum amounts.")
continue
# Update variables
stock_chosen = (constants.STOCK_OPTIONS[int(result[0])-1])
stats['recipe'][stock_chosen] = int(result[1])
# Display ingredient being change and to what new amount
print(green(f'Updated {stock_chosen.capitalize()} to '
+ f'{result[1]} per serving.'))
print_press_enter_to("Press Enter to continue...")
continue
daily_menu(stats)
def set_selling_price(stats):
'''
Allow user to set selling price of hotdogs
'''
while True:
clear_terminal()
# Set variable(s)
curr_price = stats["selling_price"]
production_cost = cost_to_make(stats)
net_profit = round(curr_price - production_cost, 2)
# Header
print(f'{cyan("Set the selling price of your product")}')
print(constants.LINE)
# Display text to user
text = green("£" + str(round(production_cost, 2)))
print(f'\nThe current cost for to make your your product is {text}')
text = green("£"+"{:.2f}".format(stats["selling_price"]))
print(f'\nCurrent selling price is {text}')
# Change colour of profit margin based on positive or negative
# number.
if net_profit >= 0:
print(f'\n{green("Profit per serving is: ")}£{net_profit}')
else:
print(f'\n{red("Loss per serving is: ")}£{net_profit}')
print_go_back()
# Get user input for new selling price.
new_price = input(f'\n{orange("Enter new price: £")}')
# Validate user input
if validate_price_change(new_price):
# If user puts 0, go back to game menu.
if float(new_price) == 0:
break
# Update selling price to user input
new_price = round(float(new_price), 2)
stats["selling_price"] = float(new_price)
print(green('\nUpdated selling price to '
+ f'£{"{:.2f}".format(new_price)}'))
# User input to continue
print_press_enter_to("Press Enter to continue...")
daily_menu(stats)
def validate_price_change(data):
'''
Check user input valid value for price change
'''
try:
try:
float_value = float(data)
except TypeError:
print_error_message("Invalid input.")
return False
if float_value >= 0:
return True
raise ValueError()
except ValueError:
print_error_message("Invalid input.")
return False
return True
def help_menu(stats):
'''
Displays help screen to the user
'''
clear_terminal()
print(constants.HELP_SCREEN1)
print_press_enter_to("Press Enter to continue...")
print(constants.HELP_SCREEN2)
print_press_enter_to("Press Enter to continue...")
print(constants.HELP_SCREEN3)
print_press_enter_to("Press Enter to continue...")
print(constants.HELP_SCREEN4)
print_press_enter_to("Press Enter to return to menu...")
daily_menu(stats)