/// <summary> /// Selects categories for the second round: /// Updates values for round 2 /// Selects questions for second round /// Attempts to find unused questions and resets used status if there are not enough unused questions /// Attempts to include a picture question, but allows used status to take precedence /// Under the above conditions, selects 1 question for each value in each category /// Marks the selected questions as used ///Randomly selects two questions as a daily doubles /// /// </summary> /// <returns>true if round was set up successfully and false otherwise</returns> private bool setupSecondRound() { currentRound = 2; questions.Clear(); roundCategories.Clear(); values = (from v in values select 2 * v).ToList(); bool needPicture = false; List <int> usedQuestions = new List <int>(); Random rnd = new Random(); //choose questions from second 6 categories for (int i = 6; i < 12; i++) { string currentCategory = gameCategories[i]; List <object> categoryQuestions = getUnusedQuestionsByCategory(currentCategory); if (categoryQuestions == null) { return(false); } //reset the questions if we do not have enough in this to populate this category if (!checkForAllLevels(categoryQuestions)) { bool result = resetQuestionUsage(); if (result == false) { return(false); } categoryQuestions = getUnusedQuestionsByCategory(currentCategory); if (categoryQuestions == null) { return(false); } } //choose a question for each level for (int j = 1; j <= 5; j++) { List <object> questionsAtLevel = (from q in categoryQuestions where (((QuestionData)q).level == j) select q).ToList(); List <object> pictureQuestions = questionsAtLevel.Where(q => (!((QuestionData)q).image_file.Equals(""))).ToList(); Question question; if (pictureQuestions.Count > 0 && needPicture) { int index = rnd.Next(pictureQuestions.Count); question = new Question(200 * j, (QuestionData)pictureQuestions[index]); needPicture = false; } else { int index = rnd.Next(questionsAtLevel.Count); question = new Jeopardy_Game.Question(200 * j, (QuestionData)questionsAtLevel[index]); } this.addQuestion(question); usedQuestions.Add(question.data.question_id); } } //mark questions used bool usedResult = updateUsedQuestions(usedQuestions); if (usedResult == false) { return(false); } //choose a daily double string ddCategory = roundCategories[rnd.Next(6)]; int ddValue = values[rnd.Next(5)]; getQuestion(ddCategory, ddValue).wagerActive = true; //choose a second daily double that is different than the first one string dd2Category = ddCategory; int dd2Value = ddValue; while ((dd2Category.Equals(ddCategory)) && (dd2Value == ddValue)) { dd2Category = roundCategories[rnd.Next(6)]; dd2Value = values[rnd.Next(5)]; } getQuestion(dd2Category, dd2Value).wagerActive = true; return(true); }
/// <summary> /// Determines categories for the game /// Selects categories for the first round: /// Selects questions for first round /// Attempts to find unused questions and resets used status if there are not enough unused questions /// Attempts to include a picture question, but allows used status to take precedence /// Under the above conditions, selects 1 question for each value in each category /// Marks the selected questions as used ///Randomly selects one question as a daily double /// /// </summary> /// <returns>true if round was set up successfully and false otherwise</returns> private bool setupFirstRound() { currentRound = 1; bool needPicture = false; List <int> usedQuestions = new List <int>(); //select categories gameCategories = getCategories(); if (gameCategories == null || gameCategories.Count < 13) { return(false); } //randomize the order Random rnd = new Random(); gameCategories = gameCategories.OrderBy(x => rnd.Next()).ToList(); //choose questions from first 6 categories for (int i = 0; i < 6; i++) { string currentCategory = gameCategories[i]; List <object> categoryQuestions = getUnusedQuestionsByCategory(currentCategory); if (categoryQuestions == null) { return(false); } //reset the questions if we do not have enough in this to populate this category if (!checkForAllLevels(categoryQuestions)) { bool result = resetQuestionUsage(); if (result == false) { return(false); } categoryQuestions = getUnusedQuestionsByCategory(currentCategory); if (categoryQuestions == null) { return(false); } } //choose a question for each level for (int j = 1; j <= 5; j++) { List <object> questionsAtLevel = (from q in categoryQuestions where (((QuestionData)q).level == j) select q).ToList(); List <object> pictureQuestions = questionsAtLevel.Where(q => (!((QuestionData)q).image_file.Equals(""))).ToList(); Question question; if (pictureQuestions.Count > 0 && needPicture) { int index = rnd.Next(pictureQuestions.Count); question = new Question(100 * j, (QuestionData)pictureQuestions[index]); needPicture = false; } else { int index = rnd.Next(questionsAtLevel.Count); question = new Jeopardy_Game.Question(100 * j, (QuestionData)questionsAtLevel[index]); } this.addQuestion(question); usedQuestions.Add(question.data.question_id); } } //mark questions used bool usedResult = updateUsedQuestions(usedQuestions); if (usedResult == false) { return(false); } //choose a daily double string ddCategory = roundCategories[rnd.Next(6)]; int ddValue = values[rnd.Next(5)]; getQuestion(ddCategory, ddValue).wagerActive = true; return(true); }