-
Notifications
You must be signed in to change notification settings - Fork 0
/
level.py
55 lines (44 loc) · 1.59 KB
/
level.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
import os,copy
class Level:
matrix = []
hist_matrix = []
def __init__(self, level_num):
del self.matrix[:]
del self.hist_matrix[:]
# Create level
with open(os.path.dirname(os.path.abspath(__file__)) + '/Levels/level' + str(level_num), 'r') as dosya:
for row in dosya.read().splitlines():
letters = row.strip().split("\t")
self.matrix.append(list(letters))
def get_matrix(self):
return self.matrix
def save_history(self, matrix):
pass#self.hist_matrix.append(copy.deepcopy(matrix))
def undo(self):
if len(self.hist_matrix) > 0:
last_matrix = self.hist_matrix.pop()
self.matrix = last_matrix
return last_matrix
else:
return self.matrix
def get_player_pos(self):
# Iterate all Rows
for r in range(0, len(self.matrix)):
# Iterate all columns
for c in range(0, len(self.matrix[r])):
if self.matrix[r][c] == "P":
return [r, c]
def get_apple_positions(self):
apples = []
for r in range(0, len(self.matrix)):
for c in range(0, len(self.matrix[r])):
if self.matrix[r][c] == "A":
apples.append([r, c])
return apples
def get_size(self):
max_row_length = 0
for i in range(0, len(self.matrix)):
row_length = len(self.matrix[i])
if row_length > max_row_length:
max_row_length = row_length
return [len(self.matrix), max_row_length]