hoangsonww/2048-Game

Feature: Undo Move Functionality

Open

#5 opened on Sep 5, 2025

View on GitHub
 (0 comments) (0 reactions) (1 assignee)Swift (14 forks)auto 404
bugdocumentationenhancementgood first issuehelp wantedquestion

Repository metrics

Stars
 (20 stars)
PR merge metrics
 (PR metrics pending)

Description

Summary

Add an Undo Move feature that allows players to revert their last move in the 2048 game. This will enhance the gameplay experience across iOS (Swift), Android (Kotlin), and Web (JavaScript/HTML) versions.


Why

  • Many players accidentally swipe in the wrong direction, leading to frustrating mistakes.
  • Undo functionality improves usability and accessibility, especially for casual players.
  • Aligns with many modern 2048 variations that already support undo.

Scope

  • Store the previous game state (grid + score) before each move.

  • Provide a single-step undo option (only the last move can be undone).

  • Add an Undo button in the UI for all platforms:

    • SwiftUI (iOS) → button below the board.
    • Android (Kotlin) → Material button in game toolbar.
    • Web (JS) → simple button under the board.

Implementation Plan

  1. State Management

    • Save a copy of the game board and score before applying a move.
    • Limit history to 1 previous state (no multiple undos).
  2. UI Updates

    • Add “Undo” button to all UIs.
    • Disable button if no undo is available.
  3. Logic

    • On button press, restore the previous board + score.
    • Clear undo history after use.
  4. Testing

    • Verify undo works after swiping in all directions.
    • Ensure score also reverts correctly.
    • Test across Web, iOS, and Android builds.

Acceptance Criteria

  • ✅ Undo button visible and functional across all platforms.
  • ✅ Game state (tiles + score) restores correctly.
  • ✅ Undo only available once per move.
  • ✅ No crashes or inconsistencies when undoing after a new move.

Test Plan

  • Unit Tests: Confirm previous board state is saved and restored correctly.
  • UI Tests: Validate that pressing Undo restores the board visually.
  • Cross-Platform Tests: Verify behavior is consistent across Swift, Kotlin, and JavaScript versions.

Contributor guide