-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathingredient.py
241 lines (213 loc) · 7.76 KB
/
ingredient.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
import random
from cmu_112_graphics import *
#Image credit: all food images made by me
class Ingredient:
def __init__(self, type, app):
self.type = type #str
if type == 'bread':
self.isRaw = False
self.image = app.loadImage('bread.png')
else:
self.isRaw = True
self.box = None #if on box, this = to box obj
self.plate = None
def __repr__(self):
# descrip =
# if self.plate != None:
# descrip += str(self.plate)
return self.type.capitalize()
def __eq__(self, other):
if isinstance(other, Ingredient) and self.type == other.type:
return True
else:
return False
class Veggie(Ingredient):
def __init__(self, type, app):
super().__init__(type, app)
self.isChopped = False
self.app = app
if type == 'tomato':
self.rawImage = app.loadImage('tomato.png')
self.choppedImage = app.loadImage('chopped_tomato.png')
elif type == 'lettuce':
self.rawImage = app.loadImage('lettuce.png')
self.choppedImage = app.loadImage('chopped_lettuce.png')
self.image = self.rawImage
def __repr__(self):
# chopped = ''
# if self.isChopped:
# chopped = '(chopped)'
return self.type.capitalize()
def __eq__(self, other):
if (isinstance(other, Veggie) and self.type == other.type
and self.isChopped == other.isChopped):
return True
else:
return False
#chef also has chop method
def chop(self):
self.isChopped = True
self.isRaw = False
self.image = self.choppedImage
#inherit from Veggie
class Meat(Ingredient):
def __init__(self, type, app):
super().__init__(type, app)
self.isChopped = False
self.isCooked = False
self.app = app
self.rawImage = app.loadImage('meat.png')
self.choppedImage = app.loadImage('chopped_meat.png')
self.cookedImage = app.loadImage('cooked_meat.png')
self.image = self.rawImage
def __repr__(self):
# chopped = ''
# cooked = ''
# if self.isChopped:
# chopped = '(chopped)'
# if self.isCooked:
# cooked = '(cooked)'
return self.type.capitalize()
def __eq__(self, other):
#possibly just str(self) == str(other) ???
if (isinstance(other, Meat) and self.type == other.type
and self.isChopped == other.isChopped
and self.isCooked == other.isCooked):
return True
else:
return False
#chef also has chop method, copy of veggie method
def chop(self):
self.isChopped = True
self.image = self.choppedImage
#chef also has chop method
def cook(self):
self.isCooked = True
self.isRaw = False
self.image = self.cookedImage
self.rawImage = self.choppedImage
class Burger:
def __init__(self, ingredients, app):
#ingredients is a set of the ingredient obj in burger
self.ingredients = ingredients
#sort code taken from https://www.techiedelight.com/sort-list-of-objects-python/
self.ingredients.sort(key=lambda x: x.type)
self.plate = None
self.image = None
self.imageList = False
self.app = app
self.burgerImage(app)
def __repr__(self):
name = ''
for ingred in self.ingredients:
name += str(ingred) + ', '
if name.endswith(', '):
name = name[:len(name)-2]
return name
def __eq__(self, other):
if isinstance(other, Burger) and self.ingredients == other.ingredients:
print('self', self.ingredients)
print('other', other.ingredients)
return True
else:
return False
def addIngred(self, ingred):
if isinstance(ingred, Burger):
for item in ingred.ingredients:
self.ingredients.append(item)
else: #is not a Burger
self.ingredients.append(ingred)
#sort code taken from https://www.techiedelight.com/sort-list-of-objects-python/
self.ingredients.sort(key=lambda x: x.type)
self.burgerImage(self.app)
def hasIngredType(self, name):
for ingred in self.ingredients:
if ingred.type == name:
return True
return False
def burgerImage(self, app):
if self.hasIngredType('bread'):
self.imageList = False
size = len(self.ingredients)
if size == 4:
self.image = app.loadImage('full_burg.png')
elif size == 3:
if self.hasIngredType('tomato') and self.hasIngredType('lettuce'):
self.image = app.loadImage('tom_let_burg.png')
elif self.hasIngredType('tomato') and self.hasIngredType('meat'):
self.image = app.loadImage('tomato_burg.png')
if self.hasIngredType('lettuce') and self.hasIngredType('meat'):
self.image = app.loadImage('lettuce_burg.png')
else:
if self.hasIngredType('tomato'):
self.image = app.loadImage('tom_bread.png')
elif self.hasIngredType('lettuce'):
self.image = app.loadImage('let_bread.png')
else:
self.image = app.loadImage('plain_burg.png')
else:
self.imageList = True
class Order:
def __init__(self, app):
tomato, lettuce, meat, bread = Veggie('tomato', app), Veggie('lettuce', app), Meat('meat', app), Ingredient('bread', app)
tomato.isChopped = True
lettuce.isChopped = True
meat.isChopped = True
meat.isCooked = True
ingredients = [tomato, lettuce]
self.order = Burger(ingredients, app) #burger with specific ingredients
self.orderDone = False
self.orderFailed = False
self.orderDoubled = False
#randomized order:
choices = [tomato, lettuce, (tomato, lettuce)]
item = random.choice(choices)
if isinstance(item, tuple):
self.order = Burger([bread, meat]+list(item), app)
self.image = app.loadImage('order3.png')
self.orderDoubled = True
self.totalTime = 60*10
else:
self.totalTime = 50*10
self.order = Burger([bread, meat, item], app)
if item.type == 'tomato':
self.image = app.loadImage('order2.png')
else:
self.image = app.loadImage('order1.png')
self.orderTime = self.totalTime
def __repr__(self):
descrip = ''
for ingred in self.order.ingredients:
descrip += str(ingred) + ' '
return descrip
def completeOrder(self, target): #target is a burger obj
if self.order == target:
return True
else:
return False
def countdown(self):
if self.orderTime > 0:
self.orderTime -= 1
else:
self.orderFailed = True
class Plate:
def __init__(self, app):
self.isDirty = False
self.app = app
self.counter = None
self.cleanImage = self.app.loadImage('clean_plate.png')
self.dirtyImage = self.app.loadImage('dirty_plate.png')
self.image = self.cleanImage
def __repr__(self):
descrip = 'Plate'
if self.isDirty:
descrip += '(dirty)'
else:
descrip += '(clean)'
return descrip
def makeDirty(self):
self.isDirty = True
self.image = self.dirtyImage
def makeClean(self):
self.isDirty = False
self.image = self.cleanImage