Esempio n. 1
0
        /// <summary>
        /// Setup các cell vào board.
        /// </summary>
        public void SetupBoard(bool setup)
        {
            for (var x = 1; x <= this.Width; x++)
            {
                for (var y = 1; y <= this.Height; y++)
                {
                    if (setup == false)
                    {
                        var c = new btnCell
                        {
                            XLoc      = x - 1,
                            YLoc      = y - 1,
                            CellState = CellState.Closed,
                            CellType  = CellType.Regular,
                            CellSize  = 40,
                            Board     = this
                        };
                        c.SetHienThiCell();
                        c.MouseDown += Cell_MouseClick;
                        this.btnCells[x - 1, y - 1] = c;
                        this.pnlPlay.Controls.Add(c);
                    }
                    else
                    {
                        var c = new btnCell
                        {
                            XLoc      = x - 1,
                            YLoc      = y - 1,
                            CellState = CellState.Opened,
                            CellType  = CellType.Regular,
                            CellSize  = 40,
                            Board     = this
                        };

                        c.SetHienThiCell();
                        c.Click += SetupCell_Click;
                        this.btnCells[x - 1, y - 1] = c;
                        this.pnlPlay.Controls.Add(c);
                    }
                }
            }

            this.SoGiay = 0;
            this.PnlPlayState.Controls[3].Text = this.SoGiay.ToString();
            this.TimeRun = SetTimer();
            //this.TimeRun.Start();
            this.CorrectMines   = 0;
            this.IncorrectMines = 0;
            this.pnlPlay.SetBounds((this.pnlContain.Size.Width - this.Width * 40) / 2, (this.pnlContain.Size.Height - this.Height * 40) / 2, this.Width * 40, this.Height * 40);
            this.pnlPlay.Anchor = AnchorStyles.Top & AnchorStyles.Right & AnchorStyles.Bottom & AnchorStyles.Left;

            this.checkThua         = false;
            this.checkLuuGameThang = false;
            this.PnlPlayState.Controls[4].BackgroundImage = Image.FromFile("Images\\faceVui.PNG");
        }
Esempio n. 2
0
        //Tạo lại Board có sẵn từ database
        public void SetupBoardCoSan(List <Cell> lst, int thoiGian)
        {
            for (var x = 1; x <= this.Width; x++)
            {
                for (var y = 1; y <= this.Height; y++)
                {
                    Cell cell = lst[(x - 1) * Height + y - 1];
                    var  c    = new btnCell
                    {
                        XLoc      = x - 1,
                        YLoc      = y - 1,
                        CellState = (CellState)cell.cellState,
                        CellType  = (CellType)cell.cellType,
                        CellSize  = 40,
                        Board     = this
                    };

                    c.SetHienThiCell();
                    c.MouseDown += Cell_MouseClick;

                    this.btnCells[x - 1, y - 1] = c;
                    this.pnlPlay.Controls.Add(c);
                }
            }

            for (var x = 0; x < this.Width; x++)
            {
                for (var y = 0; y < this.Height; y++)
                {
                    this.btnCells[x, y].NumMines = this.btnCells[x, y].GetNeighborCells().Where(n => n.IsMine()).Count();
                    this.btnCells[x, y].UpdateDisplay();
                    if (this.btnCells[x, y].CellType == CellType.Mine && this.btnCells[x, y].CellState == CellState.Flag)
                    {
                        this.CorrectMines++;
                    }
                }
            }
            this.PnlPlayState.Controls[2].Text = Convert.ToString(this.NumMines - this.CorrectMines);
            this.SoGiay = thoiGian;
            this.PnlPlayState.Controls[3].Text = this.SoGiay.ToString();
            this.TimeRun = SetTimer();

            this.pnlPlay.SetBounds((this.pnlContain.Size.Width - this.Width * 40) / 2, (this.pnlContain.Size.Height - this.Height * 40) / 2, this.Width * 40, this.Height * 40);
            this.pnlPlay.Anchor = AnchorStyles.Top & AnchorStyles.Right & AnchorStyles.Bottom & AnchorStyles.Left;

            this.checkThua         = false;
            this.checkLuuGameThang = false;
            this.PnlPlayState.Controls[4].BackgroundImage = Image.FromFile("Images\\faceVui.PNG");
        }