Skip to content

ayggdrasil/multiplayer-snake-game

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

2 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿ Multiplayer Snake Game

A modern HTML5 multiplayer Snake game with AI opponents, built with vanilla JavaScript and ES6 modules.

๐ŸŽฎ Features

  • Multiplayer: 1 player vs 3 AI opponents
  • Modern Graphics: HTML5 Canvas with smooth animations
  • AI System: Intelligent AI with pathfinding algorithms
  • Responsive Design: Centered game view with window alignment
  • Real-time Gameplay: 60 FPS rendering with optimized performance
  • Visual Effects: Glowing snakes, animated apples, and smooth animations

๐Ÿš€ Play Online

Play the Game

๐ŸŽฏ How to Play

  • Use Arrow Keys or WASD to control your snake (green)
  • Eat red apples to grow and increase your score
  • Avoid walls, your own tail, and other snakes
  • Survive longer than the AI opponents to win!
  • Game ends when only one snake remains or time runs out

๐Ÿ—๏ธ Architecture

Game Structure

โ”œโ”€โ”€ index.html           # Main game page
โ”œโ”€โ”€ css/
โ”‚   โ””โ”€โ”€ styles.css       # Game styling
โ””โ”€โ”€ js/
    โ”œโ”€โ”€ main.js          # Application entry point
    โ”œโ”€โ”€ engine/          # Core game engine
    โ”‚   โ”œโ”€โ”€ GameEngine.js    # Main game coordinator
    โ”‚   โ”œโ”€โ”€ GameState.js     # Game state management
    โ”‚   โ””โ”€โ”€ GameLoop.js      # Frame-based game loop
    โ”œโ”€โ”€ entities/        # Game objects
    โ”‚   โ”œโ”€โ”€ Snake.js         # Base snake class
    โ”‚   โ”œโ”€โ”€ PlayerSnake.js   # Human player
    โ”‚   โ””โ”€โ”€ AISnake.js       # AI opponent
    โ””โ”€โ”€ systems/         # Game systems
        โ”œโ”€โ”€ Renderer.js      # Canvas rendering
        โ”œโ”€โ”€ InputSystem.js   # Input handling
        โ”œโ”€โ”€ AISystem.js      # AI decision making
        โ”œโ”€โ”€ CollisionDetector.js # Physics
        โ””โ”€โ”€ AppleManager.js  # Food spawning

Technical Features

  • ES6 Modules: Modern JavaScript architecture
  • Canvas 2D API: High-performance rendering
  • Object-Oriented Design: Clean, maintainable code structure
  • Pathfinding AI: Smart AI opponents with strategic behavior
  • Responsive Layout: Automatic window centering and scaling

๐Ÿ› ๏ธ Local Development

  1. Clone the repository:

    git clone https://github.com/ayggdrasil/multiplayer-snake-game.git
    cd multiplayer-snake-game
  2. Start a local server:

    # Using Python
    python3 -m http.server 8080
    
    # Using Node.js
    npx serve .
    
    # Using PHP
    php -S localhost:8080
  3. Open your browser: Navigate to http://localhost:8080

๐ŸŽจ Game Specifications

  • Map Size: 32ร—32 grid (1,024 cells)
  • View Size: 55% of canvas for optimal gameplay
  • Game Duration: 5 minutes maximum
  • Frame Rate: 60 FPS rendering, 10 FPS game logic
  • Players: 1 human + 3 AI opponents

๐Ÿ† Game Rules

  1. Victory Conditions:

    • Last snake alive wins
    • Highest score when time expires
  2. Death Conditions:

    • Hit wall boundaries
    • Hit your own tail
    • Head-to-head collision (smaller snake dies)
    • Head-to-body collision
  3. Scoring:

    • +1 point per apple eaten
    • Longer survival = better ranking

๐Ÿค– AI Features

  • Pathfinding: A* algorithm for optimal apple collection
  • Collision Avoidance: Smart obstacle detection
  • Strategic Positioning: Corner-based starting positions
  • Adaptive Difficulty: AI scales with game progression

๐Ÿ“ฑ Browser Support

  • Chrome/Chromium 60+
  • Firefox 55+
  • Safari 12+
  • Edge 79+

๐Ÿ”ง Configuration

Game settings can be modified in js/engine/GameState.js:

  • Map dimensions
  • Game speed
  • Timer duration
  • Visual effects

๐Ÿ“„ License

MIT License - feel free to fork and modify!

๐Ÿค Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Test thoroughly
  5. Submit a pull request

๐ŸŽฏ Future Enhancements

  • Online multiplayer support
  • Power-ups and special abilities
  • Customizable snake skins
  • Leaderboard system
  • Mobile touch controls
  • Sound effects and music

Built with โค๏ธ using vanilla JavaScript and HTML5 Canvas

About

๐Ÿ Modern HTML5 multiplayer Snake game with AI opponents. Built with vanilla JavaScript, ES6 modules, and HTML5 Canvas. Features intelligent AI, smooth animations, and responsive design.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors