Esempio n. 1
0
 /// <summary>
 /// Remembers the current question (for stats) and queries a new question according to the current game settings
 /// </summary>
 private async Task NewQuestion()
 {
     if (_gamestate == GameStates.Playing)
     {
         previousQuestions.Add(_currentQuestion);
     }
     _currentQuestion =
         (await TriviaGames.GetQuestions(
              categoryId: Category.id, difficulty: Difficulty, token: _token, type: QuestionType))
         .FirstOrDefault();
 }
Esempio n. 2
0
        /// <summary>
        /// Sets all the neccessary information of the games embedbuilder to send out the startmenu
        /// including the possibly available stats
        /// </summary>
        private void PrepareStartMenue(IUserMessage socketMsg)
        {
            // Get the startmenu embedbuilder that has all the settings of this game set up
            _emb = TriviaGames.TrivaStartingEmbed(this);
            // String to build up the stats
            var stats = "";
            // Group the questions by difficulty for stats
            var orderd = previousQuestions.GroupBy(question => question.difficulty, question => question).ToList();
            // Generate the stats by saving global wins/losses and difficulty dependend wins/losses
            double overallCorrect = 0;
            double overallWrong   = 0;

            foreach (var difficulty in orderd)
            {
                if (difficulty.Key == null)
                {
                    continue;
                }
                double correct = 0;
                double wrong   = 0;
                foreach (var question in difficulty)
                {
                    if (question.correct)
                    {
                        correct++;
                    }
                    else
                    {
                        wrong++;
                    }
                }

                overallCorrect += correct;
                overallWrong   += wrong;
                stats          += $"{TriviaGames.Difficulties[difficulty.Key]}: " +
                                  $"**{(int)(correct / (correct + wrong) * 100)}%** correct ({correct}/{correct + wrong})\n";
            }
            // Only show the overall stat if the player had questions with different difficulties
            if (orderd.Count > 1)
            {
                stats += $"Overall: " +
                         $"**{(int)(overallCorrect / (Math.Max(overallCorrect + overallWrong, 1)) * 100)}%**" +
                         $" correct ({overallCorrect}/{overallCorrect + overallWrong})\n";
            }
            // Only add a field if there is actually something to show
            if (string.IsNullOrEmpty(stats) == false)
            {
                _emb.AddField("Your Stats: ", stats);
            }
            _gamestate = GameStates.StartPage;
        }
Esempio n. 3
0
 internal TriviaGame(ulong gameMessageId, ulong playerId, string category = "any",
                     string difficulty = "", string questionType = "")
 {
     PlayerId             = playerId;
     GameMessageId        = gameMessageId;
     Difficulty           = difficulty;
     QuestionType         = questionType;
     previousQuestions    = new List <Question>();
     Category             = TriviaGames.Categories.Find(cat => cat.name.ToLower() == category);
     _token               = TriviaGames.NewToken().Result;
     _currentCategoryPage = 1;
     _gamestate           = GameStates.StartPage;
     _emb = TriviaGames.TrivaStartingEmbed(this);
 }
Esempio n. 4
0
        /// <summary>
        /// Set the game embedbuilder up to be send out to show the paged categories
        /// </summary>
        private void PrepareCategoryEmb()
        {
            _emb.Fields.Clear();
            _emb.WithDescription(
                "Choose the category the questions should be in with the corresponding reaction.\n" +
                $"You can navigate the pages with {TriviaGames.ReactOptions["left"]} and {TriviaGames.ReactOptions["right"]} " +
                $"or {TriviaGames.ReactOptions["ok"]} to go back without changing the category.");
            var categories = TriviaGames.CategoriesPaged(_currentCategoryPage, CategoriesPerPage);

            for (var i = 1; i <= categories.Count; i++)
            {
                _emb.AddField(TriviaGames.ReactOptions[i.ToString()].Name + "  " + categories[i - 1].name, Constants.InvisibleString);
            }
        }
Esempio n. 5
0
        /// <summary>
        /// Set the game embedbuilder up to be send out to show a question + eventually the result of the previous one
        /// </summary>
        private async Task PreparePlayEmb(IUserMessage socketMsg, IReaction reaction)
        {
            // If the game is already in the playing state we want to show the result of the last guess
            var wrongRightMessage =
                _gamestate == GameStates.Playing
                ? GuessingResponse(socketMsg.Embeds.FirstOrDefault(), reaction)
                : null;

            await NewQuestion();

            // Set the gamestate in case we are came from the main menue
            _gamestate = GameStates.Playing;
            _emb       = TriviaGames.QuestionToEmbed(_currentQuestion, _emb);
            // Add empty field for cosmetics and one that tells how to get back to the main menue
            _emb.AddField(Constants.InvisibleString, $"{wrongRightMessage}{Constants.InvisibleString}");
            _emb.AddField(Constants.InvisibleString, $"{TriviaGames.ReactOptions["ok"]} to get back to the main menue");
        }