Ejemplo n.º 1
0
 int CountAdjacentMarkedCells(Point position)
 {
     int result = 0;
     EachAdjacentCells(position, positionAdjacent => {
         CellView cell = GetCell(positionAdjacent);
         if (cell.IsMark) {
             result++;
         }
     });
     return result;
 }
Ejemplo n.º 2
0
 void OpenAdjacentCells(Point position, bool checkMine = false)
 {
     EachAdjacentCells(position, positionAdjacent => {
         CellView cell = GetCell(positionAdjacent);
         if (!cell.IsMark) {
             if (checkMine && cell.IsMine) {
                 cell.IsExplode = true;
             }
             cell.IsOpen = true;
         }
     });
 }
Ejemplo n.º 3
0
 void CellPropertyChanged(Object sender, PropertyChangedEventArgs e)
 {
     CellView cell = (CellView)sender;
     switch (e.PropertyName) {
         case nameof(CellView.IsExplode):
             game.GameOver();
             break;
         case nameof(CellView.IsOpen):
             if (cell.AdjacentMines == 0) {
                 OpenAdjacentCells(cell.Position);
             }
             game.CheckVictory();
             break;
     }
 }
Ejemplo n.º 4
0
 public MyList<CellView> GenerateGrid()
 {
     Cells.Clear();
     List<CellView> cells = new List<CellView>();
     for (int widthIterator = 0; widthIterator < settings.WidthArea; widthIterator++) {
         for (int heightIterator = 0; heightIterator < settings.HeightArea; heightIterator++) {
             Point currentCellPosition = new Point(widthIterator, heightIterator);
             CellView cell = new CellView() {
                 IsMine = game.CheckMine(currentCellPosition),
                 AdjacentMines = GetBombsCount(currentCellPosition),
                 Position = currentCellPosition
             };
             cell.PropertyChanged += CellPropertyChanged;
             cells.Add(cell);
         }
     }
     Cells.AddRange(cells);
     return Cells;
 }