Beispiel #1
0
        private void OffsetPointToBlankTile(ref WrappingScreenGrid grid, MineField mineField, ref Point coordinates)
        {
            var searchCoordinates = coordinates;
            var maskIndex         = mineField.GetMaskIndex(coordinates);
            var tileFound         = false;

            for (var maxAdjacents = 1; maxAdjacents < 9; maxAdjacents++)
            {
                do
                {
                    searchCoordinates.X++;

                    if (searchCoordinates.X >= mineField.Width)
                    {
                        searchCoordinates.X = 0;
                        searchCoordinates.Y++;

                        if (searchCoordinates.Y >= mineField.Height)
                        {
                            searchCoordinates.Y = 0;
                        }

                        if (searchCoordinates.Y % BitMaskGrid.Size == 0)
                        {
                            maskIndex += mineField.MasksPerRow;
                        }
                    }

                    if (searchCoordinates.X % BitMaskGrid.Size == 0)
                    {
                        maskIndex++;

                        if (maskIndex >= mineField.MaskAmount)
                        {
                            maskIndex = 0;
                        }
                    }

                    if (!mineField.MineMasks[maskIndex][searchCoordinates.X, searchCoordinates.Y] &&
                        CalculateAdjacents(mineField, searchCoordinates) < maxAdjacents)
                    {
                        var offset = coordinates - searchCoordinates; // Swap?
                        grid.ShiftObserver(offset, out var wrappedBorder);

                        coordinates = searchCoordinates;
                        tileFound   = true;
                        break;
                    }
                } while (searchCoordinates != coordinates);

                if (tileFound)
                {
                    break;
                }
            }
        }
Beispiel #2
0
        private void RecalculateFrames(ref WrappingScreenGrid grid, MineField mineField, Point shift,
                                       Vector2 cameraPosition)
        {
            grid.ShiftObserver(shift, out var wrappedBorder);

            if (shift.X != 0)
            {
                RecalculateHorizontalFrames(ref grid, mineField, shift.X, wrappedBorder);
            }
            if (shift.Y != 0)
            {
                RecalculateVerticalFrames(ref grid, mineField, shift.Y, wrappedBorder);
            }
        }