public QuizBuilder(QuizGame quizGame, mapView map, Courses course, List <Trivia> questions, int Index) { if (questions[Index] == null && questions[Index + 1] == null) //If there are multiple nulls pulled from the DB course is not fully built { Console.WriteLine("Course is not fully built"); quizGame.Close(); quizGame.Dispose(); } else if (questions[Index] == null) //Try the next item in the questions if first object is null. DB initially creates a null object so just add 1 to index. //Also update the original index passed all the way from mapView { map.QuestionIndex++; currentQuestion = questions[Index + 1]; selAnswer = currentQuestion.selAnswer; Console.Out.WriteLine("Correct Answer: " + selAnswer); quizGame.questionLabel.Text = currentQuestion.Question; quizGame.button1.Text = currentQuestion.Answer1; quizGame.button2.Text = currentQuestion.Answer2; quizGame.button3.Text = currentQuestion.Answer3; quizGame.button4.Text = currentQuestion.Answer4; } else { currentQuestion = questions[Index]; selAnswer = currentQuestion.selAnswer; Console.Out.WriteLine("Correct Answer: " + selAnswer); quizGame.questionLabel.Text = currentQuestion.Question; quizGame.button1.Text = currentQuestion.Answer1; quizGame.button2.Text = currentQuestion.Answer2; quizGame.button3.Text = currentQuestion.Answer3; quizGame.button4.Text = currentQuestion.Answer4; } }
public async Task ExecuteGroupAsync(CommandContext ctx, [Description("desc-game-quiz-cat-id")] int id, [Description("desc-game-quiz-amount")] int amount = 10, [Description("desc-game-quiz-diff")] int diff = 0) { if (amount is < 5 or > 20) { throw new CommandFailedException(ctx, "cmd-err-game-quiz-amount", 5, 20); } if (diff is < 0 or > 2) { throw new CommandFailedException(ctx, "cmd-err-game-quiz-diff"); } if (this.Service.IsEventRunningInChannel(ctx.Channel.Id)) { throw new CommandFailedException(ctx, "cmd-err-evt-dup"); } IReadOnlyList <QuizQuestion>?questions = await QuizService.GetQuestionsAsync(id, amount, (QuestionDifficulty)diff); if (questions is null || !questions.Any()) { throw new CommandFailedException(ctx, "cmd-err-game-quiz-cat"); } var quiz = new QuizGame(ctx.Client.GetInteractivity(), ctx.Channel, questions); await this.RunQuizAsync(ctx, quiz); }
public void BeTrue_AfterStarting() { var quizGame = new QuizGame(new Mock <IRepository>().Object, new Mock <ICurrencyGenerator>().Object, new Mock <IAutomatedActionSystem>().Object); quizGame.StartGame(new Mock <IChatClient>().Object); quizGame.IsRunning.Should().BeTrue(); }
public void PreventJoining_GivenGameNotStarted() { var quizGame = new QuizGame(new Mock <IRepository>().Object, new Mock <ICurrencyGenerator>().Object, new Mock <IAutomatedActionSystem>().Object); string displayName = Guid.NewGuid().ToString(); var result = quizGame.AttemptToJoin(new ChatUser { DisplayName = displayName }); result.Should().Be(QuizJoinResults.NotJoinTimeResult(displayName)); }
public async Task <ActionResult> Edit(QuizGame quizGame) { if (ModelState.IsValid) { await _quizGameManager.EditAsync(quizGame); return(RedirectToAction("Index")); } return(View(new QuizGame())); }
public void AllowJoining_GivenNewUserDuringJoinWindow() { var quizGame = new QuizGame(new Mock <IRepository>().Object, new Mock <ICurrencyGenerator>().Object, new Mock <IAutomatedActionSystem>().Object); string displayName = Guid.NewGuid().ToString(); quizGame.StartGame(new Mock <IChatClient>().Object); var result = quizGame.AttemptToJoin(new ChatUser { DisplayName = displayName }); result.Should().Be(QuizJoinResults.SuccessJoinResult(displayName)); }
public void PreventJoining_GivenAlreadyCompetingUser() { var quizGame = new QuizGame(new Mock <IRepository>().Object, new Mock <ICurrencyGenerator>().Object, new Mock <IAutomatedActionSystem>().Object); var chatUser = new ChatUser { DisplayName = "Brendan" }; quizGame.StartGame(new Mock <IChatClient>().Object); quizGame.AttemptToJoin(chatUser); var result = quizGame.AttemptToJoin(chatUser); result.Should().Be(QuizJoinResults.AlreadyInGameResult(chatUser.DisplayName)); }
public Data.QuizGame CreateSingleUserGame(string userId, Guid quizId) { var quiz = _quizDb.Quizzes.FirstOrDefault(x => x.Id == quizId); if (quiz == null) { return(null); } var level = new GameLevel { Quiz = quiz }; var player = new GamePlayer { UserId = userId, IsInitiator = true }; var game = new QuizGame { CreatedAt = DateTime.Now, Levels = new List <GameLevel> { level }, Players = new List <GamePlayer> { player } }; try { //quizDb.GameLevels.Add(level); //quizDb.GamePlayers.Add(player); _quizDb.QuizGames.Add(game); _quizDb.SaveChanges(); return(game); } catch (Exception) { return(null); } }
public async Task <ActionResult> Delete(string id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } QuizGame quizGame = await _quizGameManager.GetItemAsync(id); if (quizGame == null) { return(HttpNotFound()); } return(View(quizGame)); }
public void PreventJoining_GivenQuestionsBeingAsked() { var automatedActionSystem = new FakeActionSystem(); var mockRepo = new Mock <IRepository>(); var quizGame = new QuizGame(mockRepo.Object, new Mock <ICurrencyGenerator>().Object, automatedActionSystem); string displayName = Guid.NewGuid().ToString(); quizGame.StartGame(new Mock <IChatClient>().Object); mockRepo.Setup(x => x.List(It.IsAny <DataItemPolicy <QuizQuestion> >())) .Returns(new List <QuizQuestion> { new QuizQuestion() }); automatedActionSystem.IntervalAction.Invoke(); // run the action, starting the questions var result = quizGame.AttemptToJoin(new ChatUser { DisplayName = displayName }); result.Should().Be(QuizJoinResults.NotJoinTimeResult(displayName)); }
public override Task <QuizCreatedResponse> CreateGame(QuizCreateRequest request, ServerCallContext context) { var quiz = new Domain.Entities.Quiz() { Title = request.Quiz.Title, Description = request.Quiz.Description, ImageUrl = request.Quiz.ImageUrl, Questions = request.Quiz.Questions.Select(x => new Question() { Timeout = x.Timeout, Title = x.Title, Answer = x.Answers.Select(answer => new Answer() { Description = answer.Description, IsCorrect = answer.IsCorrect }).ToList(), }).ToList() }; var random = new Random(); ulong id = (ulong)random.Next(21000000, 25000000); var game = new QuizGame() { Quiz = quiz, Id = id, Started = DateTime.UtcNow, Users = new List <Player>() }; var result = _manager.CreateNew(game); var response = new QuizCreatedResponse() { Quiz = request.Quiz, Id = result.Id }; return(Task.FromResult(response)); }
public async Task <QuizGame> GetItemAsync(string id) { QuizGame quizGame = await _quizGameRepository.GetItemAsync(id); return(quizGame); }
public async Task EditAsync(QuizGame quizGame) { await _quizGameRepository.UpdateItemAsync(quizGame.Id, quizGame); }
public async Task CreateAsync(QuizGame quizGame) { Document document = await _quizGameRepository.CreateItemAsync(quizGame); }
public void BeFalse_ByDefault() { var quizGame = new QuizGame(new Mock <IRepository>().Object, new Mock <ICurrencyGenerator>().Object, new Mock <IAutomatedActionSystem>().Object); quizGame.IsRunning.Should().BeFalse(); }
public async Task <ActionResult> Details(string id) { QuizGame quizGame = await _quizGameManager.GetItemAsync(id); return(View(quizGame)); }