Commit Graph

13 Commits

Author SHA1 Message Date
tiennm99 4f1a0fdb9d feat(02-02): implement Renderer class with tile and selection rendering
- Created Renderer class with tile rendering, selection highlighting, and fade-in animations
- Created GridManager class with tile array and selection state management (blocking dependency)
- Added tilesSelected event to GameEvents interface
- Created comprehensive test suite for Renderer with 9 test cases

**Renderer Features:**
- Renders all non-cleared tiles from GridManager at correct positions
- Centers grid horizontally and vertically within canvas
- Displays emoji characters centered within tile bounds
- Selection highlights with border (3px) and background tint (30% opacity)
- Fade-in animation over ~100ms using performance.now()
- Uses CONFIG.tile.size, gap, cornerRadius for positioning
- Respects CONFIG.colors for styling

**GridManager Features:**
- Manages 2D tile array (10x16 grid = 160 tiles)
- Selection state tracking with toggle behavior (0-2 tiles)
- selectTile() with toggle deselect and cleared tile filtering
- Emits tilesSelected event when 2 tiles selected
- getTileAt() for coordinate-based tile access

**Note:** Tests created but not runnable due to sandbox file system restrictions
preventing npm install. Implementation verified manually against plan requirements.


🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2026-03-11 02:51:11 +00:00
tiennm99 4adca72e3a fix(01-02): replace Node EventEmitter with browser-compatible implementation
Node's 'events' module doesn't work in browsers. Replaced with custom
Map-based implementation that provides the same API but works in both
Node.js and browser environments.

All 98 tests still pass.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-11 00:09:45 +07:00
tiennm99 d0a39fc031 feat(01-03): wire main.ts entry point with Game class
- Update main.ts to import and instantiate Game class
- Wait for DOMContentLoaded before initializing
- Add error event listener on game.events
- Add tick event listener (commented debug logging)
- Log initialization message to console
- Add main.test.ts with entry point tests (4 tests)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-11 00:00:32 +07:00
tiennm99 6fbe23365a feat(01-03): add Game class orchestrator with TDD
- Create Game class that orchestrates canvas, game loop, and events
- Game constructor initializes canvas, context, loop, and events
- Game.start() starts the loop and emits 'game:start' event
- Game.render() clears canvas with background color
- Handle device pixel ratio for sharp rendering
- Add comprehensive tests (15 tests) for Game class

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-10 23:58:18 +07:00
tiennm99 fdd1ffd17e refactor(01-02): fix TypeScript type issues in tests
- Changed EventEmitter generic constraint to `object` for interface compatibility
- Fixed GameLoop test closure variable narrowing issue by using array

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-10 23:51:35 +07:00
tiennm99 efcac7ad4c feat(01-02): implement Tile model class
- Implements Tile interface from types/index.ts
- Constructor with id, type, position
- emoji getter returns CONFIG.emojis[type]
- isAdjacent() checks orthogonal adjacency
- cleared property defaults to false

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-10 23:49:16 +07:00
tiennm99 080b9f22a0 test(01-02): add failing tests for Tile model class
- Tests for constructor with id, type, position
- Tests for emoji getter returning correct emoji
- Tests for isAdjacent() method with various positions
- Tests for readonly properties and cleared default

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-10 23:48:48 +07:00
tiennm99 84e92c3178 feat(01-02): implement TypedEventEmitter class
- Generic class wrapping Node's EventEmitter
- Type-safe on(), emit(), off() methods
- Added once() and removeAllListeners() methods
- Returns this for method chaining

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-10 23:47:55 +07:00
tiennm99 4609e01410 test(01-02): add failing tests for TypedEventEmitter class
- Tests for on(), emit(), off() methods
- Tests for multiple listeners and chaining
- Tests for type safety with typed payloads
- Tests for error handling and once() method
- Tests for removeAllListeners()

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-10 23:47:24 +07:00
tiennm99 e46bc1db7a test(01-02): add failing tests for GameLoop class
- Tests for start(), stop(), isRunning(), getRafId()
- Tests for update callback with deltaTime
- Tests for delta time accumulation
- Tests for loop lifecycle (start/stop multiple times)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-10 23:46:34 +07:00
tiennm99 cf62913697 feat(01-01): create shared type definitions
- Add src/types/index.ts with type definitions
- Define TilePosition interface (row, col)
- Define Tile interface (id, type, position, cleared)
- Define GameEvents interface for type-safe event handling
- Add comprehensive tests for all type definitions

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-10 23:40:44 +07:00
tiennm99 2e8dcf2f29 feat(01-01): create game configuration constants
- Add src/config.ts with CONFIG object
- Define grid settings (10 rows, 16 cols, 160 tiles)
- Define tile settings (size, gap, corner radius)
- Define 16 nature-themed emojis
- Define color palette for game elements
- Add comprehensive tests for all config values

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-10 23:39:15 +07:00
tiennm99 3e61fa2fd4 feat(01-01): create Vite project with TypeScript and Canvas
- Initialize Vite project with vanilla-ts configuration
- Add TypeScript with strict mode enabled
- Configure Vitest for testing
- Create index.html with Canvas element
- Add main.ts entry point with canvas setup
- Add setup tests for project dependencies

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-10 23:38:14 +07:00