Exemplo n.º 1
0
        public void OnNewGame(object sender, EventArgs e)
        {
            MaximumSize = new Size(0, 0);
            MinimumSize = new Size(0, 0);
            _buttons    = new List <MineButton>();
            flp_field.Controls.Clear();
            gameOver = false;
            var tmp              = Template.GetInstance;
            var size             = tmp.GetButtonSize();
            var FieldButtonCount = _presenter.SizeX * _presenter.SizeY;
            var fieldWidth       = size.Width * _presenter.SizeX;
            var fieldHeight      = size.Height * _presenter.SizeY;

            Size = new Size(fieldWidth + 45, fieldHeight + 95);
            for (var i = 0; i < FieldButtonCount; i++)
            {
                var btn = new MineButton();
                btn.PosY       = i / _presenter.SizeX;
                btn.PosX       = i % _presenter.SizeX;
                btn.MouseDown += Btn_MouseClick;
                tmp.SetUnmarkedButtonView(btn);
                flp_field.Controls.Add(btn);
                _buttons.Add(btn);
            }
            MaximumSize = Size;
            MinimumSize = Size;
        }
Exemplo n.º 2
0
 internal void SetSuspiciousButtonView(MineButton btn)
 {
     btn.Size      = GetButtonSize();
     btn.FlatStyle = btn_suspicious.FlatStyle;
     btn.Text      = btn_suspicious.Text;
     btn.BackColor = btn_suspicious.BackColor;
     btn.Margin    = new Padding(0);
     btn.Padding   = new Padding(0);
 }
Exemplo n.º 3
0
 public void SetMarkedAsMineButtonView(MineButton btn)
 {
     btn.Size      = GetButtonSize();
     btn.FlatStyle = MineMarkAsMine.FlatStyle;
     btn.Text      = MineMarkAsMine.Text;
     btn.BackColor = MineMarkAsMine.BackColor;
     btn.Margin    = new Padding(0);
     btn.Padding   = new Padding(0);
 }
Exemplo n.º 4
0
 internal void SetExplodedPressedButtonView(MineButton btn)
 {
     btn.Size      = GetButtonSize();
     btn.FlatStyle = btn_exploded_pressed.FlatStyle;
     btn.Text      = btn_exploded_pressed.Text;
     btn.BackColor = btn_exploded_pressed.BackColor;
     btn.Margin    = new Padding(0);
     btn.Padding   = new Padding(0);
 }
Exemplo n.º 5
0
        private IEnumerable <MineButton> GetNearButtons(MineButton btn)
        {
            var fromX = btn.PosX - 1;
            var toX   = btn.PosX + 1;
            var fromY = btn.PosY - 1;
            var toY   = btn.PosY + 1;

            return(_buttons.Where(x => x.PosX >= fromX && x.PosX <= toX && x.PosY >= fromY && x.PosY <= toY));
        }
Exemplo n.º 6
0
        public void SetDeactivatedButtonView(MineButton btn)
        {
            btn.Size      = GetButtonSize();
            btn.FlatStyle = btn_deactivated.FlatStyle;
            btn.Font      = btn_deactivated.Font;
            btn.FlatAppearance.BorderColor = Color.FromArgb(255, 235, 204, 172);
            btn.FlatAppearance.BorderSize  = 1;
            if (btn.NearMinesCount == 0)
            {
                btn.Text      = "";
                btn.ForeColor = Color.Black;
            }
            else
            {
                btn.Text = btn.NearMinesCount.ToString();
                switch (btn.NearMinesCount)
                {
                case 1: btn.ForeColor = Color.Blue; break;

                case 2: btn.ForeColor = Color.ForestGreen; break;

                case 3: btn.ForeColor = Color.Red; break;

                case 4: btn.ForeColor = Color.DarkBlue; break;

                case 5: btn.ForeColor = Color.DarkRed; break;

                case 6: btn.ForeColor = Color.Cyan; break;

                case 7: btn.ForeColor = Color.Magenta; break;

                case 8: btn.ForeColor = Color.Black; break;
                }
            }

            btn.BackColor = btn_deactivated.BackColor;
            btn.Margin    = new Padding(0);
            btn.Padding   = new Padding(0);
        }
Exemplo n.º 7
0
        private void RightButtonClick(MineButton btn)
        {
            switch (btn.State)
            {
            case MineButtonState.UnMarked:
                _presenter.MarkMine(btn.PosX, btn.PosY, MineButtonState.MarkAsMine);
                break;

            case MineButtonState.Suspicious:
                _presenter.MarkMine(btn.PosX, btn.PosY, MineButtonState.UnMarked);
                break;

            case MineButtonState.MarkAsMine:
                _presenter.MarkMine(btn.PosX, btn.PosY, MineButtonState.Suspicious);
                break;

            case MineButtonState.Deactivated:
                _presenter.FastOpenCells(btn.PosX, btn.PosY);
                HighlightNearCells(btn);
                break;
            }
        }
Exemplo n.º 8
0
        private void HighlightNearCells(MineButton btn)
        {
            var near = GetNearButtons(btn);
            var mam  = near.Count(x => x.State == MineButtonState.MarkAsMine);

            foreach (var item in near)
            {
                if (item.State != MineButtonState.Deactivated && item.State != MineButtonState.MarkAsMine)
                {
                    if (item.State == MineButtonState.UnMarked)
                    {
                        item.Text = (btn.NearMinesCount - mam).ToString();
                    }
                    item.FlatStyle = FlatStyle.Flat;
                }
            }
            MouseEventHandler handle = (s, a) => { };

            handle = (s, a) =>
            {
                foreach (var item in near)
                {
                    if (item.State != MineButtonState.Deactivated)
                    {
                        item.FlatStyle = FlatStyle.Standard;
                        if (item.State == MineButtonState.UnMarked)
                        {
                            item.Text = "";
                        }
                    }
                }

                btn.MouseUp -= handle;
            };
            btn.MouseUp += handle;
        }