Skip to content

Multiplayer LAN Snake Game: a real-time, competitive snake game you can play with friends on the same Wi-Fi network

Notifications You must be signed in to change notification settings

PrakharDoneria/Multiplayer-LAN-Snake-Game

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🐍 Multiplayer Snake Game (N Players)

This is a real-time multiplayer implementation of the classic Snake game built using Python (Flask/SocketIO) for the backend and JavaScript/HTML/CSS for the frontend. It supports multiple players in a single room, competitive scoring, and optional map modes (restricted boundaries or open-world wrap-around).

✨ Features

  • Real-time Multiplayer: Uses SocketIO for low-latency communication and smooth gameplay.
  • Dynamic Rooms: Players can create or join unique game rooms.
  • Competitive Play: Snakes collide with walls, their own bodies, or other snakes, leading to a reset/respawn.
  • Scoreboard: Tracks and displays scores of all players in the room.
  • Map Modes: Supports both Area Restricted (walls kill) and Open World (wrap-around) modes.
  • Sound Effects: Includes sounds for eating, respawning, button clicks, and game over.
  • Network Accessible: Configured to be accessible by other devices on the same local network.

⚙️ Setup and Installation

Follow these steps to get the game running on your machine.

1. Requirements

You must have Python 3 installed. The necessary Python libraries are listed in requirements.txt:

  • Flask
  • Flask-SocketIO
  • python-socketio
  • eventlet

2. Install Dependencies

Navigate to the project root directory in your terminal and install the required packages:

pip install -r requirements.txt

3. Run the Server

Start the application by executing the Python server file:

python "Multiplayer Snake Game/server.py"

The console will output a message indicating the server is running and listening on Port 5000.


🌐 Network Play (How to Join from Other Devices)

The server is configured to run on 0.0.0.0, which allows all devices on the same local network (like your phone or a friend's laptop) to connect.

To join, you need the local IP address of the computer running the server.

🔎 How to Get Your Local IP Address

Operating System Command to Use in Terminal/Command Prompt Look For Example Address
Windows ipconfig IPv4 Address 192.168.1.10
macOS / Linux ifconfig or ip a inet address under your active network interface (e.g., en0 or wlan0) 192.168.1.10

🔗 Joining the Game

Once you have the local IP address (e.g., 192.168.1.10), any device connected to the same Wi-Fi/router can access the game by opening a web browser and navigating to the following address:

http://[Your.Local.IP.Address]:5000

(Example: http://192.168.1.10:5000)


🕹️ How to Play

  1. Create a Room: On one device, enter a name, choose a map mode, and click "Create Room".
  2. Share Link: The creator gets an invite link with the Room ID embedded. Share this link (or just the Room ID) with others.
  3. Join the Game: Other players enter their name, the Room ID, and click "Join".
  4. Start: The game will automatically start once the minimum number of players (2) has joined.
  5. Controls: Use the W, A, S, D keys or Arrow Keys to change your snake's direction.

📁 Project Structure

Multiplayer Snake Game/
├── server.py             # Main Python Flask/SocketIO server logic.
├── requirements.txt      # Python dependencies.
├── credits.md            # Sound effect attributions.
├── static/
│   ├── css/
│   │   └── style.css     # Game styling.
│   ├── js/
│   │   ├── main.js       # Frontend game rendering and logic.
│   │   └── networking.js # SocketIO connection and room handling, includes sound logic.
│   └── sounds/
│       ├── buttonClick.mp3 # UI sound.
│       ├── eat.mp3         # Apple eaten sound.
│       ├── gameOver.mp3    # Game over/leave room sound.
│       └── respawn.mp3     # Player snake reset sound.
└── templates/
    └── index.html        # Main and only frontend page.

About

Multiplayer LAN Snake Game: a real-time, competitive snake game you can play with friends on the same Wi-Fi network

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published