示例#1
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;
        }
示例#2
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);
 }