Ejemplo n.º 1
0
        private void AddJigButtons()
        {
            int cnt = 0;

            this.lstButtons = new List <JigButton>();
            this.panel1.Controls.Clear();
            for (int j = 0; j < this.level; j++)
            {
                for (int i = 0; i < this.level; i++)
                {
                    JigButton btn = new JigButton(new Point(i, j));
                    btn.Size   = btnSize;
                    btn.Text   = (++cnt).ToString();
                    btn.Click += Btn_Click;
                    btn.Left   = 10 + i * btnSize.Width;
                    btn.Top    = 10 + j * btnSize.Height;
                    this.lstButtons.Add(btn);
                    this.panel1.Controls.Add(btn);
                }
            }
            JigButton last = this.lstButtons.Last();

            this.panel1.Controls.Remove(last);
            this.lstButtons.Remove(last);
            this.btnsCount  = this.level * this.level - 1;
            this.blankPoint = new Point(this.level - 1, this.level - 1);
        }
Ejemplo n.º 2
0
        private void Shuffle()
        {
            Random r          = new Random();
            var    randPoints = this.lstButtons.Select(x => x.CurPoint)
                                .OrderBy(x => r.Next()).ToArray();

            for (int i = 0; i < btnsCount; i++)
            {
                JigButton btn = this.lstButtons[i];
                Point     p   = randPoints[i];
                btn.ShuffleTo(p);
                btn.Left = 10 + p.X * btnSize.Width;
                btn.Top  = 10 + p.Y * btnSize.Height;
            }
            this.stepsCount = 0;
        }
Ejemplo n.º 3
0
        private void Btn_Click(object sender, EventArgs e)
        {
            JigButton btn = sender as JigButton;

            if (btn.CurPoint.X == this.blankPoint.X)
            {
                if (btn.CurPoint.Y == this.blankPoint.Y - 1)
                {
                    this.blankPoint = btn.MoveStep(0, 1);
                    this.stepsCount++;
                }
                else if (btn.CurPoint.Y == this.blankPoint.Y + 1)
                {
                    this.blankPoint = btn.MoveStep(0, -1);
                    this.stepsCount++;
                }
            }
            else if (btn.CurPoint.Y == this.blankPoint.Y)
            {
                if (btn.CurPoint.X == this.blankPoint.X - 1)
                {
                    this.blankPoint = btn.MoveStep(1, 0);
                    this.stepsCount++;
                }
                else if (btn.CurPoint.X == this.blankPoint.X + 1)
                {
                    this.blankPoint = btn.MoveStep(-1, 0);
                    this.stepsCount++;
                }
            }
            this.lblSteps.Text = "步数:" + this.stepsCount.ToString();
            if (this.CheckSucceed())
            {
                MessageBox.Show("恭喜你成功!");
            }
        }