Skip to content

A console-based, object-oriented implementation of the classic Connect 4 game in Java. Features two-player gameplay, customizable symbols, and configurable win conditions.

Notifications You must be signed in to change notification settings

StevenSaleeb/Connect4-OOP-Java

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 

Repository files navigation

Connect 4 Game – Java OOP Implementation

A fully object-oriented implementation of the classic Connect 4 game in Java. This project demonstrates encapsulation, class interaction, and modular design using core OOP principles. Players can customize their names, symbols, and the number of pieces needed to win (2–7).

Features

Two-player gameplay with custom names and symbols.
Configurable win condition: choose how many pieces need to be connected (2–7).
Validates moves to prevent placing a piece in a full column.
Detects wins vertically, horizontally, and diagonally.
Detects draw conditions when the board is full.
Console-based, interactive game with a clean, user-friendly interface.

Technologies

Java
Object-Oriented Programming: classes include ClientGUI, Game, Player, and Board.

Classes Overview

ClientGUI – Entry point of the program. Handles user input and starts the game.
Game – Controls game flow, manages players, checks for wins or draws, alternates turns.
Player – Represents a player with a name, symbol, and piece count.
Board – Represents the game board (not fully shown above), responsible for storing and displaying the grid, updating pieces, and checking for full board.

HOW TO COMPILE SOURCE CODE:

To compile everything 'src' folder at once:
    javac -d bin src/*.java

To compile individually:
    javac -d bin src/Board.java
    javac -d bin src/Player.java
    javac -d bin src/Game.java
    javac -d bin src/Client.java

HOW TO RUN SOURCE CODE:

java -cp bin Client

HOW TO COMPILE TEST CODE:

To compile everything 'test' folder at once:
    javac -cp "lib/*bin" -d bin test/*.java


To compile individually:
    javac -cp "lib/*:bin" -d bin test/BoardTest.java
    javac -cp "lib/*:bin" -d bin test/PlayerTest.java
    javac -cp "lib/*:bin" -d bin test/GameTest.java
    javac -cp "lib/*:bin" -d bin test/ClientTest.java

HOW TO RUN TEST CODE:

java -jar lib/junit-platform-console-standalone-1.6.2.jar -cp bin -c BoardTest
java -jar lib/junit-platform-console-standalone-1.6.2.jar -cp bin -c ClientTest
java -jar lib/junit-platform-console-standalone-1.6.2.jar -cp bin -c GameTest
java -jar lib/junit-platform-console-standalone-1.6.2.jar -cp bin -c PlayerTest

HOW DOES THE CODE WORK?:

The program makes a customizable Connect Four game. The ClientGUI serves as the entry point, prompting users to enter the player names, symbols, and the number of pieces required to win (between 2 and 7). This information is used to initialize the Game, which in turn creates a Board of appropriate size.

The game then enters a loop where players take turns choosing columns to drop their pieces. The Board handles updating the grid and checking for full columns. After each move, the Game class checks whether the move results in a win (horizontal, vertical, or diagonal) or a draw (board is full). If the game ends, a win or draw message is displayed and the program terminates.


1. Player manages individual player data: name, symbol, piece count

2. Board maintains and displays the game grid, and validates moves

3. Game controls the main loop and win or draw logic

4. ClientGUI handle user interaction and start the game

NOTE: there is purposefully no test code for ClientGUI class since Client class is all based on user input

About

A console-based, object-oriented implementation of the classic Connect 4 game in Java. Features two-player gameplay, customizable symbols, and configurable win conditions.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages