-
Notifications
You must be signed in to change notification settings - Fork 1
/
game_base.py
89 lines (66 loc) · 2.03 KB
/
game_base.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
class GameBase(object):
name = 'Undefined'
input_args = 0
input_are_ints = True
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self._playing = True
# @property
# def board(self):
# raise NotImplementedError("Subclass should implement this!")
@property
def is_playing(self):
return self._playing
def play(self, *args):
return ''
def next_turn(self):
return ''
def finish(self):
self._playing = False
class GameWithTurns(object):
def __init__(self, name='Undefined', name2='Undefined', *args, **kwargs):
super(GameWithTurns, self).__init__(*args, **kwargs)
self.player_one = name
self.player_two = name2
self._turn = self.player_one
def change_turn(self):
if self._turn == self.player_one:
self._turn = self.player_two
else:
self._turn = self.player_one
@property
def actual_player(self):
return self._turn
class GameWithBoard(object):
minimum = 0
cols = 0
rows = 0
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self._board = []
@property
def get_board(self):
return self._board
def set_board(self, board):
self._board = board
def create_board(self, char):
for _ in range(self.rows):
columns = []
for _ in range(self.cols):
columns.append(char)
self._board.append(columns)
def get_value(self, x, y):
return self._board[x][y]
def set_value(self, x, y, value):
self._board[x][y] = value
def in_board(self, x, y):
return self.rows > x and self.cols > y and x >= 0 and y >= 0
def in_columns(self, *args):
count_args = len(args)
if count_args == 1:
if isinstance(args, int):
return (
self.minimum <= args[0] < self.cols
)
else:
return False