Step 2: Adding constructor and drawing methods
To add the constructor and the drawing methods to the project, do the following:
-
Replace the already existing constructor in tictactoe.cpp with the following code:
The Select All button is included with all code blocks to help you move the code into your project.
-
The method paintEvent calls the drawing methods. In this example, the drawing methods draw the game board and either crosses or noughts after each move. Replace the method paintEvent in tictactoe.cpp with the following code:
-
The method drawTable draws the game board. Replace the method drawTable in tictactoe.cpp with the following code:
-
The drawCrossesAndNoughts and cellRect methods add crosses and noughts to the board. Replace the drawCrossesAndNoughts and cellRect methods in tictactoe.cpp with the following code:
-
Compile the project by selecting Build > Build Project "TicTacToe". If there are no errors, you can run the program by selecting Build > Run. An empty tic-tac-toe board will appear.
If the application is not working properly, download and use this tictactoe.cpp file; all of the methods used in this section can be found there.