-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrecorder.py
More file actions
54 lines (37 loc) · 1.24 KB
/
recorder.py
File metadata and controls
54 lines (37 loc) · 1.24 KB
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
import pickle
from .game import Player
class RunRecord():
def __init__(self, file_obj):
self.file_obj = file_obj
data = pickle.load(self.file_obj)
self.players = data[0]
self.game_history = data[1]
def get_players(self, func=None):
res = []
for colour, name, is_computer in self.players:
if is_computer:
player = Player(colour)
else:
player = Player(colour, name, func)
res.append(player)
return res
def get_game_history(self):
return self.game_history
def __iter__(self):
return iter(self.game_history)
class MakeRecord():
def __init__(self):
self.players = []
self.game_history = []
def add_player(self, player_obj):
if player_obj.choose_pawn_delegate is None:
is_computer = True
else:
is_computer = False
self.players.append((player_obj.colour,
player_obj.name, is_computer))
def add_game_turn(self, rolled_value, index):
self.game_history.append((rolled_value, index))
def save(self, file_obj):
pickle.dump([self.players, self.game_history],
file_obj)