Skip to content

DenysenkoDenys/TicTacToe

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Game functionality

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.

Programming Principles

Single Responsibility, SRP

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.

Open/Closed, OCP

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.

Liskov Substitution, LSP

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.

Interface Segregation Principle, ISP

We have small interfaces that have only the necessary methods and that can be implemented by different classes.

KISS

Classes and methods are simple and focused on a single responsibility. They only have basic, simple and necessary methods for the game.

Fail Fast

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.

Design Patterns

Factory Method

The BoardFactory factory class has a Create method that, depending on the value passed, returns a 3x3 or 4x4 board.

Memento

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.

Command

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.

Refactoring Techniques

Rename Method

It was used when the method was supplemented with functionality or changed it altogether.

Extract Method

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.

Hide Method

In the TicTacToe class methods not used by other classes have been made protected.

Consolidate Conditional Expression

Used in the CheckWinning method.

Replace Data Value with Object

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.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C# 100.0%