private void AButton_Click(object sender, System.EventArgs e) { int r, c, d; //行,列 200*200像素 int dd = this.Num; //维度; int ww = this.W; //宽度 r = this.Top / ww; //对应数组中的行索引 c = this.Left / ww; //对应数组中的列索引 d = Direction(r, c, dd); //确定能往哪个方向移动 switch (d) { case 0: //left this.Left = this.Left - ww; //向左移动 SetA(r, c - 1, GetA(r, c, dd), dd); //更新数组 SetA(r, c, 0, dd); //更新数组 TotalStep += 1; break; case 1: //up this.Top = this.Top - ww; SetA(r - 1, c, GetA(r, c, dd), dd); SetA(r, c, 0, dd); TotalStep += 1; break; case 2: //right this.Left = this.Left + ww; SetA(r, c + 1, GetA(r, c, dd), dd); SetA(r, c, 0, dd); TotalStep += 1; break; case 3: //down this.Top = this.Top + ww; SetA(r + 1, c, GetA(r, c, dd), dd); SetA(r, c, 0, dd); TotalStep += 1; break; } if (Success(dd)) { MessageBox.Show("拼图成功!!!\n" + "总计:" + TotalStep.ToString() + "步", "恭喜!"); //把最后一块补上去 mButton[dd * dd - 1].Location = new Point(600 - ww, 600 - ww); SetA(dd - 1, dd - 1, dd * dd, dd); } }
void SetStepLbls(int s) { lbl_step.Content = CurrStep.ToString() + "/" + TotalStep.ToString(); lbl_desc.Text = StepDescString[s - 1]; }