// 'get_question_result' // This action is executed from 'get_next_question' // This shows the result of the question that they answered // A timer is set for 3 seconds // When the timer runs out, the action 'try_get_next_question' is executed private void GetQuestionResult(GameContext ctx) { // set all currently playing displays to freq. 10 foreach (ServerConnection connection in ctx.Server.GetConnectionsInState(GameState.Playing)) { connection.Frequency = 11; } ctx.Session.SpectateFrequency = 11; //session.CancelQueuedAction(); int currentQuestion = ctx.Session.ValueOf <int>("current_question"); ctx.Session.SetValue("players_answered", 0); DisplayContent content = ctx.Server.GetBroadcast(11).Content; content .GetComponent("result") .Draw(ctx.Session.ValueOf <int>("current_question"), ctx.Session.GetConfigValue <int>("questioncount"), CurrentQuestion.Question, CurrentAnswers.Select((x, i) => x.IsCorrect ? $"[**{GetLetter(i).ToUpper()}**] {x.Response}" : null) .First(x => !string.IsNullOrWhiteSpace(x))); foreach (PlayerData playerData in ctx.Session.Players) { bool hasAnswered = playerData.ValueOf <bool>("has_answered"); if (!hasAnswered) { playerData.ResetProperty("streak"); } else { bool isCorrect = playerData.ValueOf <bool>("is_correct"); if (isCorrect) { int points = GetPoints(CurrentQuestion.Value, playerData.ValueOf <int>("streak"), playerData.ValueOf <int>("answer_position"), CurrentQuestion.Difficulty); playerData.AddToValue("score", points); } } playerData.ResetProperty("has_answered"); playerData.ResetProperty("is_correct"); } ctx.Session.QueueAction(TimeSpan.FromSeconds(5), "try_get_next_question"); }
private void GetNextQuestion(GameContext ctx) { // set all currently playing displays to freq. 10 foreach (ServerConnection connection in ctx.Server.GetConnectionsInState(GameState.Playing)) { connection.Frequency = 10; } ctx.Session.SpectateFrequency = 10; int currentQuestion = ctx.Session.ValueOf <int>("current_question"); CurrentQuestion = QuestionPool[currentQuestion]; ctx.Session.AddToValue("current_question", 1); DisplayContent content = ctx.Server.GetBroadcast(10).Content; content.GetComponent("question_header") .Draw( Format.Counter(ctx.Session.GetConfigValue <double>("questionduration")), ctx.Session.ValueOf <int>("current_question"), ctx.Session.GetConfigValue <int>("questioncount"), CurrentQuestion.Question); // select only 3 random answers and shuffle with the correct answer in there CurrentAnswers = Randomizer.Shuffle(Randomizer .ChooseMany(CurrentQuestion.Answers.Where(x => !x.IsCorrect), Math.Min(3, CurrentQuestion.Answers.Count(x => !x.IsCorrect))) .Append(CurrentQuestion.Answers.First(x => x.IsCorrect))); content .GetComponent("answers") .Draw(CurrentAnswers.Select((x, i) => $"[**{GetLetter(i).ToUpper()}**] {x.Response}")); content .GetComponent("footer") .Draw(CurrentQuestion.Difficulty.ToString(), string.IsNullOrWhiteSpace(CurrentQuestion.TopicOverride) ? CurrentQuestion.Topic.ToString() : CurrentQuestion.TopicOverride, $"{CurrentQuestion.Value} {Format.TryPluralize("Point", CurrentQuestion.Value)}"); ctx.Session.QueueAction(TimeSpan.FromSeconds(ctx.Session.GetConfigValue <double>("questionduration")), "get_question_result"); }