2019-04-01 13:29:13 +02:00
|
|
|
from DataModels.Cell import Cell
|
2019-04-01 14:10:14 +02:00
|
|
|
from DataModels.Road import Road
|
2019-04-01 15:45:48 +02:00
|
|
|
from DataModels.House import House
|
2019-04-02 09:47:00 +02:00
|
|
|
from DataModels.Dump import Dump
|
2019-04-01 14:36:27 +02:00
|
|
|
from config import GRID_WIDTH, GRID_HEIGHT
|
2019-04-01 13:29:13 +02:00
|
|
|
|
2019-04-01 14:10:14 +02:00
|
|
|
|
|
|
|
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)
|
|
|
|
|
2019-04-10 11:01:20 +02:00
|
|
|
def movement(self, environment, x = None ,y = None):
|
|
|
|
if((x,y) == (None, None)):
|
|
|
|
x = self.x
|
|
|
|
y = self.y
|
|
|
|
|
2019-04-01 14:10:14 +02:00
|
|
|
movement = {
|
2019-04-01 14:36:27 +02:00
|
|
|
"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)
|
2019-04-01 14:10:14 +02:00
|
|
|
}
|
2019-04-10 11:01:20 +02:00
|
|
|
|
|
|
|
forbidden_movement = {
|
|
|
|
"right": "left",
|
|
|
|
"left": "right",
|
|
|
|
"up": "down",
|
|
|
|
"down": "up"
|
|
|
|
}
|
|
|
|
|
|
|
|
return (movement, forbidden_movement)
|
|
|
|
|
|
|
|
def check_moves(self, direction, environment, x = None, y = None):
|
|
|
|
if((x,y) == (None, None)):
|
|
|
|
x = self.x
|
|
|
|
y = self.y
|
|
|
|
|
|
|
|
return ([dir for dir in self.movement(environment)[0] if self.movement(environment)[0][dir] != (x,y) and dir != self.movement(environment)[1][direction]])
|
|
|
|
|
|
|
|
def move(self, direction, environment):
|
|
|
|
self.x, self.y = self.movement(environment)[0][direction]
|
2019-04-01 14:36:27 +02:00
|
|
|
self.update_rect(self.x, self.y)
|
2019-04-01 15:45:48 +02:00
|
|
|
|
2019-04-10 11:01:20 +02:00
|
|
|
print(self.check_moves(direction, environment))
|
|
|
|
|
2019-04-01 15:45:48 +02:00
|
|
|
def collect(self, enviromnent):
|
|
|
|
x, y = [self.x, self.y]
|
|
|
|
coordinates = [(x, y - 1), (x, y + 1), (x - 1, y), (x + 1, y)]
|
|
|
|
|
|
|
|
for coordinate in coordinates:
|
2019-04-02 09:47:00 +02:00
|
|
|
if coordinate[0]<0 or coordinate[1]<0:
|
|
|
|
continue
|
2019-04-01 15:45:48 +02:00
|
|
|
try:
|
|
|
|
item = enviromnent[coordinate[0]][coordinate[1]]
|
|
|
|
except:
|
|
|
|
continue
|
|
|
|
|
2019-04-02 09:47:00 +02:00
|
|
|
if(type(item) == House or type(item) == Dump):
|
2019-04-01 15:45:48 +02:00
|
|
|
item.return_trash(self)
|
|
|
|
|
|
|
|
self.update_image()
|