Skip to content

TheM1ddleM1n/HTMLSnakeGame

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 

Repository files navigation

🐍 Snake Game Pro

A fully-featured, modern browser-based Snake game built with vanilla HTML, CSS, and JavaScript. Features persistent leaderboards, multiple difficulty levels, sound effects, haptic feedback, and comprehensive game statistics.

✨ Features

Gameplay

  • Classic Snake Mechanics: Eat food to grow and score points
  • Three Difficulty Levels: Easy (6 FPS), Medium (8 FPS), Hard (12 FPS)
  • Progressive Speed: Game increases speed every 3 food items eaten
  • Dynamic Input Buffering: Queue up to 3+ moves based on current speed
  • Pause/Resume: Pause with SPACE key or pause button with visual overlay
  • Edge Wrapping: Toggle between wrapping edges or collision walls
  • Responsive Controls: Keyboard (arrow keys, WASD), touchscreen (swipe), on-screen buttons

Audio & Haptics

  • Sound Effects: Eat sounds, game-over feedback (toggle on/off)
  • Haptic Feedback: Vibration on mobile devices for enhanced feedback
  • Audio Volume Control: Adjust through settings

Visual Enhancements

  • Particle Effects: Visual feedback when eating food
  • Glow Effects: Glowing food and snake segments
  • Pause Overlay: Clear visual "PAUSED" indicator on canvas
  • Smooth Animations: Interpolated movement and UI transitions
  • Grid Display: Toggle grid visibility in settings
  • Difficulty Indicators: Colored emoji badges (🟢 Easy, 🟡 Medium, 🔴 Hard)

Leaderboard & Statistics

  • Persistent Leaderboard: Top 10 scores saved across sessions
  • Filter by Difficulty: View scores for specific difficulty levels
  • Player Statistics:
    • Games played
    • Average score
    • Total food eaten
    • Longest snake reached
  • High Score Tracking: Automatic detection and celebration of new high scores
  • Session Leaderboard: View scores from current gaming session in game-over modal

Settings & Customization

  • Display Settings: Toggle grid and sound effects
  • Gameplay Settings: Toggle edge wrapping behavior
  • Clear Data: Reset all scores and statistics with confirmation
  • Persistent Settings: Your preferences are saved between sessions

Mobile Optimization

  • Responsive Design: Adapts perfectly to all screen sizes (360px - 4K+)
  • Touch Controls: Swipe-to-move gesture support
  • Safe Area Support: Respects notches and safe areas on modern devices
  • Optimized Button Sizing: Controls scale based on screen size
  • Portrait & Landscape: Works in both orientations

Accessibility

  • Keyboard Navigation: Full keyboard support for all UI elements
  • ARIA Labels: Screen reader friendly with proper semantic markup
  • Focus Indicators: Clear visual focus states for keyboard users
  • Tab Navigation: Navigate modals and buttons with Tab key

🎮 How to Play

Starting the Game

  1. Open index.html in any modern web browser
  2. Select your difficulty level (Easy, Medium, Hard)
  3. Click START GAME to begin

Controls

Input Action
Arrow Keys or WASD Move snake
Space or Esc Pause/Resume
Swipe (mobile) Change direction
On-screen Buttons Mobile directional controls

Game Objective

  • Eat the red food to grow and earn points
  • Avoid crashing into yourself
  • Survive as long as possible
  • Compete for the top spot on the leaderboard

📊 Game Modes & Difficulty

Easy 🟢

  • Speed: 6 FPS
  • Perfect for learning
  • No time pressure

Medium 🟡

  • Speed: 8 FPS
  • Balanced challenge
  • Recommended for most players

Hard 🔴

  • Speed: 12 FPS
  • Intense and fast-paced
  • For experienced players

Speed Scaling: Each difficulty increases speed by 1 unit every 3 food items eaten, capping at +20 units above base speed.

⚙️ Settings

Display Options

  • Show Grid: Toggle subtle background grid for reference
  • Sound Effects: Enable/disable game audio (eating, game over)

Gameplay Options

  • Wrap Edges: Toggle between wrapping around edges or collision walls

Statistics

View lifetime game statistics including:

  • Total games played
  • Average score across all games
  • Total food items eaten
  • Longest snake reached

🏆 Leaderboard System

  • Top 10 Tracked: Automatically saves your best scores
  • Difficulty Tags: Each score shows the difficulty it was achieved on
  • Persistent Storage: Leaderboard data persists across browser sessions
  • Session Highlighting: Your current game session's score is highlighted
  • Filter Feature: View leaderboard filtered by difficulty level

🛠️ Technical Features

Performance

  • Cached Grid Rendering: Grid canvas is cached to reduce draw calls
  • Efficient Particle System: Optimized DOM-based particle effects
  • Requestanimationframe: Smooth 60 FPS rendering with frame skipping
  • Minimal Redraw: Only updates necessary canvas elements per frame

Storage

  • Browser Persistent Storage: Uses window.storage API for cross-session data
  • Fallback Support: Gracefully falls back to session memory if storage unavailable
  • Data Backup: All game data (scores, stats, settings) automatically saved

Code Quality

  • Vanilla JavaScript: No dependencies, works everywhere
  • Responsive Canvas: Automatically scales to screen size
  • Mobile-First Design: Optimized for mobile, enhanced on desktop
  • Semantic HTML: Proper structure for accessibility

📱 Browser Support

Works on all modern browsers:

  • Chrome/Chromium 90+
  • Firefox 88+
  • Safari 14+
  • Edge 90+
  • Mobile browsers (iOS Safari, Chrome Mobile)

🎯 Pro Tips

  1. Queue Moves Early: Use the input buffer to plan 2-3 moves ahead on higher difficulties
  2. Corner Strategy: Use corners to your advantage for quick turns
  3. Food Placement: Food spawns randomly—be prepared for unexpected positions
  4. Speed Management: Watch the speed bar to anticipate when the game will get faster
  5. Save Your Name: Beating your high score? Save your name to the leaderboard!

🐛 Known Issues

  • Phone layout optimized but may need adjustments on very small screens
  • Some older iOS versions may have limited haptic support

🚀 Future Enhancements

Potential features for future versions:

  • Local multiplayer mode
  • Power-ups system (speed boost, shield, etc.)
  • Custom color themes
  • Sound effect volume slider
  • Online leaderboard sync
  • Replay system
  • Achievements/Badges

📄 License

Created by TheM1ddleM1n - Feel free to fork, modify, and enjoy!

🎮 Play Online

Play the live version here: HTMLSnakeGame


Enjoy the game! 🐍

About

funny game

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages