Skip to content

Z3RO-O/Snake-Game

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

7 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿ Classic Snake Game

A modern, responsive implementation of the classic Nokia Snake game built with React, TypeScript, and Tailwind CSS. Featuring automatic snake movement, high score tracking, and a beautiful split-screen UI design.

โœจ Features

๐ŸŽฎ Classic Gameplay

  • Automatic snake movement with directional control
  • Collision detection with walls and self
  • Food collection and score tracking
  • Smooth 150ms game loop for authentic feel
  • โธ๏ธ Pause/Resume: Press Esc to pause and resume the game

๐Ÿ† High Score System

  • Persistent Storage: Browser localStorage with JSON serialization
  • Unique ID System: Timestamp + random number prevents data conflicts
  • Top 10 Leaderboard: Automatically sorted highest to lowest scores
  • Date Tracking: Each score includes achievement date (YYYY-MM-DD)
  • Smart Detection: Identifies new records and qualifying scores
  • Player Tracking: Multiple scores per player with individual best tracking
  • New Record Celebrations: Animations for beating the #1 score

๐ŸŽจ Modern UI/UX

  • Split-screen layout (controls left, game right)
  • Tailwind CSS styling with cyan/orange theme
  • Custom scrollbars and hover effects
  • Responsive design optimized for laptops
  • Beautiful gradient backgrounds
  • ๐Ÿชจ Rock Wall Borders: Textured stone walls with 3D shadows
  • ๐Ÿ Realistic Snake Animation: Flowing serpent with wave motion, curved body, and directional eyes

๐Ÿ”Š Audio Effects

  • ๐ŸŽ Bite Sound: Audio feedback when eating food (bite.mp3)
  • ๐Ÿ’ฅ Collision Sound: Impact sound when hitting walls or self (collision.wav)
  • Volume-optimized audio with graceful fallback if files missing

โŒจ๏ธ Keyboard Controls

  • Arrow keys for snake direction
  • Esc to pause/unpause game
  • ENTER to start game
  • SPACE to start new game (clears player name)
  • Full keyboard navigation support

๐Ÿ”ง Technical Features

  • React 19 with TypeScript
  • Vite for fast development and builds
  • HTML5 Canvas for smooth rendering
  • Custom React hooks for state management
  • Performance optimized with useCallback
  • 60fps Animation: Smooth wave motion using requestAnimationFrame
  • Path Aliases: Clean @/ imports for better code organization

๐Ÿš€ Getting Started

Prerequisites

  • Node.js (version 16 or higher)
  • npm or yarn package manager

Installation

  1. Clone the repository

    git clone https://github.com/Z3RO-O/Snake-Game-Odyc
    cd "Snake-Game-Odyc"
  2. Install dependencies

    npm i
  3. Start the development server

    npm run dev
  4. Open your browser Navigate to http://localhost:5173 (or the URL shown in your terminal)

Build for Production

npm run build
npm run preview

๐ŸŽฎ How to Play

  1. Enter Your Name: Type your player name in the input field (spaces allowed!)
  2. Start Game: Click "๐ŸŽฎ Start Game" or press ENTER
  3. Control Snake: Use arrow keys to change direction
    • โฌ†๏ธ Up Arrow
    • โฌ‡๏ธ Down Arrow
    • โฌ…๏ธ Left Arrow
    • โžก๏ธ Right Arrow
  4. Collect Food: Guide the snake to the red apples ๐ŸŽ
  5. Avoid Collisions: Don't hit the rock walls or the snake's own body
  6. Pause Anytime: Press Esc to pause/resume the game
  7. Beat High Scores: Try to achieve the highest score possible!

Keyboard Shortcuts

  • ENTER: Start game (when name is entered)
  • SPACE: Start new game (clears player name)
  • Arrow Keys: Control snake direction during gameplay
  • Esc: Pause/unpause the game

๐Ÿ› ๏ธ Tech Stack

  • Frontend: React 19, TypeScript
  • Styling: Tailwind CSS 4.x
  • Build Tool: Vite 6.x
  • Canvas: HTML5 Canvas API
  • Storage: Browser localStorage
  • Linting: ESLint with TypeScript support

๐Ÿ“ Project Structure

src/
โ”œโ”€โ”€ components/
โ”‚   โ”œโ”€โ”€ SnakeGame.tsx      # Main game component
โ”‚   โ”œโ”€โ”€ GameCanvas.tsx     # Game rendering and logic
โ”‚   โ”œโ”€โ”€ ControlPanel.tsx   # Player controls and high scores
โ”‚   โ””โ”€โ”€ GameOverModal.tsx  # Game over screen
โ”œโ”€โ”€ hooks/
โ”‚   โ”œโ”€โ”€ useHighScores.ts   # High score management
โ”‚   โ””โ”€โ”€ useAudio.ts        # Audio effects management
โ”œโ”€โ”€ App.tsx                # App wrapper
โ”œโ”€โ”€ index.css             # Global styles & scrollbars
โ””โ”€โ”€ main.tsx              # Entry point

๐ŸŽฏ Game Features

Score System

  • +10 points per food item collected
  • Persistent high score tracking
  • Unique player identification system
  • Date tracking for each score

High Score Storage System

The game features a sophisticated high score management system:

๐Ÿ† Storage Mechanism

  • Browser localStorage: Scores persist across browser sessions
  • JSON Serialization: Efficient data storage and retrieval
  • Error Handling: Graceful fallback if localStorage is unavailable

๐Ÿ”ข Unique ID System

  • Timestamp + Random: Each score gets a unique ID (Date.now() + Math.random())
  • Prevents Conflicts: Multiple players can have same name without data loss
  • Duplicate Prevention: Same player can have multiple scores tracked separately

๐Ÿ“Š Score Management

  • Top 10 Leaderboard: Only the highest 10 scores are kept
  • Automatic Sorting: Scores sorted by highest to lowest
  • Date Tracking: Each score includes the date it was achieved (YYYY-MM-DD format)
  • Player Names: Supports any player name, defaults to "Anonymous" if empty

๐ŸŽฏ Smart Features

  • New Record Detection: Identifies when a score beats the current #1
  • High Score Qualification: Checks if score qualifies for top 10
  • Player Best Score: Tracks individual player's highest achievement
  • Clear Function: Option to reset all high scores (for development)

Visual Design

  • Snake: Realistic animated serpent with wave motion, curved body, gradient colors, and directional eyes
  • Food: Red apples with highlights and green stems
  • Walls: Textured rock borders with 3D shadows and realistic stone patterns
  • Background: Dark slate with gradient borders
  • UI: Semi-transparent panels with cyan accents

Responsive Design

  • Canvas Size: 1000x600px (automatically scales)
  • Split Layout: 300px control panel + flexible game area
  • Modern Scrollbars: Custom cyan-themed scrollbars
  • Mobile Friendly: Touch-friendly button controls

๐Ÿ› Development

Available Scripts

  • npm run dev - Start development server
  • npm run build - Build for production
  • npm run preview - Preview production build
  • npm run lint - Run ESLint

Contributing

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

๐Ÿ“œ License

This project is open source and available under the MIT License.

๐Ÿ†• Recent Updates

Version 2.0 - Enhanced Experience

๐ŸŽจ Visual Enhancements

  • Realistic Snake Animation: Replaced blocky pixels with flowing serpent featuring wave motion
  • Curved Body Rendering: Smooth quadratic Bรฉzier curves for natural snake movement
  • Directional Eyes: Snake eyes that follow the direction of movement
  • Rock Wall Borders: Textured stone walls with 3D shadows and realistic patterns
  • Apple Food Design: Red apples with highlights and green stems instead of orange squares

๐Ÿ”Š Audio System

  • Bite Sound Effects: Audio feedback when eating food
  • Collision Sound Effects: Impact sounds when hitting walls or self
  • Volume-Optimized Audio: Balanced sound levels for immersive experience

โšก Performance & Features

  • 60fps Animation: Smooth wave motion using requestAnimationFrame
  • Pause Functionality: Press Esc to pause/resume gameplay
  • Path Aliases: Clean @/ imports for better code organization
  • Optimized Rendering: Consistent patterns prevent frame drops

๐ŸŽ‰ Enjoy the Game

Have fun playing this nostalgic Snake game! Try to beat your high scores and challenge your friends! ๐Ÿ†๐Ÿ

๐Ÿ”Š Audio Files

The game includes immersive audio effects that enhance the gameplay experience. Place these audio files in the src/assets/sound/ directory:

Required Audio Files

  • bite.mp3 - Sound played when the snake eats food (50% volume)
  • collision.wav - Sound played when the snake collides with walls or itself (70% volume)

Audio Sources

You can find suitable sound effects from free sources like:

Audio Features

  • Graceful Fallback: Game continues working even if audio files are missing
  • Volume Optimization: Bite sounds at 50%, collision sounds at 70% for balanced audio
  • Performance Optimized: Audio elements are reused and preloaded for smooth playback

About

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors