- Trisha Nookala
- Soumya Devulapalli
- Language: Java
- IDE: IntelliJ IDEA
- Build Tool: Gradle
This project implements a console-based version of the classic Connect 4 game. The game is played on a 6×7 grid where two players take turns dropping pieces into columns. The goal is to connect four of the same colored pieces in a row (horizontally, vertically, or diagonally).
The system is designed using object-oriented principles and multiple design patterns to ensure modularity, flexibility, and maintainability.
Where:
connect4.factory.PieceFactoryconnect4.factory.PlayerFactoryWhy All piece and player creation goes through factory classes instead of being scattered across the codebase. This centralizes object creation so that adding a new piece color or player type only requires changing the factory.
Where:
- Win Strategy
connect4.strategy.WinStrategy(interface)connect4.strategy.StandardWinStrategy(implementation)connect4.strategy.MoveStrategy(interface)- Move Strategy
connect4.strategy.HumanStrategy(implementation)connect4.strategy.EasyStrategy(implementation)connect4.strategy.MediumStrategy(implementation)connect4.strategy.HardStrategy(implementation) Why We used the Strategy pattern in two places. For move selection, each player holds a MoveStrategy — HumanStrategy reads input, EasyStrategy picks randomly, MediumStrategy blocks and wins when possible, and HardStrategy looks ahead using minimax. For win checking, Connect4Game delegates to a WinStrategy. Swapping computer difficulty or win condition only requires writing one new class and we don't have to change anything else.
Where:
connect4.observer.GameObserver(interface)connect4.observer.ConsoleGameObserver(implementation) Why Connect4Game maintains a list of observers and notifies them when something happens : a move is made, someone wins, the game is a draw. This keeps game logic and display logic completely separate. Connect4Game never prints anything itself, it just announces events and observers decide what to do with them.
Where:
connect4.builder.Connect4GameBuilderWhy Setting up a game requires a board, two players, pieces, strategies, and a win strategy. The builder lets you configure all of this step by step through chained method calls and then call build() to get a fully assembled game. GameSetupDialog uses it to turn the user's UI selections into a ready-to-play Connect4Game.
Where:
connect4.command.GameCommand(interface)connect4.command.DropPieceCommand(implementation) Why Every move is wrapped in a DropPieceCommand that saves the game state before executing. If undo is called, it restores that saved state. SwingConnect4 keeps a stack of executed commands and clicking Undo pops the last one and reverts the board. This gives us undo support without putting any undo logic inside Connect4Game itself.
The project contains fully implemented classes with meaningful logic:
connect4.board.Board(interface)connect4.board.GridBoard(implementation)
connect4.controller.Connect4Game
connect4.player.Player(interface)connect4.player.HumanPlayerconnect4.piece.GamePiece(interface)connect4.piece.RedPiece,BluePiece
Responsibilities:
- Represent players and their assigned pieces
- Provide piece symbols and color identity
connect4.view.ConsoleBoardViewconnect4.view.ConsoleBoardViewconnect4.view.SwingConnect4connect4.view.GameSetupDialog
Responsibilities:
- Displaying the board in the terminal
BoardPlayerGamePieceWinStrategyGameObserver
Polymorphism is demonstrated through:
RedPieceandBluePieceimplementingGamePieceHumanPlayerimplementingPlayerStandardWinStrategyimplementingWinStrategyConsoleGameObserverimplementingGameObserver
This allows the program to treat different implementations uniformly.
Dependencies are passed into classes instead of being created inside them.
Example from Connect4Game:
new Connect4Game(board, players, strategy);- Run SwingConnect4.main() to launch the GUI. A setup dialog will appear to choose your game mode and difficulty.
- Run Main.main() for the console version.