This commit is contained in:
Anna Nowak 2019-03-25 16:10:53 +01:00
commit 43d91e178d
4 changed files with 53 additions and 2 deletions

View File

@ -8,7 +8,7 @@ from pygame.locals import *
import utils import utils
##INITIALIZE STATIC VARIABLES######### ##INITIALIZE STATIC VARIABLES#########
FPS = 60 FPS = 20
all_sprites = sprite.Group() all_sprites = sprite.Group()
fps_clock = time.Clock() fps_clock = time.Clock()
@ -61,6 +61,7 @@ while(1):
if(type(item) == House): if(type(item) == House):
item.generate_rubbish() item.generate_rubbish()
utils.get_statistics(all_sprites)
display.flip() display.flip()
fps_clock.tick(FPS) fps_clock.tick(FPS)
################################################################################## ##################################################################################

View File

@ -4,6 +4,8 @@ from sprites.cell import Cell
class Garbage_collector(Cell): class Garbage_collector(Cell):
def __init__(self, x, y): def __init__(self, x, y):
GC_CAPACITY = 10
Cell.__init__(self, x, y) Cell.__init__(self, x, y)
self.image = pygame.image.load("images/garbage_collector.png") self.image = pygame.image.load("images/garbage_collector.png")
self.move_options = { self.move_options = {
@ -12,6 +14,12 @@ class Garbage_collector(Cell):
"left": lambda forbidden: ('x', self.x - 1) if (self.x - 1, self.y) not in forbidden else ('x', self.x), "left": lambda forbidden: ('x', self.x - 1) if (self.x - 1, self.y) not in forbidden else ('x', self.x),
"right": lambda forbidden: ('x', self.x + 1) if (self.x + 1, self.y) not in forbidden else ('x', self.x) "right": lambda forbidden: ('x', self.x + 1) if (self.x + 1, self.y) not in forbidden else ('x', self.x)
} }
self.trash_space_taken = {
"plastic": 0,
"glass": 0,
"metal": 0
}
self.trash_collected = 0
def move(self, direction, forbidden): def move(self, direction, forbidden):
(destination, value) = self.move_options[direction](forbidden) (destination, value) = self.move_options[direction](forbidden)
@ -21,3 +29,9 @@ class Garbage_collector(Cell):
self.y = value self.y = value
self.update() self.update()
def get_collect_data(self):
return self.trash_collected
def get_space_data(self):
return self.trash_space_taken

View File

@ -22,7 +22,7 @@ class House(Cell):
self.max_metal = max_metal self.max_metal = max_metal
def generate_rubbish(self): def generate_rubbish(self):
if(random.randint(0, 50) == 1): # 1/5 szansa na wyrzucenie śmiecia w klatce if(random.randint(0, 25) == 1): # 1/25 szansa na wyrzucenie śmiecia w klatce
thrash_type = random.randint(0, 2) thrash_type = random.randint(0, 2)
self.rubbish[thrash_type] = self.rubbish[thrash_type] + 1 self.rubbish[thrash_type] = self.rubbish[thrash_type] + 1
@ -48,3 +48,6 @@ class House(Cell):
def check_rubbish_status(self): def check_rubbish_status(self):
print("plastic: " + str(self.rubbish[PLASTIC]) + " glass: " + str( print("plastic: " + str(self.rubbish[PLASTIC]) + " glass: " + str(
self.rubbish[GLASS]) + " metal: " + str(self.rubbish[METAL])) self.rubbish[GLASS]) + " metal: " + str(self.rubbish[METAL]))
def get_rubbish_data(self):
return self.rubbish

View File

@ -87,3 +87,36 @@ def generate_garbage_collector(all_sprites, obstacles_coords):
all_sprites.add(gc) all_sprites.add(gc)
return gc return gc
################################################################################## ##################################################################################
##GET STATISTICS##################################################################
def get_statistics(all_sprites):
###Garbage collector stats###
gc_taken_space_plastic = 0
gc_taken_space_metal = 0
gc_taken_space_glass = 0
gc_trash_space = 10
###Board stats###############
plastic_left = 0
metal_left = 0
glass_left = 0
total_gathered = 0
for item in all_sprites:
if(type(item) == House):
rubbish = item.get_rubbish_data()
plastic_left += rubbish[0]
glass_left += rubbish[1]
metal_left += rubbish[2]
if(type(item) == Garbage_collector):
space_taken = item.get_space_data()
gc_taken_space_plastic += space_taken.get("plastic")
gc_taken_space_glass += space_taken.get("glass")
gc_taken_space_metal += space_taken.get("metal")
total_gathered += item.get_collect_data()
print("plastic left: "+str(plastic_left)+" | glass left: "+str(glass_left)+" | metal left: "+str(metal_left))
print(" plastic: "+str(gc_taken_space_plastic)+"/"+str(gc_trash_space)+" | glass: "+str(gc_taken_space_glass)+"/"+str(gc_trash_space)+" | metal: "+str(gc_taken_space_metal)+"/"+str(gc_trash_space))
print("### TOTAL COLLECTED: "+str(total_gathered)+" ###")
##################################################################################