Design Phase Connect 4
Design Phase Connect 4
There will be 8 classes to implement. Here is a brief description of what each class will do:
● View: A class that implements the Graphic User Interface
● Model: A class that holds the data of the game. The class will hold the data of the disks
for each player and will hold the data on where players place their disks.
● Controller: A class that will extend Thread and implement ActionListener. This classic
controls the game operation and checks when the game should end.
● LeftArrow: A class that extends AbstractAction that moves the disk to the left of the
GUI.
● RightArrow: A class that extends AbstractAction that moves the disk to the right of the
GUI.
● DownArrow: A class that extends AbstractAction that moves the disk down to a column.
● TimesOut: A class that extends Thread and acts like a timer. It will hold the ability to
count to 10 in order to drop the disk in the column if the user does not decide where to
place their disk.
● ConnectFourGame: A class that creates the View, Model, TimesOut, and Controller
objects. The class starts the threads and sets the GUI visible.
The View Class Extends JFrame
Public Methods:
● Model() - Default constructor. Sets the two int variables (redDisks,yellowDisks) to 21
since these are the number of disks each player gets. Then is sets each index of the
two-dimensional array to empty.
● Void resetBoard() - Sets redDisks/yelloDisks to 21. Sets each index in the grid [ ] [ ]
array to “empty”.
● Int redDisk(int column) - sets “red” in the correct index of the grid [ ] [ ] array based on
where the disk would drop.
● Int yellowDisk(int column) - sets “yellow” in the correct index of the grid [ ] [ ] array
based on where the disk would drop.
● Boolean checkVerticalHorizontal(String disk) - disk string is either red or yellow. This
method should check for vertical and horizontal disk connections. Only 4 connected
disks are required to win the game. Therefore if four connected disks are found return
true. Else return false. (Reference image below)
●
●
● Boolean checkMinDiagonally(String disk) - disk string is either red or yellow. This disk
checks if there are four connected disks min diagonally. Only 4 connected disks are
required to win the game. Therefore if four connected disks are found return true. Else
return false. (Reference Image Below)
● Boolean checkMaxDiagonally(String disk) - disk string is either red or yellow. This
disk checks if there are four connected disks max diagonally. Only 4 connected disks are
required to win the game. Therefore if four connected disks are found return true. Else
return false. (Reference Image Below)
The Controller Class Extends Thread Implements ActionListener
Private Data Members:
View theView
Model theModel
TimesOut theTimer
Action LeftArrow
Action RightArrow
Action DownArrow
int col = 0;
int player = 1;
Public Methods:
● Controller(View view, Model model, TimesOut timer) - Constructor takes 3
parameters. The constructor should set the Controller class private data members and
the actionListener to the Play Again JButton from the View object.
● Void startThreads() - called by ConnectGameFour to start the TimesOut thread and
Controller thread.
● Void run() - Overrides the run method from Thread. It calls the timesOut() method after
10 seconds have passed and sets the seconds int variable from the TimeOuts object to
0. This method will call doNothing() to call sleep method and lastly this run method
should constantly be running.
● Void doNothing() - calls sleep method to implement the pause of the Controller Thread.
● Void checkGrid(int player) - calls the methods in the Model object to determine if there
is a winner. If there is a winner or if there are no more disks to play then the GUI should
be updated to display a winner or display a tie and it should suspend both Controller and
TimesOut threads.
● Void timesOut() - is called by the run() method after ten seconds have passed. The
method should place the disk that wasn't played by the user on the column it is above at
that moment.
● Void actionPerformed(ActionEvent e) - Overrides the actionPerformed method from
ActionListener. It should resume Controller and TimesOut threads and reset the game to
a new game.
LeftArrow Class Extends AbstractAction
● Void actionPerformed(ActionEvent e) - Overrides the actionPerformed method from
AbstractAction class. Moves the player’s disk to the left of the GUI. (Reference image
below)
ConnectFourGame Class
Methods:
● Public static void main (String[ ] args) - This class should only create the following
objects inside the main method: View, Model, TimesOut, and Controller. Then it should
start both threads to start the multi-threading. Finally it needs to set the GUI visible.