Players can choose the dimensions of the board (3x3, 4x4). Also they can undo their moves during the game. After the end of the round, you can start a new one or finish the game completely. During the game, the number of winnings of the player is counted.
All classes have their own scope of responsibility, for example, the Board class operates only with methods related to Lattice (displaying the array, recording the player's symbol in the array, saving and restoring the state of the array). Therefore, in the TicTacToe class, when it is need to write the sign of the player on the board, the WriteSign method is called, in which, after passing the necessary checks, the WriteSign method of the Board class is called.
The classes are designed to be extensible without modifying existing code. For example, the abstract Board class can be extended by adding a child class with a certain lattice dimension.
The TicTacToe class has a TicTacToeBoard field of type Board to which we can assign a variable of type Board3 or Board4 in the Create() method.
We have small interfaces that have only the necessary methods and that can be implemented by different classes.
Classes and methods are simple and focused on a single responsibility. They only have basic, simple and necessary methods for the game.
The WriteSign(int position) method of the TicTacToeBoard class and the WriteSign(int position, string sign) method of the Board class have checks for the correct functioning of the game. If these checks don't pass, an Exception is generated with a description of the error.
The BoardFactory factory class has a Create method that, depending on the value passed, returns a 3x3 or 4x4 board.
Used to store a list of board states and for the ability to revert to a previous state (i.e. cancel a player's move). Implemented in IMemento interface, BoardMemento, Board (MakeSnapshot and Restore methods), TicTacToe (Save and Undo methods) classes.
The TicTacToe class has a WriteSign method that performs certain checks, and if they pass, it calls the Board class's WriteSign method, which adds the player's sign to the board.
It was used when the method was supplemented with functionality or changed it altogether.
Separation of checks of winning combinations into CheckRows, CheckCols, CheckDiagonals methods from the CheckWinning method in the TicTacToe class. Separating the output of board and player information into the PrintGameInfo method.
In the TicTacToe class methods not used by other classes have been made protected.
Used in the CheckWinning method.
The CurrentPlayer field used to be of type string and stored the sign of the player, now it is of type Player and stores an object.