Example #1
0
        public void TryExpandZeroSquares(Point squareCoordinates)
        {
            MineCell startingSquare = mines.ElementAt(squareCoordinates);

            if (startingSquare.NeighbouringBombsCount == 0)
            {
                Queue <MineCell> zeroBombNeighboursSquares = new Queue <MineCell>(mines.Length >> 1);
                zeroBombNeighboursSquares.Enqueue(startingSquare);
                while (zeroBombNeighboursSquares.Count != 0 && !GameOver)
                {
                    MineCell currentSquare = zeroBombNeighboursSquares.Dequeue();
                    currentSquare.State = MineCellState.Opened;
                    foreach (MineCell neighbour in mines.EnumerateNeighbours(currentSquare.FieldLocation))
                    {
                        if (!neighbour.Opened)
                        {
                            neighbour.State = MineCellState.Opened;
                            if (neighbour.NeighbouringBombsCount == 0)
                            {
                                zeroBombNeighboursSquares.Enqueue(neighbour);
                            }
                        }
                    }
                }
            }
        }
Example #2
0
 protected static void OnButtonDown(MineCell obj)
 {
     if (!obj.Opened && !obj.Defused)
     {
         obj.Image = CellImagesProvider.Pressed;
     }
 }
Example #3
0
 public void DrawCells()
 {
     if (!initializing)
     {
         SuspendLayout();
         NormalizeSize();
         mines        = new MineCell[Columns, Rows];
         minesHashSet = new HashSet <MineCell>();
         for (int y = 0; y < Rows; y++)
         {
             for (int x = 0; x < Columns; x++)
             {
                 MineCell newMine = new MineCell();
                 newMine.ControlLocation             = new Point(locationOffset.X + (x << 4), locationOffset.Y + (y << 4));
                 newMine.FieldLocation               = new Point(x, y);
                 newMine.NeighbouringBombsEnumerator = GetNeighbouringBombsCount;
                 newMine.ParentBoard   = this;
                 newMine.StateChanged += new System.Action <MineCell>(OnMineCellStateChanged);
                 mines[x, y]           = newMine;
                 minesHashSet.Add(newMine);
                 Controls.Add(newMine);
             }
         }
         PerformLayout();
         ResumeLayout();
     }
 }
Example #4
0
 protected static void OnButtonUp(MineCell obj)
 {
     if (!obj.Opened && !obj.Defused)
     {
         obj.Image = CellImagesProvider.Default;
     }
 }
Example #5
0
        protected void OnMineCellStateChanged(MineCell obj)
        {
            switch (obj.State)
            {
            case MineCellState.Exploded: HandleExplosion(); break;

            case MineCellState.Opened: HandleSquareOpened(); break;

            case MineCellState.Defused: HandleSquareDefused(); break;

            case MineCellState.Closed: HandleSquareRestored(); break;
            }

            TryDeclareAutoVictory();
        }