示例#1
0
        public void OnPuzzleClick(object sender, MouseEventArgs e)
        {
            switch (e.Button)
            {
            case MouseButtons.Right:
            {
                currentBox = (MyPictureBox)sender;
                currentBox.Image.RotateFlip(RotateFlipType.Rotate180FlipNone);
                currentBox.Refresh();
                break;
            }

            case MouseButtons.Left:
            {
                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;
                    SwitchImages(firstBox, secondBox);
                    firstBox  = null;
                    secondBox = null;
                }
                break;
            }
            }
        }
示例#2
0
        private void SwitchImages(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 (isSeccessful())
            {
                System.Windows.MessageBox.Show("Well done! ", "Congratulations");
            }
        }
示例#3
0
        private void btnCut_Click(object sender, EventArgs e)
        {
            if (isPlaying)
            {
                if (System.Windows.MessageBox.Show("A puzzle is in progress.  Start new puzzle?", "New Puzzle", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
                {
                    isPlaying = false;
                }
            }

            if (!isPlaying)
            {
                if (radioButton4x4.Checked == true)
                {
                    pieces = 4;
                }
                else if (radioButton6x6.Checked == true)
                {
                    pieces = 6;
                }
                else
                {
                    pieces = 10;
                }
                puzzleBoard.Controls.Clear();

                PuzzleCutter(pieces, pieces);

                picBoxes = new MyPictureBox[numPieces];
                int[] indice = new int[numPieces];
                for (int i = 0; i < numPieces; i++)
                {
                    indice[i] = i;
                    if (picBoxes[i] == null)
                    {
                        picBoxes[i]             = new MyPictureBox();
                        picBoxes[i].MouseClick += new MouseEventHandler(OnPuzzleClick);
                        picBoxes[i].BorderStyle = BorderStyle.Fixed3D;
                    }
                    picBoxes[i].Width  = puzzleBoard.Width / pieces;
                    picBoxes[i].Height = puzzleBoard.Height / pieces;

                    picBoxes[i].Index    = i;
                    picBoxes[i].Location = new System.Drawing.Point(picBoxes[i].Width * (i % pieces), picBoxes[i].Height * (i / pieces));
                    if (!puzzleBoard.Controls.Contains(picBoxes[i]))
                    {
                        puzzleBoard.Controls.Add(picBoxes[i]);
                    }
                }
                Shuffle(ref indice);
                shufImages = new List <Bitmap>(numPieces);
                for (int i = 0; i < numPieces; i++)
                {
                    shufImages.Add((Bitmap)images[indice[i]]);
                    picBoxes[i].Image      = images[indice[i]];
                    picBoxes[i].ImageIndex = indice[i];
                }
                btnSolution.Enabled = true;
                isPlaying           = true;
            }
        }