@@ -80,7 +80,7 @@ def empty_func(self):
8080 def new_game_easy (self ):
8181 self .FIELD_WIDTH = 9
8282 self .FIELD_HEIGHT = 9
83- self .MINES_MAX = 3
83+ self .MINES_MAX = 10
8484
8585 def new_game_mid (self ):
8686 self .FIELD_WIDTH = 16
@@ -247,7 +247,7 @@ def next_mark(self, x, y):
247247 self .flagged_cells -= 1
248248
249249 def store_played_games (self ):
250- if self .MINES_MAX == 3 :
250+ if self .MINES_MAX == 10 :
251251 nome = self .controller .get_text_input ("Noobie mode" , "Insert your name" )
252252 time = self .seconds_from_start
253253 self .playersEasy .append (Player (nome , time ))
@@ -322,26 +322,37 @@ def create_file(self, model):
322322 json_obj = json .dumps (json_dict , indent = 4 )
323323 with open ("historico.json" , "w" ) as outfile :
324324 outfile .write (json_obj )
325+ outfile .close ()
325326
326327
327328class To_csv (TypeFile ):
328329 def create_file (self , model ):
329- field_names = ['Nome' , 'Tempo de Jogo' ]
330- results = []
331- if len (model .playersEasy ) != 0 :
332- easy_dict = {}
333- for player in model .playersEasy :
334- easy_dict [player .get_nome ()] = player .get_time ()
335- results .append (easy_dict )
336- if len (model .playersRandom ) != 0 :
337- rand_dict = {}
338- for player in model .playersRandom :
339- rand_dict [player .get_nome ()] = player .get_time ()
340- results .append (rand_dict )
341- with open ('historico.csv' , 'w' ) as csvfile :
330+
331+ field_names = ['nome' , 'tempo' , 'dificuldade' ]
332+ with open ('historico.csv' , 'w' , encoding = 'UTF8' ) as csvfile :
342333 writer = csv .DictWriter (csvfile , fieldnames = field_names )
343334 writer .writeheader ()
344- writer .writerows (results )
335+
336+ if len (model .playersEasy ) != 0 :
337+ for player in model .playersEasy :
338+ aux = [{'nome' : player .get_nome (), 'tempo' : player .get_time (), 'dificuldade' : 'easy' }]
339+ writer .writerows (aux )
340+
341+ if len (model .playersMid ) != 0 :
342+ for player in model .playersMid :
343+ aux = [{'nome' : player .get_nome (), 'tempo' : player .get_time (), 'dificuldade' : 'mid' }]
344+ writer .writerows (aux )
345+
346+ if len (model .playersHard ) != 0 :
347+ for player in model .playersHard :
348+ aux = [{'nome' : player .get_nome (), 'tempo' : player .get_time (), 'dificuldade' : 'hard' }]
349+ writer .writerows (aux )
350+
351+ if len (model .playersRandom ) != 0 :
352+ for player in model .playersRandom :
353+ aux = [{'nome' : player .get_nome (), 'tempo' : player .get_time (), 'dificuldade' : 'random' }]
354+ writer .writerows (aux )
355+ csvfile .close ()
345356
346357
347358class To_txt (TypeFile ):
0 commit comments