Milestone 1 Due: Thursday, Mar 4th by 11:59 PM

Milestone 2 Due: Friday, Mar 12th by 11:59 PM

Getting Started

Download CS201_Assign02_Gradle.zip Extract the zip file and import it into Eclipse

File→Import…→Gradle→Existing Gradle Project

You should see a project called CS201_Assign02_Gradle in the Package Explorer window (see Importing and Submitting Projects for details).

Your Task

In this assignment, you will complete the implementation of a Tic-Tac-Toe program that includes a GUI and the ability to load/save games. There will be two milestones:

Note that the bodies of some of the methods have the code

throw new UnsupportedOperationException("not implemented yet");

As you implement each method, simply remove this code.

TicTacToeModel class

An instance of the TicTacToeModel class will store an int representing which player’s turn it is, and a representation of the board as a 3x3 array of ints. Each element of the array will contain one of three values

Use the PLAYER_X and PLAYER_O constants defined in the model class, NOT the values 1 or 2.

To allocate a 3x3 array of int values:

int[][] board = new int[3][3];

Note that each element of the array will contain the value 0 initially.

The first dimension of the array is the rows of the board, and the second dimension is the columns. Each array element represents a location on the game board.

For the model class, you must implement the following game logic methods:

Milestone 1

Milestone 2

TicTacToeController class

An instance of the TicTacToeController class will implement methods that take a TicTacToeModel object along with other parameters as needed to call the corresponding model class game logic methods. These include:

TicTacToePanel class

An instance of the TicTacToePanel class will implement event driven methods for a GUI version of tic-tac-toe. It will use the same model and controller classes as the console version, but obtain user input via mouse and keyboard events. These include:

Note that the default board is 300x300 such that each cell is 100x100 pixels on the screen.

Example Console Session

Run the program by right-clicking on the file TicTacToeConsole.java in the src/main/java/(default package) package, and then choosing

Run As→Java Application

Here is an example session (user input in bold):

   |   |   
---|---|---
   |   |   
---|---|---
   |   |   

Player X's turn:
Enter row and column (0-2): 1 1

   |   |   
---|---|---
   | X |   
---|---|---
   |   |   

Player O's turn:
Enter row and column (0-2): 0 0

 O |   |   
---|---|---
   | X |   
---|---|---
   |   |   

Player X's turn:
Enter row and column (0-2): 4 2
Invalid move, try again

 O |   |   
---|---|---
   | X |   
---|---|---
   |   |   

Player X's turn:
Enter row and column (0-2): 0 0 
Invalid move, try again

 O |   |   
---|---|---
   | X |   
---|---|---
   |   |   

Player X's turn:
Enter row and column (0-2): 0  1

 O | X |   
---|---|---
   | X |   
---|---|---
   |   |   

Player O's turn:
Enter row and column (0-2): 0 2

 O | X | O  
---|---|---
   | X |   
---|---|---
   |   |   

Player X's turn:
Enter row and column (0-2): 2 1

 O | X | O  
---|---|---
   | X |   
---|---|---
   | X |   
   
GAME OVER!
Player X wins!
Thanks for playing!

Example GUI

Here is an example screenshot for the GUI

Game Over

Testing

In src/test/java/(default package) right-click on TicTacToeTest.java and choose Run As…→JUnit Test. This will run the JUnit tests for the TicTacToeModel class. If you have correctly implemented the TicTacToeModel class, you will see a green bar, indicating that all tests have succeeded. Note that it is important to get the constructor correct, otherwise the tests will likely fail even if the other methods are implemented correctly.

It is possible that the tests don’t test every possible situation. You may wish to add your own tests!

Grading

Milestone 1:

Milestone 2:

For both milestones, points may be deducted for poor coding style, including:

Submitting

When you are done with each milestone, submit the project to the Marmoset server using the SimpleMarmosetUploader Eclipse plugin (see Importing and Submitting Projects for details).

From Eclipse

Use the Simple Marmoset Uploader Plugin, by selecting the project (CS201_Assign02_Gradle) in the package explorer and then clicking the blue up arrow button in the toolbar (or right click and choose Submit project…). Enter your Marmoset username and password when prompted. Make sure your choose assign02_ms1 or assign02_ms2 as the inbox:

Choosing the inbox for assignment 2

After you submit

Very important: After you submit the assignment, please log into the Marmoset server and check the files you submitted to make sure that they are correct.

It is your responsibility to make sure that you have submitted your work correctly.

An Agile Approach to Developing the Tic-Tac-Toe Game Assignment

Just like for the previous assignment, it will be extremely beneficial to tackle this one again with an agile approach. Consider working on one task at a time and frequently running/testing your code.