Exemplo n.º 1
0
        void picture_clicked(object sender, EventArgs e)
        {
            Puzzlepicture temp = sender as Puzzlepicture;
            int           i    = temp.index;


            if (pictures[8].xindex == pictures[i].xindex && Math.Pow((pictures[8].yindex - pictures[i].yindex), 2) == 1)
            {
                swapPicture(pictures[8], pictures[i]);
                checkIfSolved();
                updateSequence();
            }
            else if (pictures[8].yindex == pictures[i].yindex && Math.Pow((pictures[8].xindex - pictures[i].xindex), 2) == 1)
            {
                swapPicture(pictures[8], pictures[i]);
                checkIfSolved();
                updateSequence();
            }
        }
Exemplo n.º 2
0
        void swapPicture(Puzzlepicture p1, Puzzlepicture p2)
        {
            Puzzlepicture temp = new Puzzlepicture();

            temp.position = p1.position;
            temp.xindex   = p1.xindex;
            temp.yindex   = p1.yindex;
            temp.Location = p1.Location;

            p1.position = p2.position;
            p1.xindex   = p2.xindex;
            p1.yindex   = p2.yindex;
            p1.Location = p2.Location;

            p2.position = temp.position;
            p2.xindex   = temp.xindex;
            p2.yindex   = temp.yindex;
            p2.Location = temp.Location;
        }
Exemplo n.º 3
0
        public Form1()
        {
            InitializeComponent();

            for (int c1 = 0; c1 < 9; c1++)
            {
                pictures[c1] = new Puzzlepicture();

                pictures[c1].index    = c1;
                pictures[c1].position = c1;
                pictures[c1].xindex   = c1 % 3;
                pictures[c1].yindex   = c1 / 3;
                pictures[c1].Location = new Point(pictures[c1].xindex * 125, pictures[c1].yindex * 125);
                pictures[c1].Size     = new Size(120, 120);
                pictures[c1].Image    = Image.FromFile(Application.StartupPath + "\\picture\\" + (c1 + 1) + ".jpg");
                this.Controls.Add(pictures[c1]);
                pictures[c1].Click += new EventHandler(picture_clicked);
            }
            pictures[8].Visible = false;

            shuffle();
        }