Esempio n. 1
0
        public static UserDifficulty SuggestingDifficulty(string userName)
        {
            ToFile         objnew         = SaveToFile.DeserializeLastTest(userName);
            UserDifficulty userDifficulty = UserDifficulty.Easy;

            Console.WriteLine($"Last time you did the test on {objnew.UserDifficulty} level and got {objnew.TotalScore}/{objnew.NumberOfQuestions}");
            double decimalScore = (double)objnew.TotalScore / (double)objnew.NumberOfQuestions;

            if (objnew.UserDifficulty == UserDifficulty.Easy)
            {
                if (decimalScore <= 0.7)
                {
                    Console.WriteLine($"You should stay on Easy difficulty");
                    userDifficulty = UserDifficulty.Easy;
                }
                else
                {
                    Console.WriteLine($"Easy difficulty seems to easy for you💪! You should go up to Normal difficulty");
                    userDifficulty = UserDifficulty.Normal;
                }
            }
            else if (objnew.UserDifficulty == UserDifficulty.Normal)
            {
                if (decimalScore <= 0.3)
                {
                    Console.WriteLine($"Normal difficulty seems to be to hard for you☹️. You should go down to Easy difficulty");
                    userDifficulty = UserDifficulty.Easy;
                }
                else if ((decimalScore > 0.3) && (decimalScore <= 0.7))
                {
                    Console.WriteLine($"You should stay on Normal difficulty");
                    userDifficulty = UserDifficulty.Normal;
                }
                else
                {
                    Console.WriteLine($"Normal difficulty seems to easy for you💪! You should go up to Hard difficulty");
                    userDifficulty = UserDifficulty.Hard;
                }
            }
            else if (objnew.UserDifficulty == UserDifficulty.Hard)
            {
                if (decimalScore <= 0.3)
                {
                    Console.WriteLine($"Hard difficulty seems to hard for you☹️. You should go down to Normal difficulty");
                    userDifficulty = UserDifficulty.Normal;
                }
                else if ((decimalScore > 0.3) && (decimalScore <= 0.8))
                {
                    Console.WriteLine($"You should stay on Hard difficulty");
                    userDifficulty = UserDifficulty.Hard;
                }
                else
                {
                    Console.WriteLine($"You are a maths Genius🥳! Sadly this is the hardest level");
                    userDifficulty = UserDifficulty.Hard;
                }
            }
            return(userDifficulty);
        }
        static (UserDifficulty, int, string, int, string) UserInputs(string userName)
        {
            Dictionary <string, UserDifficulty> difficultyDictionary = new Dictionary <string, UserDifficulty>
            {
                { "E", UserDifficulty.Easy },
                { "N", UserDifficulty.Normal },
                { "H", UserDifficulty.Hard }
            };

            string userInputDifficulty = "E";
            int    numberOfQuestions;
            string autoDifficultyInput = "";
            int    numberOfSeconds;
            string testOrTwoPlayer;

            Console.ForegroundColor = ConsoleColor.Magenta;
            do
            {
                Console.WriteLine("Please type '2' for 2 player and 'T' for test");
                testOrTwoPlayer = Console.ReadLine().ToUpper();
            } while (testOrTwoPlayer != "2" && testOrTwoPlayer != "T");

            if (File.Exists(FileUtils.GetUserFileName(userName)))
            {
                do
                {
                    Console.WriteLine("Would you like to continue with the suggested difficulty? Please type 'Y' or 'N'");
                    autoDifficultyInput = Console.ReadLine().Substring(0).ToUpper();
                } while (autoDifficultyInput != "Y" && autoDifficultyInput != "N");
            }

            if (autoDifficultyInput != "Y")
            {
                do
                {
                    Console.WriteLine("Which difficulty level would you like to do! Please type E for Easy, N for Normal and H for Hard");
                    userInputDifficulty = Console.ReadLine().ToUpper();
                } while (userInputDifficulty != "E" && userInputDifficulty != "N" && userInputDifficulty != "H");
            }
            UserDifficulty userDifficulty = difficultyDictionary[userInputDifficulty];

            do
            {
                Console.WriteLine("How many questions would you like to answer? Please type a number divisible by 10!");
                int.TryParse(Console.ReadLine(), out numberOfQuestions);
            } while (numberOfQuestions % 10 != 0);

            do
            {
                Console.WriteLine("How many seconds would you like the test to be? Please type a number divisible by 30!");
                int.TryParse(Console.ReadLine(), out numberOfSeconds);
            } while (numberOfSeconds % 10 != 0);
            Console.ResetColor();

            return(userDifficulty, numberOfQuestions, autoDifficultyInput, numberOfSeconds, testOrTwoPlayer);
        }
Esempio n. 3
0
 public ToFile(int numberOfQuestions, UserDifficulty userDifficulty, int totalScore, double totalEasyQuestion, double totalEasyScore, double totalNormalQuestion, double totalNormalScore, double totalHardQuestion, double totalHardScore, double easyTests, double normalTests, double hardTests)
 {
     NumberOfQuestions   = numberOfQuestions;
     UserDifficulty      = userDifficulty;
     TotalScore          = totalScore;
     TotalEasyQuestion   = totalEasyQuestion;
     TotalEasyScore      = totalEasyScore;
     TotalNormalQuestion = totalNormalQuestion;
     TotalNormalScore    = totalNormalScore;
     TotalHardQuestion   = totalHardQuestion;
     TotalHardScore      = totalHardScore;
     EasyTests           = easyTests;
     NormalTests         = normalTests;
     HardTests           = hardTests;
 }
 public ToFile(int numberOfQuestions, UserDifficulty userDifficulty, int totalScore, double totalEasyQuestion, double totalEasyScore, double totalNormalQuestion, double totalNormalScore, double totalHardQuestion, double totalHardScore, double easyTests, double normalTests, double hardTests, int twoPlayerChallengeScore, int allTimeCorrectAnswers)
 {
     NumberOfQuestions       = numberOfQuestions;
     UserDifficulty          = userDifficulty;
     TotalScore              = totalScore;
     TotalEasyQuestion       = totalEasyQuestion;
     TotalEasyScore          = totalEasyScore;
     TotalNormalQuestion     = totalNormalQuestion;
     TotalNormalScore        = totalNormalScore;
     TotalHardQuestion       = totalHardQuestion;
     TotalHardScore          = totalHardScore;
     EasyTests               = easyTests;
     NormalTests             = normalTests;
     HardTests               = hardTests;
     TwoPlayerChallengeScore = twoPlayerChallengeScore;
     AllTimeCorrectAnswers   = allTimeCorrectAnswers;
 }
Esempio n. 5
0
        static (UserDifficulty, int, string, int) UserInputs()
        {
            Dictionary <string, UserDifficulty> difficultyDictionary = new Dictionary <string, UserDifficulty>
            {
                { "E", UserDifficulty.Easy },
                { "N", UserDifficulty.Normal },
                { "H", UserDifficulty.Hard }
            };

            string userInputDifficulty = "E";
            int    numberOfQuestions;
            string autoDifficultyInput;
            int    numberOfSeconds;

            do
            {
                Console.WriteLine("Would you like to continue with the suggested difficulty? Please type 'Y' or 'N'");
                autoDifficultyInput = Console.ReadLine().Substring(0).ToUpper();
            } while (autoDifficultyInput != "Y" && autoDifficultyInput != "N");

            if (autoDifficultyInput == "N")
            {
                do
                {
                    Console.WriteLine("Which difficulty level would you like to do! Please type E for Easy, N for Normal and H for Hard");
                    userInputDifficulty = Console.ReadLine().ToUpper();
                } while (userInputDifficulty != "E" && userInputDifficulty != "N" && userInputDifficulty != "H");
            }

            UserDifficulty userDifficulty = difficultyDictionary[userInputDifficulty];

            do
            {
                Console.WriteLine("How many questions would you like to answer? Please type a number divisible by 10!");
                int.TryParse(Console.ReadLine(), out numberOfQuestions);
            } while (numberOfQuestions % 10 != 0);

            do
            {
                Console.WriteLine("How many seconds would you like the test to be? Please type a number divisible by 30!");
                int.TryParse(Console.ReadLine(), out numberOfSeconds);
            } while (numberOfSeconds % 30 != 0);

            return(userDifficulty, numberOfQuestions, autoDifficultyInput, numberOfSeconds);
        }
        public static OperationQuestionScore RunTest(int numberOfQuestionsLeft, UserDifficulty userDifficulty, int numberOfSeconds)
        {
            Random random = new Random();

            var(operationMin, operationMax) = GetPossibleOperationsByDifficulty(userDifficulty);
            var      score        = new OperationQuestionScore();
            RunTimer RunWithTimer = new RunTimer(numberOfSeconds);

            while (numberOfQuestionsLeft > 0 && RunWithTimer.IsTimeLeft)
            {
                int           mathRandomOperation = random.Next(operationMin, operationMax);
                MathOperation mathOperation       = (MathOperation)mathRandomOperation;
                var(message, correctAnswer) = GetMathsEquation(mathOperation, userDifficulty);
                if (mathRandomOperation == 4 || mathRandomOperation == 6)
                {
                    WriteToScreen($"To the nearest integer, What is {message} =", false);
                }
                else
                {
                    WriteToScreen($"What is {message} =", false);
                }

                double userAnswer = Convert.ToDouble(ReadInput());
                if (Math.Round(correctAnswer) == userAnswer)
                {
                    Console.ForegroundColor = ConsoleColor.Green;
                    WriteToScreen("Well Done!", false);
                    Console.ResetColor();
                    score.Increment(mathOperation, true);
                }
                else
                {
                    Console.ForegroundColor = ConsoleColor.Red;
                    WriteToScreen("Your answer is incorrect!", false);
                    Console.ResetColor();
                    score.Increment(mathOperation, false);
                }
                numberOfQuestionsLeft--;
                RunWithTimer.StopTimer(numberOfQuestionsLeft);
            }
            return(score);
        }
        public static void Main(string[] args)
        {
            var filePath = Path.Combine(AppContext.BaseDirectory, "AccountDetail.gitignore");

            (string userName, int LogInOrSignUp) = UserManager.LogInProcess(filePath);

            OperationQuestionScore score;
            OperationQuestionScore playerTwoScore;

            UserDifficulty userSuggestingDifficulty = UserDifficulty.Easy;

            if (File.Exists(FileUtils.GetUserFileName(userName)))
            {
                userSuggestingDifficulty = SuggestingDifficulty(userName);
            }
            var(userDifficulty, numberOfQuestions, autoDifficultyInput, numberOfSeconds, testOrTwoPlayer) = UserInputs(userName);
            string playerTwoUserName;
            int    playerTwoLogInOrSignUp;

            if (LogInOrSignUp == 1)
            {
                if (autoDifficultyInput == "Y")
                {
                    userDifficulty = userSuggestingDifficulty;
                }
            }

            Console.WriteLine("Get a piece of paper and a pen out, and Lets Start!");
            Console.WriteLine("\n");
            if (testOrTwoPlayer == "T")
            {
                score = RunTest(numberOfQuestions, userDifficulty, numberOfSeconds);

                Console.WriteLine($"Total score: {score.TotalScore} of {numberOfQuestions}");
                ScoreDisplay(numberOfQuestions, score, userDifficulty, userName);
                if (LogInOrSignUp != 3)
                {
                    StatsDisplay(score);
                    SaveToFile.SerializeLastTest(numberOfQuestions, score.TotalScore, userDifficulty, userName, score.TotalEasyQuestion, score.TotalEasyScore, score.TotalNormalQuestion, score.TotalNormalScore, score.TotalHardQuestion, score.TotalHardScore, score.EasyTests, score.NormalTests, score.HardTests, score.TwoPlayerChallengeScore, score.AllTimeCorrectAnswers);
                }
            }
            else if (testOrTwoPlayer == "2")
            {
                Console.WriteLine($"Player 1: {userName}");
                Console.WriteLine($"What is Player 2's name?");
                (playerTwoUserName, playerTwoLogInOrSignUp) = UserManager.LogInProcess(filePath);
                if (File.Exists(FileUtils.GetUserFileName(playerTwoUserName)))
                {
                    SaveToFile.DeserializeLastTest(playerTwoUserName);
                }
                Console.WriteLine($"{userName} will go first!");
                score = RunTest(numberOfQuestions, userDifficulty, numberOfSeconds);
                Console.WriteLine($"{userName} got a score of {score.PlayerOneScore} out of {numberOfQuestions}", false);
                ScoreDisplay(numberOfQuestions, score, userDifficulty, userName);
                Console.WriteLine($"Now it is {playerTwoUserName}'s turn");
                string playerTwoReady;
                do
                {
                    Console.WriteLine($"Are you ready {playerTwoUserName}?");
                    playerTwoReady = Console.ReadLine().ToUpper();
                } while (playerTwoReady != "Y");
                playerTwoScore = RunTest(numberOfQuestions, userDifficulty, numberOfSeconds);
                Console.WriteLine($"{playerTwoUserName} got a score of {playerTwoScore.PlayerTwoScore} out of {numberOfQuestions}", false);
                ScoreDisplay(numberOfQuestions, playerTwoScore, userDifficulty, playerTwoUserName);
                if (score.TotalScore > playerTwoScore.TotalScore)
                {
                    Console.ForegroundColor = ConsoleColor.Green;
                    Console.WriteLine($"{userName} won the challenge!🥳");
                    Console.ResetColor();
                    score.TwoPlayerChallengeScore++;
                }
                else if (score.TotalScore < playerTwoScore.TotalScore)
                {
                    Console.ForegroundColor = ConsoleColor.Green;
                    Console.WriteLine($"{playerTwoUserName} won the challenge!🥳");
                    Console.ResetColor();
                    playerTwoScore.TwoPlayerChallengeScore++;
                }
                else
                {
                    Console.WriteLine("This challenge ended in stalemate");
                }
                if (LogInOrSignUp != 3)
                {
                    SaveToFile.SerializeLastTest(numberOfQuestions, score.TotalScore, userDifficulty, userName, score.TotalEasyQuestion, score.TotalEasyScore, score.TotalNormalQuestion, score.TotalNormalScore, score.TotalHardQuestion, score.TotalHardScore, score.EasyTests, score.NormalTests, score.HardTests, score.TwoPlayerChallengeScore, score.AllTimeCorrectAnswers);
                    StatsDisplay(score);
                }
                if (playerTwoLogInOrSignUp != 3)
                {
                    SaveToFile.SerializeLastTest(numberOfQuestions, playerTwoScore.TotalScore, userDifficulty, playerTwoUserName, playerTwoScore.TotalEasyQuestion, playerTwoScore.TotalEasyScore, playerTwoScore.TotalNormalQuestion, playerTwoScore.TotalNormalScore, playerTwoScore.TotalHardQuestion, playerTwoScore.TotalHardScore, playerTwoScore.EasyTests, playerTwoScore.NormalTests, playerTwoScore.HardTests, playerTwoScore.TwoPlayerChallengeScore, playerTwoScore.AllTimeCorrectAnswers);
                }
            }
        }
Esempio n. 8
0
        public void CheckingIfSuggestingCorrectDifficulty()
        {
            UserDifficulty userDifficulty = CanUseManyTimes.SuggestingDifficulty("danyal");

            Assert.AreEqual(UserDifficulty.Easy, userDifficulty);
        }
Esempio n. 9
0
        public static (string message, double correctAnswer) GetMathsEquation(MathOperation mathOperation, UserDifficulty userDifficulty)
        {
            int    number1;
            int    number2;
            Random randomNumber = new Random();

            switch (mathOperation)
            {
            case MathOperation.Addition:
                number1 = randomNumber.Next(1000);
                number2 = randomNumber.Next(1000);
                return($"{number1} + {number2}", number1 + number2);

            case MathOperation.Subtraction:
                number1 = randomNumber.Next(1000);
                number2 = randomNumber.Next(1000);
                return($"{number1} - {number2}", number1 - number2);

            case MathOperation.Multiplication:
                number1 = userDifficulty == UserDifficulty.Easy ? randomNumber.Next(13) : randomNumber.Next(1000);
                number2 = userDifficulty == UserDifficulty.Easy ? randomNumber.Next(13) : randomNumber.Next(1000);
                return($"{number1} * {number2}", number1 *number2);

            case MathOperation.Division:
                number1 = randomNumber.Next(10000);
                number2 = randomNumber.Next(1000);
                return($"{number1} / {number2}", number1 / (double)number2);

            case MathOperation.Power:
                number1 = randomNumber.Next(20);
                number2 = randomNumber.Next(5);
                return($"{number1} ^ {number2}", Math.Pow(number1, number2));

            case MathOperation.SquareRoot:
                number1 = randomNumber.Next(1000);
                return($"√{number1}", Math.Sqrt(number1));

            default:
                throw new Exception();
            }
        }
Esempio n. 10
0
        public static (int operationMin, int operationMax) GetPossibleOperationsByDifficulty(UserDifficulty userDifficulty)
        {
            switch (userDifficulty)
            {
            case UserDifficulty.Easy:
                return(1, 4);

            case UserDifficulty.Normal:
                return(1, 5);

            case UserDifficulty.Hard:
                return(3, 7);

            default:
                throw new Exception();
            }
        }
            public static void SerializeLastTest(int numberOfQuestions, int totalScore, UserDifficulty userDifficulty, string userName, double totalEasyQuestion, double totalEasyScore, double totalNormalQuestion, double totalNormalScore, double totalHardQuestion, double totalHardScore, double easyTests, double normalTests, double hardTests, int twoPlayerChallengeScore, int allTimeCorrectAnswers)
            {
                ToFile     obj       = new ToFile(numberOfQuestions, userDifficulty, totalScore, totalEasyQuestion, totalEasyScore, totalNormalQuestion, totalNormalScore, totalHardQuestion, totalHardScore, easyTests, normalTests, hardTests, twoPlayerChallengeScore, allTimeCorrectAnswers);
                IFormatter formatter = new BinaryFormatter();
                Stream     stream    = new FileStream(FileUtils.GetUserFileName(userName), FileMode.Create, FileAccess.Write);

                formatter.Serialize(stream, obj);
                stream.Close();
            }
Esempio n. 12
0
        public static void ScoreDisplay(int numberOfQuestions, Calculation.OperationQuestionScore score, UserDifficulty userDifficulty, string userName)
        {
            if (File.Exists(FileUtils.GetUserFileName(userName)))
            {
                ToFile objnew = SaveToFile.DeserializeLastTest(userName);
                score.TotalEasyQuestion       = objnew.TotalEasyQuestion;
                score.TotalEasyScore          = objnew.TotalEasyScore;
                score.TotalNormalQuestion     = objnew.TotalNormalQuestion;
                score.TotalNormalScore        = objnew.TotalNormalScore;
                score.TotalHardQuestion       = objnew.TotalHardQuestion;
                score.TotalHardScore          = objnew.TotalHardScore;
                score.EasyTests               = objnew.EasyTests;
                score.NormalTests             = objnew.NormalTests;
                score.HardTests               = objnew.HardTests;
                score.TwoPlayerChallengeScore = objnew.TwoPlayerChallengeScore;
                score.AllTimeCorrectAnswers   = objnew.AllTimeCorrectAnswers;
            }

            if (userDifficulty == UserDifficulty.Easy)
            {
                Console.WriteLine($"Addition score: {score.AdditionScore} of {score.AdditionQuestion}");
                Console.WriteLine($"Subtraction score: {score.SubtractionScore} of {score.SubtractionQuestion}");
                Console.WriteLine($"Multiplication score: {score.MultiplicationScore} of {score.MultiplicationQuestion}");
                score.EasyTests++;
                score.TotalEasyQuestion += numberOfQuestions;
                score.TotalEasyScore     = Math.Round((score.TotalEasyScore + (double)(score.TotalScore / (double)numberOfQuestions) * 100) / score.EasyTests, 2);
            }
            else if (userDifficulty == UserDifficulty.Normal)
            {
                Console.WriteLine($"Addition score: {score.AdditionScore} of {score.AdditionQuestion}");
                Console.WriteLine($"Subtraction score: {score.SubtractionScore} of {score.SubtractionQuestion}");
                Console.WriteLine($"Multiplication score: {score.MultiplicationScore} of {score.MultiplicationQuestion}");
                Console.WriteLine($"Division score: {score.DivisionScore} of {score.DivisionQuestion}");
                score.NormalTests++;
                score.TotalNormalQuestion += numberOfQuestions;
                score.TotalNormalScore     = Math.Round((score.TotalNormalScore + (double)(score.TotalScore / (double)numberOfQuestions) * 100) / score.NormalTests, 2);
            }
            else if (userDifficulty == UserDifficulty.Hard)
            {
                Console.WriteLine($"Multipication score: {score.MultiplicationScore} of {score.MultiplicationQuestion}");
                Console.WriteLine($"Division score: {score.DivisionScore} of {score.DivisionQuestion}");
                Console.WriteLine($"Power score: {score.PowerScore} of {score.PowerQuestion}");
                Console.WriteLine($"Squareroot score: {score.SquareRootScore} of {score.SquareRootQuestion}");
                score.HardTests++;
                score.TotalHardQuestion += numberOfQuestions;
                score.TotalHardScore     = Math.Round((score.TotalHardScore + (double)(score.TotalScore / (double)numberOfQuestions) * 100) / score.HardTests, 2);
            }
            score.AllTimeCorrectAnswers += score.TotalScore;
            Console.WriteLine("\n");
        }
Esempio n. 13
0
        public static void Main(string[] args)
        {
            Console.WriteLine("To Login Type 1, To Create a new account Type 2");
            int LogInOrSignUp;

            do
            {
                int.TryParse(Console.ReadLine(), out LogInOrSignUp);
            } while (LogInOrSignUp != 1 && LogInOrSignUp != 2);

            var filePath    = Path.Combine(AppContext.BaseDirectory, "AccountDetails.txt");
            var userName    = "";
            var password    = "";
            var successfull = false;
            var userDetails = Users.DeserializeAccountDetails(filePath);

            if (userDetails is null)
            {
                userDetails = new Users();
            }

            while (!successfull)
            {
                if (LogInOrSignUp == 1)
                {
                    Console.WriteLine("Write your username:"******"Enter your password:"******"You have logged in successfully!");
                        successfull = true;
                        break;
                    }
                    else
                    {
                        Console.WriteLine("Your username or password is incorect, try again!");
                    }
                }
                else
                {
                    Console.WriteLine("Enter a username:"******"The username is taken. Try another one.");
                    }
                    else
                    {
                        Console.WriteLine("Enter a password:"******"A new account for {userName} has been created!");
                    }
                }
            }

            ToFile         objnew                   = SaveToFile.DeserializeLastTest(userName);
            double         totalEasyQuestion        = objnew.TotalEasyQuestion;
            double         totalEasyScore           = objnew.TotalEasyScore;
            double         totalNormalQuestion      = objnew.TotalNormalQuestion;
            double         totalNormalScore         = objnew.TotalNormalScore;
            double         totalHardQuestion        = objnew.TotalHardQuestion;
            double         totalHardScore           = objnew.TotalHardScore;
            double         easyTests                = objnew.EasyTests;
            double         normalTests              = objnew.NormalTests;
            double         hardTests                = objnew.HardTests;
            UserDifficulty userSuggestingDifficulty = UserDifficulty.Easy;

            if (File.Exists($"{userName}.txt"))
            {
                userSuggestingDifficulty = CanUseManyTimes.SuggestingDifficulty(userName);
            }
            var(userDifficulty, numberOfQuestions, autoDifficultyInput, numberOfSeconds) = UserInputs();

            if (LogInOrSignUp == 1)
            {
                if (autoDifficultyInput == "Y")
                {
                    userDifficulty = userSuggestingDifficulty;
                }
            }

            var score = RunTest(numberOfQuestions, userDifficulty, numberOfSeconds);

            Console.WriteLine($"Total score: {score.TotalScore} of {numberOfQuestions}");

            if (userDifficulty == UserDifficulty.Easy)
            {
                Console.WriteLine($"Addition score: {score.AdditionScore} of {score.AdditionQuestion}");
                Console.WriteLine($"Subtraction score: {score.SubtractionScore} of {score.SubtractionQuestion}");
                Console.WriteLine($"Multiplication score: {score.MultiplicationScore} of {score.MultiplicationQuestion}");
                easyTests++;
                totalEasyQuestion = totalEasyQuestion + numberOfQuestions;
                totalEasyScore    = Math.Round((totalEasyScore + ((double)score.TotalScore / (double)numberOfQuestions) * 100) / easyTests, 2);
            }
            else if (userDifficulty == UserDifficulty.Normal)
            {
                Console.WriteLine($"Addition score: {score.AdditionScore} of {score.AdditionQuestion}");
                Console.WriteLine($"Subtraction score: {score.SubtractionScore} of {score.SubtractionQuestion}");
                Console.WriteLine($"Multiplication score: {score.MultiplicationScore} of {score.MultiplicationQuestion}");
                Console.WriteLine($"Division score: {score.DivisionScore} of {score.DivisionQuestion}");
                normalTests++;
                totalNormalQuestion = totalNormalQuestion + numberOfQuestions;
                totalNormalScore    = Math.Round((totalNormalScore + ((double)score.TotalScore / (double)numberOfQuestions) * 100) / normalTests, 2);
            }
            else if (userDifficulty == UserDifficulty.Hard)
            {
                Console.WriteLine($"Multipication score: {score.MultiplicationScore} of {score.MultiplicationQuestion}");
                Console.WriteLine($"Division score: {score.DivisionScore} of {score.DivisionQuestion}");
                Console.WriteLine($"Power score: {score.PowerScore} of {score.PowerQuestion}");
                Console.WriteLine($"Squareroot score: {score.SquareRootScore} of {score.SquareRootQuestion}");
                hardTests++;
                totalHardQuestion = totalHardQuestion + numberOfQuestions;
                totalHardScore    = Math.Round((totalHardScore + ((double)score.TotalScore / (double)numberOfQuestions) * 100) / hardTests, 2);
            }
            string statisticsDisplay;

            do
            {
                Console.WriteLine("Would you like to see your all time statistics? Please type 'Y' or 'N'");
                statisticsDisplay = Console.ReadLine();
            } while (statisticsDisplay != "Y" && statisticsDisplay != "N");
            if (statisticsDisplay == "Y")
            {
                Console.WriteLine($"You have answered {totalEasyQuestion} easy questions so far with an average score of {totalEasyScore}%");
                Console.WriteLine($"You have answered {totalNormalQuestion} normal questions so far with an average score of {totalNormalScore}%");
                Console.WriteLine($"You have answered {totalHardQuestion} hard questions so far with an average score of {totalHardScore}%");
            }
            SaveToFile.SerializeLastTest(numberOfQuestions, score.TotalScore, userDifficulty, userName, totalEasyQuestion, totalEasyScore, totalNormalQuestion, totalNormalScore, totalHardQuestion, totalHardScore, easyTests, normalTests, hardTests);
        }
Esempio n. 14
0
 public static (int operationMin, int operationMax) GetPossibleOperationsByDifficulty(UserDifficulty userDifficulty)
 {
     return(userDifficulty switch
     {
         UserDifficulty.Easy => (1, 4),
         UserDifficulty.Normal => (1, 5),
         UserDifficulty.Hard => (3, 7),
         _ => throw new Exception(),
     });
Esempio n. 15
0
            public static void SerializeLastTest(int numberOfQuestions, int totalScore, UserDifficulty userDifficulty, string userName, double totalEasyQuestion, double totalEasyScore, double totalNormalQuestion, double totalNormalScore, double totalHardQuestion, double totalHardScore, double easyTests, double normalTests, double hardTests)
            {
                ToFile     obj       = new ToFile(numberOfQuestions, userDifficulty, totalScore, totalEasyQuestion, totalEasyScore, totalNormalQuestion, totalNormalScore, totalHardQuestion, totalHardScore, easyTests, normalTests, hardTests);
                IFormatter formatter = new BinaryFormatter();
                Stream     stream    = new FileStream($"{userName}.txt", FileMode.Create, FileAccess.Write);

                formatter.Serialize(stream, obj);
                stream.Close();
            }