-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathScore.py
67 lines (47 loc) · 1.53 KB
/
Score.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
''' Author: Edmundo Daniel Hidalgo
Project 1
Score.py
Score.py should only save, read, and return the score data
'''
import sys
import os
import io
import csv
from Board import *
# This is the name of the save file
SCORE_SAVE_FILE = 'saves.csv'
def get_game_data(gameBoard):
# Grab this data from the game board class!
gameData = {"width" : gameBoard.get_width(),
"height" : gameBoard.get_height(),
'mineCount' : '5',
'goodFlags' : '1',
'badFlags' : '1',
'win' : True}
return gameData
# Should we save the game so that the player can open and close their game?
#def save_game(): I'm not sure how it will handle the Cells()!
# People will also cheat!!!!
def save_score(gameBoard):
try: # Check to see if the save file already exists
saveFile = open(SCORE_SAVE_FILE, 'a')
with saveFile as write_file:
saveFields = ['width', 'height', 'mineCount', 'goodFlags', 'badFlags', 'win']
csvWriter = csv.DictWriter(saveFile, fieldnames = saveFields)
csvWriter.writeheader()
csvWriter.writerow(get_game_data(gameBoard))
saveFile.close()
except IOError:
print('Error' + str(IOError)) # Scary!!! I haven't test this or know how!
tB = GameBoard(2, 2, 2)
aB = GameBoard(3, 7, 4)
bB = GameBoard(4, 4, 6)
cB = GameBoard(6, 4, 1)
dB = GameBoard(4, 5, 7)
eB = GameBoard(5, 5, 3)
save_score(tB)
save_score(aB)
save_score(bB)
save_score(cB)
save_score(dB)
save_score(eB)