Ejemplo n.º 1
0
        public static OperationQuestionScore RunTest(int numberOfQuestionsLeft, UserDifficulty userDifficulty, int numberOfSeconds)
        {
            Random random = new Random();

            var(operationMin, operationMax) = GetPossibleOperationsByDifficulty(userDifficulty);
            var          score        = new OperationQuestionScore();
            RunWithTimer RunWithTimer = new RunWithTimer(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)
                {
                    CanUseManyTimes.WriteToScreen($"To the nearest integer, What is {message} =", false);
                }
                else
                {
                    CanUseManyTimes.WriteToScreen($"What is {message} =", false);
                }

                double userAnswer = Convert.ToDouble(CanUseManyTimes.ReadInput());
                if (Math.Round(correctAnswer) == userAnswer)
                {
                    Console.ForegroundColor = ConsoleColor.Green;
                    CanUseManyTimes.WriteToScreen("Well Done!", false);
                    Console.ResetColor();
                    score.Increment(mathOperation, true);
                }
                else
                {
                    Console.ForegroundColor = ConsoleColor.Red;
                    CanUseManyTimes.WriteToScreen("Your answer is incorrect!", false);
                    Console.ResetColor();
                    score.Increment(mathOperation, false);
                }
                numberOfQuestionsLeft--;
                RunWithTimer.StopTimer(numberOfQuestionsLeft);
            }
            return(score);
        }
Ejemplo n.º 2
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);
        }