From 4d807fe0c925f33d1f2759bab6f1979fb1fbcee4 Mon Sep 17 00:00:00 2001 From: Anna Nowak Date: Mon, 25 Mar 2019 16:19:24 +0100 Subject: [PATCH] cleaning time --- game.py | 2 +- sprites/hud.py | 32 ++++++++++++++++++++++++++++++++ utils.py | 33 --------------------------------- 3 files changed, 33 insertions(+), 34 deletions(-) diff --git a/game.py b/game.py index b1927ce..384f503 100644 --- a/game.py +++ b/game.py @@ -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) ################################################################################## diff --git a/sprites/hud.py b/sprites/hud.py index a7f18d5..1d552bc 100644 --- a/sprites/hud.py +++ b/sprites/hud.py @@ -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)+" ###") diff --git a/utils.py b/utils.py index 4cd11bf..46cc6f8 100644 --- a/utils.py +++ b/utils.py @@ -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)+" ###") -##################################################################################