Example #1
0
        public GameController(int elx, int ely, Puzzle p, GameViewController gvc, IPuzzleGamePage pgp)
        {
            elementsX = elx;
            elementsY = ely;
            puzzle = p;
            gameViewController = gvc;
            gamePage = pgp;
            inputState = InputState.RELEASED_NO_SELECTION;

            randomize(elx, ely);
            gameViewController.setRandomization(randomMask);

            assembled = false;

            startTime = 0;
            thread = new GameThread(this);
        }
        protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);
            reload = State.ContainsKey("assembled");

            // reload puzzles and page state
            if (reload)
            {
                itime = (long)State["itime"];
                imoves = (int)State["imoves"];
                nextPuzzleOpened = (bool)State["nextPuzzleOpened"];
                time = Utils.formatTime(itime);
                moves = imoves.ToString();
                assembled = (bool)State["assembled"];
                if (assembled)
                {
                    prevTime = (long)State["prevTime"];
                    prevMoves = (int)State["prevMoves"];
                    uploaded = (bool)State["uploaded"];
                    if (uploaded)
                    {
                        internetBestMoves = (int)State["internetBestMoves"];
                        internetBestTime = (long)State["internetBestTime"];
                        internetPlace = (int)State["internetPlace"];
                    }
                }
            }

            puzzleAdapter = (Application.Current as mPuzzle.App).puzzleAdapter;

            puzzle = puzzleAdapter.puzzleDic[puzzleAdapter.selectedPuzzle];
            diff = puzzleAdapter.selectedDifficulty;

            gameViewController = new GameViewController(3 + (int)diff, 5 + (int)diff, gameCanvas, Dispatcher);
            gameController = new GameController(3 + (int)diff, 5 + (int)diff, puzzle, gameViewController, this);

            if (reload)
            {
                gameViewController.digout(this.State);
                gameController.digout(this.State);

                if (assembled)
                {
                    if (uploaded)
                    {
                        scorePanelInternet.Visibility = Visibility.Visible;
                        resPlace.Text = internetPlace.ToString();
                        res4.Text = " Time: " + Utils.formatTime(internetBestTime) + "; Moves: " + internetBestMoves;
                        scorePanelInternet.Visibility = Visibility.Visible;
                    }
                    else
                    {
                        buttonUpload.Visibility = Visibility.Visible;
                    }

                    bool betterScore = (imoves < prevMoves) || (imoves == prevMoves && itime < prevTime) || (prevMoves == 0 && prevTime == 0);
                    if (betterScore)
                        beterScoreText.Text = " Better score achieved!";
                    else
                        beterScoreText.Text = " ";

                    res1.Text = " Time: " + time + "; Moves: " + moves;
                    res2.Text = " Time: " + Utils.formatTime(prevTime) + "; Moves: " + prevMoves;

                    scorePanel.Visibility = Visibility.Visible;

                    if (nextPuzzleOpened)
                        buttonNextPuzzle.Visibility = Visibility.Visible;

                    buttonPause.Visibility = Visibility.Collapsed;
                }

                movesText.Text = moves;
                timeText.Text = time;
            }

            Uri bitmapUri = new Uri(puzzle.puzzleImage, UriKind.Relative);
            BitmapImage bitmap = new BitmapImage(bitmapUri);
            bitmap.ImageOpened += new EventHandler<RoutedEventArgs>(bitmap_Loaded);
            gameViewController.setBitmap(bitmap);
        }
Example #3
0
        protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);
            reload = State.ContainsKey("assembled");

            // reload puzzles and page state
            if (reload)
            {
                itime            = (long)State["itime"];
                imoves           = (int)State["imoves"];
                nextPuzzleOpened = (bool)State["nextPuzzleOpened"];
                time             = Utils.formatTime(itime);
                moves            = imoves.ToString();
                assembled        = (bool)State["assembled"];
                if (assembled)
                {
                    prevTime  = (long)State["prevTime"];
                    prevMoves = (int)State["prevMoves"];
                    uploaded  = (bool)State["uploaded"];
                    if (uploaded)
                    {
                        internetBestMoves = (int)State["internetBestMoves"];
                        internetBestTime  = (long)State["internetBestTime"];
                        internetPlace     = (int)State["internetPlace"];
                    }
                }
            }

            puzzleAdapter = (Application.Current as mPuzzle.App).puzzleAdapter;

            puzzle = puzzleAdapter.puzzleDic[puzzleAdapter.selectedPuzzle];
            diff   = puzzleAdapter.selectedDifficulty;

            gameViewController = new GameViewController(3 + (int)diff, 5 + (int)diff, gameCanvas, Dispatcher);
            gameController     = new GameController(3 + (int)diff, 5 + (int)diff, puzzle, gameViewController, this);

            if (reload)
            {
                gameViewController.digout(this.State);
                gameController.digout(this.State);

                if (assembled)
                {
                    if (uploaded)
                    {
                        scorePanelInternet.Visibility = Visibility.Visible;
                        resPlace.Text = internetPlace.ToString();
                        res4.Text     = " Time: " + Utils.formatTime(internetBestTime) + "; Moves: " + internetBestMoves;
                        scorePanelInternet.Visibility = Visibility.Visible;
                    }
                    else
                    {
                        buttonUpload.Visibility = Visibility.Visible;
                    }

                    bool betterScore = (imoves < prevMoves) || (imoves == prevMoves && itime < prevTime) || (prevMoves == 0 && prevTime == 0);
                    if (betterScore)
                    {
                        beterScoreText.Text = " Better score achieved!";
                    }
                    else
                    {
                        beterScoreText.Text = " ";
                    }

                    res1.Text = " Time: " + time + "; Moves: " + moves;
                    res2.Text = " Time: " + Utils.formatTime(prevTime) + "; Moves: " + prevMoves;

                    scorePanel.Visibility = Visibility.Visible;

                    if (nextPuzzleOpened)
                    {
                        buttonNextPuzzle.Visibility = Visibility.Visible;
                    }

                    buttonPause.Visibility = Visibility.Collapsed;
                }

                movesText.Text = moves;
                timeText.Text  = time;
            }

            Uri         bitmapUri = new Uri(puzzle.puzzleImage, UriKind.Relative);
            BitmapImage bitmap    = new BitmapImage(bitmapUri);

            bitmap.ImageOpened += new EventHandler <RoutedEventArgs>(bitmap_Loaded);
            gameViewController.setBitmap(bitmap);
        }