A real-time multiplayer Connect-4 style game built with Next.js, Socket.io, and TypeScript. Play with 3 players using simple 3-digit room codes.
- 🎮 3-Player Gameplay: Connect-4 mechanics adapted for 3 players
- 🔐 Room System: Create or join games using 3-digit room codes (000-999)
- ⚡ Real-time: Powered by Socket.io for instant updates
- 🎨 Modern UI: Beautiful gradients, smooth animations, and responsive design
- 🚀 Vercel Ready: Optimized for Vercel deployment with API routes
- Node.js 18+ installed
- npm or yarn package manager
- Install dependencies:
npm install- Run the development server:
npm run dev- Open http://localhost:3000 in your browser
npm run build
npm start- Create a Room: Enter your name and click "Create Room" to get a 3-digit room code
- Share the Code: Share the room code with 2 friends
- Join the Game: Friends enter the room code to join
- Play: Take turns dropping pieces - first to get 4 in a row wins!
- Players: Exactly 3 players required to start
- Board: 7 columns × 6 rows
- Objective: First player to get 4 pieces in a row (horizontal, vertical, or diagonal) wins
- Turns: Players take turns in order (Player 1 → Player 2 → Player 3)
- Colors:
- Player 1: Red 🔴
- Player 2: Yellow 🟡
- Player 3: Green 🟢
- Push your code to GitHub:
git init
git add .
git commit -m "Initial commit: 4-in-a-row game"
git remote add origin <your-repo-url>
git push -u origin main- Go to vercel.com and sign in
- Click "New Project" and import your GitHub repository
- Vercel will auto-detect Next.js settings
- Click "Deploy" - your app will be live in seconds!
# Install Vercel CLI globally
npm install -g vercel
# Deploy from project directory
vercel
# Follow the promptsThis app uses Socket.io with API routes for Vercel compatibility. The Socket.io server runs on /api/socket as a Next.js API route, which works perfectly with Vercel's serverless functions.
No environment variables or special configuration needed!
- Frontend: Next.js 14, React 18, TypeScript
- Backend: Next.js API Routes with Socket.io
- Styling: CSS with modern gradients and animations
- Real-time: Socket.io (API route compatible)
- Deployment: Vercel-optimized
4inrow/
├── src/
│ ├── app/
│ │ ├── page.tsx # Main game component
│ │ ├── layout.tsx # Root layout
│ │ └── globals.css # Global styles
│ ├── pages/
│ │ └── api/
│ │ └── socket.ts # Socket.io API route
│ └── types/
│ ├── game.ts # Game type definitions
│ └── socket.ts # Socket type definitions
├── package.json
├── tsconfig.json
├── next.config.js
└── vercel.json # Vercel configuration
Unlike traditional Socket.io setups that require a persistent server, this implementation uses:
- API Route:
/api/socket.tsinitializes Socket.io server - Client Connection: Connects to
/api/socketpath - Stateful Server: Socket.io maintains connections even on serverless
This approach is fully compatible with Vercel's infrastructure!
If you see 404 errors for /socket.io:
- Make sure you've pushed the latest code
- Verify
/src/pages/api/socket.tsexists - Redeploy on Vercel
# Clear Next.js cache
rm -rf .next
# Reinstall dependencies
rm -rf node_modules
npm install
# Restart dev server
npm run dev- Add chat functionality
- Implement player statistics
- Add sound effects
- Support for different board sizes
- Spectator mode
- Game replay system
MIT
Built with ❤️ using Next.js and Socket.io