Would it violate the SRPSingle Responsibility Principle if I will add more responsibilityresponsibilities to this class to not only decide if someone has won the game, but who has won (X or O)? What is the best way to add responsibility to this?
public interface IGameEndAnalyzer
{
bool IsGameEnd(IBoard board);
}
public class GameEndAnalyzer : IGameEndAnalyzer
{
public bool IsGameEnd(IBoard board)
{
return IsAnyRowHasAllSameValue(board) ||
IsAnyColumnHasAllSameValue(board) ||
IsLeftDiagonalHasAllSameValue(board) ||
IsRightDiagonalHasAllSameValue(board);
}
private bool IsAnyRowHasAllSameValue(IBoard board)
{
for (int rowIndex = Board.Row.Top; rowIndex <= Board.Row.Bottom; rowIndex++)
{
var isSameValue = board
.Cells
.WhereInRow(rowIndex)
.AllCellIs_O_Or_X();
if (isSameValue)
{
return true;
}
}
return false;
}
private bool IsAnyColumnHasAllSameValue(IBoard board)
{
for (int columnIndex = Board.Column.Left; columnIndex <= Board.Column.Right; columnIndex++)
{
var isSameValue = board
.Cells
.WhereInRow(columnIndex)
.AllCellIs_O_Or_X();
if (isSameValue)
{
return true;
}
}
return false;
}
private bool IsLeftDiagonalHasAllSameValue(IBoard board)
{
var isSameValue = board
.Cells
.WhereInDiagonalLeft()
.AllCellIs_O_Or_X();
return isSameValue;
}
private bool IsRightDiagonalHasAllSameValue(IBoard board)
{
var isSameValue = board
.Cells
.WhereInDiagonalRight()
.AllCellIs_O_Or_X();
return isSameValue;
}
}