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);
        }
Exemple #2
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");
        }
        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);
                }
            }
        }
Exemple #4
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);
        }