Пример #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();
            }
        }
Пример #2
0
        //approve that the tile can be marked
        protected void ApproveTileMark(object sender, EventArgs args)
        {
            Tile temp = (Tile)sender;

            //if tile is not already marked
            if (!temp.isMarked())
            {
                if (remainingFlags > 0)
                {                //if there are remaining flags, mark the tile and update remaining flags
                    temp.Mark();
                    remainingFlags--;
                }
            }
            else
            {            //if tile is already mark, remove the flag and update remaining flags
                temp.Mark();
                remainingFlags++;
            }
            remainingFlags_l.Text = Convert.ToString(remainingFlags);            //update the remaining flags display
        }