Пример #1
0
 private static void RevealAdjacentBlankTiles(ITileSimulation tile)
 {
     foreach (ITileSimulation t in BoardRevealer.GetAdjacentTiles(tile))
     {
         t.ForceReveal();
     }
 }
Пример #2
0
        void IBoardSimulation.OnTileFlagged(ITileSimulation tile)
        {
            // Bump game simulation
            _game.OnGameInput();

            if (tile.isFlagged)
            {
                flagsRemaining--;

                // Are we out of flags? If so, check for victory
                if (flagsRemaining == 0)
                {
                    if (Game.Game.CheckVictoryConditions(this))
                    {
                        ((IGameSimulation)_game).GameWon();
                    }
                }
            }
            else
            {
                flagsRemaining++;
            }

            // Update flags in game
            _game.currentData.flagsRemaining = flagsRemaining;
        }
Пример #3
0
        public static List <ITileSimulation> GetAdjacentTiles(ITileSimulation sourceTile)
        {
            checkedTiles = new List <ITileSimulation> {
                sourceTile
            };
            revealTiles = new List <ITileSimulation> {
                sourceTile
            };
            CollectAdjacentBlankTiles(sourceTile);
            revealTiles = GetBorderTiles(revealTiles);

            return(revealTiles);
        }
Пример #4
0
 private static void CollectAdjacentBlankTiles(ITileSimulation sourceTile)
 {
     checkedTiles.Add(sourceTile);
     foreach (ITileSimulation tile in sourceTile.neighbors)
     {
         if (tile != null &&
             tile.tileType == Tile.Tile.TileType.Blank)
         {
             if (!checkedTiles.Contains(tile))
             {
                 CollectAdjacentBlankTiles(tile);
                 revealTiles.Add(tile);
             }
         }
     }
 }
Пример #5
0
        void IBoardSimulation.OnTileSelected(ITileSimulation tile)
        {
            // Bump game simulation
            _game.OnGameInput();

            // What was the tile type we selected?
            if (tile.tileType == Tile.Tile.TileType.Bomb)
            {
                RevealAllBombs(tiles);
                ((IGameSimulation)_game).GameLost();
            }
            else if (tile.tileType == Tile.Tile.TileType.Blank)
            {
                RevealAdjacentBlankTiles(tile);
            }
        }
        public static ITileSimulation[] GetNeighborTiles(
            ITileSimulation sourceTile,
            ITileSimulation[,] board,
            int boardWidth,
            int boardHeight)
        {
            ITileSimulation[] neighbors = new ITileSimulation[8];
            neighbors[0] = GetTileForIndex(GetNWNeighborIndex(sourceTile.boardIndex, boardHeight), board);
            neighbors[1] = GetTileForIndex(GetNNeighborIndex(sourceTile.boardIndex, boardHeight), board);
            neighbors[2] = GetTileForIndex(GetNENeighborIndex(sourceTile.boardIndex, boardWidth, boardHeight), board);
            neighbors[3] = GetTileForIndex(GetENeighborIndex(sourceTile.boardIndex, boardWidth, boardHeight), board);
            neighbors[4] = GetTileForIndex(GetSENeighborIndex(sourceTile.boardIndex, boardWidth, boardHeight), board);
            neighbors[5] = GetTileForIndex(GetSNeighborIndex(sourceTile.boardIndex, boardHeight), board);
            neighbors[6] = GetTileForIndex(GetSWNeighborIndex(sourceTile.boardIndex, boardHeight), board);
            neighbors[7] = GetTileForIndex(GetWNeighborIndex(sourceTile.boardIndex, boardHeight), board);

            return(neighbors);
        }
        private static ITileSimulation GetTileForIndex(int index, ITileSimulation[,] boardTiles)
        {
            if (index == -1)
            {
                return(null);
            }

            ITileSimulation instance = null;

            foreach (var square in boardTiles)
            {
                if (square.boardIndex == index)
                {
                    instance = square;
                    break;
                }
            }
            return(instance);
        }
Пример #8
0
        public Board(
            BoardData inData,
            Game.Game inGame,
            int seed)
        {
            // Set data
            boardSize = new Tuple <int, int>(inData.xSize, inData.ySize);
            _game     = inGame;

            // Create board tiles
            tiles = new ITileSimulation[inData.xSize, inData.ySize];
            int runningIndex = 0;

            for (int i = 0; i < inData.xSize; i++)
            {
                for (int e = 0; e < inData.ySize; e++)
                {
                    tiles[i, e] = new Tile.Tile(this)
                    {
                        boardPosition = new Tuple <int, int>(i, e),
                        boardIndex    = runningIndex
                    };
                    runningIndex++;
                }
            }

            // Distribute bombs amongst tiles
            totalBombs     = DistributeBombs(inData.bombProbability, tiles, seed);
            flagsRemaining = totalBombs;

            // Assign "neighbor numbers"
            SetNeighborNumbers(tiles, inData.xSize, inData.ySize);

            // Tiles are finished setting up
            OnBoardSetupComplete(tiles);
        }