Пример #1
0
        /// <summary>
        /// Verifies if the user's input is correct or not. Applies game logic based on result.
        /// </summary>
        /// <param name="input">The user's answer</param>
        public void SubmitAnswer(String input)
        {
            try
            {
                int answer;
                Int32.TryParse(input, out answer);

                if (answer == currentAnswer)
                {
                    ++score;

                    gameUIView.UpdateScore(String.Format("Score: {0}", score));

                    DisplayCorrect();
                }
                else
                {
                    DisplayIncorrect();
                }

                --questionNum;
                if (questionNum == 0)
                {
                    timer.Stop();
                    highScoresLogic.AddScore(new UserScore(player.Name, score, time, type));
                    HighScores highScores = new HighScores(highScoresLogic, new UserScore(player.Name, score, time, type));
                    gameUIView.CloseWindow();
                    highScores.ShowDialog();
                }
                gameUIView.ClearTxtAnswer();

                gameUIView.UpdateQuestion(GenerateQuestion());
            }
            catch (Exception ex)
            {
                HandleError(MethodInfo.GetCurrentMethod().DeclaringType.Name,
                            MethodInfo.GetCurrentMethod().Name, ex.Message);
            }
        }
Пример #2
0
        /// <summary>
        /// Attatches the GUI to the current game
        /// </summary>
        /// <param name="gameUIView">The GUI that implements the GameUIView</param>
        public void AttatchView(GameUIView gameUIView)
        {
            this.gameUIView = gameUIView;

            gameUIView.UpdateQuestion(GenerateQuestion());
        }