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(); }
protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); SetContentView(Resource.Layout.Overview); MediaPlayer soundClap = MediaPlayer.Create(this, Resource.Raw.sound_clap); soundClap.Start(); // Get their results. int score = Intent.GetIntExtra("Score", 0); int questions = Intent.GetIntExtra("Questions", 0); int wrong = Intent.GetIntExtra("Wrong", 0); int totalTime = Intent.GetIntExtra("TotalTime", 0); string difficulty = Intent.GetStringExtra("Difficulty"); DifficultyLevel level = DifficultyLevelGet.FromString(difficulty); List <string> wrongQuestions = new List <string>(); // If they got more than 0 wrong questions, get them. if (wrong > 0) { for (int i = 0; i < wrong; i++) { wrongQuestions.Add(Intent.GetStringExtra(QuestionView.I_WRONG_Q + i)); } } // improve w change header. // Update values with the gathered values. FindViewById <TextView>(Resource.Id.txtQOverview).Text = $"{score}/{questions}"; FindViewById <TextView>(Resource.Id.txtTimeTaken).Text = $"In {totalTime}s"; TextView modeData = FindViewById <TextView>(Resource.Id.txtMode); modeData.Text = $"In {difficulty} mode"; modeData.SetTextColor(level.GetColor()); TextView improvementsHeader = FindViewById <TextView>(Resource.Id.txtQImproveHeader); TextView improvements = FindViewById <TextView>(Resource.Id.txtQImprove0); // Clear any possible history. improvements.Text = ""; if (wrongQuestions.Count == 0) { // If got 0 questions wrong, hide the header. improvementsHeader.Visibility = Android.Views.ViewStates.Invisible; } else { // Show the header incase hidden improvementsHeader.Visibility = Android.Views.ViewStates.Visible; // For each wrong question, append to the improvements text. wrongQuestions.ForEach(delegate(string wrongQuestion) { improvements.Text += wrongQuestion + "\n"; }); } // When they want to start again, start DifficultySelect page view. FindViewById <Button>(Resource.Id.btnGoAgain).Click += delegate { soundClap.Stop(); StartActivity(typeof(DifficultySelect)); }; }