예제 #1
0
        /// <summary>
        /// Construct a GamePage with the specified player
        /// </summary>
        /// <param name="player"></param>
        public GamePage(Player player)
        {
            InitializeComponent();

            // assign the player passed to the player field
            this.player = player;

            // generate an Equation and set the result variable to the return value of method Generate
            result = equation.Generate();

            // generate a random Potato
            randomPotato = Potato.Generate();

            // update GUI labels with the numbers generated by the equation
            DisplayEquation();

            // display potato images to GUI
            DisplayPotatoImages();
        }
예제 #2
0
        /// <summary>
        /// Reusable method that checks losing and winning conditions for player and sends them to the corresponding page.
        /// It also takes an answer which allows me to reuse it in all button event handlers by passing a different argument
        /// for each one
        /// </summary>
        /// <param name="answer">A Player's answer to the Equation</param>
        private void Answer(int answer)
        {
            // check the Player's answer against the actual result of the Equation
            if (answer == result)
            {
                // increment rightAnswers field if the answer is correct
                rightAnswers++;
                player.Score += 50;

                // might have to call DisplayStats here instead to give the user a glimpse of their final stats and comment other
                //DisplayStats();

                // ***** CHANGE THIS BACK TO 10 (ITS JUST 5 NOW FOR TESTING PURPOSES OF DATASET) *****
                // check winning condition
                if (rightAnswers == 10)
                {
                    // later send some Player object or any object with data the Win page requires
                    NavigationService.Navigate(new WinPage(player));
                }
            }
            else
            {
                // decrement Player's lives if the answer is wrong
                player.Lives--;
                // get the image from the statsPanel at the index specified and cast (with keyword as) the return type to an Image
                Image image = statsPanel.Children[heartIndex] as Image;
                // set the source of the heart image to a blank heart
                image.Source = new BitmapImage(new Uri(@"/Images/empty_heart.png", UriKind.Relative)); // = null; (for no image at all)
                // decrement the heartIndex in order to change the correct heart next time
                heartIndex--;

                // decrement the player score by 25
                player.Score -= 25;

                // might have to call DisplayStats here instead to give the user a glimpse of their final stats and comment other
                //DisplayStats();

                // check losing condition
                if (player.Lives == 0)
                {
                    // later send some Player object or any object with data the Lose page requires
                    NavigationService.Navigate(new LosePage(player));
                }
            }


            ClearPotatoImages();

            // Eitherway, generate another problem and store its result into the result field
            result = equation.Generate();

            // generate a random Potato
            randomPotato = Potato.Generate();

            // might have to comment this one out but not sure and call this method above where I specified myself
            DisplayStats();

            // update the GUI to display the new problem
            DisplayEquation();

            DisplayPotatoImages();
        }