-
Notifications
You must be signed in to change notification settings - Fork 1
/
stats.py
37 lines (26 loc) · 842 Bytes
/
stats.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
import csv
this_level = 1
lives = 5
player_lives = 5
blue_ghosts_num = 2
red_ghosts_num = 1
green_ghosts_num = 0
orange_ghosts_num = 0
apples_rate = 0
default_level = object()
def load_from_file(file='stats.csv', level=default_level):
global blue_ghosts_num, red_ghosts_num, green_ghosts_num, orange_ghosts_num, this_level
if level is default_level:
level = this_level
this_level = level
with open(file) as csvfile:
csv_reader = csv.reader(csvfile, delimiter=';')
row_count = sum(1 for row in csv_reader)
csvfile.seek(0)
level = min(level + 1, row_count)
for i in range(level):
row = next(csv_reader)
blue_ghosts_num = int(row[0])
red_ghosts_num = int(row[1])
green_ghosts_num = int(row[2])
orange_ghosts_num = int(row[3])