private QuizGameInfo GetSqlBasedQuestion(string channelName) { if (!m_allQuestions.ContainsKey(channelName)) { SqlDataReader channelOverrideData = m_databaseHandler.GetSelectData(new string[] { "*" }, "QuizCategoryOverride", $"WHERE channel like {channelName.ToLower()}"); if (channelOverrideData != null) { string condition = ""; if (channelOverrideData.HasRows) { channelOverrideData.Read(); string categoryOverrides = channelOverrideData["category_list"].ToString(); string[] categories = categoryOverrides.Split(','); condition = "WHERE "; for (int i = 0; i < categories.Length; ++i) { condition += $"category like \'{categories[i]}\' {(i < categories.Length - 1 ? "or " : "")}"; } } SqlDataReader questionListData = m_databaseHandler.GetSelectData(new string[] { "*" }, "Questions", condition); if (questionListData != null) { m_allQuestions.Add(channelName, new List <QuizGameInfo>()); while (questionListData.Read()) { QuizGameInfo newQuestion = new QuizGameInfo(questionListData["question"].ToString(), questionListData["answer"].ToString(), (int)questionListData["winners"], 0); m_allQuestions[channelName].Add(newQuestion); } } else { // TODO: Something went wrong in the Question Query throw new Exception($"QuizContentLoader.GetSqlBasedQuestion({channelName}), Something went wrong in the Question Query"); } } else { // TODO: Something went wrong in the Channel Override Query throw new Exception($"QuizContentLoader.GetSqlBasedQuestion({channelName}), Something went wrong in the Channel Override Query"); } } QuizGameInfo question; do { question = m_allQuestions[channelName][m_rng.Next(0, m_allQuestions[channelName].Count)]; }while (m_usedQuestions[channelName].Contains(question)); m_usedQuestions[channelName].Add(question); return(question); }
public void StartNewGame(QuizGameInfo quizGameInfo) { if (m_currentGameContent != null) { return; } m_currentGameContent = quizGameInfo; m_numberOfWinners = quizGameInfo.NumberOfWinners; m_currentWinners.Clear(); }
private void PrepareNewGameIfReady(string channelName, QuizGame quizGame) { if (quizGame.ReadyForNewGame()) { // Get a new question for this quiz game. QuizGameInfo newGameQuestion = GetNewQuestion(channelName); // Set the hint cooldown quizGame.SetHintCooldown(HINT_COOLDOWN); // Set the quiz up quizGame.StartNewGame(newGameQuestion); // Send message in channel SendNewGameMessage(channelName); } }
private QuizGameInfo GetFileBasedQuestion(string channelName) { List <QuizGameInfo> randomQuestionList = new List <QuizGameInfo>(); QuizGameInfo randomQuestion = null; if (m_quizGameContent.QuizGames.ContainsKey("default")) { randomQuestionList.AddRange(m_quizGameContent.QuizGames["default"]); } if (m_quizGameContent.QuizGames.ContainsKey(channelName)) { randomQuestionList.AddRange(m_quizGameContent.QuizGames[channelName]); } if (m_usedQuestions.ContainsKey(channelName)) { if (m_usedQuestions[channelName].Count == randomQuestionList.Count) { m_usedQuestions[channelName].Clear(); } } else { m_usedQuestions.Add(channelName, new List <QuizGameInfo>()); } while (randomQuestion == null) { int iRandomIndex = m_rng.Next(0, randomQuestionList.Count); if (!m_usedQuestions[channelName].Contains(randomQuestionList[iRandomIndex])) { randomQuestion = randomQuestionList[iRandomIndex]; m_usedQuestions[channelName].Add(randomQuestion); } } return(randomQuestion); }
public void EndGame() { m_currentGameContent = null; }
public QuizGame() { m_currentGameContent = null; m_currentWinners = new List <string>(); }