예제 #1
0
        // Author: Samuel Stahl
        //Checks first for illegal move and returns true if found
        // else returns false if move is legal
        //After illegal move check, checks for imenent collision with bottom or block in grid and sets AboutToPlace if true
        public static bool CheckForCollisions(BlockGrid grid, List <Block> blocks, GameShape shape)
        {
            List <Vector2> occupiedCoordinates = grid.GetOccupiedCoordinates();

            //Checks for illegal collisions with boundary or occupied areas and returns true if collision found
            foreach (Block b in blocks)
            {
                Vector2 blockCoord = b.GetPosition();
                //left boundary check
                if (blockCoord.X < 0)
                {
                    return(true);
                }
                //right boundary check
                else if (blockCoord.X >= grid.GetGridColumnCount())
                {
                    return(true);
                }
                //bottom boundary check
                else if (blockCoord.Y < 0)
                {
                    return(true);
                }
                //check for illegal overlap
                else if (occupiedCoordinates.Contains(blockCoord))
                {
                    return(true);
                }
            }
            return(false);
        }
예제 #2
0
        private static void checkAndApply(InputAction action, BlockGrid grid, GameShape shape)
        {
            List <Block>   shapeBlocks         = shape.CalcBlocksPostAction(action);
            List <Vector2> occupiedCoordinates = grid.GetOccupiedCoordinates();
            bool           collision           = CheckForCollisions(grid, shapeBlocks, shape);

            CheckForCollisions(grid, shape.blocks, shape);
            if (!collision)
            {
                shape.ApplyAction(action);
            }
            checkAboutToPlace(shape.blocks, shape, occupiedCoordinates);
        }
예제 #3
0
        public void PlaceShapeTest()
        {
            List <Vector2> expectedPoints;
            BlockGrid      grid = BasicBlockGridInitialize(out expectedPoints);

            //test that the all points from shapes exist on grid
            List <Vector2> points = grid.GetOccupiedCoordinates();

            foreach (Vector2 p in expectedPoints)
            {
                //check if p in expected points
                if (!points.Contains(p))
                {
                    Assert.Fail("Block at point: {0}, {1} not found on grid", p.X, p.Y);
                }
            }
        }
예제 #4
0
        public void RemoveMultipleLinesTest()
        {
            List <Vector2> expectedPoints;
            BlockGrid      grid = RemoveLinesInitialize(out expectedPoints);

            //Get indexes of lines to remove
            List <int> lineIndexes = grid.GetCompletedLines();

            //Remove lines and shift above blocks down
            grid.RemoveLines(lineIndexes);

            //check that blocks removed and remaining above blocks shifted down
            List <Vector2> points = grid.GetOccupiedCoordinates();

            foreach (Vector2 p in expectedPoints)
            {
                //check if p in expected points
                if (!points.Contains(p))
                {
                    Assert.Fail("Block at point: {0}, {1} not found on grid", p.X, p.Y);
                }
            }
        }