Exemplo n.º 1
0
        // Modified From https://docs.microsoft.com/en-us/windows/uwp/launch-resume/activate-an-app

        /*  -- Method Header Comment
         * Name	:	EnsurePageCreatedAndActivate
         * Purpose :	Creates the MainPage if it isn't already created.  Also activates
         *          the window so it takes foreground and input focus. Checks how the app was closed,
         *          if by user or terminated, data will be resumed
         * Inputs	:	LaunchActivatedEventArgs args
         * Outputs	:	None
         * Returns	:	None
         */
        private void EnsurePageCreatedAndActivate(LaunchActivatedEventArgs args)
        {
            // create the window if it doesn't exist
            if (Window.Current.Content == null)
            {
                Window.Current.Content = new MainPage();
            }
            // activate the window
            Window.Current.Activate();
            // if the app was closed by termination or by the user
            if (args.PreviousExecutionState == ApplicationExecutionState.Terminated ||
                args.PreviousExecutionState == ApplicationExecutionState.ClosedByUser)
            {
                // resume state
                StateManagement.App_Resuming(Window.Current.Content as MainPage);
            }
        }
Exemplo n.º 2
0
        /*  -- Method Header Comment
         * Name	:	StartButton_Click
         * Purpose :	Called when the start button is clicked
         * Inputs	:	object sender, SuspendingEventArgs e
         * Outputs	:	None
         * Returns	:	None
         */
        private void StartButton_Click(object sender, RoutedEventArgs e)
        {
            if (!StateManagement.WasSuspended)
            {
                if (_firstGame)
                {
                    // add all the buttons into the array
                    StateManagement.AddButtonsToArray(this);
                    // initalize the coordinates of the empty square, which will always start in the bottom right corner
                    StateManagement.EmptySquare.X = 600;
                    StateManagement.EmptySquare.Y = 600;
                }

                // assign a randomized number to each button
                AssignButtonValues();

                // assign the player name and init game time
                StateManagement.PlayerName = NameBox.Text;
                StateManagement.GameTime   = 0;
            }
            else
            {
                // reset suspended flag after the game has resumed
                StateManagement.WasSuspended = false;
            }
            // enable buttons when the start button is clicked
            foreach (var b in StateManagement.buttonArray)
            {
                b.IsEnabled = true;
            }
            // reset firstGame flag
            _firstGame = false;
            // display the timer and start it
            TimerBlock.Text = TimeSpan.FromSeconds(StateManagement.GameTime).ToString();
            StateManagement.gameTimer.Start();
            // modify button contents
            StartButton.Content = "Restart";
        }