Here is example code showing a Tic Tac Toe class I made. It is
more involved than I asked for in class, but it is fully operational and
could be used in many situations.
TicTacToe.java can do the following:
-
Setup/reset board.
-
Check/Set board value
-
Determine winner
-
Print board
Game.java does the following:
-
Instantiates a TicTacToe object
-
Sets/retrieves values
-
Prints board and winner
Example run:
calico(100)% java Game
Square 1 has a value: 2
Error, square value not set!
X | O | X
---+---+---
O | O | X
---+---+---
X | X | O
This game is a Draw
Below is a blank board
| |
---+---+---
| |
---+---+---
| |