cleaning time

This commit is contained in:
Anna Nowak 2019-03-25 16:19:24 +01:00
parent 43d91e178d
commit 4d807fe0c9
3 changed files with 33 additions and 34 deletions

View File

@ -61,7 +61,7 @@ while(1):
if(type(item) == House):
item.generate_rubbish()
utils.get_statistics(all_sprites)
hud.get_statistics(all_sprites)
display.flip()
fps_clock.tick(FPS)
##################################################################################

View File

@ -1,4 +1,6 @@
import pygame
from sprites.house import House
from sprites.garbage_collector import Garbage_collector
from config import HUD_HEIGHT
HUD_COLOR = (51,21,4)
WHITE = (255,255,255)
@ -22,3 +24,33 @@ class Hud():
map_glass_text = font.render("Glass: 0",True,WHITE)
overall_text = font.render("Garbage thrown away: 0",True,WHITE)
GAMEWINDOW.blit(overall_text,(20, 20))
def get_statistics(self, 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)+" ###")

View File

@ -87,36 +87,3 @@ def generate_garbage_collector(all_sprites, obstacles_coords):
all_sprites.add(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)+" ###")
##################################################################################