public TriviaQuestion GetRandomQuestion(List <string> exclude) { if (pool.Count == 0) { return(null); } TriviaQuestion tq = pool[_r.Next(0, pool.Count)]; if (exclude.Count > 0 && exclude.Count < pool.Count) { while (exclude.Contains(tq.Question)) { tq = pool[_r.Next(0, pool.Count)]; } } return(tq); }
public TriviaQuestionsPool() { _r = new Random(); pool = new List <TriviaQuestion>(); JArray arr = JArray.Parse(File.ReadAllText("questions.txt")); foreach (var item in arr) { TriviaQuestion tq; tq = new TriviaQuestion((string)item["Question"], (string)item["Answer"]); if (item?["Category"] != null) { tq.Category = item["Category"].ToString(); } pool.Add(tq); } }
public TriviaQuestionsPool() { _r = new Random(); pool = new List<TriviaQuestion>(); JArray arr = JArray.Parse(File.ReadAllText("questions.txt")); foreach (var item in arr) { TriviaQuestion tq; tq = new TriviaQuestion((string)item["Question"], (string)item["Answer"]); if (item?["Category"] != null) { tq.Category = item["Category"].ToString(); } pool.Add(tq); } }
private void LoadNextRound() { Channel ch = client.GetChannel(_channellId); if(currentQuestion!=null) oldQuestions.Add(currentQuestion.Question); currentQuestion = TriviaQuestionsPool.Instance.GetRandomQuestion(oldQuestions); if (currentQuestion == null || isQuit) { #pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed ch.Send("Trivia bot stopping. :\\\n" + GetLeaderboard()); #pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed FinishGame(); return; } Timer t = new Timer(); t.Interval = 2500; t.Enabled = true; t.Elapsed += async (s, ev) => { active = true; await ch.Send(currentQuestion.ToString()); t.Enabled = false; timeout.Enabled = true;//starting countdown of the next question stopwatch.Reset(); stopwatch.Start(); }; return; }