Implementing a chess game
At this point, you are ready to employ your newly gained skills in rendering graphics with Qt to create a game that uses widgets with custom graphics. The hero of today will be chess and other chess-like games.
Time for action – Developing the game architecture
Create a new Qt Widgets Application
project. After the project infrastructure is ready, choose New File or Project
from the File
menu and choose to create a C++ Class
. Call the new class ChessBoard
and set QObject
as its base class. Repeat the process to create a ChessAlgorithm
class derived from QObject
and another one called ChessView
, but choose QWidget
as the base class this time. You should end up with a file named main.cpp
and four classes:
MainWindow
will be our main window class that contains aChessView
ChessView
will be the widget that displays our chess boardChessAlgorithm
will contain the game logicChessBoard
will hold the state of the chess board and provide it toChessView
andChessAlgorithm
Now...