C # Jigsaw Puzzle code

Source: Internet
Author: User

Using system;
Using system. Collections. Generic;
Using system. componentmodel;
Using system. Data;
Using system. drawing;
Using system. text;
Using system. Windows. forms;

Namespace windowsapplication1
{
Public partial class form9: Form
{
Public static int AA;
Public static int BB;
Private system. Windows. Forms. picturebox [,] T;
Public form9 ()
{
Initializecomponent ();
}

Private void form9_load (Object sender, eventargs E)
{
T = new picturebox [3, 3] {picturebox1, picturebox2, picturebox3 },
{Picturebox4, picturebox5, picturebox6 },
{Picturebox7, picturebox8, picturebox9}
};
For (INT I = 0; I <= 2; I ++)
{
For (Int J = 0; j <= 2; j ++)
{
T [I, j]. Enabled = false;
}
}
}
Private void picturebox#click (Object sender, eventargs E)
{
Bb ++;
Label2.text = BB. tostring ();
If (picturebox2.image = NULL)
{
Picturebox2.image = picturebox1.image;
Picturebox1.image = NULL;
}
Else if (picturebox4.image = NULL)
{
Picturebox4.image = picturebox1.image;
Picturebox1.image = NULL;
}

}
Private void picturebox2_click (Object sender, eventargs E)
{
Bb ++;
Label2.text = BB. tostring ();
If (picturebox1.image = NULL)
{
Picturebox1.image = picturebox2.image;
Picturebox2.image = NULL;
}
Else if (picturebox3.image = NULL)
{
Picturebox3.image = picturebox2.image;
Picturebox2.image = NULL;
}
Else if (picturebox5.image = NULL)
{
Picturebox5.image = picturebox2.image;
Picturebox2.image = NULL;
}
}

Private void picturebox3_click (Object sender, eventargs E)
{
Bb ++;
Label2.text = BB. tostring ();
If (picturebox2.image = NULL)
{
Picturebox2.image = picturebox3.image;
Picturebox3.image = NULL;
}
Else if (picturebox6.image = NULL)
{
Picturebox6.image = picturebox3.image;
Picturebox3.image = NULL;
}
}

Private void picturebox4_click (Object sender, eventargs E)
{
Bb ++;
Label2.text = BB. tostring ();
If (picturebox1.image = NULL)
{
Picturebox1.image = picturebox4.image;
Picturebox4.image = NULL;
}
Else if (picturebox5.image = NULL)
{
Picturebox5.image = picturebox4.image;
Picturebox4.image = NULL;
}
Else if (picturebox7.image = NULL)
{
Picturebox7.image = picturebox4.image;
Picturebox4.image = NULL;
}
}

Private void picturebox6_click (Object sender, eventargs E)
{
Bb ++;
Label2.text = BB. tostring ();
If (picturebox5.image = NULL)
{
Picturebox5.image = picturebox6.image;
Picturebox6.image = NULL;
}
Else if (picturebox3.image = NULL)
{
Picturebox3.image = picturebox6.image;
Picturebox6.image = NULL;
}
Else if (picturebox8.image = NULL)
{
Picturebox8.image = picturebox6.image;
Picturebox6.image = NULL;
}
}

Private void picturebox5_click (Object sender, eventargs E)
{
Bb ++;
Label2.text = BB. tostring ();
If (picturebox2.image = NULL)
{
Picturebox2.image = picturebox5.image;
Picturebox5.image = NULL;
}
Else if (picturebox4.image = NULL)
{
Picturebox4.image = picturebox5.image;
Picturebox5.image = NULL;
}
Else if (picturebox6.image = NULL)
{
Picturebox6.image = picturebox5.image;
Picturebox5.image = NULL;
}
Else if (picturebox9.image = NULL)
{
Picturebox9.image = picturebox5.image;
Picturebox5.image = NULL;
}
}

Private void picturebox7_click (Object sender, eventargs E)
{
Bb ++;
Label2.text = BB. tostring ();
If (picturebox4.image = NULL)
{
Picturebox4.image = picturebox7.image;
Picturebox7.image = NULL;
}
Else if (picturebox9.image = NULL)
{
Picturebox9.image = picturebox7.image;
Picturebox7.image = NULL;
}
}

Private void picturebox9_click (Object sender, eventargs E)
{
Bb ++;
Label2.text = BB. tostring ();
If (picturebox8.image = NULL)
{
Picturebox8.image = picturebox9.image;
Picturebox9.image = NULL;
}
Else if (picturebox7.image = NULL)
{
Picturebox7.image = picturebox9.image;
Picturebox9.image = NULL;
}
Else if (picturebox5.image = NULL)
{
Picturebox5.image = picturebox9.image;
Picturebox9.image = NULL;
}
}

Private void picturebox8_click (Object sender, eventargs E)
{
Bb ++;
Label2.text = BB. tostring ();
If (picturebox6.image = NULL)
{
Picturebox6.image = picturebox8.image;
Picturebox8.image = NULL;
}
Else if (picturebox9.image = NULL)
{
Picturebox9.image = picturebox8.image;
Picturebox8.image = NULL;
}
}

Private void label2_textchanged (Object sender, eventargs E)
{
Try
{
If (Int. parse (label2.text) >=200)
{
MessageBox. Show ("You have exceeded the maximum number of steps in the game. Please come back! "," NOTE ",

Messageboxbuttons. OK, messageboxicon. information );
Application. Exit ();
}
}
Catch {}
}

Private void button#click (Object sender, eventargs E)
{
Button2.enabled = true;
Picturebox9.image = NULL;
AA = AA + 1;
For (INT m = 0; m <= 2; m ++)
{
For (INT n = 0; n <= 2; n ++)
{
T [M, N]. Enabled = true;
}
}
SS:
Switch (aa)
{
Case 1:
{
Clipboard. setimage (picturebox1.image );
Picturebox1.image = picturebox5.image;
Picturebox5.image = clipboard. getimage ();
Clipboard. Clear ();
Clipboard. setimage (picturebox2.image );
Picturebox2.image = picturebox4.image;
Picturebox4.image = clipboard. getimage ();
Clipboard. Clear ();
Clipboard. setimage (picturebox3.image );
Picturebox3.image = picturebox8.image;
Picturebox8.image = clipboard. getimage ();
Clipboard. Clear ();
Button1.enabled = false;
Break;
}
Case 2:
{
Clipboard. setimage (picturebox1.image );
Picturebox1.image = picturebox6.image;
Picturebox6.image = clipboard. getimage ();
Clipboard. Clear ();
Clipboard. setimage (picturebox2.image );
Picturebox2.image = picturebox8.image;
Picturebox8.image = clipboard. getimage ();
Clipboard. Clear ();
Clipboard. setimage (picturebox3.image );
Picturebox3.image = picturebox5.image;
Picturebox5.image = clipboard. getimage ();
Clipboard. Clear ();
Button1.enabled = false;
Break;
}
Case 3:
{
Clipboard. setimage (picturebox2.image );
Picturebox2.image = picturebox5.image;
Picturebox5.image = clipboard. getimage ();
Clipboard. Clear ();
Clipboard. setimage (picturebox4.image );
Picturebox4.image = picturebox6.image;
Picturebox6.image = clipboard. getimage ();
Clipboard. Clear ();
Clipboard. setimage (picturebox3.image );
Picturebox3.image = picturebox8.image;
Picturebox8.image = clipboard. getimage ();
Clipboard. Clear ();
Button1.enabled = false;
Break;
}
Case 4:
{
Clipboard. setimage (picturebox1.image );
Picturebox1.image = picturebox8.image;
Picturebox8.image = clipboard. getimage ();
Clipboard. Clear ();
Clipboard. setimage (picturebox3.image );
Picturebox3.image = picturebox5.image;
Picturebox5.image = clipboard. getimage ();
Clipboard. Clear ();
Clipboard. setimage (picturebox6.image );
Picturebox6.image = picturebox9.image;
Picturebox9.image = clipboard. getimage ();
Clipboard. Clear ();
Button1.enabled = false;
Break;
}
Default:
{
AA = 1;
Goto SS;
}
}
}

Private void button2_click (Object sender, eventargs E)
{
Picturebox1.image = picturebox10.image;
Picturebox2.image = picturebox12.image;
Picturebox3.image = picturebox13.image;
Picturebox4.image = picturebox14.image;
Picturebox5.image = picturebox15.image;
Picturebox6.image = picturebox16.image;
Picturebox7.image = picturebox17.image;
Picturebox8.image = picturebox18.image;
Picturebox9.image = NULL;
Label2.text = "";
BB = 0;
Button2.enabled = false;
Button1.enabled = true;
For (INT m = 0; m <= 2; m ++)
{
For (INT n = 0; n <= 2; n ++)
{
T [M, N]. Enabled = false;
}
}
}

Private void form9_activated (Object sender, eventargs E)
{
If (picturebox1.image = picturebox10.image &&
Picturebox2.image = picturebox12.image &&
Picturebox3.image = picturebox13.image &&
Picturebox4.image = picturebox14.image &&
Picturebox5.image = picturebox15.image &&
Picturebox6.image = picturebox16.image &&
Picturebox7.image = picturebox17.image &&
Picturebox8.image = picturebox18.image &&
Picturebox9.image = NULL)
{
MessageBox. Show ("Congratulations! You have completed the puzzle! "," Prompt ", messageboxbuttons. OK,

Messageboxicon. information );
}
}

}
}
 

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.