diff --git a/tetris.py b/tetris.py index c892aef..6513332 100644 --- a/tetris.py +++ b/tetris.py @@ -92,11 +92,6 @@ class HashableDict(dict): class Action(NamedTuple): - key: int - type: Type - repeat: bool - desc: str - class Type(Enum): # In Game ROTATE_LEFT = auto() @@ -113,6 +108,11 @@ class Action(NamedTuple): # Help CLOSE_HELP = auto() + key: int + type: Type + repeat: bool + desc: str + @staticmethod def make_map(*acts): return HashableDict({act.key: act for act in acts}) @@ -590,6 +590,8 @@ class Game: & set(self.pending_actions) ): self.subcell_move = 0 + if Action.Type.DROP not in self.pending_actions: + self.stop_drop = False while self.pending_actions: match self.pending_actions.pop(0): case Action.Type.ROTATE_LEFT: @@ -598,7 +600,7 @@ class Game: self.rotate_current_piece(Direction.RIGHT) case Action.Type.SWAP_HOLD: self.swap_with_hold() - case Action.Type.DROP: + case Action.Type.DROP if not self.stop_drop: self.doing_drop = True case Action.Type.MOVE_LEFT: self.move_current_piece(Direction.LEFT) @@ -614,6 +616,8 @@ class Game: for dx, cell in enumerate(row): if cell: self.board[y + dy][x + dx] = piece.color + # prevent user from accidentally dropping next piece too + self.stop_drop = True def advance_piece(self): speed = ( @@ -954,6 +958,7 @@ class Game: def clear_board(self): self.board = make_matrix(*Game.BOARD_SIZE) + # not in __init__ to facilitate debugging in ipython def init(self): pygame.init() self.screen = pygame.display.set_mode( @@ -967,6 +972,7 @@ class Game: pygame.key.stop_text_input() self.key_states = defaultdict(lambda: False) self.pending_actions = [] + self.stop_drop = False self.help_mode = False self.high_score = 0