Added house stats, removed hud display
This commit is contained in:
parent
5454710e15
commit
04ee4fc1da
13
game.py
13
game.py
@ -25,7 +25,7 @@ interactables = {
|
|||||||
|
|
||||||
##GAMEWINDOW##########################
|
##GAMEWINDOW##########################
|
||||||
WINDOW_WIDTH = PLAY_WIDTH
|
WINDOW_WIDTH = PLAY_WIDTH
|
||||||
WINDOW_HEIGHT = PLAY_HEIGHT + HUD_HEIGHT
|
WINDOW_HEIGHT = PLAY_HEIGHT #+ HUD_HEIGHT
|
||||||
GAMEWINDOW = display.set_mode((WINDOW_WIDTH, WINDOW_HEIGHT), 0, 32)
|
GAMEWINDOW = display.set_mode((WINDOW_WIDTH, WINDOW_HEIGHT), 0, 32)
|
||||||
hud = Hud(home_amount,WINDOW_WIDTH, WINDOW_HEIGHT,GAMEWINDOW)
|
hud = Hud(home_amount,WINDOW_WIDTH, WINDOW_HEIGHT,GAMEWINDOW)
|
||||||
display.set_caption('Smieciarz WMI')
|
display.set_caption('Smieciarz WMI')
|
||||||
@ -46,14 +46,7 @@ hud_break = 0
|
|||||||
#######################################
|
#######################################
|
||||||
|
|
||||||
##INIT CSV FILE########################
|
##INIT CSV FILE########################
|
||||||
currentDT = datetime.datetime.now()
|
csv_name, houses_csv_name = utils.init_csv()
|
||||||
csv_name = "logs/stats_" + currentDT.strftime("%Y%m%d%H%M%S") + ".csv"
|
|
||||||
|
|
||||||
with open(csv_name, 'w', newline='') as csvfile:
|
|
||||||
filewriter = csv.writer(csvfile, delimiter=',', quotechar='|', quoting=csv.QUOTE_MINIMAL)
|
|
||||||
row = ['Plastic left', "Glass left", "Metal left", "GC plastic", "GC glass", "GC metal", "Total collected"]
|
|
||||||
filewriter.writerow(row)
|
|
||||||
csvfile.close()
|
|
||||||
#######################################
|
#######################################
|
||||||
|
|
||||||
##GAME LOOP#######################################################################
|
##GAME LOOP#######################################################################
|
||||||
@ -86,7 +79,7 @@ while(1):
|
|||||||
|
|
||||||
if(hud_break == 0):
|
if(hud_break == 0):
|
||||||
###################################
|
###################################
|
||||||
hud.get_statistics(all_sprites, csv_name)
|
hud.get_statistics(all_sprites, csv_name, houses_csv_name)
|
||||||
display.flip()
|
display.flip()
|
||||||
fps_clock.tick(FPS)
|
fps_clock.tick(FPS)
|
||||||
##################################################################################
|
##################################################################################
|
||||||
|
12
logs/houses_stats_20190327101235.csv
Normal file
12
logs/houses_stats_20190327101235.csv
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
House 1 plastic,House 1 glass,House 1 metal,House 2 plastic,House 2 glass,House 2 metal,House 3 plastic,House 3 glass,House 3 metal,House 4 plastic,House 4 glass,House 4 metal
|
||||||
|
5,7,7,5,9,3,7,4,3,8,4,9
|
||||||
|
6,7,7,5,9,3,8,4,3,8,8,9
|
||||||
|
7,7,8,6,9,3,9,4,4,9,8,10
|
||||||
|
7,9,9,7,9,3,10,4,4,9,9,10
|
||||||
|
7,9,9,7,10,3,0,1,0,10,5,5
|
||||||
|
8,9,9,7,10,4,1,1,0,10,6,5
|
||||||
|
8,9,10,7,10,6,2,1,1,10,6,5
|
||||||
|
5,10,6,0,0,1,3,1,1,10,7,5
|
||||||
|
6,10,7,1,0,1,3,2,1,10,7,5
|
||||||
|
9,10,8,2,0,1,4,2,2,10,9,5
|
||||||
|
9,10,8,3,0,1,5,4,3,10,9,5
|
|
5
logs/houses_stats_20190327101837.csv
Normal file
5
logs/houses_stats_20190327101837.csv
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
House 1 plastic,House 1 glass,House 1 metal,House 2 plastic,House 2 glass,House 2 metal,House 3 plastic,House 3 glass,House 3 metal,House 4 plastic,House 4 glass,House 4 metal
|
||||||
|
10,10,3,10,9,0,8,0,10,3,3,7
|
||||||
|
10,10,4,10,10,0,9,1,10,3,3,7
|
||||||
|
0,1,0,10,10,0,9,1,10,4,4,7
|
||||||
|
1,2,0,10,10,2,9,1,10,5,5,7
|
|
@ -1,18 +0,0 @@
|
|||||||
Plastic left,Glass left,Metal left,GC plastic,GC glass,GC metal,Total collected
|
|
||||||
27,21,18,0/10,0/10,0/10,0
|
|
||||||
30,21,20,0/10,0/10,0/10,0
|
|
||||||
31,23,21,0/10,0/10,0/10,0
|
|
||||||
33,25,23,0/10,0/10,0/10,0
|
|
||||||
34,26,24,0/10,0/10,0/10,0
|
|
||||||
34,32,26,0/10,0/10,0/10,0
|
|
||||||
34,32,26,0/10,0/10,0/10,0
|
|
||||||
35,32,28,0/10,0/10,0/10,0
|
|
||||||
38,36,33,0/10,0/10,0/10,0
|
|
||||||
29,26,24,10/10,10/10,10/10,30
|
|
||||||
30,26,25,0/10,10/10,10/10,30
|
|
||||||
30,27,27,0/10,0/10,0/10,30
|
|
||||||
23,18,18,10/10,10/10,10/10,60
|
|
||||||
13,10,19,10/10,10/10,10/10,80
|
|
||||||
13,11,22,1/10,1/10,10/10,82
|
|
||||||
14,13,13,2/10,3/10,10/10,95
|
|
||||||
14,14,15,0/10,0/10,0/10,95
|
|
|
12
logs/stats_20190327101235.csv
Normal file
12
logs/stats_20190327101235.csv
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
Plastic left,Glass left,Metal left,GC plastic,GC glass,GC metal,Total collected
|
||||||
|
25,24,22,0/10,0/10,0/10,0
|
||||||
|
27,28,22,0/10,0/10,0/10,0
|
||||||
|
31,28,25,0/10,0/10,0/10,0
|
||||||
|
33,31,26,0/10,0/10,0/10,0
|
||||||
|
24,25,17,10/10,10/10,10/10,30
|
||||||
|
26,26,18,0/10,0/10,10/10,30
|
||||||
|
27,26,22,0/10,0/10,0/10,30
|
||||||
|
18,18,13,10/10,10/10,10/10,60
|
||||||
|
20,19,14,10/10,10/10,10/10,60
|
||||||
|
25,21,16,10/10,0/10,0/10,60
|
||||||
|
27,23,17,0/10,0/10,0/10,60
|
|
5
logs/stats_20190327101837.csv
Normal file
5
logs/stats_20190327101837.csv
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
Plastic left,Glass left,Metal left,GC plastic,GC glass,GC metal,Total collected
|
||||||
|
31,22,20,0/10,0/10,0/10,0
|
||||||
|
32,24,21,0/10,0/10,0/10,0
|
||||||
|
23,16,17,10/10,10/10,4/10,24
|
||||||
|
25,18,19,10/10,0/10,0/10,24
|
|
@ -26,7 +26,7 @@ class Hud():
|
|||||||
overall_text = font.render("Garbage thrown away: 0",True,WHITE)
|
overall_text = font.render("Garbage thrown away: 0",True,WHITE)
|
||||||
GAMEWINDOW.blit(overall_text,(20, 20))
|
GAMEWINDOW.blit(overall_text,(20, 20))
|
||||||
|
|
||||||
def get_statistics(self, all_sprites, csv_name):
|
def get_statistics(self, all_sprites, csv_name, houses_csv_name):
|
||||||
###Garbage collector stats###
|
###Garbage collector stats###
|
||||||
gc_taken_space_plastic = 0
|
gc_taken_space_plastic = 0
|
||||||
gc_taken_space_metal = 0
|
gc_taken_space_metal = 0
|
||||||
@ -39,12 +39,17 @@ class Hud():
|
|||||||
glass_left = 0
|
glass_left = 0
|
||||||
total_gathered = 0
|
total_gathered = 0
|
||||||
|
|
||||||
|
houses_data = []
|
||||||
|
|
||||||
for item in all_sprites:
|
for item in all_sprites:
|
||||||
if(type(item) == House):
|
if(type(item) == House):
|
||||||
rubbish = item.get_rubbish_data()
|
rubbish = item.get_rubbish_data()
|
||||||
plastic_left += rubbish[0]
|
plastic_left += rubbish[0]
|
||||||
glass_left += rubbish[1]
|
glass_left += rubbish[1]
|
||||||
metal_left += rubbish[2]
|
metal_left += rubbish[2]
|
||||||
|
houses_data.append(str(rubbish[0]))
|
||||||
|
houses_data.append(str(rubbish[1]))
|
||||||
|
houses_data.append(str(rubbish[2]))
|
||||||
if(type(item) == Garbage_collector):
|
if(type(item) == Garbage_collector):
|
||||||
space_taken = item.get_space_data()
|
space_taken = item.get_space_data()
|
||||||
gc_taken_space_plastic += space_taken.get("plastic")
|
gc_taken_space_plastic += space_taken.get("plastic")
|
||||||
@ -60,4 +65,9 @@ class Hud():
|
|||||||
filewriter = csv.writer(csvfile, delimiter=',', quotechar='|', quoting=csv.QUOTE_MINIMAL)
|
filewriter = csv.writer(csvfile, delimiter=',', quotechar='|', quoting=csv.QUOTE_MINIMAL)
|
||||||
row = [str(plastic_left), str(glass_left), str(metal_left), str(gc_taken_space_plastic)+"/"+str(gc_trash_space), str(gc_taken_space_glass)+"/"+str(gc_trash_space), str(gc_taken_space_metal)+"/"+str(gc_trash_space), str(total_gathered)]
|
row = [str(plastic_left), str(glass_left), str(metal_left), str(gc_taken_space_plastic)+"/"+str(gc_trash_space), str(gc_taken_space_glass)+"/"+str(gc_trash_space), str(gc_taken_space_metal)+"/"+str(gc_trash_space), str(total_gathered)]
|
||||||
filewriter.writerow(row)
|
filewriter.writerow(row)
|
||||||
csvfile.close()
|
csvfile.close()
|
||||||
|
|
||||||
|
with open(houses_csv_name, 'a', newline='') as csvfile:
|
||||||
|
filewriter = csv.writer(csvfile, delimiter=',', quotechar='|', quoting=csv.QUOTE_MINIMAL)
|
||||||
|
filewriter.writerow(houses_data)
|
||||||
|
csvfile.close()
|
||||||
|
29
utils.py
29
utils.py
@ -1,6 +1,8 @@
|
|||||||
import sys
|
import sys
|
||||||
import getopt
|
import getopt
|
||||||
import random
|
import random
|
||||||
|
import csv
|
||||||
|
import datetime
|
||||||
from config import PLAY_WIDTH, PLAY_HEIGHT, home_amount
|
from config import PLAY_WIDTH, PLAY_HEIGHT, home_amount
|
||||||
from sprites.cell import CELL_SIZE
|
from sprites.cell import CELL_SIZE
|
||||||
from sprites.grass import Grass
|
from sprites.grass import Grass
|
||||||
@ -69,3 +71,30 @@ def generate_garbage_collector(all_sprites, obstacles_coords):
|
|||||||
all_sprites.add(gc)
|
all_sprites.add(gc)
|
||||||
return gc
|
return gc
|
||||||
##################################################################################
|
##################################################################################
|
||||||
|
|
||||||
|
##INIT CSV FILES#######################
|
||||||
|
def init_csv():
|
||||||
|
|
||||||
|
currentDT = datetime.datetime.now().strftime("%Y%m%d%H%M%S")
|
||||||
|
stats_csv_name = "logs/stats_" + currentDT + ".csv"
|
||||||
|
|
||||||
|
with open(stats_csv_name, 'w', newline='') as csvfile:
|
||||||
|
filewriter = csv.writer(csvfile, delimiter=',', quotechar='|', quoting=csv.QUOTE_MINIMAL)
|
||||||
|
row = ["Plastic left", "Glass left", "Metal left", "GC plastic", "GC glass", "GC metal", "Total collected"]
|
||||||
|
filewriter.writerow(row)
|
||||||
|
csvfile.close()
|
||||||
|
|
||||||
|
houses_csv_name = "logs/houses_stats_" + currentDT + ".csv"
|
||||||
|
|
||||||
|
with open(houses_csv_name, 'w', newline='') as csvfile:
|
||||||
|
filewriter = csv.writer(csvfile, delimiter=',', quotechar='|', quoting=csv.QUOTE_MINIMAL)
|
||||||
|
row = []
|
||||||
|
for i in range(home_amount):
|
||||||
|
row.append("House "+str(i+1)+" plastic")
|
||||||
|
row.append("House "+str(i+1)+" glass")
|
||||||
|
row.append("House "+str(i+1)+" metal")
|
||||||
|
filewriter.writerow(row)
|
||||||
|
csvfile.close()
|
||||||
|
|
||||||
|
return stats_csv_name, houses_csv_name
|
||||||
|
#######################################
|
||||||
|
Loading…
Reference in New Issue
Block a user