Skip to content

fix : cleaned up handle_keypress arrow key handling in 2048-Game - #1849

Closed
tmdeveloper007 wants to merge 1 commit into
steam-bell-92:mainfrom
tmdeveloper007:#1845
Closed

fix : cleaned up handle_keypress arrow key handling in 2048-Game#1849
tmdeveloper007 wants to merge 1 commit into
steam-bell-92:mainfrom
tmdeveloper007:#1845

Conversation

@tmdeveloper007

Copy link
Copy Markdown
Contributor

Summary of What Has Been Done

Simplified and hardened the handle_keypress method in games/2048-Game/2048-Game.py by removing the conditional .lower() call and using .get() with direct key-to-action mapping.

Changes Made

  • Removed the faulty event.keysym.lower() if len(event.keysym) == 1 else event.keysym conditional
  • Changed to direct event.keysym usage
  • Added uppercase key variants (A, W, S, D) directly to the move_map instead of relying on .lower() transformation
  • Changed from if key not in move_map check + dict lookup to safer .get() with None check
  • Uses action() instead of move_map[key]() to avoid double lookup

Impact it Made

  • Removes the edge-case condition that could cause unexpected behavior with certain key events
  • Makes keyboard handling more explicit and maintainable
  • Handles both lowercase and uppercase WASD keys directly without string transformation

Closes #1845

Note: please assign this PR to the tmdeveloper007 account.

@vercel

vercel Bot commented Jul 29, 2026

Copy link
Copy Markdown

@tmdeveloper007 is attempting to deploy a commit to the Anuj's projects Team on Vercel.

A member of the Team first needs to authorize it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix : prevent KeyError when pressing arrow keys in 2048-Game handle_keypress

2 participants