Skip to content

feat(snake): wrap snake through walls instead of crashing - #2

Merged
clovisphere merged 2 commits into
devfrom
feat/wall-wrapping
Jun 17, 2026
Merged

clovisphere merged 2 commits into
devfrom
feat/wall-wrapping

Conversation

@clovisphere

@clovisphere clovisphere commented Jun 17, 2026

Copy link
Copy Markdown
Owner

Summary

  • nextHead now wraps using modulo instead of returning null on wall contact
  • Removed the wall-crash check from the game loop in main.js
  • Updated the "How to play" overlay to reflect the new behaviour
  • Updated README rules section accordingly

Test plan

  • 47/47 tests pass (bun test)
  • Snake wraps left→right, right→left, top→bottom, bottom→top
  • Self-collision and timer expiry still cost a life
  • "How to play" overlay shows the correct wall behaviour

Summary by CodeRabbit

Release Notes

  • New Features

    • Wall wrapping: Hitting a wall now wraps the snake to the opposite side with no penalty. Colliding with your tail or letting the clock expire still costs a life.
    • Added smooth wrap-around transition animation.
  • Documentation

    • Updated in-game rules and help text to clarify the new wall-wrapping mechanic.

@coderabbitai

coderabbitai Bot commented Jun 17, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: c774267a-e8c0-45fe-baee-daf8758dcc8d

📥 Commits

Reviewing files that changed from the base of the PR and between 73cd5a2 and a2c8db9.

📒 Files selected for processing (6)
  • README.md
  • public/css/style.css
  • public/js/main.js
  • public/js/snake.js
  • public/js/ui.js
  • tests/snake.test.js

📝 Walkthrough

Walkthrough

Wall-collision death is replaced with modulo-based wrap-around in nextHead. The game loop tracks a wrapGhost state object populated in step() when a boundary is crossed; renderGrid uses it to animate a ghost head sliding off one edge while the real head enters from the opposite side. Tests, README, and in-game help text are updated to match.

Changes

Wall Wrap Feature

Layer / File(s) Summary
nextHead wrap logic and step() wrapGhost state
public/js/snake.js, tests/snake.test.js, public/js/main.js
nextHead uses modulo to always return a valid in-bounds position instead of null; step() detects boundary crossings and sets G.wrapGhost with entry/exit coordinates; startGame() initializes wrapGhost: null; tests assert wrapped coordinates instead of null for each boundary direction.
Wrap ghost animation rendering
public/js/ui.js, public/js/main.js, public/css/style.css
render() clears G.wrapGhost each frame; renderGrid builds the head element separately, attaches optional wrapFrom per segment, spawns a temporary exit-ghost element that animates off the edge, and applies notrans + translated transform to wrap-entering segments for a snap-in effect; .ent rule repositioned in stylesheet.
Copy updates
README.md, public/js/ui.js
README splits the life-loss bullet into wall-wrap (no penalty) and tail/clock (costs a life); in-game helpHTML updated to match.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐍 The wall was once a deadly foe,
now I zoom through, high and low.
Modulo math, a gentle trick—
ghost slides out, then snaps in quick.
No life lost, just round I go! 🎉

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main feature change: implementing wall-wrapping instead of crashing for the snake game.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/wall-wrapping

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@clovisphere
clovisphere changed the base branch from main to dev June 17, 2026 05:57
@clovisphere
clovisphere merged commit 90e6508 into dev Jun 17, 2026
2 checks passed
@clovisphere
clovisphere deleted the feat/wall-wrapping branch June 17, 2026 06:03
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.

1 participant