Skip to content

Latest commit

 

History

History
75 lines (58 loc) · 2.92 KB

File metadata and controls

75 lines (58 loc) · 2.92 KB

Chess Game

This project is a real-time, multiplayer chess game built using Node.js, Express, Socket.IO, and Chess.js. It allows two players to connect and play a game of chess against each other in a web browser.

Code Explanation

The application is structured into several key files:

  • app.js: This is the main server-side file. It sets up the Express server, handles static file serving, configures Socket.IO for real-time communication, and manages the chess game logic using the Chess.js library.
  • public/css/style.css: This file contains the CSS for styling the chessboard, squares, and pieces. It ensures the board is visually appealing and responsive.
  • public/js/chessgame.js: This client-side JavaScript file handles the rendering of the chessboard, drag-and-drop functionality for pieces, and communication with the server via Socket.IO. It uses the Chess.js library to manage game state on the client.
  • views/index.ejs: This EJS template file defines the structure of the main game page, including the chessboard container and links to the necessary CSS and JavaScript files.

Folder and File Structure

chess/
├── app.js
├── package-lock.json
├── package.json
├── public/
│   ├── css/
│   │   └── style.css
│   └── js/
│       └── chessgame.js
└── views/
    └── index.ejs
  • app.js: Main server file.
  • package.json: Defines project metadata and dependencies.
  • package-lock.json: Records the exact versions of dependencies.
  • public/: Contains static assets.
    • public/css/: Contains CSS stylesheets.
      • style.css: Custom styles for the chess game.
    • public/js/: Contains client-side JavaScript files.
      • chessgame.js: Client-side game logic and rendering.
  • views/: Contains EJS template files.
    • index.ejs: The main HTML template for the game.

How to Run or Deploy the Project

To run this project locally, follow these steps:

  1. Clone the repository:

    git clone <repository_url>
    cd chess
  2. Install dependencies:

    npm install
  3. Start the server:

    node app.js
  4. Access the game: Open your web browser and navigate to http://localhost:3000.

Dependencies and Technologies Used

  • Node.js: Server-side JavaScript runtime.
  • Express: Web framework for Node.js.
  • Socket.IO: Library for real-time, bidirectional, event-based communication.
  • Chess.js: JavaScript library for chess move generation, validation, and game state tracking.
  • EJS: Embedded JavaScript templating.
  • Tailwind CSS (via CDN): Utility-first CSS framework for styling.

Examples

Once the server is running, open http://localhost:3000 in two different browser tabs or windows to simulate two players. Each player will be assigned a role (white or black), and you can start playing chess by dragging and dropping pieces.