Naprawiono zbieranie z domkow, dodano mozliwosc oddawania smieci
This commit is contained in:
parent
e2f76d06a5
commit
ac0ca70b35
@ -1,22 +1,35 @@
|
||||
class Container():
|
||||
def __init__(self, max, y=0, g=0, b=0):
|
||||
self.y, self.g, self.b = y, g, b
|
||||
self.yellow, self.green, self.blue = y, g, b
|
||||
self.max = max
|
||||
|
||||
def empty(self):
|
||||
self.y, self.g, self.b = 0, 0, 0
|
||||
def empty(self, trash_type=None, trash=None):
|
||||
if trash_type == None:
|
||||
self.yellow, self.green, self.blue = 0, 0, 0
|
||||
elif trash_type == "yellow":
|
||||
trash[0] += self.yellow
|
||||
self.yellow = 0
|
||||
elif trash_type == "green":
|
||||
trash[1] += self.green
|
||||
self.green = 0
|
||||
elif trash_type == "blue":
|
||||
trash[2] += self.blue
|
||||
self.blue = 0
|
||||
return trash
|
||||
|
||||
|
||||
def status(self):
|
||||
return [self.y, self.g, self.b]
|
||||
return [self.yellow, self.green, self.blue]
|
||||
|
||||
|
||||
def add(self, trash):
|
||||
my_trash = [self.y, self.g, self.b]
|
||||
my_trash = [self.yellow, self.green, self.blue]
|
||||
leftovers = [0, 0, 0]
|
||||
for i in range(0, len(trash)):
|
||||
while(my_trash[i] < self.max and trash[i] > 0):
|
||||
my_trash[i] += 1
|
||||
trash[i] -= 1
|
||||
self.y, self.g, self.b = my_trash
|
||||
self.yellow, self.green, self.blue = my_trash
|
||||
result = [0, 0, 0]
|
||||
for i in range(0, len(trash)):
|
||||
result[i] = trash[i] - leftovers[i]
|
||||
|
@ -4,4 +4,10 @@ from DataModels.Cell import Cell
|
||||
class Dump( Cell ):
|
||||
def __init__( self, x, y, max_rubbish, dump_type, yellow = 0, green = 0, blue = 0 ):
|
||||
Cell.__init__( self, x, y, max_rubbish, yellow, green, blue, dump_type )
|
||||
self.dump_type = dump_type
|
||||
|
||||
def return_trash(self, collector):
|
||||
dump_type = self.dump_type.lower()[5:]
|
||||
self.container.yellow, self.container.green, self.container.blue = collector.container.empty(dump_type,
|
||||
[self.container.yellow, self.container.green, self.container.blue])
|
||||
self.update_image()
|
||||
|
@ -1,6 +1,7 @@
|
||||
from DataModels.Cell import Cell
|
||||
from DataModels.Road import Road
|
||||
from DataModels.House import House
|
||||
from DataModels.Dump import Dump
|
||||
from config import GRID_WIDTH, GRID_HEIGHT
|
||||
|
||||
|
||||
@ -24,12 +25,14 @@ class GC(Cell):
|
||||
coordinates = [(x, y - 1), (x, y + 1), (x - 1, y), (x + 1, y)]
|
||||
|
||||
for coordinate in coordinates:
|
||||
if coordinate[0]<0 or coordinate[1]<0:
|
||||
continue
|
||||
try:
|
||||
item = enviromnent[coordinate[0]][coordinate[1]]
|
||||
except:
|
||||
continue
|
||||
|
||||
if(type(item) == House):
|
||||
if(type(item) == House or type(item) == Dump):
|
||||
item.return_trash(self)
|
||||
|
||||
self.update_image()
|
||||
|
@ -4,8 +4,9 @@ from DataModels.Cell import Cell
|
||||
class House(Cell):
|
||||
def __init__(self, x, y, max_rubbish, yellow=0, green=0, blue=0):
|
||||
Cell.__init__(self, x, y, max_rubbish, yellow, green, blue)
|
||||
print(f"Domek: {x} {y}")
|
||||
|
||||
def return_trash(self, collector):
|
||||
self.container.y, self.container.g, self.container.b = collector.container.add(
|
||||
[self.container.y, self.container.g, self.container.b])
|
||||
self.container.yellow, self.container.green, self.container.blue = collector.container.add(
|
||||
[self.container.yellow, self.container.green, self.container.blue])
|
||||
self.update_image()
|
||||
|
@ -1,7 +1,7 @@
|
||||
6 5
|
||||
1 0
|
||||
Y R R R E H
|
||||
E R E R R R
|
||||
H R B R H R
|
||||
E R B R R R
|
||||
H R E R E R
|
||||
E R R R R G
|
||||
E H E E R H
|
||||
E H E H R H
|
||||
|
Loading…
Reference in New Issue
Block a user