Beginning Tic-Tac-Toe development

My first project here will be the Tic-Tac-Toe game. It is quite easy to develop and I think it is perfect to begin with.

Planned game features:

Full player vs player support (no plans for any kind of an AI at the moment);
Victory detection
Starting with the games architecture, I am planning on having the following classes:

MainWindow This class will be responsible for drawing the games main window. It will draw the games board and place the 9 BoardCellView classes in their correct places;
BoardCellView - Very simple class that is responsible for drawing the players symbol when it is clicked;
GameController This is the games central class, responsible for every choice in the game. I will explain it in more detail later on this post;
BoardCellModel - Another very simple class. Its only objective is to save the state of a BoardCellView class.
The image above shows the interactions between classes during the games two main phases, the starting (or restarting) a new game and when the user clicks on a board cell.

The start of a new game begins with GameController initializing both MainWindow and BoardCellModel. These classes proceed to reset their configurations to the default values. The GameController is then required to create the BoardCellView classes (if they are not created yet) and place them on the MainWindows board through the PlaceCell() method. Upon placing a new cell on the board, the MainWindow class is also responsible for its initialization. After these procedures, the board is correctly drawn and the game is ready to start.

One of the players then proceeds to select one of the boards cells, clicking it. BoardCellView, which registered the clicked() event, receives this notification and passes it to the GameController. Upon receiving this notification, this class determines the current player and modifies the corresponding BoardCellModel, which then emits a ModelUpdated signal that is captured by the BoardCellView, forcing an update to the cell display and drawing the players symbol. Meanwhile, the GameController class has also started to verify if one of the players has won or if the game resulted in a draw. If any of these cases occur, it will issue the CreatePopup method of the MainWindow class which creates a new window popup for the user, notifying him of the games status. The user will then be able to restart or quit the game.

As you can see, the game is quite simple. I will now proceed with the games development and as soon as it is completed, I will create a new post. If you have any feedback or questions, please feel free to comment here.

Source link:

Follow Luuux

Related Posts

Trending Technology