Beispiel #1
0
        private void createGrid(int mapID)
        {
            presetID = mapID;
            //creating empty field

            cells = new Cell[rowsCount, columnsCount];
            for (int i = 0; i < rowsCount; i++)
            {
                for (int j = 0; j < columnsCount; j++)
                {
                    var cell = new Cell(i, j, BRICK_WIDTH, BRICK_HEIGHT);
                    cell.cleared += onCellCleared;
                    cells[i, j] = cell;
                }
            }

            //fill it with cells
            string[] presetData = roomLink.maps.getMapCode(mapID).Split(new[] {'|'});
            int cellI = 0;
            int cellJ = 0;
            int brickID = 0;
            for (int i = 0; i < presetData.Length; i++)
            {
                string[] cellData = presetData[i].Split(new[] {','});
                cellJ = Convert.ToInt16(cellData[0]);
                cellI = Convert.ToInt16(cellData[1]);
                brickID = Convert.ToInt16(cellData[2]);
                cells[cellI, cellJ].attachBrick(brickID);
            }
        }
        public AroundCellData(Cell[,] cells, int currentCellI, int currentCellJ, FieldSimulation field)
        {
            if (currentCellI < 0 || currentCellJ < 0 || currentCellI >= field.fieldCells.columnsCount ||
                currentCellJ >= field.fieldCells.rowsCount) //out of the "box"
            {
                leftBorderNearby = rightBorderNearby = topBorderNearby = bottomBorderNearby = true;
                return;
            }

            topBorderNearby = (currentCellJ - 1) < 0;
            bottomBorderNearby = (currentCellJ + 1) >= field.fieldCells.rowsCount;
            rightBorderNearby = (currentCellI + 1) >= field.fieldCells.columnsCount;
            leftBorderNearby = (currentCellI - 1) < 0;

            //Testing 1 cell down
            if (!bottomBorderNearby && cells[currentCellJ + 1, currentCellI].notEmpty)
                _cells.Add(cells[currentCellJ + 1, currentCellI]);

            //		//Testing 1 cell right, 1 cell down
            if (!bottomBorderNearby && !rightBorderNearby && cells[currentCellJ + 1, currentCellI + 1].notEmpty)
                _cells.Add(cells[currentCellJ + 1, currentCellI + 1]);

            //Testing 1 cell right
            if (!rightBorderNearby && cells[currentCellJ, currentCellI + 1].notEmpty)
                _cells.Add(cells[currentCellJ, currentCellI + 1]);

            //		//Testing 1 cell up, 1 cell down
            if (!rightBorderNearby && !topBorderNearby && cells[currentCellJ - 1, currentCellI + 1].notEmpty)
                _cells.Add(cells[currentCellJ - 1, currentCellI + 1]);

            //Testing 1 cell up
            if (!topBorderNearby && cells[currentCellJ - 1, currentCellI].notEmpty)
                _cells.Add(cells[currentCellJ - 1, currentCellI]);

            //		//Testing 1 cell left, 1 cell up
            if (!leftBorderNearby && !topBorderNearby && cells[currentCellJ - 1, currentCellI - 1].notEmpty)
                _cells.Add(cells[currentCellJ - 1, currentCellI - 1]);

            //Testing 1 cell left
            if (!leftBorderNearby && cells[currentCellJ, currentCellI - 1].notEmpty)
                _cells.Add(cells[currentCellJ, currentCellI - 1]);

            //		//Testing 1 cell down, 1 cell left
            if (!topBorderNearby && !leftBorderNearby && field.fieldCells.rowsCount > currentCellJ + 1 &&
                cells[currentCellJ + 1, currentCellI - 1].notEmpty)
                _cells.Add(cells[currentCellJ + 1, currentCellI - 1]);

            if (cells[currentCellJ, currentCellI].notEmpty) //cell in which ball is (it could be skipped before)
                _cells.Add(cells[currentCellJ, currentCellI]);
        }
 private static bool ballInYTunnel(Cell cell, Ball ball)
 {
     return ball.y >= cell.y && ball.y <= (cell.y + GameConfig.BRICK_HEIGHT);
 }
 private static bool ballInXTunnel(Cell cell, Ball ball)
 {
     return ball.x >= cell.x && ball.x <= (cell.x + GameConfig.BRICK_WIDTH);
 }