Mooc C # push block code

Source: Internet
Author: User
Tags shuffle

Push Block games It's an interesting little game Mooc has code I still play it myself familiar with C #

1 usingSystem;2 usingSystem.Collections.Generic;3 usingSystem.ComponentModel;4 usingSystem.Data;5 usingSystem.Drawing;6 usingSystem.Linq;7 usingSystem.Text;8 usingSystem.Threading.Tasks;9 usingSystem.Windows.Forms;Ten  One namespaceWindowsFormsApplication4 A { -      Public Partial classForm1:form -     { the          PublicForm1 () -         { - InitializeComponent (); -         } +         Const intN =4; -button[,] buttons =Newbutton[n, N]; +         Private voidForm1_Load (Objectsender, EventArgs e) A         { atGenerateallbuttons ();//Generate button -         } -  -         Private voidButton1_Click (Objectsender, EventArgs e) -         { -Shuffle ();//upset in         } -         voidgenerateallbuttons () to         { +             intX = the, Y = -, W = $, D = -; -              for(intR=0; r<n;r++) the             { *                  for(intc =0; c < N; C++) $                 {Panax Notoginseng                     intnum = R * N +C; -Button BTN =NewButton (); theBtn. Text = (num +1). ToString (); +Btn. Top = Y + R *D; ABtn. left = X + c *D; theBtn. Width =W; +Btn. Height =W; -Btn. Visible =true; $Btn. Tag = R * N +C; $  -Btn. Click + =NewEventHandler (Btn_click); -Buttons[r, C] =btn; the                      This. Controls.Add (BTN); -                 }Wuyi             } theButtons[n-1N1]. Visible =false; -         } Wu  -         voidShuffle () About         { $Random ran =NewRandom (); -              for(intI=0; I < -; i++) -             { -                 intA =ran. Next (N); A                 intb =ran. Next (N); +                 intc =ran. Next (N); the                 intD =ran. Next (N); - Swap (buttons[a, b], buttons[c, d]); $             } the         } the         voidSwap (Button A,button b) the         { the             stringt =A.text; -A.text =B.text; inB.text =T; the  the             BOOLv =a.visible; AboutA.visible =b.visible; theB.visible =v; the         } the         voidBtn_click (Objectsender, EventArgs e) +         { -Button btn = Sender asButton; theButton blank =Findblank ();Bayi             if(Isnear (btn, blank)) the             { the Swap (btn, blank); - blank. Focus (); -             } the             if(Resultisok ()) the             { theMessageBox.Show ("congratulation!"); the             } -  the         } the Button Findblank () the         {94              for(intR =0; R < N; r++) the                  for(intc =0; c < N; C++) the                 { the                     if(!Buttons[r, C]. Visible)98                     { About                         returnButtons[r, c]; -                     }101                 }102             return NULL;103         }104         BOOLisnear (Button A, button B) the         {106             intx = (int) A.tag;107             inty = (int) B.tag;108             if(x/n = = y/n && (x% N +1= = y% N | | X% N-1= = y%N))109                 return true; the             if(x% n = = y% n && (x/n+1==y/n| | x/n-1==y/N))111                 return true; the             return false;113         } the         BOOLResultisok () the         { the              for(intR =0; R < N; r++)117                  for(intc =0; c < N; C++)118                 {119                     if(Buttons[r, C]. Text! = (R * N + C +1). ToString ()) -                     {121                         return false;122                     }123                 }124             return true; the         }126     }127}

Mooc C # push block code

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.