Skip to content

Commit

Permalink
Pick random wrong answer for joker (not first)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mike Klimek committed Oct 15, 2017
1 parent 05d0c85 commit 63a411a
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
4 changes: 4 additions & 0 deletions MovieQuiz/Extensions/ShuffleExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,9 @@ public static List<T> Shuffle<T>(this List<T> list)
{
return list.OrderBy(item => rnd.Next()).ToList();
}
public static T Random<T>(this List<T> list)
{
return list.Shuffle().Take(1).Single();
}
}
}
2 changes: 1 addition & 1 deletion MovieQuiz/Models/Quiz.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class Quiz
public string CorrectAnswer { get { return questions[QuestionNumber].CorrectAnswer; } }
public List<string> WrongAnswers { get { return questions[QuestionNumber].WrongAnswers; } }
public List<string> Answers { get { return WrongAnswers.Concat(new[] { CorrectAnswer }).ToList().Shuffle(); } }
public string JokerAnswer { get { return questions[QuestionNumber].WrongAnswers[0]; } }
public string JokerAnswer { get { return questions[QuestionNumber].WrongAnswers.Random(); } }

public Quiz(List<Question> questions)
{
Expand Down

0 comments on commit 63a411a

Please sign in to comment.