Update terminis.py
This commit is contained in:
parent
5a72fe9f4b
commit
ced30e38b1
@ -99,13 +99,20 @@ class Tetromino:
|
|||||||
self.fall_timer = None
|
self.fall_timer = None
|
||||||
self.hold_enabled = True
|
self.hold_enabled = True
|
||||||
|
|
||||||
def move(self, movement, lock=True):
|
def possible_position(self, minoes_position, movement):
|
||||||
potential_position = self.position + movement
|
potential_position = self.position + movement
|
||||||
if all(
|
if all(
|
||||||
self.matrix.is_free_cell(mino_position+potential_position)
|
self.matrix.is_free_cell(mino_position+potential_position)
|
||||||
for mino_position in self.minoes_position
|
for mino_position in minoes_position
|
||||||
):
|
):
|
||||||
self.position = potential_position
|
return potential_position
|
||||||
|
else:
|
||||||
|
return None
|
||||||
|
|
||||||
|
def move(self, movement, lock=True):
|
||||||
|
possible_position = self.possible_position(self.minoes_position, movement)
|
||||||
|
if possible_position:
|
||||||
|
self.position = possible_position
|
||||||
self.postpone_lock()
|
self.postpone_lock()
|
||||||
self.rotated_last = False
|
self.rotated_last = False
|
||||||
self.matrix.refresh()
|
self.matrix.refresh()
|
||||||
@ -134,13 +141,10 @@ class Tetromino:
|
|||||||
for mino_position in self.minoes_position
|
for mino_position in self.minoes_position
|
||||||
)
|
)
|
||||||
for rotation_point, liberty_degree in enumerate(self.SUPER_ROTATION_SYSTEM[self.orientation][direction], start=1):
|
for rotation_point, liberty_degree in enumerate(self.SUPER_ROTATION_SYSTEM[self.orientation][direction], start=1):
|
||||||
potential_position = self.position + liberty_degree
|
possible_position = self.possible_position(potential_minoes_positions, liberty_degree)
|
||||||
if all(
|
if possible_position:
|
||||||
self.matrix.is_free_cell(potential_mino_position+potential_position)
|
|
||||||
for potential_mino_position in potential_minoes_positions
|
|
||||||
):
|
|
||||||
self.orientation = (self.orientation+direction) % 4
|
self.orientation = (self.orientation+direction) % 4
|
||||||
self.position = potential_position
|
self.position = possible_position
|
||||||
self.minoes_position = potential_minoes_positions
|
self.minoes_position = potential_minoes_positions
|
||||||
self.postpone_lock()
|
self.postpone_lock()
|
||||||
self.rotated_last = True
|
self.rotated_last = True
|
||||||
@ -167,7 +171,7 @@ class Tetromino:
|
|||||||
|
|
||||||
def lock(self):
|
def lock(self):
|
||||||
self.lock_timer = None
|
self.lock_timer = None
|
||||||
if not self.move(Movement.DOWN, lock=False):
|
if not self.possible_position(self.minoes_position, Movement.DOWN):
|
||||||
if self.fall_timer:
|
if self.fall_timer:
|
||||||
self.fall_timer = scheduler.cancel(self.fall_timer)
|
self.fall_timer = scheduler.cancel(self.fall_timer)
|
||||||
self.matrix.lock(self.t_spin())
|
self.matrix.lock(self.t_spin())
|
||||||
@ -642,8 +646,9 @@ class Game:
|
|||||||
|
|
||||||
def start_piece(self):
|
def start_piece(self):
|
||||||
self.matrix.piece.position = Matrix.PIECE_POSITION
|
self.matrix.piece.position = Matrix.PIECE_POSITION
|
||||||
if self.matrix.piece.move(Movement.STILL, lock=False):
|
if self.matrix.piece.possible_position(self.matrix.piece.minoes_position, Movement.STILL):
|
||||||
self.matrix.piece.fall_timer = scheduler.enter(Tetromino.fall_delay, 2, self.matrix.piece.fall, tuple())
|
self.matrix.piece.fall_timer = scheduler.enter(Tetromino.fall_delay, 2, self.matrix.piece.fall, tuple())
|
||||||
|
self.matrix.refresh()
|
||||||
else:
|
else:
|
||||||
self.over()
|
self.over()
|
||||||
|
|
||||||
@ -686,7 +691,7 @@ class Game:
|
|||||||
|
|
||||||
self.matrix.piece, self.hold.piece = self.hold.piece, self.matrix.piece
|
self.matrix.piece, self.hold.piece = self.hold.piece, self.matrix.piece
|
||||||
self.hold.piece.position = self.hold.PIECE_POSITION
|
self.hold.piece.position = self.hold.PIECE_POSITION
|
||||||
self.hold.piece.minoes_positions = self.hold.piece.MINOES_POSITIONS
|
self.hold.piece.minoes_position = self.hold.piece.MINOES_POSITIONS
|
||||||
self.hold.piece.hold_enabled = False
|
self.hold.piece.hold_enabled = False
|
||||||
self.hold.refresh()
|
self.hold.refresh()
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user