Esempio n. 1
0
 public MineSweeper(int height, int width, int numberOfMines, int squareWidth, GraphicTools graphicTools)
 {
     this._height       = height;
     this._width        = width;
     this.NumberOfMines = numberOfMines;
     this.SquareWidth   = squareWidth;
     this._graphicTools = graphicTools;
     this._fields       = new Field[height, width];
     Form();
 }
Esempio n. 2
0
        private void startBTN_Click(object sender, EventArgs e)
        {
            if (beginnerRB.Checked)
            {
                _height        = 9;
                _width         = 9;
                _numberOfMines = 10;
            }
            if (intermediateRB.Checked)
            {
                _height        = 16;
                _width         = 16;
                _numberOfMines = 40;
            }
            if (expertRB.Checked)
            {
                _height        = 16;
                _width         = 30;
                _numberOfMines = 99;
            }

            _opening  = true;
            _gameOver = false;
            _numberOfFlaggedFields = 0;
            minesRemainingLBL.Text = (_numberOfMines - _numberOfFlaggedFields).ToString();
            timer1.Stop();
            timeLBL.Text = "000";
            int distanceFromTopOfForm = 100;

            pictureBox1.SetBounds(
                x: ClientRectangle.Width / 2 - _width * _squareWidth / 2,
                y: distanceFromTopOfForm + ((ClientRectangle.Height - distanceFromTopOfForm) - _height * _squareWidth) / 2,
                width: _width * _squareWidth,
                height: _height * _squareWidth);
            pictureBox1.Refresh();
            var graphicTools = new GraphicTools(pictureBox1.CreateGraphics(), new Pen(Color.Gray, 2),
                                                new SolidBrush(Color.LightSlateGray), new SolidBrush(Color.DarkGray));

            _mineSweeper = new MineSweeper(_height, _width, _numberOfMines, _squareWidth, graphicTools);
            _mineSweeper.Show();
        }
Esempio n. 3
0
        public void Show(GraphicTools graphicTools)
        {
            if (Open)
            {
                graphicTools.Graphic.FillRectangle(graphicTools.OpenField, X, Y, Width, Width);
                if (SurroundingMines > 0)
                {
                    Color fontColor;
                    switch (SurroundingMines)
                    {
                    case 1:
                        fontColor = Color.Blue;
                        break;

                    case 2:
                        fontColor = Color.Green;
                        break;

                    case 3:
                        fontColor = Color.Red;
                        break;

                    case 4:
                        fontColor = Color.DarkBlue;
                        break;

                    case 5:
                        fontColor = Color.DarkRed;
                        break;

                    case 6:
                        fontColor = Color.DarkGreen;
                        break;

                    case 7:
                        fontColor = Color.Black;
                        break;

                    case 8:
                        fontColor = Color.DarkSlateGray;
                        break;

                    default:
                        fontColor = Color.White;
                        break;
                    }

                    Font myFont = new Font("Arial", Width / 2f);
                    graphicTools.Graphic.DrawString(SurroundingMines.ToString(), myFont, new SolidBrush(fontColor), X + Width / 6, Y + Width / 6);
                }
            }
            if (!Open)
            {
                graphicTools.Graphic.FillRectangle(graphicTools.ClosedField, X, Y, Width, Width);
            }
            if (Flagged)
            {
                var flag = new[]
                {
                    new Point(X + Width / 6, Y + 2 * Width / 6),
                    new Point(X + 5 * Width / 6, Y + Width / 6),
                    new Point(X + 5 * Width / 6, Y + Width / 2)
                };
                graphicTools.Graphic.FillPolygon(graphicTools.Red, flag);
                graphicTools.Graphic.DrawLine(graphicTools.BlackPen, X + 5 * Width / 6, Y + Width / 6, X + 5 * Width / 6,
                                              Y + 5 * Width / 6);
            }

            //drawing square around field
            graphicTools.Graphic.DrawLine(graphicTools.Pen, X, Y, X + Width, Y);
            graphicTools.Graphic.DrawLine(graphicTools.Pen, X, Y, X, Y + Width);
            graphicTools.Graphic.DrawLine(graphicTools.Pen, X + Width, Y + Width, X + Width, Y);
            graphicTools.Graphic.DrawLine(graphicTools.Pen, X + Width, Y + Width, X, Y + Width);
        }