Welcome to Count 4, a two-player game where the objective is to align four of your pieces either vertically, horizontally, or diagonally. This game is a digital version of the classic Connect Four game.
In Count 4, two players take turns to drop colored pieces into a 7x6 grid. The first player to get four of their pieces in a row—either vertically, horizontally, or diagonally—wins the game. The players' pieces are color-coded as follows:
- Player 1:
rgb(255,206,103)
- Player 2:
rgb(254,102,135)
- A: Move the pointer left.
- D: Move the pointer right.
- Enter: Drop a piece into the current column.
To set up and run the game, follow these steps:
-
Clone the repository:
git clone <repository-url>
-
Navigate to the project directory:
cd count-4-game
-
Open
index.html
in your web browser to start the game.
- Open the game in your browser.
- Use the 'A' and 'D' keys to move the pointer left and right.
- Press 'Enter' to drop your piece into the selected column.
- The game alternates between Player 1 and Player 2 automatically.
- A timer counts down from 30 seconds for each move. If the timer runs out, the turn automatically switches to the other player.
- The game ends when a player connects four pieces in a row or the grid is full.
The game logic is implemented using JavaScript and includes functions to handle the following:
- Moving the pointer (
evnt
function) - Dropping pieces into the grid
- Checking for a win condition (
check
function)- Vertical check
- Horizontal check (left and right)
- Diagonal checks (both directions)
- Displaying the current player and timer
- evnt(a): Handles keypress events to move the pointer and drop pieces.
- check(pos, py): Checks if the player has won after dropping a piece.
- vertical(pos, py): Checks vertical alignment.
- left(pos, py) and right(pos, py): Check horizontal alignment.
- diag_up_left(pos, py), diag_up_right(pos, py), diag_down_left(pos, py), and diag_down_right(pos, py): Check diagonal alignment.
- succ(py, p): Declares the winner and stops the game.
- Add an AI opponent for single-player mode.
- Improve the user interface and animations.
- Add sound effects for better engagement.
- Implement a restart game option.
Feel free to contribute to the project by submitting issues or pull requests. Enjoy the game!