欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

C# 拼圖魔方小游戲

 更新時(shí)間:2020年02月28日 16:27:23   作者:[Stephen-kzx]  
這篇文章主要介紹了C# 拼圖魔方小游戲,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧

工作閑暇之余去逛了逛CodeProject,剛好現(xiàn)有項(xiàng)目主要用到就是winform,瀏覽了下照片,找到上周帶著蛋撻打疫苗回家的照片,于是新生一記,如何把這些圖片玩起來~

80后應(yīng)該都有印象,小時(shí)候有種玩具,叫做拼圖魔方,90后00后的世界這種玩具應(yīng)該早已滅絕了。一個(gè)塑料小板,上面分隔了很多小圖框,通過移動(dòng)這些小圖框,最后拼接成完整的圖片

話不多說開始吧~ 先上一張?jiān)瓐D

代碼也很簡單,主要就是通過BitMap分隔現(xiàn)有(后面有時(shí)間可以優(yōu)化下,讓玩家自動(dòng)上傳圖片,應(yīng)該會(huì)更有意思)圖片,然后Random隨機(jī)打亂分割后圖片的順序,通過點(diǎn)擊小方格來完成圖片的拼圖,為了更方便玩家,每個(gè)小方格添加了序號(hào),玩家也可以不參考原圖,按照小方格上的序號(hào)進(jìn)行拼圖

序號(hào)功能實(shí)現(xiàn)主要是類MyButton集成父類Button實(shí)現(xiàn):

public class MyButton : Button
  {
    private int number; 
    public int Number
    {
      get
      {
        return this.number;
      }
      set
      {
        this.Text = value.ToString();
        this.number = value;
      }
    } 
    public MyButton()
    {
    }
  }

隨機(jī)分隔

Random r = new Random();
      int[] a = new int[24];
      int i = 0;
      int b;
      bool exist;
      while (i != a.Length)
      {
        exist = false;
        b = (r.Next(24) + 1);
        for (int j = 0; j < a.Length; j++)
          if (a[j] == b) exist = true;
        if (!exist) a[i++] = b;
      }
      for (int j = 0; j < a.Length; j++)
        ButtonArray[j].Number = a[j];
      // set picture pieces as the background image
      int Number;
      int Row, Column;
      for (int k = 0; k < 5; k++)
      {
        for (int j = 0; j < 5; j++)
        {
          if (k == 4)
            if (j == 4) break;
          Number = ButtonArray[k * 5 + j].Number; //Get The Number Of Button
          Row = (Number - 1) / 5;
          Column = (Number - 1) - (Row * 5);
          ButtonArray[k * 5 + j].Image = CurrentBitmapImage.Clone(new Rectangle(new Point(Column * 75, Row * 75), new Size(75, 75)), System.Drawing.Imaging.PixelFormat.DontCare);
        }
      }

點(diǎn)擊小方格,通過改變當(dāng)前點(diǎn)擊的小方格X,Y坐標(biāo)來更新小方格的位置

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() + " Moves\n\rDo You Want To Play Another Game ?", "Congratulation", MessageBoxButtons.YesNo) == DialogResult.Yes)
          this.LoadNewGame();
        else
          this.Close();
      }
    }
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() + " Moves\n\rDo You Want To Play Another Game ?", "Congratulation", MessageBoxButtons.YesNo) == DialogResult.Yes)
          this.LoadNewGame();
        else
          this.Close();
      }
    }

具體效果如下:

代碼有很多已知的可以優(yōu)化的地方,后面有閑暇時(shí)間會(huì)處理,如果大家有更好的建議,不妨在下方評(píng)論區(qū)告知,在此感謝~

點(diǎn)擊下載源碼

到此這篇關(guān)于C# 拼圖魔方小游戲的文章就介紹到這了,更多相關(guān)C# 拼圖魔方內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • C#基于cookie實(shí)現(xiàn)的購物車功能

    C#基于cookie實(shí)現(xiàn)的購物車功能

    這篇文章主要介紹了C#基于cookie實(shí)現(xiàn)的購物車功能,結(jié)合完整實(shí)例形式分析了C#基于cookie創(chuàng)建購物車的具體步驟與相關(guān)技巧,需要的朋友可以參考下
    2015-12-12
  • c# 基于任務(wù)的異步編程模式(TAP)

    c# 基于任務(wù)的異步編程模式(TAP)

    這篇文章主要介紹了c# 基于任務(wù)的異步編程模式(TAP)的相關(guān)資料,幫助大家更好的理解和學(xué)習(xí)c# 異步編程的相關(guān)知識(shí),感興趣的朋友可以了解下
    2020-11-11
  • C#使用符號(hào)表實(shí)現(xiàn)查找算法

    C#使用符號(hào)表實(shí)現(xiàn)查找算法

    本文詳細(xì)講解了C#使用符號(hào)表實(shí)現(xiàn)查找算法,文中通過示例代碼介紹的非常詳細(xì)。對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2022-04-04
  • 詳解C#如何讀寫config配置文件

    詳解C#如何讀寫config配置文件

    這篇文章主要介紹了詳解C#如何讀寫config配置文件,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2017-12-12
  • WinForm實(shí)現(xiàn)程序一段時(shí)間不運(yùn)行自動(dòng)關(guān)閉的方法

    WinForm實(shí)現(xiàn)程序一段時(shí)間不運(yùn)行自動(dòng)關(guān)閉的方法

    這篇文章主要介紹了WinForm實(shí)現(xiàn)程序一段時(shí)間不運(yùn)行自動(dòng)關(guān)閉的方法,涉及WinForm計(jì)時(shí)器及進(jìn)程操作的相關(guān)技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下
    2015-09-09
  • c#掃描圖片去黑邊(掃描儀去黑邊)

    c#掃描圖片去黑邊(掃描儀去黑邊)

    最近項(xiàng)目遇到一個(gè)問題,需要對(duì)掃描出來的圖片進(jìn)行去除黑邊,下面是實(shí)現(xiàn)代碼,需要的朋友可以參考下
    2014-03-03
  • c# 數(shù)據(jù)庫的 sql 參數(shù)封裝類的編寫

    c# 數(shù)據(jù)庫的 sql 參數(shù)封裝類的編寫

    c# 數(shù)據(jù)庫的 sql 參數(shù)封裝類的編寫...
    2007-12-12
  • C#中使用Spire.doc對(duì)word的操作方式

    C#中使用Spire.doc對(duì)word的操作方式

    這篇文章主要介紹了C#中使用Spire.doc對(duì)word的操作方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2023-01-01
  • C#泛型語法詳解

    C#泛型語法詳解

    本文詳細(xì)講解了C#中的泛型語法,文中通過示例代碼介紹的非常詳細(xì)。對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2022-07-07
  • c#中var關(guān)鍵字用法淺談

    c#中var關(guān)鍵字用法淺談

    這篇文章介紹了c#中var關(guān)鍵字用法,有需要的朋友可以參考一下
    2013-10-10

最新評(píng)論