-
Notifications
You must be signed in to change notification settings - Fork 0
/
board.py
47 lines (39 loc) · 1.56 KB
/
board.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
from box import Box
class Board():
def __init__(self, size_horizontal, size_vertical):
self.board = []
self.size_horizontal = size_horizontal
self.size_vertical = size_vertical
self.free_columns = list(range(self.size_horizontal))
for row in range(self.size_vertical):
line = []
for column in range(self.size_horizontal):
element = Box('.', (row, column))
line.append(element)
self.board.append(line)
def draw_board(self):
print()
for row in range(self.size_vertical):
print(" |", end = "")
for column in range(self.size_horizontal):
print(self.board[row][column].get_character(), end="")
print("|", end = "")
print()
print(" ==" + self.size_horizontal * 2 * "=" + "= ")
print()
def get_free_columns(self):
return self.free_columns
def remove_free_column(self, column):
self.free_columns.remove(column)
def add_free_column(self, column):
self.free_columns.append(column)
def check_row(self, column):
row = self.size_vertical - 1
while self.board[row][column].get_character() != ".":
row -= 1
assert(row >= 0)
return row
def change_character(self, character, row, column):
self.board[row][column].set_character(character)
def get_character(self, row, column):
return self.board[row][column].get_character()