A classic snake game built with pure HTML, CSS, and JavaScript. Control the snake to eat food, grow longer, and achieve high scores!
- Classic Snake Mechanics: Control a snake that continuously moves forward
- Food Collection: Eat red food items to grow longer and increase your score
- Collision Detection: Game ends when hitting walls or the snake's own body
- Auto-movement: Snake keeps moving in the current direction
- Direction Control: Use arrow keys or WASD to change direction (cannot reverse)
Choose from 4 difficulty settings that control the snake's speed:
- Easy (ๆ ข้) - 150ms update speed - Perfect for beginners
- Medium (ไธญ้) - 100ms update speed - Balanced gameplay (default)
- Hard (ๅฟซ้) - 60ms update speed - For experienced players
- Expert (ๆฅต้) - 35ms update speed - Ultimate challenge!
- Score Tracking: Earn 10 points for each food item
- High Score: Automatically saves your best score
- Player Names: Customize your player name for saved scores
- Score History: View all saved scores with difficulty levels
- Export Scores: Download scores as a
.txtfile
- Animated Snake: Realistic snake with directional eyes and animated tongue
- Gradient Body: Body segments with gradient opacity for depth
- Rounded Graphics: Modern, smooth visual design
- Grid Background: Clear grid for better spatial awareness
- Color-coded Difficulty Badges: Easy visual identification of difficulty levels
- Open
index.htmlin your web browser - Enter your player name (optional)
- Select your preferred difficulty level
- Click "Start Game"
- Arrow Keys or WASD to control direction:
- โฌ๏ธ Up: Arrow Up or W
- โฌ๏ธ Down: Arrow Down or S
- โฌ ๏ธ Left: Arrow Left or A
- โก๏ธ Right: Arrow Right or D
- The snake starts moving automatically to the right
- Use controls to change direction (cannot reverse into yourself)
- Eat the red food to grow longer and earn points
- Avoid hitting walls or your own body
- Try to achieve the highest score possible!
- Start Game: Begin a new game
- Pause/Resume: Pause or resume the current game
- Save Score: Save your current score with player name and difficulty
- View Saved Scores: Open modal to see all saved scores
- Download scores.txt: Export all scores to a text file
class1/
โโโ index.html # Main HTML structure
โโโ style.css # Styling and animations
โโโ game.js # Game logic and functionality
โโโ README.md # This file
- HTML5 Canvas: For game rendering
- Vanilla JavaScript: Game logic and controls
- CSS3: Modern styling with gradients and animations
- LocalStorage: Persistent score and high score storage
- Canvas Size: 600x600 pixels
- Grid Size: 20 pixels per tile
- Tile Count: 30x30 grid
- Initial Snake Length: 5 segments
- Score per Food: 10 points
easy: 150ms
medium: 100ms
hard: 60ms
expert: 35mssnakeHighScore: Stores the highest score achievedsnakeSavedScores: Array of all saved game scores
Each saved score includes:
- Player name
- Score value
- Difficulty level
- Date and time
SNAKE GAME (่ฒช้ฃ่) - SAVED SCORES
==================================================
#1 - PlayerName
Score: 150
Difficulty: HARD
Date: 10/8/2025, 10:15:30 PM
--------------------------------------------------
- Easy: Green (#d4edda / #155724)
- Medium: Yellow (#fff3cd / #856404)
- Hard: Red (#f8d7da / #721c24)
- Expert: Blue (#d1ecf1 / #0c5460)
- Snake Body: Green (#4CAF50)
- Snake Head: Dark Green (#2E7D32)
- Food: Orange-Red (#FF5722)
- Background: Light Gray (#f0f0f0)
- Grid Lines: Light Gray (#e0e0e0)
- Adapts to different screen sizes
- Mobile-friendly controls information
- Flexible layout for various devices
- Clear visual feedback for game states
- Smooth animations and transitions
- Intuitive controls and UI
- Persistent data across sessions
- Prevents backward movement (anti-reverse logic)
- Smart food placement (never spawns on snake)
- Accurate collision detection
- Smooth continuous movement
- Add sound effects and background music
- Implement power-ups and special items
- Add obstacles and maze levels
- Multiplayer mode
- Mobile touch controls
- Leaderboard with online sync
- Different snake skins/themes
- Achievement system
None currently. If you find any bugs, please report them!
This is a free, open-source educational project. Feel free to use, modify, and distribute.
Simply open index.html in any modern web browser. No build process or dependencies required!
- Chrome (recommended)
- Firefox
- Safari
- Edge
- Any modern browser with HTML5 Canvas support
Enjoy the game! ๐๐ฎ
Classic Snake Game (่ฒช้ฃ่) - Pure Frontend Implementation