コード例 #1
0
        public void RotateShape(Field field, RotationDirection direction)
        {
            var shadowShape = shapeService.CopyShape(field.ActiveShape);

            shapeService.Rotate(shadowShape, direction);

            if (fieldService.CanMoveShape(field, shadowShape))
            {
                shapeService.Rotate(field.ActiveShape, direction);
            }
        }
コード例 #2
0
        public void Rotate_WhenDirectionIsClockwise_RotatesShapeClockwise()
        {
            // Arrange
            var shape = new Shape
            {
                //╚╗
                Boxes = new List <Box>
                {
                    new Box
                    {
                        X = 0,
                        Y = 0
                    },
                    new Box
                    {
                        X = 0,
                        Y = 1
                    },
                    new Box
                    {
                        X = 1,
                        Y = 1
                    },
                    new Box
                    {
                        X = 1,
                        Y = 2
                    }
                },
                CenterX = 1,
                CenterY = 1
            };

            // Act
            sut.Rotate(shape, RotationDirection.CLOCKWISE);

            // Assert
            Assert.True(shape.Boxes.SingleOrDefault(b => b.X == 0 && b.Y == 2) != null);
            Assert.True(shape.Boxes.SingleOrDefault(b => b.X == 1 && b.Y == 2) != null);
            Assert.True(shape.Boxes.SingleOrDefault(b => b.X == 1 && b.Y == 1) != null);
            Assert.True(shape.Boxes.SingleOrDefault(b => b.X == 2 && b.Y == 1) != null);
        }