Skip to content
README.md 3.12 KiB
Newer Older
jmagm4@umsystem.edu's avatar
jmagm4@umsystem.edu committed
# Connect Four Game
jmagm4@umsystem.edu's avatar
jmagm4@umsystem.edu committed

jmagm4@umsystem.edu's avatar
jmagm4@umsystem.edu committed
This is a simple implementation of the Connect Four game in Java. The game is played on a 6x7 grid where two players take turns dropping colored disks into the columns. The first player to connect four of their colored disks in a row, column, or diagonal wins the game. If the board is full and no player has won, the game ends in a draw.
jmagm4@umsystem.edu's avatar
jmagm4@umsystem.edu committed

jmagm4@umsystem.edu's avatar
jmagm4@umsystem.edu committed
## How to Play
jmagm4@umsystem.edu's avatar
jmagm4@umsystem.edu committed

jmagm4@umsystem.edu's avatar
jmagm4@umsystem.edu committed
1. The program will display the board on the console, with the column numbers on top and the disk colors as R (red) and Y (yellow). The board has 6 rows and      	7 columns, and initially all the cells are empty.
jmagm4@umsystem.edu's avatar
jmagm4@umsystem.edu committed

jmagm4@umsystem.edu's avatar
jmagm4@umsystem.edu committed
2. The program will prompt the first player (red) to choose a column (0-6) to drop their disk. The player can enter an integer from 0 to 6, and the program will drop the disk in the lowest available row of that column. If the column is full or the input is invalid, the program will display an error message and ask the player to try again.
jmagm4@umsystem.edu's avatar
jmagm4@umsystem.edu committed

jmagm4@umsystem.edu's avatar
jmagm4@umsystem.edu committed
3. The program will then switch to the second player (yellow) and repeat the same process. The players will alternate turns until one of them wins the game or the board is full.
jmagm4@umsystem.edu's avatar
jmagm4@umsystem.edu committed

jmagm4@umsystem.edu's avatar
jmagm4@umsystem.edu committed
4. The program will check if the current player has formed a line of four disks of their own color after each move. If so, the program will display the board and a congratulatory message for the winner. If the board is full and no one has won, the program will display the board and a message indicating a draw.
jmagm4@umsystem.edu's avatar
jmagm4@umsystem.edu committed

jmagm4@umsystem.edu's avatar
jmagm4@umsystem.edu committed
5. The program will then terminate.
jmagm4@umsystem.edu's avatar
jmagm4@umsystem.edu committed

jmagm4@umsystem.edu's avatar
jmagm4@umsystem.edu committed
## Rules
jmagm4@umsystem.edu's avatar
jmagm4@umsystem.edu committed

jmagm4@umsystem.edu's avatar
jmagm4@umsystem.edu committed
- Each player has a color: RED and YELLOW.
- Players take turns dropping their colored disks into the columns.
- Disks are dropped into the lowest available row in the chosen column.
- The first player to connect four disks of their color in a row, column, or diagonal wins.
- If the board is full and no player has won, the game ends in a draw.
jmagm4@umsystem.edu's avatar
jmagm4@umsystem.edu committed

jmagm4@umsystem.edu's avatar
jmagm4@umsystem.edu committed
## Code Structure
jmagm4@umsystem.edu's avatar
jmagm4@umsystem.edu committed

jmagm4@umsystem.edu's avatar
jmagm4@umsystem.edu committed
- ConnectFour.java: Contains the main game logic including board initialization, player input, disk dropping, win detection, and board display.
jmagm4@umsystem.edu's avatar
jmagm4@umsystem.edu committed

jmagm4@umsystem.edu's avatar
jmagm4@umsystem.edu committed
## Constants
jmagm4@umsystem.edu's avatar
jmagm4@umsystem.edu committed

jmagm4@umsystem.edu's avatar
jmagm4@umsystem.edu committed
- ROWS: Number of rows on the game board (6).
- COLUMNS: Number of columns on the game board (7).
- RED: Constant representing the RED player's disk.
- YELLOW: Constant representing the YELLOW player's disk.
- EMPTY: Constant representing an empty space on the board.
jmagm4@umsystem.edu's avatar
jmagm4@umsystem.edu committed

jmagm4@umsystem.edu's avatar
jmagm4@umsystem.edu committed
## Functions
jmagm4@umsystem.edu's avatar
jmagm4@umsystem.edu committed

jmagm4@umsystem.edu's avatar
jmagm4@umsystem.edu committed
- main: Main method where the game is initialized and played.
- displayBoard: Method to display the current state of the game board.
- dropDisk: Method to drop a disk into a specified column.
- isWinningMove: Method to check if a disk drop results in a winning move.
- isBoardFull: Method to check if the game board is full.
jmagm4@umsystem.edu's avatar
jmagm4@umsystem.edu committed

jmagm4@umsystem.edu's avatar
jmagm4@umsystem.edu committed
## Dependencies
jmagm4@umsystem.edu's avatar
jmagm4@umsystem.edu committed

jmagm4@umsystem.edu's avatar
jmagm4@umsystem.edu committed
- This program uses the java.util.Scanner class for user input.
jmagm4@umsystem.edu's avatar
jmagm4@umsystem.edu committed

jmagm4@umsystem.edu's avatar
jmagm4@umsystem.edu committed
|0 1 2 3 4 5 6 |
| | | | | | | |
| | | | | | | |
| | | | | | | |
| | | | | | | |
| | | | | | | |
| | | | | | | |
Please choose a column (0-6) to drop the RED disk: 3
|0 1 2 3 4 5 6 |
| | | | | | | |
| | | | | | | |
| | | | | | | |
| | | | | | | |
| | | | | | | |
| | | |R| | | |
Please choose a column (0-6) to drop the YELLOW disk: 4
|0 1 2 3 4 5 6 |
| | | | | | | |
| | | | | | | |
| | | |R| | | |
| | | |R| | | |
| | | |R| |Y| |
| | | |R|Y|Y| |
...
Congratulations! RED has won the game!
jmagm4@umsystem.edu's avatar
jmagm4@umsystem.edu committed

## License