Skip to content

Mohitsaini2028/ChessHub

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ChessHub

  1. clone the repository
  2. Run npm install
  3. Run npm run start
  4. open browser http://localhost:8080

File Structure

  • app->config - database configuration
  • app->controllers - routes and server-side events
  • app->models - schema
  • app->views - template
  • public - contain static files like css, images, and js
  • index.js - entry point of the application
  • Technology-

    Node.js Express MongoDB HTML CSS JS

    I have used Node.js in this project because it is perfect for real time communication and in the required chess game we have to update the data in real-time basis. I have used socket library for establishing real-time connection.

    Events

    socketServer.js (File)

  • submitName - This event will fire when a user enter his name for registration.
  • sendJoinRequest - This event will fire when a user send join game request from server side.
  • acceptGameRequest - This event will fire when a user accept the game request.
  • chessMove - This event will fire when a user move chess pieces. It will send a broadcast of movement of chess peices.
  • gameWon - This event will fire when a user won a game.
  • disconnect - This event will fire when a user left the room. It will remove the current user from the user's array.

    socketClient.js (File)

  • joinRequestRecieved - This event will fire when a user recieved join game request.
  • joinGameRequest - This event will fire when a user send join game request from client side.
  • gameRequestAccepted - This event will fire when opponent accept the join request.
  • opponentDisconnect - This event will fire when a opponent left the room. It will reset the chessboard.
  • chess.js (File)

  • oppntWon - It will fire when opponent won.
  • oppntChessMove - It will fire when opponent move the chess pieces.
  • Functions

    chess.js (File)

  • onDragStart - This function check keep track of the game stage. If the user won or lost it will display message.
  • onDragStart - This function check keep track of the user move. It will check if the move is possible or not and after the condition satisfaction the move is made.
  • updateStatus - This function update move color, check checkmate condition,and check draw conditon.
  • API Url

  • /move/ - It will create or append the move.
  • /move/:id/ - It will fetch the all the moves of the room, provided in the query parameter.
  • Database

    I have used MongoDB because it can handle variety of data and huge amount of data. It offers a MongoDB Node.js Driver which provides a JavaScript API and implements the network protocol required to read and write from a local or remote MongoDB database.

    Database configuration path -

    app->config->database.js

    Models

    Models contain the schema document. Match is the name of Schema which store the game information, id of user and moves.

    Entity Relationship Diagram

    er chess

    match
  • roomId - It is the primary key
  • moves - It is the array which store id of the moves.
  • moves
  • move_id - It is the primary key.
  • color - It store the color of the move peice.
  • from - From where the peice has moved.
  • to - to which position the peice will move.
  • peice - It represent the peice type.

  • Work Overview

    Landing Page

    chrome_EMWd7M29hM

    Game request

    Game request send receiver's end
    chrome_DMMoWD7bQo chrome_J0q8DIch3z

    Game Stage

    chrome_gtgCePJ0vT

    Get moves data

    chrome_TWsUkEgpVP

    About

    No description, website, or topics provided.

    Resources

    Stars

    Watchers

    Forks

    Releases

    No releases published

    Packages

    No packages published