using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
Image[] image = new Image[25];
Panel[] panel = new Panel[25];
Random rd = new Random();
Point[] LegalMove = new Point[]
{
new Point(0,1), new Point(0,5),
new Point(1,0), new Point(1,2), new Point(1,6),
new Point(2,1), new Point(2,3), new Point(2,7),
new Point(3,2), new Point(3,4), new Point(3,8),
new Point(4,3), new Point(4,9),
new Point(5,0), new Point(5,6), new Point(5,10),
new Point(6,1), new Point(6,5), new Point(6,7), new Point(6,11),
new Point(7,2), new Point(7,6), new Point(7,8), new Point(7,12),
new Point(8,3), new Point(8,7), new Point(8,9), new Point(8,13),
new Point(9,4), new Point(9,8), new Point(9,14),
new Point(10,5), new Point(10,11), new Point(10,15),
new Point(11,6), new Point(11,10), new Point(11,12), new Point(11,16),
new Point(12,7), new Point(12,11), new Point(12,13), new Point(12,17),
new Point(13,8), new Point(13,12), new Point(13,14), new Point(13,18),
new Point(14,9), new Point(14,13), new Point(14,19),
new Point(15,10), new Point(15,16), new Point(15,20),
new Point(16,11), new Point(16,15), new Point(16,17), new Point(16,21),
new Point(17,12), new Point(17,16), new Point(17,18), new Point(17,22),
new Point(18,13), new Point(18,17), new Point(18,19), new Point(18,23),
new Point(19,14), new Point(19,18), new Point(19,24),
new Point(20,15), new Point(20,21),
new Point(21,16), new Point(21,20), new Point(21,22),
new Point(22,17), new Point(22,21), new Point(22,23),
new Point(23,18), new Point(23,22), new Point(23,24),
new Point(24,19), new Point(24,23)
};
int Count = 0;
public Form1()
{
InitializeComponent();
image[0] = null;
image[1] = new Bitmap(Properties.Resources.T01);
image[2] = new Bitmap(Properties.Resources.T02);
image[3] = new Bitmap(Properties.Resources.T03);
image[4] = new Bitmap(Properties.Resources.T04);
image[5] = new Bitmap(Properties.Resources.T05);
image[6] = new Bitmap(Properties.Resources.T06);
image[7] = new Bitmap(Properties.Resources.T07);
image[8] = new Bitmap(Properties.Resources.T08);
image[9] = new Bitmap(Properties.Resources.T09);
image[10] = new Bitmap(Properties.Resources.T10);
image[11] = new Bitmap(Properties.Resources.T11);
image[12] = new Bitmap(Properties.Resources.T12);
image[13] = new Bitmap(Properties.Resources.T13);
image[14] = new Bitmap(Properties.Resources.T14);
image[15] = new Bitmap(Properties.Resources.T15);
image[16] = new Bitmap(Properties.Resources.T16);
image[17] = new Bitmap(Properties.Resources.T17);
image[18] = new Bitmap(Properties.Resources.T18);
image[19] = new Bitmap(Properties.Resources.T19);
image[20] = new Bitmap(Properties.Resources.T20);
image[21] = new Bitmap(Properties.Resources.T21);
image[22] = new Bitmap(Properties.Resources.T22);
image[23] = new Bitmap(Properties.Resources.T23);
image[24] = new Bitmap(Properties.Resources.T24);
panel[0] = panel0;
panel[1] = panel1;
panel[2] = panel2;
panel[3] = panel3;
panel[4] = panel4;
panel[5] = panel5;
panel[6] = panel6;
panel[7] = panel7;
panel[8] = panel8;
panel[9] = panel9;
panel[10] = panel10;
panel[11] = panel11;
panel[12] = panel12;
panel[13] = panel13;
panel[14] = panel14;
panel[15] = panel15;
panel[16] = panel16;
panel[17] = panel17;
panel[18] = panel18;
panel[19] = panel19;
panel[20] = panel20;
panel[21] = panel21;
panel[22] = panel22;
panel[23] = panel23;
panel[24] = panel24;
button1_click(this, null);
}
private void button1_click(object sender, EventArgs e)
{
for (int i = 0; i <= 24; i++)
panel[i].Tag = i;
int k1, k2, t;
for (int i = 0; i <= 20; i++)
{
k1 = rd.Next(25);
k2 = rd.Next(25);
t = (int)panel[k1].Tag;
panel[k1].Tag = panel[k2].Tag;
panel[k2].Tag = t;
}
for (int i = 0; i <= 24; i++)
panel[i].BackgroundImage = image[(int)panel[i].Tag];
Count = 0;
label1.Text = Count.ToString();
for (int i = 0; i <= 24; i++)
panel[i].Enabled = true;
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void panel0_Click(object sender, EventArgs e)
{
Panel x = (Panel)sender;
int SelectedPanelNo = 0;
for (int i = 0; i <= 24; i++)
{
if (panel[i] == x)
{
SelectedPanelNo = i;
break;
}
}
int EmptyPanelNo = 0;
for (int i = 0; i <= 24; i++)
{
if ((int)panel[i].Tag == 0)
{
EmptyPanelNo = i;
break;
}
}
int k;
for(int i= 0; i<80; i++)
{
if(LegalMove[i].X == SelectedPanelNo && LegalMove[i].Y == EmptyPanelNo)
{
Count++;
label1.Text = Count.ToString();
k = (int)panel[SelectedPanelNo].Tag;
panel[SelectedPanelNo].Tag = panel[EmptyPanelNo].Tag;
panel[EmptyPanelNo].Tag = k;
panel[SelectedPanelNo].BackgroundImage = image[(int)panel[SelectedPanelNo].Tag];
panel[EmptyPanelNo].BackgroundImage = image[(int)panel[EmptyPanelNo].Tag];
break;
}
}
if ((int)panel[0].Tag == 1 && (int)panel[1].Tag == 2 && (int)panel[2].Tag == 3 && (int)panel[3].Tag == 4 && (int)panel[4].Tag == 5 &&
(int)panel[5].Tag == 6 && (int)panel[6].Tag == 7 && (int)panel[7].Tag == 8 && (int)panel[8].Tag == 9 && (int)panel[9].Tag == 10 &&
(int)panel[10].Tag == 11 && (int)panel[11].Tag == 12 && (int)panel[12].Tag == 13 && (int)panel[13].Tag == 14 && (int)panel[14].Tag == 15 &&
(int)panel[15].Tag == 16 && (int)panel[16].Tag == 17 && (int)panel[17].Tag == 18 && (int)panel[18].Tag == 19 && (int)panel[19].Tag == 20 &&
(int)panel[20].Tag == 21 && (int)panel[21].Tag == 22 && (int)panel[22].Tag == 23 && (int)panel[23].Tag == 24)
{
for (int i = 0; i <= 24; i++)
panel[i].Enabled = false;
MessageBox.Show("GOOD JOB");
}
}
}
}