コード例 #1
0
        public void RotateShape()
        {
            if (ShapeIsOutOfTopOrBottomModelBorders())
            {
                return;
            }

            var nextStateOfCurrentShape = _currentShape.Clone() as Shape;

            nextStateOfCurrentShape.CurrentState = _currentShape.CurrentState == ShapeState.DegreeRotation270 ? ShapeState.Base : _currentShape.CurrentState + 1;

            // Check the next shape state for out of model borders.
            if (_currentShape.LocationY + nextStateOfCurrentShape.BottomBorder > _modelHeight - 1 ||
                _currentShape.LocationX + nextStateOfCurrentShape.LeftBorder < 0 ||
                _currentShape.LocationX + nextStateOfCurrentShape.RightBorder > _modelWidth - 1)
            {
                return;
            }

            // Check the next shape state for contact with other shapes.
            for (var i = nextStateOfCurrentShape.TopBorder; i <= nextStateOfCurrentShape.BottomBorder; i++)
            {
                for (var j = nextStateOfCurrentShape.LeftBorder; j <= nextStateOfCurrentShape.RightBorder; j++)
                {
                    if (Model[nextStateOfCurrentShape.LocationY + i, nextStateOfCurrentShape.LocationX + j] != BlockType.Empty &&
                        nextStateOfCurrentShape.States[nextStateOfCurrentShape.CurrentState][i, j] != BlockType.Empty &&
                        _currentShape.States[_currentShape.CurrentState][i, j] == BlockType.Empty)
                    {
                        return;
                    }
                }
            }

            EraseCurrentShape();
            _currentShape.CurrentState = nextStateOfCurrentShape.CurrentState;
            PlaceCurrentShape();
        }