SZI2019SmieciarzWmi/DataModels/GC.py
2019-04-01 15:45:48 +02:00

37 lines
1.3 KiB
Python

from DataModels.Cell import Cell
from DataModels.Road import Road
from DataModels.House import House
from config import GRID_WIDTH, GRID_HEIGHT
class GC(Cell):
def __init__(self, x, y, max_rubbish, yellow=0, green=0, blue=0):
Cell.__init__(self, x, y, max_rubbish, yellow, green, blue)
def move(self, direction, environment):
x, y = [self.x, self.y]
movement = {
"right": (x + 1, y) if x + 1 < GRID_WIDTH and type(environment[x + 1][y]) == Road else (x, y),
"left": (x - 1, y) if x - 1 >= 0 and type(environment[x - 1][y]) == Road else (x, y),
"down": (x, y + 1) if y + 1 < GRID_HEIGHT and type(environment[x][y + 1]) == Road else (x, y),
"up": (x, y - 1) if y - 1 >= 0 and type(environment[x][y - 1]) == Road else (x, y)
}
self.x, self.y = movement[direction]
self.update_rect(self.x, self.y)
def collect(self, enviromnent):
print('collect')
x, y = [self.x, self.y]
coordinates = [(x, y - 1), (x, y + 1), (x - 1, y), (x + 1, y)]
for coordinate in coordinates:
try:
item = enviromnent[coordinate[0]][coordinate[1]]
except:
continue
if(type(item) == House):
item.return_trash(self)
self.update_image()