This is a simple Connect Four game implemented using JavaScript, HTML, and CSS. Players take turns dropping pieces into a grid, and the first to connect four pieces in a row, column, or diagonal wins!
- Two-Player Mode: Red and Yellow players alternate turns.
- Interactive Grid: Click to drop pieces into the columns.
- Win Detection: Checks for horizontal, vertical, and diagonal victories.
- Local Storage Support: Saves game state between sessions.
- Simple UI: Built with JavaScript, no external libraries required.
- HTML – Structure of the game board
- CSS – Styling for the game UI
- JavaScript – Game logic and local storage management
- Open the
index.htmlfile in a browser. - Click on a column to drop a piece.
- The game alternates between Red (R) and Yellow (Y) players.
- The first player to connect four pieces wins.
- The winner is displayed on the screen.
- The game state is saved in Local Storage.
/connect-four │── index.html # Main HTML file │── styles.css # Styling file │── script.js # JavaScript logic │── assets/ # Images & icons │── README.md # Project documentation
-
Grid Initialization
- The board is a 6x7 grid initialized with empty spaces.
- Event listeners are added to each cell.
-
Placing a Piece
- The piece falls to the lowest available row in the selected column.
- The color of the piece changes based on the current player.
-
Win Conditions
- The game checks for a winning sequence in:
- Horizontal (left to right)
- Vertical (top to bottom)
- Diagonal (both directions)
- The game checks for a winning sequence in:
-
Game Over
- The game announces the winner and stops further moves.
-
Local Storage
- The game state is stored using
localStorage. - The saved game is loaded when the page is refreshed.
- The game state is stored using
- AI Mode for single-player gameplay.
- Leaderboard to track scores.
If you'd like to improve the game, feel free to fork the repository and submit a pull request.
Enjoy playing Connect Four! 🎮🔥