Advertisement
Guest User

Untitled

a guest
Jun 24th, 2019
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.82 KB | None | 0 0
  1. namespace ABCD.UI.Model
  2. {
  3. public class Quiz
  4. {
  5. public User ActiveUser { get; private set; }
  6. public User InActiveUser { get; private set; }
  7.  
  8. public int NumberOfQuestions { get; }
  9. public int CurrentQuestion { get; private set; }
  10.  
  11. public int QuestionsPerStage => NumberOfQuestions / 2;
  12.  
  13. public Quiz(int numberOfQuestions, User activeUser, User inActiveUser)
  14. {
  15. NumberOfQuestions = numberOfQuestions;
  16. ActiveUser = activeUser;
  17. InActiveUser = inActiveUser;
  18. }
  19.  
  20. public int MatchingResults(User activeUser, User inActiveUser)
  21. {
  22. int activeUserCount = activeUser.OwnAnswers.Count(n => inActiveUser.ColleagueAnswers.Select(n1 => n1.Option).Contains(n.Option));
  23. int inActiveUserCount = inActiveUser.OwnAnswers.Count(n => activeUser.ColleagueAnswers.Select(n1 => n1.Option).Contains(n.Option));
  24. return activeUserCount + inActiveUserCount;
  25. }
  26.  
  27. public void SwapUsers()
  28. {
  29. var temp = ActiveUser;
  30. ActiveUser = InActiveUser;
  31. InActiveUser = temp;
  32. }
  33.  
  34. public void NextQuestion()
  35. {
  36. CurrentQuestion++;
  37. }
  38. }
  39. }
  40.  
  41. using System;
  42. using System.Collections.Generic;
  43. using System.Linq;
  44. using System.Text;
  45.  
  46. using Android.App;
  47. using Android.Content;
  48. using Android.OS;
  49. using Android.Runtime;
  50. using Android.Views;
  51. using Android.Widget;
  52. using ABCD.UI.DataLayer;
  53. using ABCD.UI.Model;
  54. using Newtonsoft.Json;
  55.  
  56. namespace ABCD.UI
  57. {
  58. [Activity(Label = "ABCDMenu")]
  59. public class QuizQuestion : Activity
  60. {
  61. private int _currentQuestionAnswer;
  62.  
  63. protected override void OnCreate(Bundle savedInstanceState)
  64. {
  65. base.OnCreate(savedInstanceState);
  66. SetContentView(Resource.Layout.quizQuestion);
  67.  
  68. // Retrieve next Question ID, or default to 1
  69. Quiz myQuiz = JsonConvert.DeserializeObject<Quiz>(Intent.GetStringExtra("myQuiz"));
  70.  
  71. User activeUser = myQuiz.ActiveUser;
  72. User inActiveUser = myQuiz.InActiveUser;
  73.  
  74. // Assign views from layout
  75. Button nextQuestionButton = FindViewById<Button>(Resource.Id.nextQuestionButton);
  76. TextView questionTextView = FindViewById<TextView>(Resource.Id.questionTextView);
  77. TextView currentUserTextView = FindViewById<TextView>(Resource.Id.currentUserTextView);
  78. ListView questionListView = FindViewById<ListView>(Resource.Id.questionListView);
  79.  
  80. // If final question
  81. if (myQuiz.EndOfSecondPhase())
  82. {
  83. nextQuestionButton.Text = "Results";
  84. }
  85.  
  86. myQuiz.NextQuestion();
  87. currentUserTextView.Text = $"Asking {activeUser}";
  88.  
  89. IAbcdRepository repository = new SqLiteAbcdRepository();
  90. Question question = repository.GetQuestionById(myQuiz.CurrentQuestion);
  91.  
  92. // Assign the question to the text view
  93. questionTextView.Text = question.ToString();
  94.  
  95. // Assign each question option to the list view
  96. List<String> options = question.GetOptions();
  97. questionListView.Adapter = new ArrayAdapter(this, Android.Resource.Layout.SimpleListItemSingleChoice, options);
  98. questionListView.ChoiceMode = ChoiceMode.Single;
  99.  
  100. // Click event to move to next activity
  101. nextQuestionButton.Click += (sender, e) =>
  102. {
  103.  
  104. Intent mainIntent;
  105. mainIntent = new Intent(this, typeof(QuizQuestion));
  106.  
  107. mainIntent.PutExtra("myQuiz", JsonConvert.SerializeObject(myQuiz));
  108. StartActivity(mainIntent);
  109. };
  110.  
  111. // Enable next question button once item is selected
  112. questionListView.ItemClick += (sender, e) =>
  113. {
  114. _currentQuestionAnswer = e.Position;
  115. nextQuestionButton.Enabled = true;
  116. };
  117. }
  118.  
  119. }
  120. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement