A real-time multiplayer memory card game built with React and WebSockets. Players compete to match pairs of cards in a shared deck, with live synchronization across connected clients.
- Memory Matching: Classic card matching game with numbers 1-10
- Multiplayer Support: 2 players can join the same room
- Real-time Synchronization: Moves are instantly synchronized between players
- Turn-based Play: Players alternate turns when no match is found
- Live Updates: Card flips and matches are broadcast to all players in real-time
- Room Management: Players can join rooms by ID
- Game State Sync: Deck shuffling and game start are synchronized
- Connection Handling: Automatic cleanup when players disconnect
- Card Flipping Animation: Smooth reveal/hide animations
- Match Detection: Automatic pair matching with visual feedback
- Turn Management: Automatic player switching on misses
- Game Pause: Pauses when waiting for second player to join
- React 19: Modern React with hooks for state management
- Vite: Fast build tool with Hot Module Replacement (HMR)
- ESLint: Code linting and formatting
- CSS Modules: Component-scoped styling
- Node.js: JavaScript runtime for the server
- WebSocket (ws library): Real-time bidirectional communication
- Express-like WebSocket Server: Custom WebSocket server implementation
- Vite Dev Server: Fast development with HMR
- ESLint: Code quality and consistency
- npm: Package management
- Railway : Deployment of front-end and back-end
Game/
├── public/ # Static assets
├── src/
│ ├── components/ # React components
│ │ ├── Card.jsx # Individual card component
│ │ └── Roomjoin.jsx # Room joining interface
│ ├── assets/ # Images and media
│ ├── App.jsx # Main application component
│ ├── main.jsx # Application entry point
│ └── index.css # Global styles
├── server.js # WebSocket server
├── package.json # Dependencies and scripts
├── vite.config.js # Vite configuration
└── eslint.config.js # ESLint configuration
- Node.js (v16 or higher)
- npm
- Clone the repository:
git clone <repository-url>
cd Game- Install dependencies:
npm install- Start the WebSocket server:
node server.js- In a new terminal, start the development server:
npm run dev- Open your browser and navigate to
http://localhost:5173
npm run build
npm run preview- Join a Room: Enter a room ID to join or create a room
- Wait for Players: Game starts automatically when 2 players join
- Take Turns: Click cards to flip them and find matching pairs
- Score Points: Each match earns a point for the current player
- Win the Game: Player with the most matches wins!
The game uses a simple WebSocket protocol for communication:
JOIN: Join a room with specified roomIdMOVE: Send a card flip action with cardIndex and cardValue
JOIN_SUCCESS: Room joined successfully with deck and playerIdSTART_GAME: Game can begin (room is full)REMOTE_MOVE: Opponent's move with card detailsPAUSE_GAME: Game paused (waiting for players)ERROR: Error messages (e.g., room full)
npm run dev- Start development servernpm run build- Build for productionnpm run lint- Run ESLintnpm run preview- Preview production build
- ESLint configuration includes React hooks and refresh plugins
- TypeScript types available for React components
- Modern JavaScript (ES modules)
- Fork the repository
- Create a feature branch
- Make your changes
- Run linting:
npm run lint - Test multiplayer functionality
- Submit a pull request
This project is licensed under the MIT License.