Example #1
0
        private void OnCellOpened(SapperCell opened)
        {
            if (opened.IsBomb)
            {
                Object.Instantiate(
                    Resources.Load <GameObject>(ExplosionPrefabPath),
                    opened.transform.position,
                    Quaternion.identity)
                .DestroyAsVisualEffect();

                Fail();

                this.character.GetComponent <ActorComponent>().PlayAnimation("death");
                return;
            }

            var cells = BoardNavigator.Instance.WithinCircle(opened.transform.position, 1).Walkable();

            foreach (var cell in cells)
            {
                var sapperCell = CellAt(cell.transform.position);

                if (sapperCell.IsBomb)
                {
                    continue;
                }

                if (sapperCell.BombsNearby > 0)
                {
                    sapperCell.OpenSilently();
                }
                else
                {
                    sapperCell.Open();
                }
            }
        }
Example #2
0
        private void gameFieldDataGridView_CellPainting(object sender, DataGridViewCellPaintingEventArgs e)
        {
            string content;
            //отрисовка фона
            SapperCell cell = game.Field[e.RowIndex, e.ColumnIndex];

            e.CellStyle.BackColor = cell.state == CellState.OPEN ? Color.White : Color.LightGray;
            if (cell.state == CellState.OPEN && cell.mine)
            {
                e.CellStyle.BackColor = Color.Black;
            }
            e.PaintBackground(e.CellBounds, false);
            g = e.Graphics;
            Rectangle rect = e.CellBounds;
            Point     p0   = rect.Location;
            Point     p1   = new Point(p0.X + 5, p0.Y + 1);

            //отрисовка цифр
            if (cell.state == CellState.OPEN && cell.mine == false && cell.aroundMinesCount != 0)
            {
                content = Convert.ToString(cell.aroundMinesCount);
                e.Graphics.DrawString(content, gameFieldDataGridView.Font, Brushes.Black, e.CellBounds, cellStringFormat);
            }
            if (cell.state == CellState.OPEN && cell.mine == false && cell.aroundMinesCount == 0)
            {
                content = "";
                e.Graphics.DrawString(content, gameFieldDataGridView.Font, Brushes.Black, e.CellBounds, cellStringFormat);
            }
            if (cell.state == CellState.OPEN && cell.mine == true)//проигрыш
            {
                content = "*";
                e.Graphics.DrawString(content, gameFieldDataGridView.Font, Brushes.Red, e.CellBounds, cellStringFormat);
            }
            //отрисовка флага
            if (cell.state == CellState.FLAG)
            {
                PointF   point1 = new PointF(p0.X + 3, p0.Y + 3);
                PointF   point2 = new PointF(p0.X + 3, p0.Y + 10);
                PointF   point3 = new PointF(p0.X + CELL_SIZE - 5, p0.Y + 5);
                PointF[] points =
                {
                    point1, point2, point3
                };
                g.DrawLine(Pens.Black, p0.X + 3, p0.Y + 3, p0.X + 4, p0.Y + CELL_SIZE - 2);
                g.DrawPolygon(Pens.Red, points);
                g.FillPolygon(Brushes.Red, points);
            }
            //отрисовка вопроса
            if (cell.state == CellState.PROBLEM)
            {
                content = "?";
                e.Graphics.DrawString(content, gameFieldDataGridView.Font, Brushes.Black, e.CellBounds, cellStringFormat);
                cell.state = CellState.HIDDEN;
            }
            if (cell.state == CellState.REHIDDEN)
            {
                content = "";
                e.Graphics.DrawString(content, gameFieldDataGridView.Font, Brushes.Black, e.CellBounds, cellStringFormat);
            }
            //сообщаем, что ячейка грида полностью отрисована
            e.Handled = true;
        }