C# 拼图魔方小游戏

2020-02-28 18:01:33于丽
private void myButton_LocationChanged(object sender, EventArgs e)
    {
      MyButton A = sender as MyButton;
      YouWin = true;
      int ButtonNumber;
      this.NumberOfMoves++;
      if (ButtonArray == null)
      {
        this.FrmMain_Load(sender, e);
      }
      for (int i = 0; i < 5; i++)
      {
        if (YouWin == false)
          break;
        else for (int j = 0; j < 5; j++)
          {
            ButtonNumber = i * 5 + j;
            if (i == 4 && j == 4)
              break;
            else if (GetNumber(ButtonArray[ButtonNumber].Location.X, ButtonArray[ButtonNumber].Location.Y) == ButtonArray[ButtonNumber].Number)
              continue;
            else
            {
              YouWin = false;
              break;
            }
          }
      }
      if (YouWin)
      {

        if (MessageBox.Show("You Win This Game in " + this.NumberOfMoves.ToString() + " MovesnrDo You Want To Play Another Game ?", "Congratulation", MessageBoxButtons.YesNo) == DialogResult.Yes)
          this.LoadNewGame();
        else
          this.Close();
      }
    }

具体效果如下:

代码有很多已知的可以优化的地方,后面有闲暇时间会处理,如果大家有更好的建议,不妨在下方评论区告知,在此感谢~

【点击下载源码】

到此这篇关于C# 拼图魔方小游戏的文章就介绍到这了,更多相关C# 拼图魔方内容请搜索易采站长站以前的文章或继续浏览下面的相关文章希望大家以后多多支持易采站长站!