-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathboard.py
More file actions
81 lines (71 loc) · 2.5 KB
/
board.py
File metadata and controls
81 lines (71 loc) · 2.5 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
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
from colorama import Fore
from random import randint
import os
board = []
free = []
temp_free = []
bricks = []
class Brick:
def __inti__(self, x, y):
self.x = x
self.y = y
class Board:
def __init__(self, hei=46, wid=164):
self.hei = hei
self.wid = wid
for i in range(hei):
width = []
for j in range(wid):
if(i < 2 or i > (hei - 3) or j < 4 or j > (wid - 5)):
width.append('#')
else:
if(i % 4 < 2 and j % 8 < 4):
width.append('#')
else:
width.append(" ")
if(i % 2 is 0 and j % 4 is 0):
free.append((i, j))
board.append(width)
temp_free[:] = free
self.allocate_bricks()
def board_print(self):
for i in range(self.hei):
for j in range(self.wid):
if(board[i][j] == '#'):
print("\033[92m{}\033[00m".format(
str(board[i][j])), end='')
elif(board[i][j] == '/'):
print("\033[93m{}\033[00m".format(
str(board[i][j])), end='')
elif(board[i][j] == 'E'):
print("\033[91m{}\033[00m".format(
str(board[i][j])), end='')
elif(not type(board[i][j]) is int):
print("\033[34m{}\033[00m".format(
str(board[i][j])), end='')
else:
print(board[i][j], end='')
print('\n', end='')
def free_board(self):
return free
def allocate_bricks(self):
N = randint(20, 80)
for num in range(N):
x = randint(1, len(temp_free) - 3)
if((temp_free[x] != (4, 4)) and (temp_free != (2, 8))):
bricks.append(temp_free[x])
temp_free.remove(temp_free[x])
for x in bricks:
board[x[0]][x[1]] = '/'
board[x[0] + 1][x[1]] = '/'
board[x[0]][x[1]] = board[x[0]][x[1]] = '/'
board[x[0]][x[1] + 1] = board[x[0] + 1][x[1] + 1] = '/'
board[x[0]][x[1] + 2] = board[x[0] + 1][x[1] + 2] = '/'
board[x[0]][x[1] + 3] = board[x[0] + 1][x[1] + 3] = '/'
def refresh(self):
os.system('clear')
self.board_print()
def reset_board(self):
temp_free[:] = free
os.system('clear')
self.board_print()