java programming
Final Project Specification
Task
Enhance and correct a Tic Tac Toe game. The game is intended to be played against a computer.
The object TicTacToeBoard is initialized to indicate if the computer is the player 1 or player 2 and if the Computer plays in Random or “Smart” mode. Your task is to allow turns between the player and computer and to determine if a winner exists.
Keyboard input implies using the Scanner object.
Review the ‘break;’ and ‘continue;’ commands from the Week 8 “Things to Know” section.
Ideally, do 1 task at a time and test the results. The tasks are arranged so that the previous work will help with your testing.
The TicTacToeBoard class uses a Character class which is a wrapper class for char. It allows for the value null. Thus, the board values can be ‘X’,’O’ or null.
Deliverables
Submit the modified and corrected TicTacToe class and TicTacToeBoard class.
Be sure to submit both files. If you neglect to include a file, you must email me the missing file before the due date.
The files GuiBoard.java and WinOptions.java do not need to be included as there are no required changes.
Program Assumptions
The TicTacToeBoard is instantiated with the Computer as player 2. This setting also determines who is ‘X’ and who is ‘O’. ‘X’ always goes first.
You can set the smart mode to true or false or prompt to set it as desired.
In the TicTacToe board will have null values in the ‘squares’ when started.
Program Requirements
1. In the TicTacToe class and TicTacToeBoard class, modify the comment headers to include your name and student ID and semester.
2. Create a loop in the TicTacToe class to play the game. This will be referred to as the ‘main’ loop for this process.
a. Create an int variable for row position. This declaration should be done only once and before the loop starts.
b. Create an int variable for column position. This declaration should be done before the loop starts.
c. Inside the loop, do the following tasks
i. Display “Your Turn” and prompt to enter a row number (0-2) to place your TicTacToe square.
ii. Prompt to enter a column number (0-2) to place your TicTacToe square.
iii. Call the setValue() method of the TicTacToeBoard instance with the input given.
1. setValue requires 2 parameters, Row and Column.
2. setValue is a boolean value method. It generates a true or false result. If the setValue method returns false, it was unable to process the request. When this occurs, display “Try again” and resume this loop (2c).
iv. Call the method hasWinner() of the TicTacToeBoard instance.
1. If hasWinner() returns true then
a. Call the method theWinnerIs() of the TicTacToeBoard instance and display the value returned from theWinnerIs() method as in the example below.
i.e. “The winner is X”
b. Exit the loop.
v. Call the method theComputersTurn() of the TicTacToeBoard instance. If this method returns a false value, display that “The computer has forfeited” and exit the loop.
vi. Do task iv again – placed after task v.
d. After the loop is completed – display “Game over” from the main() method.
3. The method setValue() in the TicTacToeBoard class can be called with out of range numeric values and create a runtime error. Modify the setValue method so that it returns false if data passed is not in the range of possible values. (0 – 2).
4. The TicTacToeBoard class does not have a way to indicate that all entries are loaded. Create a public method named hasSquaresAvailable() in the the TicTacToeBoard class that will report true if there are available squares or false is the board is full. (Review the existing checkFirstPlay() method for a similar example.)
a. Call this new method from the TicTacToe class inside the main loop.
i. Do this before calls to setValue().
ii. Do this before calls to theComputersTurn().
iii. If there are no remaining spaces then:
1. Display “No Available spaces”.
2. Terminate the loop.
5. The TicTacToeBoard class currently only checks rows and columns.
XXX X
OX
OXO X
O
O
OOX O
O
X
It does not check diagonal values.
XXO XO
O
OXX X
O
X
OOX
O
XX
a. Create a private method inside the TicTacToeBoard class named checkForDiagonalWin that will check for a possible diagonal win . This method does not need internal loops. Study how the private method checkRowOrColumnForWinner() works to understand what to look for. Be careful to check for null values before doing other compares as this can result in a null pointer exception.
b. Call the method created above in step 8a from the theWinnerIs() method in the TicTacToeBoard class.
5 points Extra Credit – Change the valid input range from 0 -2 to 1-3 for the row and column indicators as part of the processing in the TicTacToe class. Do not change the setValue method in the TicTacToeBoard class. All other work must be completed to receive extra credit.
Grading Rubric
Requirements |
Percemtage |
|
Working program with no crashes or run time errors. No Eclipse Warnings – No TODOS, etc. All COSC-Programming Guide Rules are honored. |
25 |
|
Code contains useful comments. These can be per method and as desired. |
10 |
|
Step 1 |
5 |
|
Step 2 |
20 |
|
Step 3 |
15 |
|
Step 4 |
10 |
|
Step 5 |
15 |
|
|
|
12/4/2020 Service Specification Page 2
December 4, 2020 Page 3