This is a two player Connect 4 console game made with Java. The project was made for an assignment as part of the MSc Software Engineering at the School of Computing, UWTSD. Module: ACCA7000 - Programming and Software Testing
Junit is used to implement unit tests.
The project runs from Main.java, which will initiate a game of Connect4 with the option to replay when the game is complete.
When the program is first run, players are prompted to choose who will start. Players will then take turns making moves until the game is complete. The game ends when the winning player gets four of their counters in a vertical, horizontal, or diagonal row, or is a draw if the game grid is filled without a matching four in a row of counters.
In a normal turn, a message prompts a player to select a column to drop their counter (O or X) into. The player's counter is then placed in the top available space in the column if the column is not full.
Players have one Blitz and Time Bomb optional special move available per game of Connect 4. These special moves are accessed by typing a letter command into the turn prompt: 'T' - Time Bomb 'B' - Blitz
The Blitz special move clears an entire vertical column on the game grid, leaving an empty column. After entering the 'B' command, the player will be prompted to select a column to clear.
The time bomb special move lets a player drop a '*' counter into a column, which will 'explode'. When the time bomb goes off it clears all counters directly surrounding it by one space vertically, horizontally and diagonally.
Order of play for a time bomb special move:
- Player A enters the 'T' command for their turn. They will then be prompted to choose a column for the time bomb.
- Player B takes a turn
- Player A takes a turn
- Player B takes a turn
- The time bomb goes of, clearing counters around it.
- Normal game play resumes.
There are several criteria validation and prompts to re-enter values within the project. If a user enters an invalid value, they will be prompted to select again with a message highlighting the error.
Examples of validation and error prompts:
- Selecting a column
- Column number entered needs to be within range of columns in the game grid
- Column needs to have space for a counter
- Special move:
- command needs to be one of the valid commands 'T' or 'B'
- If the player has used up their special move, they will not be allowed to retake it.
- When choosing a player to start the game, the value entered needs to be '1' or'2'
When the win or draw conditions have been met, and end game message is printed to the console with an option to replay the game.

This project has been completed alongside an essay on the software engineering design principles of high cohesion, low coupling, information hiding, and data hiding. An attempt has been made to apply these principles in the Connect 4 console game, with aspects of OOP applied.
Research and links used to learn new concepts:
- Classes and contructors in Java [1]
- Using 'this' keyword in Java [2]
- Learning how to use regular expressions and syntax [3]
- Public vs Private access modifiers in Java [4]
- Creating objects in Java [5]
To improve this project with more time, I would:
- Add a game play option to choose a custom grid size and custom number for the length of row to win a game.
- Work on the test and replace method calls with stubs or mocks. Currently, there are some interdependencies.
- Refactor some longer methods, and improve the logic in particular in the timeBombExplosion method.
- add an AI opponent.
Agnes Beviz
[1] JavaTpoint. (2021). Constructors in Java. Available: https://www.javatpoint.com/java-constructor
[2] W3Schools. (2023). Java this Keyword. Available: https://www.w3schools.com/java/ref_keyword_this.asp
[3] MDN Web Docs. (2023). Regular expression syntax cheat sheet. Available: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions/Cheatsheet
[4] GeeksForGeeks. (2021). Available: https://www.geeksforgeeks.org/public-vs-private-access-modifiers-in-java/
[5] Oracle Java Documentation. (2022). Available: https://docs.oracle.com/javase/tutorial/java/javaOO/objectcreation.html


