forked from natelee3/the_covid_trail
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstore.py
122 lines (99 loc) · 3.42 KB
/
store.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
from pygame import mixer
mixer.init()
mixer.music.set_volume(0.3)
# Items
FOOD = 'food'
BULLETS = 'bullets'
FUEL = 'fuel'
PHONE_CHARGE = 'phone_charger'
HAND_SANITIZER = 'hand_sanitizer'
list_of_items = [FOOD, BULLETS, FUEL, PHONE_CHARGE, HAND_SANITIZER]
items = {
FOOD: 20,
BULLETS: 30,
FUEL: 40,
PHONE_CHARGE: 20,
HAND_SANITIZER: 5
}
def sound(file):
sound = mixer.Sound("audio/%s" % file)
return mixer.Sound.play(sound)
def store(party):
total_amount_spent = 0
while True:
print("\033c")
print("Your party has $%d available." % (party.money))
if party.money < 10:
print("Your party does not have enough money to buy anything from the store.")
break
print("""
><><><><><><><><><>><><><><><><><><><><><><><><
What would you like to purchase? (1-5)
-----------------------------------------------
[ 1 ] Food $20
[ 2 ] Hand Sanitizer $10
[ 3 ] Fuel $40
[ 4 ] Phone Charger $20
[ 5 ] Bullets $30
[ 6 ] Return to main menu
------------------------------------------------
><><><><><><><><><><><><><><><><><><><><><><><><
""")
choice = input(">>> ")
if choice == "1":
item = FOOD
elif choice == "2":
item = HAND_SANITIZER
elif choice == "3":
item = FUEL
elif choice == "4":
item = PHONE_CHARGE
elif choice == "5":
item = BULLETS
elif choice == "6":
break
else:
print("Please enter a number between 1 and 6.")
continue
print("""
><><><><><><><><><>><><><><><><><><><><><><><><
How many would you like?
><><><><><><><><><>><><><><><><><><><><><><><><
""")
# Validation loop
while True:
quantity = input(">>> ")
try:
quantity = int(quantity)
break
except:
print("Please enter a number greater than 0")
# total for this specific item
total = items[item] * quantity
# Check if they have enough money to buy this.
if party.money - total < 0:
print("You do not have enough money. Please try again.")
continue
# decrease party total cash amount
party.money -= total
# add item(s) to inventory
if item == FOOD:
party.food += quantity
elif item == BULLETS:
party.bullets += quantity
elif item == FUEL:
party.fuel += quantity
elif item == PHONE_CHARGE:
party.phone_charge += quantity
elif item == HAND_SANITIZER:
party.hand_sanitizer += quantity
# calculate total amount being spent
total_amount_spent += items[item] * quantity
sound("cash.wav")
print("That will be $%d for a total of $%d. Your party now has..." % (total, total_amount_spent))
party.print_party_supplies()
keep_going = input("Would you like to buy something else? (Y/N) ")
if keep_going.upper() == "N":
break
elif keep_going.upper() == "Y":
continue