Esempio n. 1
0
        public void StartGame()
        {
            TotalTime.Text  = GameTime.ToString();
            TotalBombs.Text = Count.ToString();

            ProgressBar.Value = 0;

            MinePanel.BackgroundImage = null;

            Dictionary <Coords, Mine> boxes = new Dictionary <Coords, Mine>();

            int a, b;

            MinePanel.Controls.Clear();
            for (a = 0; a < X; a++)
            {
                for (b = 0; b < Y; b++)
                {
                    Mine mine = new Mine(a * MineWidth, b * MineHeight, MineWidth, MineHeight, a, b);
                    MinePanel.Controls.Add(mine);
                    boxes.Add(new Coords(a, b), mine);
                }

                ProgressBar.Value = (int)Math.Round((double)50 * a / X);
            }

            Mines.Init(boxes, X, Y);

            Random random    = new Random();
            int    generated = 0;

            while (generated < Count)
            {
                a = random.Next(0, X);
                b = random.Next(0, Y);
                if (!(Mines.Boxes[new Coords(a, b)].IsBomb))
                {
                    Mines.Boxes[new Coords(a, b)].IsBomb = true;
                    generated++;
                }
                ProgressBar.Value = (int)Math.Round((double)50 * generated / Count) + 50;
            }

            Mines.Marked     = 0;
            Mines.IsFinished = false;
            Mines.IsBombed   = false;

            _GameTimeLeft = GameTime;

            if (_Timer != null)
            {
                GameTimeLeft   = GameTime;
                _Timer.Enabled = true;
                _Timer.Start();
            }
        }
Esempio n. 2
0
        private void AutoSearch()
        {
            List <Mine> neiboughers = Mines.GetNeiboughers(A, B);

            neiboughers.ForEach(x => x.FlatStyle = FlatStyle.Standard);
            if (this.Arround != 0 && this.Arround == neiboughers.Where(m => m.IsMarked && m.IsBomb).ToList <Mine>().Count&& this.Arround == neiboughers.Where(m => m.IsMarked).ToList <Mine>().Count)
            {
                neiboughers.ForEach(x => x.AutoOpen());
            }
        }
Esempio n. 3
0
        public void Check()
        {
            if (Mines.IsFinished)
            {
                return;
            }

            if (!this.IsBomb && !this.IsOpened && this.Arround == 0)
            {
                this.Open();
                Mines.GetNeiboughers(A, B).ForEach(x => x.Check());
            }
        }
Esempio n. 4
0
        private void MineLeftClick(object sender, MouseEventArgs e)
        {
            if (Mines.IsFinished)
            {
                return;
            }

            this.Check();
            this.Open();


            if (this.IsBomb)
            {
                Mines.OpenAll();
                this.BackColor   = Color.Red;
                Mines.IsFinished = true;
                Mines.IsBombed   = true;
            }
        }
Esempio n. 5
0
        private void Mine_MouseUp(object sender, MouseEventArgs e)
        {
            if (Mines.IsFinished)
            {
                return;
            }

            if (IsLeftPressed && IsRightPressed)
            {
                List <Mine> neiboughers = Mines.GetNeiboughers(A, B);
                neiboughers.Where(x => !x.IsOpened).ToList <Mine>().ForEach(x => x.FlatStyle = FlatStyle.Popup);
            }

            if (IsLeftPressed != IsRightPressed)
            {
                IsLeftPressed  = false;
                IsRightPressed = false;
            }
        }