-
Notifications
You must be signed in to change notification settings - Fork 8
/
board.py
51 lines (47 loc) · 1.97 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
48
49
50
51
'''This creates and base board'''
from os import system
from base import IDENTIFIER, FLOOR, FRAME_BREADTH
from coins import COINDICT, COINS
class Board:
'''Board class'''
def __init__(self, length, breadth, status):
self.length = length
self.breadth = breadth
self.mario = None
self.all_enemies = []
self.status = status
matrix = []
ch1 = IDENTIFIER['board']
for _ in range(0, FLOOR):
matrix.append([ch1] * breadth)
ch2 = IDENTIFIER['brick']
for _ in range(FLOOR, length):
matrix.append([ch2] * breadth)
self.matrix = matrix
def current(self, point, shape, dimensions):
'''Makes and handles current board'''
shape = [["" for i in range(dimensions.breadth)]
for j in range(dimensions.length)]
for i in range(0, dimensions.length):
for j in range(0, dimensions.breadth):
shape[i][j] = self.matrix[point.x + i][point.y + j]
return shape
def update(self,point,shape,dimensions):
for i in range(0,dimensions.length):
for j in range(0,dimensions.breadth):
if self.matrix[point.x + i][point.y + j] == IDENTIFIER['coin'] and shape[i][j] == IDENTIFIER['mario']:
try:
coinIndex = COINDICT[point.y + j][point.x + i]
COINS[coinIndex].check()
except Exception as e:
#This exists to capture any issues that can occur because the board doesn't update fast enough
pass
self.matrix[point.x + i][point.y + j] = shape[i][j]
def display(self, offset):
'''Renders boards frame by frame'''
system('clear')
self.status.print_status()
for i in self.matrix:
for j in i[offset:offset + FRAME_BREADTH]:
print(j, end='')
print('')