From 8fa0a412ee2b9b4fa64ae9e508de400614c28c0f Mon Sep 17 00:00:00 2001 From: tiennm99 Date: Mon, 13 Apr 2026 21:52:31 +0700 Subject: [PATCH] feat: add header, scores, keyboard input, and overlays (Stories 1.4-1.6) ScoreBoard shows current/best score. Keyboard arrow keys control gameplay via input-handler module. GameMessage overlay shows win/game over states with Keep Going, Try Again, and New Game actions. Co-Authored-By: Claude Opus 4.6 (1M context) --- .../sprint-status.yaml | 6 +- src/App.svelte | 57 ++++++++++++++++++- src/components/GameMessage.svelte | 44 ++++++++++++++ src/components/ScoreBoard.svelte | 14 +++++ src/lib/input-handler.js | 12 ++++ 5 files changed, 127 insertions(+), 6 deletions(-) create mode 100644 src/components/GameMessage.svelte create mode 100644 src/components/ScoreBoard.svelte create mode 100644 src/lib/input-handler.js diff --git a/_bmad-output/implementation-artifacts/sprint-status.yaml b/_bmad-output/implementation-artifacts/sprint-status.yaml index 2be6f43..31f06b1 100644 --- a/_bmad-output/implementation-artifacts/sprint-status.yaml +++ b/_bmad-output/implementation-artifacts/sprint-status.yaml @@ -47,9 +47,9 @@ development_status: 1-1-project-scaffold-and-dev-environment: review 1-2-game-logic-module: review 1-3-game-board-and-tile-rendering: review - 1-4-game-header-score-display-and-new-game-button: backlog - 1-5-keyboard-input-and-interactive-gameplay: backlog - 1-6-win-and-game-over-overlays: backlog + 1-4-game-header-score-display-and-new-game-button: review + 1-5-keyboard-input-and-interactive-gameplay: review + 1-6-win-and-game-over-overlays: review epic-1-retrospective: optional # Epic 2: Save Progress & Keep Playing diff --git a/src/App.svelte b/src/App.svelte index 8c82ab6..507f130 100644 --- a/src/App.svelte +++ b/src/App.svelte @@ -1,7 +1,10 @@ -
- + + +
+
+
+

2048

+ +
+
+

Join the numbers and get to the 2048 tile!

+ +
+
+
+ + +
diff --git a/src/components/GameMessage.svelte b/src/components/GameMessage.svelte new file mode 100644 index 0000000..9e37655 --- /dev/null +++ b/src/components/GameMessage.svelte @@ -0,0 +1,44 @@ + + +{#if type} +
+

{message}

+ {#if type === 'win'} +
+ + +
+ {:else} + + {/if} +
+{/if} diff --git a/src/components/ScoreBoard.svelte b/src/components/ScoreBoard.svelte new file mode 100644 index 0000000..2d5e597 --- /dev/null +++ b/src/components/ScoreBoard.svelte @@ -0,0 +1,14 @@ + + +
+
+ Score + {score} +
+
+ Best + {bestScore} +
+
diff --git a/src/lib/input-handler.js b/src/lib/input-handler.js new file mode 100644 index 0000000..a98726a --- /dev/null +++ b/src/lib/input-handler.js @@ -0,0 +1,12 @@ +import { DIRECTIONS } from './constants.js'; + +const KEY_MAP = { + ArrowUp: DIRECTIONS.UP, + ArrowDown: DIRECTIONS.DOWN, + ArrowLeft: DIRECTIONS.LEFT, + ArrowRight: DIRECTIONS.RIGHT, +}; + +export function getDirectionFromKey(key) { + return KEY_MAP[key] || null; +}