Ejemplo n.º 1
0
        internal void ResetPuzzle()
        {
            if (this.puzzleItem == null)
            {
                return;
            }

            if (imageStream != null)
            {
                imageStream.Dispose();
                imageStream = null;
            }

            byte[] imageData = PuzzleData.LoadImageData(this.puzzleItem.ImageFile);

            this.imageStream = new System.IO.MemoryStream(imageData);

            BitmapImage bi = new BitmapImage();

            bi.BeginInit();
            bi.StreamSource = imageStream;
            bi.EndInit();

            Image image = new Image();

            image.Source  = bi;
            image.Stretch = Stretch.Uniform;

            this.CalcPuzzleSize(bi.PixelWidth, bi.PixelHeight);

            image.MouseDown += this.puzzleImageMouseButtonEventHandler;

            Border border = new Border();

            border.Style = App.Current.FindResource("puzzleBorderStyle") as Style;

            border.Child  = image;
            border.Width  = puzzleSize.Width;
            border.Height = puzzleSize.Height;

            this.unsubscribEvent();

            this.puzzleHostingPanel.Children.Clear();
            this.puzzleHostingPanel.Children.Add(border);

            this.statusLabel.Text       = "";
            this.answerLabel.Text       = "";
            this.totalSteps             = -1;
            this.usedSteps              = -1;
            this.getAnswerBtn.IsEnabled = false;
            this.nextStepBtn.IsEnabled  = false;
            this.movedSteps             = 0;
        }
Ejemplo n.º 2
0
        private void CreatePuzzle()
        {
            this.puzzleHostingPanel.Children.Clear();

            this.puzzleGrid            = new PuzzleGrid();
            this.puzzleGrid.PuzzleWon += delegate(object sender, EventArgs e)
            {
                this.getAnswerBtn.IsEnabled        = false;
                this.nextStepBtn.IsEnabled         = false;
                this.showNumbersCheckBox.IsEnabled = false;

                this.Dispatcher.BeginInvoke(new ThreadStart(() =>
                {
                    ResultWindow win = new ResultWindow();
                    win.State        = ResultState.Pass;
                    win.ShowMessage(MessageWindowCallback);
                }),
                                            DispatcherPriority.ApplicationIdle,
                                            null);
            };

            if (puzzleStream != null)
            {
                puzzleStream.Dispose();
                puzzleStream = null;
            }

            byte[] imageData = PuzzleData.LoadImageData(this.puzzleItem.ImageFile);

            if (this.puzzleStream != null)
            {
                this.puzzleStream.Dispose();
                this.puzzleStream = null;
            }

            this.puzzleStream = new System.IO.MemoryStream(imageData);

            BitmapImage bi = new BitmapImage();

            bi.BeginInit();
            bi.StreamSource = this.puzzleStream;
            bi.EndInit();

            Image image = new Image();

            image.Source = bi;

            image.Width  = puzzleSize.Width;
            image.Height = puzzleSize.Height;

            this.elementToChopUp = image;

            this.puzzleGrid.MoveMade += new EventHandler <HandledEventArgs>(OnMoveMade);

            this.puzzleGrid.IsApplyingStyle = true;
            this.puzzleGrid.NumRows         = PuzzleSetting.Instance.Rows;
            this.puzzleGrid.NumCols         = PuzzleSetting.Instance.Cols;

            this.puzzleGrid.ElementToChopUp = elementToChopUp;
            this.puzzleGrid.PuzzleSize      = puzzleSize;

            this.puzzleGrid.ShowNumbers(this.showNumbersCheckBox.IsChecked.Value);

            this.puzzleGrid.ShouldAnimateInteractions = true;

            this.showNumbersCheckBox.IsEnabled = true;

            puzzleHostingPanel.Children.Add(this.puzzleGrid);
        }