Exemple #1
0
        public void SetShape(ITetrisShape shape, Color color)
        {
            var startingY = -shape.Points.Select(p => p.Y).Max() - 1;
            var location  = new Point((_gameGrid.Width - 1) / 2, startingY);

            _movingShape = new PositionedShape(shape, color, location);
        }
            public void WhenConstructedLocationIsSetCorrectly(int X, int Y)
            {
                var point = new Point(X, Y);
                var shape = new PositionedShape(new StaticShape(new[] { new Point(1, 1) }), Color.Red, point);

                Assert.AreEqual(point, shape.Location);
            }
            public void WhenConstructedColorIsSetCorrectly(string colorName)
            {
                var color = Color.FromName(colorName);
                var shape = new PositionedShape(new StaticShape(new[] { new Point(1, 1) }), color, new Point(1, 1));

                Assert.AreEqual(color, shape.Color);
            }
Exemple #4
0
    static List <Vector3[]> GenerateBlockers(List <PositionedShape> shapes, float portion)
    {
        List <Vector3[]> blockers = new List <Vector3[]>();

        foreach (var shapeGroup in shapes.GroupBy(s => s.originalType))
        {
            if (shapeGroup.Count() == 1)
            {
                // get pairs
                IEnumerable <IEnumerable <PositionedShape> > pairs = Extensions.GetPermutations(shapeGroup, 2);

                foreach (IEnumerable <PositionedShape> pair in pairs)
                {
                    var             pairAsList = pair.ToArray();
                    PositionedShape shape0     = pairAsList[0];
                    PositionedShape shape1     = pairAsList[1];

                    // TODO
                    // GetLeftConnectingTriangles
                }
            }
        }


        return(blockers);
    }
            public void WhenMoveIsCalledNewShapeIsMoved(int X, int Y, int offsetX, int offsetY)
            {
                var shapeMock  = new Mock <ITetrisShape>();
                var shape      = new PositionedShape(shapeMock.Object, Color.Red, new Point(X, Y));
                var movedShape = shape.Move(new Point(offsetX, offsetY));

                Assert.AreEqual(movedShape.Location, new Point(X + offsetX, Y + offsetY));
            }
Exemple #6
0
    static IEnumerable <Vector3[]> GetLeftConnectingTriangles(PositionedShape s0, PositionedShape s1)
    {
        IEnumerable <Vector3[]> nodePairs = Extensions
                                            .GetPermutations(s0.nodes, 2)
                                            .Select(p => p.ToArray());

        return(s1.nodes
               .SelectMany(n => PairsAndOneToTriangles(nodePairs, n)));
    }
Exemple #7
0
        private bool MoveShapeIfPossible(PositionedShape proposedShape)
        {
            var positionedPoints = Array.ConvertAll(proposedShape.Shape.Points, p => new ColouredPoint(proposedShape.Color, p.Move(proposedShape.Location)));

            if (!_gameGrid.CanAdd(positionedPoints.Where(p => p.Point.Y >= 0)))
            {
                return(false);
            }

            _movingShape = proposedShape;
            return(true);
        }
            public void WhenRotateIsCalledNRotatedShapeIsReturned()
            {
                var shapeMock    = new Mock <ITetrisShape>();
                var rotatedShape = new Mock <ITetrisShape>();

                shapeMock.Setup(p => p.Rotate()).Returns(rotatedShape.Object);

                var shape      = new PositionedShape(shapeMock.Object, Color.Red, new Point(0, 0));
                var movedShape = shape.Rotate();

                Assert.AreEqual(rotatedShape.Object, movedShape.Shape);
            }
Exemple #9
0
        public bool CommitShape()
        {
            //If there is no shape it's trivially commitable.
            if (_movingShape == null)
            {
                return(true);
            }

            var locatedPoints = _movingShape.Shape.Points.Select(p => new ColouredPoint(_movingShape.Color, p.Move(_movingShape.Location)));

            if (!_gameGrid.TryAdd(locatedPoints))
            {
                return(false);
            }

            _movingShape = null;
            return(true);
        }