/// <summary> /// Returns a string value indicating the answer (first character), the state (second character), and the /// user's answer (third character). /// </summary> /// <param name="includeUserAnswer"></param> /// <returns></returns> internal string ToString(bool includeUserAnswer) { StringBuilder sTemp = new StringBuilder(); // Instantiate a new String Builder class. sTemp.Append(Answer.ToString()); // Append the answer. sTemp.Append(CellState.GetHashCode()); // Append the cell state as a numeric value. if (includeUserAnswer) // Do we need to include the user's answer? { sTemp.Append(UserAnswer.ToString()); // Yes, include the user's answer. } return(sTemp.ToString()); // Return the resulting string. }
private void NextIssue(object o) { CurrentIssue.IsAnswered = true; // Save answer var isCorrect = false; switch (IssueType) { case IssueTypes.Selection: { // ReSharper disable PossibleNullReferenceException var selectedByUserIssueIndex = Answers.IndexOf(Answers.First(a => a.SelectedByUser)) + 1; var correctIssueIndex = CurrentIssue.Answers.IndexOf(CurrentIssue.Answers.First(a => a.IsCorrect)) + 1; // ReSharper restore PossibleNullReferenceException AppController.UserInfo.Answers[_currentSet].Add(new UserAnswer { IsCorrect = (isCorrect = selectedByUserIssueIndex == correctIssueIndex), Answer = selectedByUserIssueIndex.ToString("0"), CorrectAnswer = correctIssueIndex.ToString("0"), Points = CurrentIssue.CorrectAnswerPoints }); } break; case IssueTypes.SelectionInImage: AppController.UserInfo.Answers[_currentSet].Add(new UserAnswer { IsCorrect = (isCorrect = UserAnswer == CorrectAnswer), Answer = UserAnswer.ToString("0"), CorrectAnswer = CorrectAnswer.ToString("0"), Points = CurrentIssue.CorrectAnswerPoints }); break; case IssueTypes.ImageSelection: { // ReSharper disable AssignNullToNotNullAttribute var userSelection = Answers.Where(a => a.SelectedByUser).Select(a => a.OriginalImageFileName).ToList(); var correctSelection = CurrentIssue.Answers.Where(a => a.Selected).Select(a => a.ImageFileName).ToList(); // ReSharper restore AssignNullToNotNullAttribute AppController.UserInfo.Answers[_currentSet].Add(new UserAnswer { IsCorrect = (isCorrect = userSelection.Count == correctSelection.Count && userSelection.All(correctSelection.Contains)), Answer = string.Empty, CorrectAnswer = string.Empty, Points = CurrentIssue.CorrectAnswerPoints }); } break; case IssueTypes.Order: AppController.UserInfo.Answers[_currentSet].Add(new UserAnswer { // ReSharper disable AssignNullToNotNullAttribute IsCorrect = (isCorrect = !Answers.Where((answer, index) => answer.OrderNo != index).Any()), // ReSharper restore AssignNullToNotNullAttribute Answer = string.Empty, CorrectAnswer = string.Empty, Points = CurrentIssue.CorrectAnswerPoints }); break; case IssueTypes.Placement: isCorrect = PlacementCorrectAnswer1.Count == CurrentIssue.PlacementCorrectAnswer1.Count && !PlacementCorrectAnswer1.Where( (imageFileName, index) => imageFileName != Path.Combine(_currentDirectory, CurrentIssue.PlacementCorrectAnswer1[index])).Any(); isCorrect &= PlacementCorrectAnswer2.Count == CurrentIssue.PlacementCorrectAnswer2.Count && !PlacementCorrectAnswer2.Where( (imageFileName, index) => imageFileName != Path.Combine(_currentDirectory, CurrentIssue.PlacementCorrectAnswer2[index])).Any(); isCorrect &= NumberOfShelves < 3 || (PlacementCorrectAnswer3.Count == CurrentIssue.PlacementCorrectAnswer3.Count && !PlacementCorrectAnswer3.Where( (imageFileName, index) => imageFileName != Path.Combine(_currentDirectory, CurrentIssue.PlacementCorrectAnswer3[index])).Any()); isCorrect &= NumberOfShelves < 4 || (PlacementCorrectAnswer4.Count == CurrentIssue.PlacementCorrectAnswer4.Count && !PlacementCorrectAnswer4.Where( (imageFileName, index) => imageFileName != Path.Combine(_currentDirectory, CurrentIssue.PlacementCorrectAnswer4[index])).Any()); isCorrect &= NumberOfShelves < 5 || (PlacementCorrectAnswer5.Count == CurrentIssue.PlacementCorrectAnswer5.Count && !PlacementCorrectAnswer4.Where( (imageFileName, index) => imageFileName != Path.Combine(_currentDirectory, CurrentIssue.PlacementCorrectAnswer5[index])).Any()); AppController.UserInfo.Answers[_currentSet].Add(new UserAnswer { IsCorrect = isCorrect, Answer = string.Empty, CorrectAnswer = string.Empty, Points = CurrentIssue.CorrectAnswerPoints }); break; } if (isCorrect) { AppController.UserInfo.CorrectAnswers[_currentSet]++; AppController.UserInfo.CorrectAnswerPoints[_currentSet] += CurrentIssue.CorrectAnswerPoints; } else { AppController.UserInfo.IncorrectAnswers[_currentSet]++; } // Go to the either next issue or result page var issue = GetNextIssue(); if (issue == null) { var page = o as Page; if (page != null && page.NavigationService != null) { page.NavigationService.Navigate(AppController.GetPage(ApplicationPages.ResultPage)); } } else { SetNewIssue(issue); } }