Since I am just learning the basics of java so doing tic-tac-toe alone is impossible for me that's why i am waiting for someone's complete java code of it. Here is all i know about it:
Tic-tac-toe is played on a 3 x 3 grid. Two players take turns at selecting squares on the grid, the first marking his or her moves with an "O" (British, "nought"), the second, with "X" ("cross"). The first player to select three squares in a row -- horizontally, vertically, or diagonally -- wins the game.
The program should draw the game board using a simple representation, with the squares numbered from 1 to 9, such as: 1 | 2 | 3 ----------- 4 | 5 | 6 ----------- 7 | 8 | 9
It should then prompt the user to select one of the squares, by number. It should check that a valid selection has been made (i.e., the number is in range and was not previously selected by either player) and, if not, print an appropriate message and prompt again. The following example illustrates such an interaction: X | X | 3 ----------- 4 | O | 6 ----------- 7 | O | 9
Your move? 2 Please enter one of the digits shown on the board. Your move? 17 Please enter one of the digits shown on the board. Your move? 3
Once the human player has made a valid selection, the program should choose a square for its move. It should then indicate which square was selected and print an updated representation of the board, indicating the human player's moves with O's and its own moves with X's. The next round of play then commences with another prompt to the human player, as in: I chose square 4.
X | X | O ----------- X | O | 6 ----------- 7 | O | 9
Your move? After each move -- both the human's and its own -- the program should check for a winner. If a player has won, an appropriate message should be printed and the game ends. For example, if the human player wins, it might print: X | X | O ----------- 4 | O | 6 ----------- O | 8 | 9
Congratulations. You won. If the computer wins, it might print the following: X | X | O ----------- X | O | O ----------- X | O | 9
I won. Let's play again soon. The program should also check for a no-win condition, in which all squares have been selected, but neither player has won: X | O | X ----------- X | O | O ----------- O | X | 9
1st of all create a enum called ClickedBy with the values NONE, PLAYER1 and PLAYER2.
Would also work with int, but a enum is more elegant and easier to read
now create a array ClickedBy[3][3] and set every value to ClickedBy.NONE
how to draw the board and the numbers I let up to you. A approach might be to use a gridlayout, put in 9 labels and that's it. set Text alignment of each to center.
add a mouseclick listener to each. When clicked, check if the specified field is allready taken (velue must be different from NONE) and set it according to the player who's turn is it. After each click you must set the new player of course and start the evaluation if one row contains 3 equal values != NONE