Ejemplo n.º 1
0
        public void OpenCell(Сell field)
        {
            if (Status == GameStatus.Play)
            {
                if (field.Status == CellStatus.Mark)
                {
                    Marks.AddClick(field);
                }
                else if (!Mines.IsPresent(field))
                {
                    AddVisibleСell(field);

                    if (VisibleСells.IsCompleted(Size, CountMines))
                    {
                        Status = GameStatus.Victory;
                        VisibleMarkMine();
                        VisibleСells.Add(Mines);
                    }
                }
                else
                {
                    Status = GameStatus.GameOver;
                    VisibleСells.Add(new CellExplosion(field));
                    VisibleMarkMine();
                    VisibleСells.Add(Mines);
                }
            }
        }
Ejemplo n.º 2
0
        private void VisibleMarkMine()
        {
            var markMineList = new ListСell();

            foreach (Сell fieldIntersection in ListСell.Intersection(Marks, Mines))
            {
                markMineList.Add(new CellMine(fieldIntersection, true));
            }

            VisibleСells.Add(markMineList);
        }
Ejemplo n.º 3
0
        private int CountMineAroundCell(Сell field)
        {
            var aroundCells = VisibleСells.GetAroundCellsNoTags(field, Size);
            var countMine   = 0;

            foreach (Сell acell in aroundCells)
            {
                if (Mines.IsPresent(acell))
                {
                    countMine++;
                }
            }

            return(countMine);
        }
Ejemplo n.º 4
0
 public Сell this[int row, int column]
 {
     get
     {
         if (VisibleСells.IsPresent(new Сell(row, column)))
         {
             return(VisibleСells[row, column]);
         }
         else if (Marks.IsPresent(new Сell(row, column)))
         {
             return(Marks[row, column]);
         }
         else
         {
             return(new CellAbsent(new Сell(row, column)));
         }
     }
 }
Ejemplo n.º 5
0
        private void AddVisibleСell(Сell field)
        {
            var countMine = CountMineAroundCell(field);

            if (countMine == 0)
            {
                VisibleСells.Add(new Сell(field.Row, field.Column));

                var aroundCells = VisibleСells.GetAroundCellsNoTags(field, Size);
                foreach (Сell acell in aroundCells)
                {
                    AddVisibleСell(acell);
                }
            }
            else
            {
                VisibleСells.Add(new CellValue(field, countMine));
            }
        }