Esempio n. 1
0
        //recursively loop through all neighbour empty tiles and open them
        private void OpenEmptyRecursive(Tile tile)
        {
            if (!tile.isEmpty() && !tile.isMarked())
            {            //if tile is not empty, open it and return
                tile.Open();
                return;
            }
            else if (tile.BeingProcessed || tile.isMarked())            //if tile is marked and being processed, stop processing it
            {
                return;
            }

            //set tile to being processed
            tile.BeingProcessed = true;

            //process tiles in all 8 directions
            if (tile.GridCoords.X - 1 > -1)
            {
                OpenEmptyRecursive(gameFieldTiles.ElementAt(tile.GridCoords.Y).ElementAt(tile.GridCoords.X - 1));
            }
            if (tile.GridCoords.X - 1 > -1 && tile.GridCoords.Y - 1 > -1)
            {
                OpenEmptyRecursive(gameFieldTiles.ElementAt(tile.GridCoords.Y - 1).ElementAt(tile.GridCoords.X - 1));
            }
            if (tile.GridCoords.Y - 1 > -1)
            {
                OpenEmptyRecursive(gameFieldTiles.ElementAt(tile.GridCoords.Y - 1).ElementAt(tile.GridCoords.X));
            }
            if (tile.GridCoords.Y - 1 > -1 && tile.GridCoords.X + 1 < gameFieldTiles.ElementAt(1).Count)
            {
                OpenEmptyRecursive(gameFieldTiles.ElementAt(tile.GridCoords.Y - 1).ElementAt(tile.GridCoords.X + 1));
            }
            if (tile.GridCoords.X + 1 < gameFieldTiles.ElementAt(1).Count)
            {
                OpenEmptyRecursive(gameFieldTiles.ElementAt(tile.GridCoords.Y).ElementAt(tile.GridCoords.X + 1));
            }
            if (tile.GridCoords.X + 1 < gameFieldTiles.ElementAt(1).Count&& tile.GridCoords.Y + 1 < gameFieldTiles.Count)
            {
                OpenEmptyRecursive(gameFieldTiles.ElementAt(tile.GridCoords.Y + 1).ElementAt(tile.GridCoords.X + 1));
            }
            if (tile.GridCoords.X < gameFieldTiles.ElementAt(1).Count&& tile.GridCoords.Y + 1 < gameFieldTiles.ElementAt(1).Count)
            {
                OpenEmptyRecursive(gameFieldTiles.ElementAt(tile.GridCoords.Y + 1).ElementAt(tile.GridCoords.X));
            }
            if (tile.GridCoords.X - 1 > -1 && tile.GridCoords.Y + 1 < gameFieldTiles.ElementAt(1).Count)
            {
                OpenEmptyRecursive(gameFieldTiles.ElementAt(tile.GridCoords.Y + 1).ElementAt(tile.GridCoords.X - 1));
            }

            //open the tile if its not marked and not a mine
            if (!tile.isMarked() && !tile.isMine)
            {
                tile.Open();
            }
        }