private void FillAllFreeCells()
{
int directionRow = 1;
int directionCol = 1;
int number = 1;
while (true)
{
this.matrix[this.row, this.col] = number;
if (!this.IsCellAvailable(this.row, this.col))
{
this.FindAllFreeCell();
if (this.IsCellAvailable(this.row, this.col))
{
number++;
this.matrix[this.row, this.col] = number;
directionRow = 1;
directionCol = 1;
}
else
{
break;
}
}
int nextRow = this.row + directionRow;
int nextCol = this.col + directionCol;
if (!this.IsInRange(nextRow) || !this.IsInRange(nextCol) || this.matrix[nextRow, nextCol] != 0)
{
while (!this.IsInRange(nextRow) || !this.IsInRange(nextCol) || this.matrix[nextRow, nextCol] != 0)
{
this.GetNewDirection(ref directionRow, ref directionCol);
nextRow = this.row + directionRow;
nextCol = this.col + directionCol;
}
}
this.row = nextRow;
this.col = nextCol;
number++;
}
}