This is a networked implementation of the classic Bomberman game built in C. The project features a client-server architecture where multiple players can connect and compete in real-time matches. Players navigate a grid-based arena, place bombs to eliminate opponents, and communicate via an in-game chat system.
- Multiplayer Support: Two game modes available
- Free-for-all (4 players)
- Team-based 2v2 (4 players in 2 teams)
- Real-time Gameplay: UDP multicast for efficient game state synchronization
- Interactive Terminal UI: Built with ncurses for a responsive gaming experience
- In-game Chat: Players can communicate during matches
- Bomb Mechanics: Strategic bomb placement with explosion patterns
- Player Spawning: Players spawn at grid corners for balanced gameplay
Communication Protocols:
- TCP: Used for reliable client-server communication (game setup, chat messages, player status)
- UDP Multicast: Used for real-time game state updates (grid changes, player movements)
- Multi-threading: Server handles multiple clients concurrently using pthreads
Network Configuration:
- TCP Port: 4000
- UDP Port: 5000
- Multicast addresses:
- Free-for-all:
ff12::1:2:3on port 10000 - 2v2 mode:
ff12::1:2:4on port 10001
- Free-for-all:
Project Structure:
.
├── client/ # Client-side code
│ ├── main_client.c
│ ├── connexion_client.c
│ ├── ncurses.c # Terminal UI rendering
│ ├── move.c # Player movement handling
│ ├── ready.c # Player ready state management
│ └── ...
├── serveur/ # Server-side code
│ ├── main_server.c
│ ├── game.c # Game loop and event handling
│ ├── launch_game.c # Grid initialization and multicast
│ ├── manage_action.c # Player action processing
│ ├── bomb.c # Bomb explosion logic
│ └── ...
└── Makefile # Build configuration
Game parameters can be modified in serveur/globals_serv.h:
NB_JOUEURS_4J: Number of players for free-for-all (default: 2 for testing)NB_JOUEURS_2V2: Number of players for 2v2 mode (default: 4)HEIGHT: Grid height (default: 20)WIDTH: Grid width (default: 20)MULTICAST: Network interface name (default: "eth0")
The project uses a root-level Makefile that orchestrates compilation of both client and server components.
- GCC compiler
- ncurses library
- pthread library
- IPv6 network support
Compile everything:
makeThis creates two executables:
client/bomberman_clientserveur/bomberman_serv
Clean build artifacts:
make cleanIn one terminal, launch the server:
make server_runOr directly:
cd serveur
./bomberman_servThe server will:
- Bind to TCP port 4000 and UDP port 5000
- Wait for client connections
- Display connection status messages
In separate terminals (one per player), launch clients:
make client_runOr directly:
cd client
./bomberman_clientEach client will be prompted to choose a game mode:
- Press
1for free-for-all mode (every man for himself) - Press
2for 2v2 team mode - Press
porPto quit
After selecting a mode, players must declare themselves ready by typing any message and pressing Enter. There's a 60-second timeout for readiness declaration.
Once all required players are ready, the game starts automatically.
- Arrow Up: Move up
- Arrow Down: Move down
- Arrow Left: Move left
- Arrow Right: Move right
- F1: Place a bomb
- Type text: Compose a chat message
- F4: Send chat message
- Ctrl+C: Quit the game/server
O: Empty spaceX: Indestructible wall (white)x: Destructible wall (yellow)B: Bomb (red)1-4: Players (colored by ID: cyan, green, magenta, blue)
- Objective: Be the last player standing (free-for-all) or eliminate the opposing team (2v2)
- Spawning: Players spawn at the four corners of the grid
- Bombs:
- Explode after 3 seconds
- Create cross-shaped explosion patterns
- Destroy destructible walls
- Eliminate players caught in the blast
- Walls:
- Indestructible walls block movement and explosions
- Destructible walls can be blown up to create paths
- Victory: Last surviving player/team wins
Game Initialization (TCP):
- Client connects to server
- Client selects game mode (CODEREQ 1 or 2)
- Server responds with game setup (CODEREQ 9 or 10) including multicast address
- Client subscribes to multicast group
- Client sends ready signal (CODEREQ 3 or 4)
During Gameplay:
- UDP Multicast: Server broadcasts grid updates at ~20Hz
- Initial grid (CODEREQ 11)
- Grid modifications (CODEREQ 12)
- UDP Unicast: Clients send actions to server (CODEREQ 5)
- TCP: Chat messages (CODEREQ 7 client → CODEREQ 13 server broadcast)
Game End:
- Player elimination (CODEREQ 20)
- Game victory announcement (CODEREQ 15 for free-for-all, CODEREQ 16 for 2v2)
Server won't start:
- Check if ports 4000/5000/10000/10001 are available
- Ensure you have permissions to bind to these ports
- Verify IPv6 is enabled on your system
Client can't connect:
- Verify the server is running
- Check the
SERVER_ADDRinclient/globals_client.hmatches your server's IPv6 address - Ensure network interface name in
MULTICASTconstant matches your system
Game doesn't start:
- Verify all required players have joined and declared ready
- Check server console for error messages
- Ensure the number of players matches configuration in
globals_serv.h
Multicast issues:
- Verify the network interface name (
eth0by default) is correct for your system - Use
ip link showto list available interfaces - Update
MULTICASTconstant inserveur/globals_serv.hif needed
- The project uses IPv6 for all network communication
- Server is designed to handle one game instance at a time
- Memory management is handled explicitly (malloc/free)
- Threading is used for concurrent client handling and asynchronous bomb explosions
- Grid state is shared between threads with mutex protection
This is an educational project developed for learning network programming and game development concepts.