Due : Thursday Dec 14th at 11:59pm (reading day)
In this lab you will build a simple, graphicTic Tac Toe game. You will
have the opportunity to practice the concept we have covered recently:
selection, repitition, and Arrays, a simple collection. As always Read the entire lab before beginning
To practice your programming skills, particularly
- Implement selection
- Imeplement repitition
- To use an array.
First make sure you do all of your work in a directory called lab5.
You must implement the five classes in the UML diagram below along with
the methods and instance variables listed in the UML diagram. The
intended meaning and functionality of these methods are shown below the
UML diagram. You may add any additional instance variables or methods
that you believe will make your program easier to write.
- TicTacToe class
- this is the main overarching class. All other objects in the
system are part of this class. The main method needs to be implemented
in this class.
- main: in the main method, create a TicTacToe object and then call playGame
- TicTacToe: the constructor should initialize all of the intance variables. The _board instance variable should be initialized as an empty board. Display the JFrame, and add the BoardDisplay to it here or in a method called from here. Ignore the <<create>> it is an artifact of the UML software.
- getBoard should return the _board array.
- playGame should do the following things until the game is won.
- first ask the user for a move (using the _input object)
- Update the board with the users move
- check to see if there is a winner
- get a move from the _player
- Update the board with the AI move
- check to see if there is a winner
- if there is a winner (either AI or human), post a message telling the player so as soon as either the player or the AI wins.
- AIplayer class
- this class encapsulates what it is to be an AI player. Since
this is an introductory computer science class, you may write a very
simple AI player that chooses a random free square to place its mark.
- chooseMove should select a move. The diagram shows no return
type, but you really want one, an int would be one possible return
type, but exactly what you use for a return value is up to you, it
depends on your implementation.
- Referee class : this class just has to check to see if there is a winner of the game given the current board.
- CheckWinner is passed a reference to the board and should check
to see if there is a winner. It should return true if there is a
winner, false if there is not. Alternately, if you choose, you may have
it return who won and change the return type.
- UserMove: this class needs to get a movc from the user
- getUserMove: this method should return a representation of the
square that the user wants to choose for this move. I have it setup to
return an int, but if your design uses a different type to represent a
move, feel free to use it instead. You need to ask the user what move
they want to make. Use whatever technique you want to read input from
the user (Scanner, JOptionPane or something else if you like)
- Board Display: this class is the equivlent to the drawing panel in the last lab, it must extend JPanel
- _game should be the active TicTacToe object
- PaintComponent is where you will draw the board. You need to
draw the grid. (perhaps a series of drawLine commands) and the X
and O characters for the existing moves.
Once again this is a lab that has several parts to it. I recommend that
you begin with A very basic TicTacToe class and then add the
BoardDisplay object. Once you can see this on your screen, add the
hatches of the board.
I sussgest at that point, work on getting the user input and dispalying
it. Once you have that, you will need to get the AI move and display
it. Then you can finally look at seeing who won the game.
Since you have quite a bit of flexibility in this lab, your readme will have more weight than before.
As always, you need to include these things in your readme
- Your name
- How do I run your program? What class has the main method in it. How is in the input read in? and so forth
- What did you do and why? <this section has greater importance this time since there are many ways to do this lab>
- Any errors or incomplete parts of your program
Then zip up your lab5 directory and submit as usual.