// <summary>Method to prepare user performance and pass it on the Overview page.</summary> private void GoToOverview() { // Create new intent with their data. Intent intent = new Intent(this, typeof(Overview)); intent.PutExtra("Score", this.score); intent.PutExtra("Questions", MAX_QUESTIONS); intent.PutExtra("TotalTime", this.totalElapsedTime); intent.PutExtra("Difficulty", this.difficultyLevel.ToString()); // Declare how many wrong questions they will have so Overview will know how many to expect. intent.PutExtra("Wrong", this.wrongQuestions.Count); // If they got more than 0 questions wrong. if (this.wrongQuestions.Count > 0) { for (int i = 0; i < this.wrongQuestions.Count; i++) { RandomQuestion wrongQuestion = this.wrongQuestions[i]; String equation = wrongQuestion.GetEquation(); // Construct a correct equation by removing the "?" at the end of the equation and appending the correct answer. intent.PutExtra(I_WRONG_Q + i, equation.Remove(equation.Length - 1) + wrongQuestion.GetAnswer()); } } this.soundRight.Stop(); this.soundWrong.Stop(); // Change page. StartActivity(intent); }
// <summary>Gets a new <c>RandomQuestion</c>.</summary> public RandomQuestion GetNewQuestion() { // Gets random index from all the operators. int randIndex = random.Next(operators.Count); // Makes new question with the random operator. RandomQuestion randomQuestion = new RandomQuestion( this.operators.ElementAt(randIndex) ); return(randomQuestion); }
// <summary>Sets the next question, or if the <c>MAX_QUESTIONS</c> is reached it will prepare for going to the Overview page view.</summary> public void NextQuestion() { // If the next question is the max amount of questions to ask, go to overview. if (this.currentQuestionNumber++ == MAX_QUESTIONS) { this.GoToOverview(); return; } // Hide the image saying if they are right or wrong. this.imgRightWrong.Hide(true); // Get new question. this.currentQuestion = GetNewQuestion(); // Restart timer. if (this.easyTimer != null) { this.easyTimer.Restart(); } // Update text fields for the new question. this.UpdateTextFields(); }
protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); SetContentView(Resource.Layout.QuestionView); // Parse difficulty from Intent. string difficulty = Intent.GetStringExtra("Difficulty"); this.difficultyLevel = DifficultyLevelGet.FromString(difficulty); // If timer exists, stop and dispose so a new one can be created. if (this.easyTimer != null) { this.easyTimer.Stop(); this.easyTimer.Dispose(); this.easyTimer = null; } // Assign a countdown/up depending on the difficulty level. switch (this.difficultyLevel) { case DifficultyLevel.Easy: // Want to keep track of time they are spending even if not countdown. this.easyTimer = new EasyTimer(EasyTimer.TimerType.Up, 1000); break; case DifficultyLevel.Medium: // They have 20 seconds (20000ms) to answer each question. this.easyTimer = new EasyTimer(EasyTimer.TimerType.Down, 1000, 20, 0); break; case DifficultyLevel.Hard: // They have 10 seconds (10000ms) to answer each question. this.easyTimer = new EasyTimer(EasyTimer.TimerType.Down, 1000, 10, 0); break; } // Load operators. if (operators.Count == 0) { operators.Add(Operator.Add, "+"); operators.Add(Operator.Subtract, "-"); operators.Add(Operator.Multiply, "*"); operators.Add(Operator.Divide, "÷"); } // Load page. if (page == null) { LoadPage(); } else { // Since the page exists, reset all the values. this.score = 0; this.currentQuestion = null; this.totalElapsedTime = 0; this.UpdateTextFields(); this.wrongQuestions.Clear(); } // If they easy, don't show them the time remaining. if (this.difficultyLevel == DifficultyLevel.Easy) { this.txtTimeRemaining.Hide(true); } else { this.txtTimeRemaining.Show(); // Assign countdown logic. this.easyTimer.TargetReachedEvent += delegate { // If they've answered or the time is already up, ignore when the target reaches, even if it shoudln't. if (this.currentQuestion.Answered && !this.currentQuestion.TimeUp) { return; } // Register the time is up and add register as wrong question. this.currentQuestion.TimeUp = true; this.wrongQuestions.Add(this.currentQuestion); }; } // Everytime the timer ticks regardless of difficulty. this.easyTimer.Tick(delegate { // If there is no current question or it is answered, ignore. if (this.currentQuestion != null && this.currentQuestion.Answered) { return; } // If their time is up. if (this.currentQuestion != null && this.currentQuestion.TimeUp) { this.inAnswer.AllowInteraction(false); this.txtTimeRemaining.Color(this.remainingColorNone); this.txtTimeRemaining.Text("TIMEUP!"); this.btnSubmit.Text("Next Question"); } else { // Track elapsed time as they are still answering the question. // If easy, txtTimeRemaining is hidden so doesn't matter to set text. this.txtTimeRemaining.Text($"{this.easyTimer.Value}s remaining"); this.totalElapsedTime++; this.UpdateRemainingColor(); } }); NextQuestion(); }