dots-and-boxes is an online multiplayer implementation of the classic Dots and Boxes game. This project brings the traditional paper-and-pencil game to the digital world, enabling users to play with up to three players in real-time. The game leverages web sockets for seamless communication between players, ensuring an engaging and low-latency multiplayer experience.
![Screen Shot 2024-01-16 at 10 50 49 PM](https://private-user-images.githubusercontent.com/80851741/297273545-b82b1729-3e6c-4f81-996c-1f1b3b5a8e14.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjAzMjA2MTMsIm5iZiI6MTcyMDMyMDMxMywicGF0aCI6Ii84MDg1MTc0MS8yOTcyNzM1NDUtYjgyYjE3MjktM2U2Yy00ZjgxLTk5NmMtMWYxYjNiNWE4ZTE0LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA3MDclMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwNzA3VDAyNDUxM1omWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWM0ZTUxNWQwNjBlNzM2MzRlZmMxMzE4M2ExMjhkNDlhN2I3YWYxOWIxYzE4OWJiOWNkYWM0MzY5NmQ3MTQwNzEmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.UzR6WG-FxxifpTBffd0cvwyB8MTPIknK75J7DVQCzB0)
- Frontend: HTML, CSS, JavaScript
- Backend: Node.js with Socket.io
-
Game Initialization:
- The game starts by initializing the game board and necessary variables.
- Cells are represented using the
cell
class defined incell.js
.
-
Game Loop:
- The
runGameLoop
function runs continuously, updating the game state and rendering changes on the canvas.
- The
-
Event Listeners:
- Event listeners are added to the canvas for mouse movements and clicks to detect player actions.
- Socket.io is used to emit and receive events related to game moves and turns.
-
Highlighting and Moves:
- Cells are highlighted based on mouse movements, indicating potential moves.
- Players can click to make moves, and the game logic processes and updates the board accordingly.
-
Scoring and Game Over:
- Scores are tracked for each player based on the number of squares formed.
- The game ends when all possible squares are formed, and a modal displays the winner and scores.
-
Server Initialization:
- The server is set up using Node.js and Socket.io to handle real-time communication.
- The server manages game rooms, tracks player turns, and facilitates interactions between clients.
-
Room Creation and Joining:
- Players can create a new game, generating a unique room code.
- Existing games are joined by entering the room code.
-
Turn Switching:
- Turns are managed on the server, ensuring synchronized gameplay.
- Players take turns, and the server emits events to activate and deactivate event listeners accordingly.
-
Real-time Communication:
- Socket.io is employed for real-time communication between clients and the server.
- Events such as moves, highlights, and turn switches are broadcasted to all players in the same room.
-
Create a New Game:
- Click the "Create Game" button on the landing page.
- Share the generated game code with others to join.
-
Join an Existing Game:
- Enter the provided game code on the landing page and click "Join."
-
Gameplay:
- Players take turns making moves to form squares.
- Highlighting and moves made from one player is transmitted to other players through web sockets.
- Scores are updated based on the number of squares claimed.