Skip to content

Client/Server multiplayer implementation of the dots and boxes game ๐Ÿš€

Notifications You must be signed in to change notification settings

aaayyuusshh/dots-and-boxes

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

51 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

Dots & Boxes Multiplayer Game

Overview

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.

Screenshots

Screen Shot 2024-01-16 at 10 50 49 PM

Waiting for players: Screenshot 2024-05-30 at 6 06 39โ€ฏAM

Game screen of one client: Screenshot 2024-05-30 at 6 08 52โ€ฏAM

Gameplay with 3 clients: Screenshot 2024-05-30 at 6 14 06โ€ฏAM

Technologies Used

  • Frontend: HTML, CSS, JavaScript
  • Backend: Node.js with Socket.io

Game Logic and Architecture

1. Frontend (main.js)

  • Game Initialization:

    • The game starts by initializing the game board and necessary variables.
    • Cells are represented using the cell class defined in cell.js.
  • Game Loop:

    • The runGameLoop function runs continuously, updating the game state and rendering changes on the canvas.
  • 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.

2. Backend (server.js)

  • 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.

How to Play

  1. Create a New Game:

    • Click the "Create Game" button on the landing page.
    • Share the generated game code with others to join.
  2. Join an Existing Game:

    • Enter the provided game code on the landing page and click "Join."
  3. 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.

Miscellaneous Planning

dots-and-boxes-1

dots-and-boxes-2

dots-and-boxes-3

dots-and-boxes-4

dots-and-boxes-5

dots-and-boxes-6

dots-and-boxes-7

About

Client/Server multiplayer implementation of the dots and boxes game ๐Ÿš€

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published