Fix bug with python 3.12 and improve dropping

This commit is contained in:
2026-05-01 04:26:34 -07:00
parent 70053aa94d
commit 8516b43924
+12 -6
View File
@@ -92,11 +92,6 @@ class HashableDict(dict):
class Action(NamedTuple): class Action(NamedTuple):
key: int
type: Type
repeat: bool
desc: str
class Type(Enum): class Type(Enum):
# In Game # In Game
ROTATE_LEFT = auto() ROTATE_LEFT = auto()
@@ -113,6 +108,11 @@ class Action(NamedTuple):
# Help # Help
CLOSE_HELP = auto() CLOSE_HELP = auto()
key: int
type: Type
repeat: bool
desc: str
@staticmethod @staticmethod
def make_map(*acts): def make_map(*acts):
return HashableDict({act.key: act for act in acts}) return HashableDict({act.key: act for act in acts})
@@ -590,6 +590,8 @@ class Game:
& set(self.pending_actions) & set(self.pending_actions)
): ):
self.subcell_move = 0 self.subcell_move = 0
if Action.Type.DROP not in self.pending_actions:
self.stop_drop = False
while self.pending_actions: while self.pending_actions:
match self.pending_actions.pop(0): match self.pending_actions.pop(0):
case Action.Type.ROTATE_LEFT: case Action.Type.ROTATE_LEFT:
@@ -598,7 +600,7 @@ class Game:
self.rotate_current_piece(Direction.RIGHT) self.rotate_current_piece(Direction.RIGHT)
case Action.Type.SWAP_HOLD: case Action.Type.SWAP_HOLD:
self.swap_with_hold() self.swap_with_hold()
case Action.Type.DROP: case Action.Type.DROP if not self.stop_drop:
self.doing_drop = True self.doing_drop = True
case Action.Type.MOVE_LEFT: case Action.Type.MOVE_LEFT:
self.move_current_piece(Direction.LEFT) self.move_current_piece(Direction.LEFT)
@@ -614,6 +616,8 @@ class Game:
for dx, cell in enumerate(row): for dx, cell in enumerate(row):
if cell: if cell:
self.board[y + dy][x + dx] = piece.color self.board[y + dy][x + dx] = piece.color
# prevent user from accidentally dropping next piece too
self.stop_drop = True
def advance_piece(self): def advance_piece(self):
speed = ( speed = (
@@ -954,6 +958,7 @@ class Game:
def clear_board(self): def clear_board(self):
self.board = make_matrix(*Game.BOARD_SIZE) self.board = make_matrix(*Game.BOARD_SIZE)
# not in __init__ to facilitate debugging in ipython
def init(self): def init(self):
pygame.init() pygame.init()
self.screen = pygame.display.set_mode( self.screen = pygame.display.set_mode(
@@ -967,6 +972,7 @@ class Game:
pygame.key.stop_text_input() pygame.key.stop_text_input()
self.key_states = defaultdict(lambda: False) self.key_states = defaultdict(lambda: False)
self.pending_actions = [] self.pending_actions = []
self.stop_drop = False
self.help_mode = False self.help_mode = False
self.high_score = 0 self.high_score = 0