private static void MoveMatrix(Position position) { for (int i = 0; i < _squareCount; i++) { for (int j = 0; j < _squareCount; j++) { if (_pointMatrix[i, j] != null) { var currentMarbleMatrix = _pointMatrix[i, j]; if (currentMarbleMatrix != null && currentMarbleMatrix.Marble != null) { switch (position) { case Position.E: { bool isWall = IsWall(i, j, i, _squareCount - 1); if (isWall) { for (int k = j; k < _squareCount; k++) { if (_pointMatrix[i, k] != null && _pointMatrix[i, k].Wall != null) { _pointMatrix[i, k] = _pointMatrix[i, j]; _pointMatrix[i, j] = null; } else { _pointMatrix[i, _squareCount - 1] = _pointMatrix[i, j]; _pointMatrix[i, j] = null; } } } } break; case Position.N: break; case Position.S: { if (i == _squareCount - 1) { continue; } bool isWall = IsWall(i, j, _squareCount - 1, j); if (isWall) { for (int l = i; l < _squareCount; l++) { if (_pointMatrix[l, j] != null && _pointMatrix[l, j].Wall != null) { _pointMatrix[l, j] = _helper.DeepClone(_pointMatrix[i, j]) as IPoint; _pointMatrix[l, j].Wall = null; _pointMatrix[i, j].Marble = null; break; } } } else { _pointMatrix[_squareCount - 1, j] = _helper.DeepClone(_pointMatrix[i, j]) as IPoint; _pointMatrix[_squareCount - 1, j].Wall = null; if (_pointMatrix[i, j].Wall != null) { _pointMatrix[i, j].Marble = null; } else { _pointMatrix[i, j] = null; } } } break; case Position.W: { bool isWall = IsWall(i, _squareCount - 1, i, j); if (isWall) { for (int k = j; k < _squareCount; k++) { if (_pointMatrix[i, j - k] != null && _pointMatrix[i, j - k].Wall != null) { _pointMatrix[i, j - k] = _pointMatrix[i, j]; _pointMatrix[i, j] = null; } else { _pointMatrix[i, j - _squareCount - 1] = _pointMatrix[i, j]; _pointMatrix[i, j] = null; } } } } break; default: break; } } } } } }