Ejemplo n.º 1
0
        public async Task GetResults(CommandContext ctx)
        {
            var strBuilder = new StringBuilder("### _Game Results_ ###\n");

            strBuilder.AppendLine($"Rounds played: {_roundCount}");
            strBuilder.AppendLine();

            var highestPlayer = new UserGameData(null);


            foreach (var(user, gameData) in _players)
            {
                strBuilder.AppendLine($"{user.Username} results:");
                if (gameData.Points > highestPlayer.Points)
                {
                    highestPlayer = gameData;
                }
                strBuilder.Append(gameData.GetGameData());
                strBuilder.AppendLine();
            }

            strBuilder.AppendLine($"Player: {highestPlayer.User.Mention} Wins with {highestPlayer.Points} points!");

            await ctx.RespondAsync(strBuilder.ToString());
        }
Ejemplo n.º 2
0
        public async Task AskQuestion(CommandContext ctx)
        {
            var question = GameMaster.GetQuestion(_askedQuestions.Select(q => q.Id).ToList());
            await ctx.RespondAsync($"Question: {question.QuestionText} [Time limit: 1 min]");

            var interactivity = ctx.Client.GetInteractivityModule();

            var answer = await interactivity.WaitForMessageAsync(msg =>
            {
                // If this user has already answered this question, do not accept any new answers.
                if (_players.ContainsKey(msg.Author) &&
                    _players[msg.Author].QuestionsAnswered.ContainsKey(question.QuestionText))
                {
                    msg.DeleteAsync();
                    return(false);
                }

                var result   = question.VerifyAnswer(msg.Content);
                var response = false;
                switch (result.AnswerStatus)
                {
                case AnswerStatus.PartiallyCorrect:
                    if (_players.ContainsKey(msg.Author))
                    {
                        var player = _players[msg.Author];
                        player.AddAnswer(question.QuestionText, msg.Content, (int)((double)question.Points / 2));
                    }
                    else
                    {
                        var userData = new UserGameData(msg.Author);
                        userData.AddAnswer(question.QuestionText, msg.Content, (int)((double)question.Points / 2));
                        _players.TryAdd(msg.Author, userData);
                    }

                    break;

                case AnswerStatus.Error:
                    _logger.Error(result.Exception, $"Error parsing command for question: {question.QuestionText}");

                    break;

                case AnswerStatus.NormalCorrect:
                    if (_players.ContainsKey(msg.Author))
                    {
                        var player = _players[msg.Author];
                        player.AddAnswer(question.QuestionText, msg.Content, question.Points);
                    }
                    else
                    {
                        var userData = new UserGameData(msg.Author);
                        userData.AddAnswer(question.QuestionText, msg.Content, question.Points);
                        _players.TryAdd(msg.Author, userData);
                    }

                    response = true;
                    break;

                case AnswerStatus.BonusCorrect:
                    if (_players.ContainsKey(msg.Author))
                    {
                        var player = _players[msg.Author];
                        player.AddAnswer(question.QuestionText, msg.Content, question.BonusPoints.Value);
                    }
                    else
                    {
                        var userData = new UserGameData(msg.Author);
                        userData.AddAnswer(question.QuestionText, msg.Content, question.BonusPoints.Value);
                        _players.TryAdd(msg.Author, userData);
                    }

                    response = true;
                    break;

                case AnswerStatus.Incorrect:
                    if (_players.ContainsKey(msg.Author))
                    {
                        var player = _players[msg.Author];
                        player.AddAnswer(question.QuestionText, msg.Content, 0);
                    }
                    else
                    {
                        var userData = new UserGameData(msg.Author);
                        userData.AddAnswer(question.QuestionText, msg.Content, 0);
                        _players.TryAdd(msg.Author, userData);
                    }
                    break;
                }

                msg.DeleteAsync();
                return(response);
            }, TimeSpan.FromMinutes(1));

            if (answer != null)
            {
                await ctx.RespondAsync($"User: {answer.User.Mention} answered correctly! [Round Over]");
            }
            else
            {
                await ctx.RespondAsync("Timeout reached! [Round Over]");
            }

            _roundCount++;

            _askedQuestions.Add(question);
        }