예제 #1
0
        public Form1()
        {
            InitializeComponent();

            this.ClientSize = new Size(MineBotton.widthAdHeight * buttonXCount, MineBotton.widthAdHeight * buttonYCount);

            List <MineBotton> mineButtons = GetMineButtons(buttonXCount, buttonYCount, mineCount);

            for (int i = 0; i < buttonXCount; i++)
            {
                for (int j = 0; j < buttonYCount; j++)
                {
                    MineBotton button = mineButtons.FirstOrDefault(t => t.PositionX == i && t.PositionY == j);
                    buttons.Add(button ?? new MineBotton(i, j, false));
                }
            }

            foreach (var button in buttons)
            {
                for (int i = 0; i < 9; i++)
                {
                    int xOffset = i % 3 - 1;
                    int yOffset = i / 3 - 1;
                    if (!(xOffset == 0 && yOffset == 0))
                    {
                        RegisteAndSetMineCount(button.PositionX + xOffset, button.PositionY + yOffset, button);
                    }
                }
            }

            this.Controls.AddRange(buttons.ToArray());
        }
예제 #2
0
        private MineBotton GetBttonByPosition(int x, int y)
        {
            MineBotton mineButton = null;

            if (x >= 0 && x < this.buttonXCount &&
                y >= 0 && x < this.buttonYCount)
            {
                mineButton = this.buttons.FirstOrDefault(b => b.PositionX == x && b.PositionY == y);
            }

            return(mineButton);
        }
예제 #3
0
        private void RegisteAndSetMineCount(int x, int y, MineBotton registerToButton)
        {
            MineBotton mineButton = GetBttonByPosition(x, y);

            if (mineButton != null)
            {
                mineButton.RegisterShowStatusToButton(registerToButton);

                if (registerToButton.IsMine)
                {
                    mineButton.AddMineAroundAccount();
                }
            }
        }
예제 #4
0
 public void RegisterShowStatusToButton(MineBotton button)
 {
     button.ButtonArroundShowStatusEventHandler += this.ShowStatus;
 }