A fully functional implementation of the classic BANG! card game with real-time multiplayer functionality using WebSocket technology.
- Full BANG! game rules and mechanics
- 4-7 player support
- Role-based gameplay (Sheriff, Deputy, Outlaw, Renegade)
- 16 unique characters with special abilities
- Complete card deck with all game cards
- Turn-based gameplay with multiple phases
- Victory condition detection
- Player elimination system
- WebSocket-based real-time communication using Socket.io
- Room creation and management
- Player ready system
- Live game state synchronization
- Automatic disconnection handling
- Real-time game log updates
- Responsive design for desktop and mobile
- Intuitive game board layout
- Clear player status display
- Interactive card playing system
- Target selection for offensive cards
- Turn indicator and phase display
- Game log for action tracking
- React 18 - UI framework
- TypeScript - Type safety
- TailwindCSS - Styling
- Vite - Build tool
- Socket.io-client - WebSocket client
- React Router - Navigation
- Lucide React - Icons
- Node.js - Runtime
- Express - Web server
- Socket.io - WebSocket server
- UUID - Unique ID generation
bang-game/
├── bang-game-frontend/ # React frontend
│ ├── src/
│ │ ├── pages/
│ │ │ ├── HomePage.tsx # Room creation/joining
│ │ │ └── GameRoom.tsx # Main game interface
│ │ ├── services/
│ │ │ └── socketService.ts # WebSocket service
│ │ └── App.tsx # Main app with routing
│ ├── public/
│ └── package.json
│
└── bang-game-backend/ # Node.js backend
├── src/
│ ├── controllers/
│ │ └── socketController.js # Socket event handlers
│ ├── models/
│ │ ├── cards.js # Card definitions
│ │ ├── characters.js # Character abilities
│ │ └── roles.js # Role system
│ ├── services/
│ │ └── gameService.js # Game logic
│ └── server.js # Express + Socket.io server
└── package.json
- Node.js 18+ or higher
- pnpm (recommended) or npm
cd bang-game-backend
pnpm install
pnpm startThe backend server will run on http://localhost:3001
For development with auto-reload:
pnpm devcd bang-game-frontend
pnpm install
pnpm devThe frontend will run on http://localhost:5173
The backend can be configured via environment variables:
PORT=3001 # Server port (default: 3001)Create a .env file in the frontend directory:
VITE_SOCKET_URL=http://localhost:3001 # Backend URLFor production deployment, update this to your backend server URL.
- Sheriff: Eliminate all Outlaws and the Renegade (revealed at start)
- Deputy: Protect the Sheriff (hidden identity)
- Outlaw: Kill the Sheriff (hidden identity)
- Renegade: Be the last player alive (hidden identity)
- Draw Phase: Draw 2 cards from the deck
- Play Phase: Play cards from your hand
- Discard Phase: End turn (automatic when you choose to end)
- BANG!: Shoot another player (requires Missed! to defend)
- Missed!: Defend against a BANG!
- Beer: Recover 1 life point
- Panic!: Steal a card from a player at distance 1
- Cat Balou: Discard a card from any player
- Weapons: Extend shooting range
- Equipment: Special items (Barrel, Mustang, Scope, etc.)
16 unique characters with special abilities including:
- Bart Cassidy, Black Jack, Calamity Janet
- El Gringo, Jesse Jones, Jourdonnais
- Kit Carlson, Lucky Duke, Paul Regret
- Pedro Ramirez, Rose Doolan, Sid Ketchum
- Slab the Killer, Suzy Lafayette, Vulture Sam
- Willy the Kid
createRoom- Create a new game roomjoinRoom- Join an existing roomleaveRoom- Leave current roomtoggleReady- Toggle ready statusstartGame- Start the game (host only)drawCards- Draw cards during draw phaseplayCard- Play a card from handrespondToBang- Respond to a BANG! attackendTurn- End current turngetRoomInfo- Get room informationgetRoomsList- Get list of all rooms
roomUpdated- Room state changedgameStarted- Game has startedgameStateUpdated- Game state changedresponseRequired- Player must respond to actionplayerJoined- Player joined roomplayerLeft- Player left room
# Backend
cd bang-game-backend
pnpm test
# Frontend
cd bang-game-frontend
pnpm test# Frontend
cd bang-game-frontend
pnpm build
# Backend (no build needed, runs directly)The backend can be deployed to any Node.js hosting service (Heroku, Railway, Render, etc.)
- Set environment variables
- Deploy the
bang-game-backenddirectory - Ensure the PORT is correctly configured
The frontend can be deployed to static hosting (Vercel, Netlify, etc.)
- Update
VITE_SOCKET_URLto production backend URL - Build the application:
pnpm build - Deploy the
distdirectory
- Ensure backend is running on port 3001
- Check firewall settings
- Verify CORS configuration
- Check WebSocket support in browser
- Minimum 4 players required to start
- All players must be ready before starting
- Only host can start the game
- Cards must be played during play phase
- Additional card types (Gatling, Duel, Indians, etc.)
- Full character ability implementation
- Equipment and weapon mechanics
- Distance calculation system
- Advanced game features (Dynamite, Jail, etc.)
- Player statistics and leaderboards
- Spectator mode
- Chat system
- Game replays
- Mobile app version
MIT License - Feel free to use and modify for your projects
Developed by MiniMax Agent Based on the original BANG! card game by Emiliano Sciarra
Contributions are welcome! Please feel free to submit issues and pull requests.
For issues and questions, please open an issue on GitHub.