public CSharpTrivia2020Form() { InitializeComponent(); triviaController = new TriviaController(this); listBox1.Items.Add("General Knowledge Quiz"); listBox1.Items.Add("Math Quiz"); }
// Start is called before the first frame update void Start() { SimpleController_UsingPlayerInput.playerIsOnRollerCoaster = false; if (SceneManager.GetActiveScene().name.Equals("RollercoasterThemePark") && Main.playedTwinkieMemory) { // Start off on the rollercoaster RideRailcoaster.StartRide(GameObject.FindGameObjectWithTag("Player"), true); // Show twinkie trivia TriviaController.StartNewTriviaRound("twinkie"); } }
public void Index_HttpGet_CorrectlyReturnsRightView() { var controller = new TriviaController(); var result = controller.Index(); // Assert the output Assert.IsNotNull(result); Assert.IsTrue(result is ViewResult); var viewResult = result as ViewResult; // Assert the View and Model Assert.AreEqual("Index", viewResult.ViewName); Assert.IsNotNull(viewResult.Model); Assert.IsTrue(viewResult.Model is TriviaModel); }
public void Index_HttpPost_CorrectlyRedirectsToIncorrectView() { //Arrange var model = new TriviaModel { SubmittedAnswer = "Tom Hanks" }; var controller = new TriviaController(); //Act var result = controller.Index(model); //Assert Assert.IsNotNull(result); Assert.IsTrue(result is RedirectToRouteResult); var redirectResult = result as RedirectToRouteResult; //Assert the right action is redirected Assert.AreEqual("Incorrect", redirectResult.RouteValues["action"]); }
public ManageQuestionsForm(TriviaController triviaController, Form mainForm) { this.triviaController = triviaController; this.mainForm = mainForm; }
public async Task SingleTriviaCommandAsync(CommandContext ctx, [Description("How many questions to ask. Leave blank for a single question.")] int questions = 1, [Description("The category to pick questions from. If you want this random, leave it blank or use an id of 0.")] QuestionCategory questionCategory = QuestionCategory.All) { var cfg = this._model.Configs.Find(ctx.Guild.Id); if (cfg is null) { cfg = new GuildConfig(ctx.Guild.Id); this._model.Configs.Add(cfg); await this._model.SaveChangesAsync(); } if (cfg.TriviaQuestionLimit <= 0) { cfg.TriviaQuestionLimit = 1; } int qNumber = questions; if (qNumber > cfg.TriviaQuestionLimit) { qNumber = cfg.TriviaQuestionLimit; await ctx.RespondAsync($"Set the question number to this server's question limit: {qNumber}"); } if (qNumber <= 0) { qNumber = 1; } var game = await TriviaController.StartGame(ctx.Channel.Id, qNumber, questionCategory); if (game is null) { await ctx.RespondAsync("Failed to start a new game - A game is already in progress!"); return; } try { var interact = ctx.Client.GetInteractivity(); await ctx.RespondAsync($"Starting a new game of trivia with {qNumber} questions!"); while (await game.PopNextQuestion(out TriviaQuestion? question)) { #pragma warning disable CS8602 // Dereference of a possibly null reference. // False positive. var mapped = question.GetMappedAnswers(); #pragma warning restore CS8602 // Dereference of a possibly null reference. var embed = new DiscordEmbedBuilder() .WithColor(DiscordColor.Purple) .WithTitle("Trivia!") .WithDescription("You have 20 seconds to answer this question! Type the number of the answer that is correct to win!") .AddField(question.QuestionString, mapped.Item1) .AddField("Difficulty", $"`{question.DifficultyString}`", true) .AddField("Category", question.CategoryString); await ctx.RespondAsync(embed: embed); var response = await interact.WaitForMessageAsync(x => x.ChannelId == ctx.Channel.Id && x.Author.Id == ctx.Member.Id, TimeSpan.FromSeconds(20)); if (response.TimedOut) { await ctx.RespondAsync($"The question wans't answered in time! The correct answer was: {question.PossibleAnswers[question.CorrectAnswerKey]}"); break; // Goto finally block } var trivia = this._model.TriviaPlayers.Find(response.Result.Author.Id); if (trivia is null) { trivia = new TriviaPlayer(response.Result.Author.Id); this._model.Add(trivia); } var answerString = response.Result.Content.ToLowerInvariant().Trim(); if (answerString == mapped.Item2.ToString() || answerString == mapped.Item3) { // Response is correct await ctx.RespondAsync($"Thats the correct answer! You earned {question.Worth.ToMoney()}"); var wallet = this._model.Wallets.Find(response.Result.Author.Id); if (wallet is null) { wallet = new Wallet(response.Result.Author.Id); await this._model.AddAsync(wallet); } wallet.Add(question.Worth); trivia.Points += question.Worth / 10; trivia.QuestionsCorrect++; } else { // Response is incorrect await ctx.RespondAsync($"Thats not the right answer! The correct answer was: {question.PossibleAnswers[question.CorrectAnswerKey]}"); trivia.Points--; trivia.QuestionsIncorrect++; } if (trivia.Username != ctx.Member.Username) { trivia.Username = ctx.Member.Username; } await this._model.SaveChangesAsync(); } } finally { TriviaController.EndGame(ctx.Channel.Id); await ctx.RespondAsync("Trivia Game Complete!"); } }
// MVC Pattern // - Model: Quiz // - View: Question Form // - Controller: Trivia Controller public QuestionForm(TriviaController triviaController, Form formOwner) { InitializeComponent(); this.triviaController = triviaController; Owner = formOwner; }
void Start() { triviaController = FindObjectOfType <TriviaController> (); }
public void Setup() { _mockMediator = new Mock <IMediator>(); _controller = new TriviaController(_mockMediator.Object); }