litris update
This commit is contained in:
17
field.py
17
field.py
@@ -14,7 +14,6 @@ class Field():
|
|||||||
else:
|
else:
|
||||||
self.state = [[' ' for cols in range(Field.WIDTH)]
|
self.state = [[' ' for cols in range(Field.WIDTH)]
|
||||||
for rows in range(Field.HEIGHT)]
|
for rows in range(Field.HEIGHT)]
|
||||||
#self.rotate_90_degree_clckwise(self.state)
|
|
||||||
self.cleared_rows = 1
|
self.cleared_rows = 1
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
@@ -24,7 +23,8 @@ class Field():
|
|||||||
'{:2d} |'.format(i) + ' '.join(row) + '|'
|
'{:2d} |'.format(i) + ' '.join(row) + '|'
|
||||||
for i, row in enumerate(self.state)]) + '\n' + BAR
|
for i, row in enumerate(self.state)]) + '\n' + BAR
|
||||||
|
|
||||||
def matrixflip(self, m, d):
|
@staticmethod
|
||||||
|
def matrixflip(m, d):
|
||||||
tempm = m.copy()
|
tempm = m.copy()
|
||||||
if d == 'h':
|
if d == 'h':
|
||||||
for i in range(0, len(tempm), 1):
|
for i in range(0, len(tempm), 1):
|
||||||
@@ -33,14 +33,16 @@ class Field():
|
|||||||
tempm.reverse()
|
tempm.reverse()
|
||||||
return (tempm)
|
return (tempm)
|
||||||
|
|
||||||
def rotate_90_degree_anticlckwise(self, matrix):
|
@staticmethod
|
||||||
|
def rotate_90_degree_anticlckwise(matrix):
|
||||||
new_matrix = []
|
new_matrix = []
|
||||||
for i in range(len(matrix[0]), 0, -1):
|
for i in range(len(matrix[0]), 0, -1):
|
||||||
new_matrix.append(list(map(lambda x: x[i - 1], matrix)))
|
new_matrix.append(list(map(lambda x: x[i - 1], matrix)))
|
||||||
|
|
||||||
return new_matrix
|
return new_matrix
|
||||||
|
|
||||||
def rotate_90_degree_clckwise(self, matrix):
|
@staticmethod
|
||||||
|
def rotate_90_degree_clckwise(matrix):
|
||||||
new_matrix = []
|
new_matrix = []
|
||||||
for i in range(len(matrix[0])):
|
for i in range(len(matrix[0])):
|
||||||
li = list(map(lambda x: x[i], matrix))
|
li = list(map(lambda x: x[i], matrix))
|
||||||
@@ -58,9 +60,8 @@ class Field():
|
|||||||
self.state[row] = [' ' for cols in range(Field.WIDTH)]
|
self.state[row] = [' ' for cols in range(Field.WIDTH)]
|
||||||
|
|
||||||
def rotate_state(self):
|
def rotate_state(self):
|
||||||
self.state = self.rotate_90_degree_anticlckwise(self.state)
|
self.state = Field.rotate_90_degree_anticlckwise(self.state)
|
||||||
#self.state = self.matrixflip(self.state, 'v')
|
|
||||||
#print(self.state)
|
|
||||||
|
|
||||||
def get_line_count(self):
|
def get_line_count(self):
|
||||||
return self.cleared_rows
|
return self.cleared_rows
|
||||||
@@ -158,7 +159,7 @@ class Field():
|
|||||||
|
|
||||||
def predict_gaps_in_next_rotation(self):
|
def predict_gaps_in_next_rotation(self):
|
||||||
tmp_state = copy(self.state)
|
tmp_state = copy(self.state)
|
||||||
tmp_state = self.rotate_90_degree_anticlckwise(tmp_state)
|
tmp_state = Field.rotate_90_degree_anticlckwise(tmp_state)
|
||||||
for row in range(int(self.HEIGHT/2)):
|
for row in range(int(self.HEIGHT/2)):
|
||||||
tmp_state[row] = [' ' for cols in range(Field.WIDTH)]
|
tmp_state[row] = [' ' for cols in range(Field.WIDTH)]
|
||||||
return sum(
|
return sum(
|
||||||
|
|||||||
@@ -100,8 +100,7 @@ class Litris(GameBase):
|
|||||||
|
|
||||||
def update_field_with_stored_edges(self):
|
def update_field_with_stored_edges(self):
|
||||||
if self.move_mode == 4:
|
if self.move_mode == 4:
|
||||||
state_copy = copy(self.field_state_storage[1])
|
state_copy = Field.rotate_90_degree_clckwise(copy(self.field_state_storage[1]))
|
||||||
state_copy = state_copy.rotate_90_degree_clckwise()
|
|
||||||
for i in range(11,20,1):
|
for i in range(11,20,1):
|
||||||
for e in range(0,2,1):
|
for e in range(0,2,1):
|
||||||
self.field.state[i][e] = state_copy[i][e]
|
self.field.state[i][e] = state_copy[i][e]
|
||||||
|
|||||||
Reference in New Issue
Block a user