-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfoodClasses.py
64 lines (51 loc) · 1.71 KB
/
foodClasses.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
# Mckenna Brown
import pygame
from setup import *
class Food():
def __init__(self, ingredients):
self.recipe = []
for ingr in ingredients:
self.recipe.append(Ingredient(ingr))
# self.recipe = ingredients # a list. can have repeats
# ordered. must be put on in this order
self.ingredients = [self.recipe[0]]
self.x = -100
self.y = 550
self.r = 66
def __repr__(self):
return "Food object, ingredients: " + str(self.ingredients)
def __eq__(self, other):
if not isinstance(other, Food):
return False
return self.ingredients == other.ingredients and \
self.recipe == other.recipe
def __hash__(self):
return hash(tuple(self.recipe))
def addIngredient(self, ingredient):
i = len(self.ingredients)
if self.recipe[i] != ingredient: # can't drag that
return False
else:
self.ingredients.append(ingredient)
def move(self, dx, dy):
self.x += dx
self.y += dy
def draw(self):
for ingredient in self.ingredients:
screen.blit(pygame.image.load(ingredient.name), \
(self.x - self.r, self.y - self.r))
class Ingredient():
def __init__(self, img):
self.name = img
self.img = pygame.image.load(img)
self.r = 66
def __eq__(self, other):
if not isinstance(other, Ingredient):
return False
return self.name == other.name
def __hash__(self):
return hash(self.name)
def __repr__(self):
return "Ingredient obj w img: " + self.name
def draw(self, x, y): # for when dragging the item
screen.blit(self.img, (x, y))