Skip to content

NickTheDevOpsGuy/Snake

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

91 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿ Snake โ€” React + TypeScript Edition

A minimalist Snake clone built with React, TypeScript, and HTML Canvas โ€” focused on mastering game loops, keyboard input, and UI feedback using React hooks and refs.

CI Built with React TypeScript TailwindCSS License Last Commit Contributions welcome

๐Ÿงฉ This project is part of my ongoing React fundamentals journey exploring how to handle real-time loops, keyboard input, and canvas drawing inside React without heavy frameworks.


๐Ÿ•น๏ธ Preview

๐ŸŽฅ Gameplay Sneak Peek

Gameplay preview


๐ŸŒ Live Demo

Try Snake here: https://snake-beryl-six.vercel.app/


๐ŸŽฏ Features

๐Ÿง  Core Gameplay

  • โšก Smooth Canvas Rendering โ€” real-time updates without unnecessary re-renders
  • ๐ŸŽฎ Arrow Key Controls โ€” responsive movement with spacebar restart
  • ๐ŸŽ Dynamic Food Spawning โ€” random positions, never overlaps the snake
  • ๐Ÿ’ฅ Collision Detection โ€” walls and self-collision instantly end the game
  • ๐Ÿ” Clean Restart Logic โ€” quick replay loop with instant feedback
  • ๐Ÿ’ซ Animated Score Pop โ€” subtle CSS bump when you eat food
  • ๐ŸŒ‘ Dark Grid Aesthetic โ€” modern look with subtle borders and Tailwind styling

๐Ÿš€ Enhanced Features

  • ๐Ÿ”Š Sound Effects โ€” satisfying audio feedback for moves, food, and game-over
  • ๐Ÿงฉ Difficulty Presets โ€” easy, medium, and hard options that scale board size and speed
  • ๐Ÿฅ• Emoji Food Items โ€” random fruits and veggies add playful variety
  • ๐Ÿ’พ Persistent Best Score โ€” keeps your top score across sessions (local leaderboard per difficulty)
  • ๐ŸŽ‰ Celebrations โ€” confetti on new high score and every 5 points
  • โธ๏ธ Pause / Resume Hotkey โ€” toggle with the P key
  • ๐Ÿงฑ Dynamic Speed Scaling โ€” snake speeds up as you grow
  • ๐Ÿงญ Modular Hook Architecture โ€” reusable logic with useSnakeGame, useTicker, and friends
  • โš™๏ธ Strict TypeScript + ESLint โ€” clean, type-safe codebase with zero warnings

๐Ÿ† Leaderboard

Scores are stored locally in your browser. Your best scores per difficulty appear in the Leaderboard from the main menu.


Contributing

We love contributions of all kinds! Whether itโ€™s fixing a bug, suggesting a feature, or polishing docs, your help makes this game better.

How to join in:

Every contribution, big or small, helps keep this project alive ๐ŸŽ‰


๐Ÿšง Roadmap

Check upcoming ideas and milestones in the Project Roadmap.


Acknowledgements

Snake is a community project, shaped by everyone whoโ€™s played, tested, and contributed.
Every commit, idea, and bug report makes the game better.

Contributors

Meet all our amazing Contributors


๐Ÿ“‚ Project Structure

๐Ÿ“ Click to expand project file structure
.
โ”œโ”€โ”€ .github
โ”‚   โ”œโ”€โ”€ ISSUE_TEMPLATE
โ”‚   โ”‚   โ”œโ”€โ”€ bug.yml
โ”‚   โ”‚   โ”œโ”€โ”€ config.yml
โ”‚   โ”‚   โ”œโ”€โ”€ documentation.yml
โ”‚   โ”‚   โ”œโ”€โ”€ enhancement_refactor.yml
โ”‚   โ”‚   โ”œโ”€โ”€ feature_request.yml
โ”‚   โ”‚   โ””โ”€โ”€ question_discussion.yml
โ”‚   โ”œโ”€โ”€ workflows
โ”‚   โ”‚   โ”œโ”€โ”€ snake-ci.yml
โ”‚   โ”‚   โ””โ”€โ”€ vercel-production.yml
โ”‚   โ””โ”€โ”€ pull_request_template.md
โ”œโ”€โ”€ .gitignore
โ”œโ”€โ”€ .husky
โ”‚   โ”œโ”€โ”€ pre-commit
โ”‚   โ””โ”€โ”€ pre-push
โ”œโ”€โ”€ .prettierignore
โ”œโ”€โ”€ .prettierrc
โ”œโ”€โ”€ .prettierrc.json
โ”œโ”€โ”€ .prettierrc.yml
โ”œโ”€โ”€ .stylelintrc.json
โ”œโ”€โ”€ CONTRIBUTORS.md
โ”œโ”€โ”€ eslint.config.js
โ”œโ”€โ”€ index.html
โ”œโ”€โ”€ package-lock.json
โ”œโ”€โ”€ package.json
โ”œโ”€โ”€ playwright.config.ts
โ”œโ”€โ”€ public
โ”‚   โ”œโ”€โ”€ snake.svg
โ”‚   โ””โ”€โ”€ sounds
โ”‚       โ”œโ”€โ”€ food.mp3
โ”‚       โ”œโ”€โ”€ gameover.mp3
โ”‚       โ””โ”€โ”€ move.mp3
โ”œโ”€โ”€ README.md
โ”œโ”€โ”€ scripts
โ”‚   โ””โ”€โ”€ precheck.sh
โ”œโ”€โ”€ e2e
โ”‚   โ””โ”€โ”€ app.spec.ts
โ”œโ”€โ”€ src
โ”‚   โ””โ”€โ”€ app
โ”‚       โ”œโ”€โ”€ App.tsx
โ”‚       โ”œโ”€โ”€ assets
โ”‚       โ”‚   โ””โ”€โ”€ snake-gameplay.gif
โ”‚       โ”œโ”€โ”€ components
โ”‚       โ”‚   โ”œโ”€โ”€ AchievementsModal.tsx
โ”‚       โ”‚   โ”œโ”€โ”€ CountdownOverlay.tsx
โ”‚       โ”‚   โ”œโ”€โ”€ GameOverOverlay.tsx
โ”‚       โ”‚   โ”œโ”€โ”€ HUD.tsx
โ”‚       โ”‚   โ”œโ”€โ”€ HowToPlayModal.tsx
โ”‚       โ”‚   โ”œโ”€โ”€ LeaderboardModal.tsx
โ”‚       โ”‚   โ”œโ”€โ”€ MenuScreen.tsx
โ”‚       โ”‚   โ”œโ”€โ”€ MobileControls.tsx
โ”‚       โ”‚   โ”œโ”€โ”€ SettingsModal.tsx
โ”‚       โ”‚   โ”œโ”€โ”€ SnakeCanvas.tsx
โ”‚       โ”‚   โ””โ”€โ”€ StatsScreen.tsx
โ”‚       โ”œโ”€โ”€ constants
โ”‚       โ”‚   โ”œโ”€โ”€ foodThemes.ts
โ”‚       โ”‚   โ”œโ”€โ”€ game.ts
โ”‚       โ”‚   โ”œโ”€โ”€ skins.ts
โ”‚       โ”‚   โ””โ”€โ”€ themes.ts
โ”‚       โ”œโ”€โ”€ data
โ”‚       โ”‚   โ””โ”€โ”€ achievements.ts
โ”‚       โ”œโ”€โ”€ hooks
โ”‚       โ”‚   โ”œโ”€โ”€ useBestScore.ts
โ”‚       โ”‚   โ”œโ”€โ”€ useCanvas2D.ts
โ”‚       โ”‚   โ”œโ”€โ”€ useGameScale.ts
โ”‚       โ”‚   โ”œโ”€โ”€ useGameSession.ts
โ”‚       โ”‚   โ”œโ”€โ”€ useGameSetup.ts
โ”‚       โ”‚   โ”œโ”€โ”€ useInput.ts
โ”‚       โ”‚   โ”œโ”€โ”€ useLeaderboard.ts
โ”‚       โ”‚   โ”œโ”€โ”€ usePauseHotkey.ts
โ”‚       โ”‚   โ”œโ”€โ”€ useSettings.ts
โ”‚       โ”‚   โ”œโ”€โ”€ useSnakeGame.ts
โ”‚       โ”‚   โ”œโ”€โ”€ useSwipe.ts
โ”‚       โ”‚   โ””โ”€โ”€ useTicker.ts
โ”‚       โ”œโ”€โ”€ main.tsx
โ”‚       โ”œโ”€โ”€ services
โ”‚       โ”‚   โ”œโ”€โ”€ achievementService.ts
โ”‚       โ”‚   โ”œโ”€โ”€ achievementService.test.ts
โ”‚       โ”‚   โ”œโ”€โ”€ statsService.ts
โ”‚       โ”‚   โ””โ”€โ”€ statsService.test.ts
โ”‚       โ”œโ”€โ”€ styles
โ”‚       โ”‚   โ””โ”€โ”€ App.css
โ”‚       โ”œโ”€โ”€ types
โ”‚       โ”‚   โ”œโ”€โ”€ game.ts
โ”‚       โ”‚   โ”œโ”€โ”€ index.ts
โ”‚       โ”‚   โ””โ”€โ”€ ui.ts
โ”‚       โ””โ”€โ”€ utils
โ”‚           โ”œโ”€โ”€ canvas.ts
โ”‚           โ”œโ”€โ”€ gameTick.ts
โ”‚           โ”œโ”€โ”€ haptics.ts
โ”‚           โ”œโ”€โ”€ logic.ts
โ”‚           โ”œโ”€โ”€ logic.test.ts
โ”‚           โ”œโ”€โ”€ seedRandom.ts
โ”‚           โ”œโ”€โ”€ share.ts
โ”‚           โ”œโ”€โ”€ soundGenerator.ts
โ”‚           โ””โ”€โ”€ speed.ts
โ”œโ”€โ”€ tsconfig.json
โ”œโ”€โ”€ tsconfig.node.json
โ””โ”€โ”€ vite.config.ts

Getting Started

Requirements: Node 18+

Clone & Run

  1. Clone repo
git clone git@github.com:NickTheDevOpsGuy/Snake.git
  1. Install dependencies
npm install
  1. Start dev server
npm run dev
  1. Run tests (optional):
npm test
  1. In your browser, visit http://localhost:5173

Tech Stack

Name Version Description
React ^19.x UI library for building components.
Vite ^7.x Fast dev server & bundler.

Scripts

Run with npm run <script> (see package.json for full list).

Category Script What it does
Dev dev Start Vite dev server
build Type-check (tsc -b) then build with Vite
preview Preview the production build
Test test Placeholder test script (exits 0)
test:watch Run Vitest in watch mode
Deploy predeploy Build before deploy
deploy Publish dist/ to GitHub Pages via gh-pages
Lint/Format lint ESLint for JS/TS (., extensions: js, jsx, ts, tsx)
lint:fix ESLint with --fix
format Prettier write across the repo
format:check Prettier check (no writes)
lint:css Stylelint for **/*.{css,scss} (includes build output unless ignored)
lint:css:fix Stylelint --fix for src/**/*.{css,scss}
Checks check Run Prettier (write) then ESLint
check:fix Run Prettier (write) then ESLint with --fix
TypeScript tscheck TypeScript type-check only (no emit)
Tooling precheck Run scripts/precheck.sh (project preflight)
Git Hooks prepare Run Husky setup on install

๐Ÿฆ Built by NickDoesDevOps

Created with โ˜•, curiosity, and a bit of chaos by Nicholas Clark.
Follow my learning-in-public journey:
GitHub: @NickTheDevOpsGuy โ€ข LinkedIn: @NickDoesDevOps

๐Ÿท #NickDoesDevOpsโ€ƒ#LearningInPublicโ€ƒ#BuiltInPublic

About

A minimalist Snake game built with React + TypeScript, featuring smooth canvas rendering, responsive controls, and a clean dark theme.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages