Premium
Vue Snake Game (Grid + Food + Collision)
Build a Snake game in Vue 3 using a grid board. Support keyboard controls, food spawning, score updates, and game-over handling for wall/body collisions.
- Render a fixed-size board (for example 14×14) with snake body and food…
- Move the snake using Arrow keys (optionally WASD).
What you’ll build / What this tests
This premium vue coding focuses on Vue Snake Game (Grid + Food + Collision). You’ll apply vue and composition-api thinking with hard level constraints. The prompt emphasizes Build a Snake game in Vue 3 using a grid board. Support keyboard controls, food spawning,….
Learning goals
- Translate the prompt into a clear vue API signature and return shape.
- Apply vue, composition-api, reactivity techniques to implement vue snake game (grid + food + collision).
- Handle hard edge cases without sacrificing readability.
- Reason about time/space complexity and trade-offs in vue.
Key decisions to discuss
- Define the exact input/output contract before coding.
- Prioritize predictable edge-case handling over micro-optimizations.
Evaluation rubric
- Correctness: covers required behaviors and edge cases.
- Clarity: readable structure and predictable control flow.
- Complexity: avoids unnecessary work for large inputs.
- API discipline: no mutation of inputs; returns expected shape.
- Testability: solution is easy to unit test.
Constraints / Requirements
- Render a fixed-size board (for example 14×14) with snake body and food cells.
- Move the snake using Arrow keys (optionally WASD).
- Run game ticks on an interval while the game is running.
- Eating food should grow the snake and increment score.
- Colliding with walls or snake body should end the game.
- Provide Start/Pause and Reset controls.
- Expose score and current snake length in the UI.
- Keep keyboard interactions stable (no reverse-direction bug).
- Initial state shows a short snake, one food cell, and score 0.
- Press Start to begin movement; snake advances one cell per tick.
Mini snippet (usage only)
// Example usage
const input = /* vue snake game (grid + food + collision) input */;
const result = solve(input);
console.log(result);
// Edge case check
const empty = input ?? null;
const fallback = solve(input);
console.log(fallback);
// Expected: describe output shape, not the implementation
// (no solution code in preview)Common pitfalls
- Mutating inputs instead of returning a new value.
- Skipping edge cases like empty input, duplicates, or nulls.
- Overlooking time complexity for large inputs.
Related questions
Upgrade to FrontendAtlas Premium to unlock this challenge. Already upgraded? Sign in to continue.