コード例 #1
0
        private void SwitchImage(MyPictureBox box1, MyPictureBox box2)
        {
            int tmp = box2.ImageIndex;

            box2.Image      = images[box1.ImageIndex];
            box2.ImageIndex = box1.ImageIndex;
            box1.Image      = images[tmp];
            box1.ImageIndex = tmp;
            if (isSuccessful())
            {
                labelStatus.Text = "Well Done, Amigo! =o)";
                NewGameInit();
            }
        }
コード例 #2
0
        private void PlayLevel()
        {
            if (pictureBoxWhole != null)
            {
                groupboxPuzzle.Controls.Remove(pictureBoxWhole);
                pictureBoxWhole.Dispose();
                pictureBoxWhole = null;
            }
            if (pictureBoxes == null)
            {
                images       = new Image[currentLevel];
                pictureBoxes = new PictureBox[currentLevel];
            }
            int numRow = (int)Math.Sqrt(currentLevel);
            int numCol = numRow;
            int unitX  = groupboxPuzzle.Width / numRow;
            int unitY  = groupboxPuzzle.Height / numCol;

            int[] indice = new int[currentLevel];
            for (int i = 0; i < currentLevel; i++)
            {
                indice[i] = i;
                if (pictureBoxes[i] == null)
                {
                    pictureBoxes[i]             = new MyPictureBox();
                    pictureBoxes[i].Click      += new EventHandler(OnPuzzleClick);
                    pictureBoxes[i].BorderStyle = BorderStyle.Fixed3D;
                }
                pictureBoxes[i].Width  = unitX;
                pictureBoxes[i].Height = unitY;

                ((MyPictureBox)pictureBoxes[i]).Index = i;

                CreateBitmapImage(image, images, i, numRow, numCol, unitX, unitY);
                pictureBoxes[i].Location = new Point(unitX * (i % numCol), unitY * (i / numCol));
                if (!groupboxPuzzle.Controls.Contains(pictureBoxes[i]))
                {
                    groupboxPuzzle.Controls.Add(pictureBoxes[i]);
                }
            }
            shuffle(ref indice);
            for (int i = 0; i < currentLevel; i++)
            {
                pictureBoxes[i].Image = images[indice[i]];
                ((MyPictureBox)pictureBoxes[i]).ImageIndex = indice[i];
            }
        }
コード例 #3
0
 public void OnPuzzleClick(object sender, EventArgs e)
 {
     if (firstBox == null)
     {
         firstBox             = (MyPictureBox)sender;
         firstBox.BorderStyle = BorderStyle.FixedSingle;
     }
     else if (secondBox == null)
     {
         secondBox             = (MyPictureBox)sender;
         firstBox.BorderStyle  = BorderStyle.Fixed3D;
         secondBox.BorderStyle = BorderStyle.FixedSingle;
         SwitchImage(firstBox, secondBox);
         firstBox  = null;
         secondBox = null;
     }
 }