Using a TicTacToe class such as this example, write a program that allows the user to play a game of Tic Tac Toe against the computer. The program must allow a human user to play against the computer with the user being X's and the computer O's. The user should go first in the first round. This assignment will be graded on style and efficiency. The player must be able to play a new game and feedback should be given to the player indicating how many games have been won, loss and drawn.
Add the following features for full credit:
- make the program user-friendly
- the user's inputs must be validated to ensure that the position is legal and not already taken. If the move is invalid, display the message "Invalid move!"
- computer moves must be valid and not overwrite previous human or computer moves
- end the game immediately when the a player wins or when there is a draw and announce who the winner was
- display the board after the computer makes its move and its the player's turn
- After each game is over, the user must be able to play a new game again as the letter X however the computer or the player must randomly be assigned the first move.
For extra credit:
- you can also add "artificial intelligence" to the computer so that it blocks the user's attempts to win and is therefore unbeatable. That is, the computer always forces a draw whether it goes first or last.
Part of your grade for this project will be determined by the
creativity, complexity and overall appearance of your design while part of the grade will be based on how much you learned from the Java API and used it in an interesting way. If you are creating a console text only output, it should include gridlines such as
x | x | o
--------
o | x | o
--------
x | o | x
Your output must be functional, appealing, and creative whether it is text-based or graphical and uses Paint, Canvas, or other components such as Buttons and JLabels.
Your
program must follow the class Coding Standards.
Upload the following files to the specified location. Your first name and last initial should replace "JohnD" in the filenames.
- a screen capture graphic named TicTacToeJohnD.png
- a pdf of your source code named TicTacToeJohnD.pdf
- a screencast of your project's execution named TicTacToeJohnD.mp4 Be sure that the video shows the player hitting a wall and being reset to the beginning. The video must show the player winning the maze by reaching the end.
- the complete project folder compressed into a zip file and renamed TicTacToeJohnD.zip
Original Version
Write a game of Tic Tac Toe using this TicTacToe.java file as a model.
The program must allow a human user to play against the computer with the user being x's and the computer o's. The user should go first. This assignment will be graded on style and efficiency.
Add the following features for full credit:
- make the program more user-friendly than the template by having the user type integers between 1 and 3 rather than 0 and 2
- the user's inputs must be validated to ensure that the position is legal and not already taken. If the move is invalid, display the message "Invalid move!"
- computer moves must be valid and not overwrite previous human or computer moves
- end the game appropriately when the a player wins or when there is a draw and announce who the winner was
- display the board after the computer makes its move and its the player's turn
- After each game is over, the user should be asked if he would like to play again or not. But the computer should always remain o's.
- use constants, loops, additional static methods, the length method, and all other means of efficiency so the program can be easily understood and maintained in the future
For extra credit:
- you can also add "artificial intelligence" to the computer so that it blocks the user's attempts to win and is therefore unbeatable. That is, the computer always forces a draw whether it goes first or last.
- use traditional gridlines in your board's display as in
x | x | o
--------
o | x | o
--------
x | o | x
Your program must follow the class Coding Standards.
You must hand in the following on separate pages stapled in this specified order:
- The source code for the TicTacToe class.
- Call the instructor to your computer to receive a run-time grade for this project.