// UI update
        public override void Update()
        {
            ConsoleWriter.PrintNewLine();
            ConsoleWriter.PrintNewLine();

            ConsoleUtils.DoAction("Choose mode", "", "1", true,

                                  new ConsoleUtils.ActionParams("1", "1. Practice mode ", delegate(ConsoleUtils.ActionParamsContext context)
            {
                _sm.PushInNextFrame(new ChooseDifficultyLevelState().Initialize(_sm));
            }),
                                  new ConsoleUtils.ActionParams("2", "2. Cumulative operations ", delegate(ConsoleUtils.ActionParamsContext context) {
                int maxAdditionNumber       = ConsoleReader.GetUserInputInt("Max Addition digit. (Leave it as 0 to ignore this operation)", 0);
                int maxSubstractionNumber   = ConsoleReader.GetUserInputInt("Max Substraction digit. (Leave it as 0 to ignore this operation)", 0);
                int maxMultiplicationNumber = ConsoleReader.GetUserInputInt("Max Multiplication digit. (Leave it as 0 to ignore this operation)", 0);

                int startingNumber = ConsoleReader.GetUserInputInt("Starting Number", 0);
                int questions      = ConsoleReader.GetUserInputInt("Question count", 25);

                QLib.FSM.iContext cummulativeContext = CumulativeOperationState.GetContext(maxAdditionNumber, maxSubstractionNumber, maxMultiplicationNumber, startingNumber, questions);
                _sm.PushInNextFrame(new CumulativeOperationState().Initialize(_sm), cummulativeContext);
            }),

                                  //new ConsoleUtils.ActionParams("2", "2. Learning mode", delegate (ConsoleUtils.aActionParamsContext context)
                                  //{
                                  //    ConsoleWriter.PrintInRed("Not yet implemented");
                                  //}),
                                  new ConsoleUtils.ActionParams("b", "b. back", delegate(ConsoleUtils.ActionParamsContext context)
            {
                Exit();
            })
                                  );
        }
        private void StartSession()
        {
            controller.StartSession();

            while (controller.IsNextQuestionAvailable())
            {
                QuestionProvider.Question q = controller.GetNextQuestion();
                ConsoleWriter.Print($"{q.a} {q.operatorStr} {q.b}");
                int ans = ConsoleReader.GetUserInputInt("");
                if (!controller.IsAnswerForCurrentQuestionRight(ans))
                {
                    ConsoleWriter.PrintInColor("Naah. That was not right!", ConsoleColor.Yellow);
                }
                controller.SetAnswerForCurrentQuestionAndEndSessionIfRequired(ans);
            }

            ShowResults();
        }
Exemple #3
0
        private void StartSession()
        {
            Random      rand       = new Random(Guid.NewGuid().GetHashCode());
            DateTime    startTime  = DateTime.Now;
            DateTime    endTime    = DateTime.Now;
            int         questions  = context.questions;
            Stack <int> operations = new Stack <int>();

            while (questions > 0)
            {
                int  op      = rand.GetRangeInclusive(1, 3);// add, sub, mul
                bool opFound = false;
                switch (op)
                {
                case 1:
                    if (context.AdditionOp)
                    {
                        opFound = true;
                    }
                    break;

                case 2:
                    if (context.SubstractionOp)
                    {
                        opFound = true;
                    }
                    break;

                case 3:
                    if (context.MultiplicationOp)
                    {
                        opFound = true;
                    }
                    break;
                }
                if (opFound)
                {
                    operations.Push(op);
                    questions--;
                }
            }

            int cumulativeNumber = context.startingNumber;

            ConsoleWriter.Print($"{cumulativeNumber}");
            int rightAns = 0, wrongAns = 0;

            while (operations.Count > 0)
            {
                int op        = operations.Pop();
                int randomNum = 0;
                int answer    = 0;
                switch (op)
                {
                case 1:
                    Utils.Assert(context.AdditionOp);
                    randomNum         = rand.GetRangeInclusive(0, context.maxNumberToAdd);
                    cumulativeNumber += randomNum;
                    answer            = ConsoleReader.GetUserInputInt("+" + randomNum);
                    break;

                case 2:
                    Utils.Assert(context.SubstractionOp);
                    randomNum         = rand.GetRangeInclusive(0, context.maxNumberToSub);
                    cumulativeNumber -= randomNum;
                    answer            = ConsoleReader.GetUserInputInt("-" + randomNum);
                    break;

                case 3:
                    Utils.Assert(context.MultiplicationOp);
                    randomNum         = rand.GetRangeInclusive(0, context.maxNumberToMul);
                    cumulativeNumber *= randomNum;
                    answer            = ConsoleReader.GetUserInputInt("*" + randomNum);
                    break;
                }

                if (answer != cumulativeNumber)
                {
                    ConsoleWriter.PrintInColor("Naah. That was not right!", ConsoleColor.Yellow);
                    ConsoleWriter.Print($"{cumulativeNumber}");
                    wrongAns++;
                }
                else
                {
                    rightAns++;
                }
            }
            endTime = DateTime.Now;

            ShowResults(rightAns, wrongAns, startTime, endTime);
        }
        // UI update
        public override void Update()
        {
            ConsoleWriter.PrintNewLine();
            ConsoleWriter.PrintNewLine();

            ConsoleUtils.DoAction("Choose Level of difficulty", "", "1", true,

                                  new ConsoleUtils.ActionParams("1", "1. Level 1 (25 questions)", delegate(ConsoleUtils.ActionParamsContext context)
            {
                int levelNumber = 1;
                int questions   = 25;
                challengeInputs = new QuestionProviderInput(90 /* success percent*/, (int)(questions * 2.5) /* three star time*/, questions * 4 /*two star*/, questions * 6 /*Single star*/);
                challengeInputs.AddAdditionModule(questions /*Questions*/, 0, 5, 0, 5);


                _sm.PushInNextFrame(new ChallengeSessionState().Initialize(_sm), ChallengeSessionState.GetContext(levelNumber, challengeInputs));
            }),

                                  new ConsoleUtils.ActionParams("2", "2. Level 2 (25 questions)", delegate(ConsoleUtils.ActionParamsContext context)
            {
                int levelNumber = 2;
                int questions   = 25;
                challengeInputs = new QuestionProviderInput(90 /* success percent*/, (int)(questions * 2.5) /* three star time*/, questions * 4 /*two star*/, questions * 6 /*Single star*/);
                challengeInputs.AddAdditionModule(questions /*Questions*/, 0, 10, 0, 10);


                _sm.PushInNextFrame(new ChallengeSessionState().Initialize(_sm), ChallengeSessionState.GetContext(levelNumber, challengeInputs));
            }),

                                  new ConsoleUtils.ActionParams("3", "3. Level 3 (25 questions)", delegate(ConsoleUtils.ActionParamsContext context)
            {
                int levelNumber = 3;
                int questions   = 25;
                challengeInputs = new QuestionProviderInput(90 /* success percent*/, (int)(questions * 2.5) /* three star time*/, questions * 4 /*two star*/, questions * 6 /*Single star*/);
                challengeInputs.AddMultiplicationModule(questions / 3 /*Questions*/, 2, 6, 2, 6);
                challengeInputs.AddAdditionModule(questions / 3, 0, 12, 0, 12);
                challengeInputs.AddSubstractionModule(questions / 3, 10, 20, 0, 10);

                _sm.PushInNextFrame(new ChallengeSessionState().Initialize(_sm), ChallengeSessionState.GetContext(levelNumber, challengeInputs));
            }),
                                  new ConsoleUtils.ActionParams("4", "4. Level 4 (25 questions)", delegate(ConsoleUtils.ActionParamsContext context)
            {
                int levelNumber = 4;
                int questions   = 25;
                challengeInputs = new QuestionProviderInput(90 /* success percent*/, (int)(questions * 2.5) /* three star time*/, questions * 4 /*two star*/, questions * 6 /*Single star*/);

                challengeInputs.AddMultiplicationModule(questions / 3 /*Questions*/, 2, 7, 2, 7);
                challengeInputs.AddAdditionModule(questions / 3, 0, 15, 0, 15);
                challengeInputs.AddSubstractionModule(questions / 3, 15, 30, 0, 10);


                _sm.PushInNextFrame(new ChallengeSessionState().Initialize(_sm), ChallengeSessionState.GetContext(levelNumber, challengeInputs));
            }),
                                  new ConsoleUtils.ActionParams("5", "5. Level 5 (50 questions)", delegate(ConsoleUtils.ActionParamsContext context)
            {
                int levelNumber = 5;
                int questions   = 25 * 2;
                challengeInputs = new QuestionProviderInput(90 /* success percent*/, (int)(questions * 2.5) /* three star time*/, questions * 4 /*two star*/, questions * 6 /*Single star*/);

                challengeInputs.AddMultiplicationModule(questions / 4, 2, 8, 2, 8);
                challengeInputs.AddAdditionModule(questions / 4, 0, 20, 0, 20);
                challengeInputs.AddSubstractionModule(questions / 4, 15, 40, 0, 15);
                challengeInputs.AddDivitionModule(questions / 4, 5);


                _sm.PushInNextFrame(new ChallengeSessionState().Initialize(_sm), ChallengeSessionState.GetContext(levelNumber, challengeInputs));
            }),
                                  new ConsoleUtils.ActionParams("6", "6. Level 6 (50 questions)", delegate(ConsoleUtils.ActionParamsContext context)
            {
                int levelNumber = 6;
                int questions   = 25 * 2;
                challengeInputs = new QuestionProviderInput(90 /* success percent*/, (int)(questions * 2.5) /* three star time*/, questions * 4 /*two star*/, questions * 6 /*Single star*/);

                challengeInputs.AddMultiplicationModule(questions / 4, 2, 9, 2, 9);
                challengeInputs.AddAdditionModule(questions / 4, 0, 30, 0, 30);
                challengeInputs.AddSubstractionModule(questions / 4, 20, 40, 0, 20);
                challengeInputs.AddDivitionModule(questions / 4, 6);


                _sm.PushInNextFrame(new ChallengeSessionState().Initialize(_sm), ChallengeSessionState.GetContext(levelNumber, challengeInputs));
            }),
                                  new ConsoleUtils.ActionParams("7", "7. Level 7 (75 questions)", delegate(ConsoleUtils.ActionParamsContext context)
            {
                int levelNumber = 7;
                int questions   = 25 * 3;
                challengeInputs = new QuestionProviderInput(90 /* success percent*/, (int)(questions * 2.5) /* three star time*/, questions * 4 /*two star*/, questions * 6 /*Single star*/);

                challengeInputs.AddMultiplicationModule(questions / 5, 2, 10, 2, 10);
                challengeInputs.AddAdditionModule(questions / 5, 0, 40, 0, 40);
                challengeInputs.AddSubstractionModule(questions / 5, 40, 80, 0, 40);
                challengeInputs.AddDivitionModule(questions / 5, 8);
                challengeInputs.AddReminderModule(questions / 5, 5);

                _sm.PushInNextFrame(new ChallengeSessionState().Initialize(_sm), ChallengeSessionState.GetContext(levelNumber, challengeInputs));
            }),
                                  new ConsoleUtils.ActionParams("8", "8. Level 8 (75 questions)", delegate(ConsoleUtils.ActionParamsContext context) {
                int levelNumber = 8;
                int questions   = 25 * 3;
                challengeInputs = new QuestionProviderInput(92 /* success percent*/, (int)(questions * 2.5) /* three star time*/, questions * 4 /*two star*/, questions * 6 /*Single star*/);

                challengeInputs.AddMultiplicationModule(questions / 5, 2, 10, 2, 10);
                challengeInputs.AddAdditionModule(questions / 5, 0, 40, 0, 40);
                challengeInputs.AddSubstractionModule(questions / 5, 30, 60, 0, 30);
                challengeInputs.AddDivitionModule(questions / 5, 9);
                challengeInputs.AddReminderModule(questions / 5, 6);

                _sm.PushInNextFrame(new ChallengeSessionState().Initialize(_sm), ChallengeSessionState.GetContext(levelNumber, challengeInputs));
            }),
                                  new ConsoleUtils.ActionParams("9", "9. Level 9 (75 questions)", delegate(ConsoleUtils.ActionParamsContext context) {
                int levelNumber = 9;
                int questions   = 25 * 3;
                challengeInputs = new QuestionProviderInput(94 /* success percent*/, (int)(questions * 2.5) /* three star time*/, questions * 4 /*two star*/, questions * 6 /*Single star*/);

                challengeInputs.AddMultiplicationModule(questions / 5, 2, 10, 2, 10);
                challengeInputs.AddAdditionModule(questions / 5, 0, 40, 0, 40);
                challengeInputs.AddSubstractionModule(questions / 5, 30, 60, 0, 30);
                challengeInputs.AddDivitionModule(questions / 5, 10);
                challengeInputs.AddReminderModule(questions / 5, 7);

                _sm.PushInNextFrame(new ChallengeSessionState().Initialize(_sm), ChallengeSessionState.GetContext(levelNumber, challengeInputs));
            }),
                                  new ConsoleUtils.ActionParams("10", "10. Level 10 (75 questions)", delegate(ConsoleUtils.ActionParamsContext context) {
                int levelNumber = 10;
                int questions   = 25 * 3;
                challengeInputs = new QuestionProviderInput(95 /* success percent*/, (int)(questions * 2.5) /* three star time*/, questions * 4 /*two star*/, questions * 6 /*Single star*/);

                challengeInputs.AddMultiplicationModule(questions / 5, 2, 10, 2, 10);
                challengeInputs.AddAdditionModule(questions / 5, 0, 40, 0, 40);
                challengeInputs.AddSubstractionModule(questions / 5, 30, 60, 0, 30);
                challengeInputs.AddDivitionModule(questions / 5, 10);
                challengeInputs.AddReminderModule(questions / 5, 10);

                _sm.PushInNextFrame(new ChallengeSessionState().Initialize(_sm), ChallengeSessionState.GetContext(levelNumber, challengeInputs));
            }),

                                  new ConsoleUtils.ActionParams("c", "c. Custom", delegate(ConsoleUtils.ActionParamsContext context) {
                int levelNumber                 = 0;
                int questionsForAddition        = ConsoleReader.GetUserInputInt("Addition question count:", 25);
                int questionsForSubstractions   = ConsoleReader.GetUserInputInt("Substractions question count:", 25);
                int questionsForMultiplications = ConsoleReader.GetUserInputInt("Multiplication question count:", 25);
                int questionsForDivision        = ConsoleReader.GetUserInputInt("Division question count:", 25);
                int questionsForReminder        = ConsoleReader.GetUserInputInt("Reminder question count:", 25);

                int questions   = questionsForAddition + questionsForMultiplications + questionsForSubstractions + questionsForReminder + questionsForDivision;   // ConsoleReader.GetUserInputInt("Number of questions", 100);
                challengeInputs = new QuestionProviderInput(90 /* success percent*/, (int)(questions * 2.5) /* three star time*/, questions * 4 /*two star*/, questions * 6 /*Single star*/);

                if (questionsForAddition > 0)
                {
                    ConsoleWriter.PrintInRed("Provide inputs for Additions:");
                    int from = ConsoleReader.GetUserInputInt("From");
                    int to   = ConsoleReader.GetUserInputInt("To");
                    challengeInputs.AddMultiplicationModule(questionsForAddition, from, to, from, to);
                }
                if (questionsForSubstractions > 0)
                {
                    ConsoleWriter.PrintInRed("Provide inputs for Substractions:");
                    int from  = ConsoleReader.GetUserInputInt("From");
                    int to    = ConsoleReader.GetUserInputInt("To");
                    int from2 = ConsoleReader.GetUserInputInt("From");
                    int to2   = ConsoleReader.GetUserInputInt("To");

                    challengeInputs.AddSubstractionModule(questionsForSubstractions, from, to, from2, to2);
                }
                if (questionsForMultiplications > 0)
                {
                    ConsoleWriter.PrintInRed("Provide inputs for Multiplications:");
                    int from  = ConsoleReader.GetUserInputInt("From");
                    int to    = ConsoleReader.GetUserInputInt("To");
                    int from2 = ConsoleReader.GetUserInputInt("From");
                    int to2   = ConsoleReader.GetUserInputInt("To");

                    challengeInputs.AddMultiplicationModule(questionsForMultiplications, from, to, from2, to2);
                }
                if (questionsForDivision > 0)
                {
                    ConsoleWriter.PrintInRed("Provide inputs for Division:");
                    int maxTable = ConsoleReader.GetUserInputInt("Max Table");

                    challengeInputs.AddDivitionModule(questionsForDivision, maxTable);
                }
                if (questionsForReminder > 0)
                {
                    ConsoleWriter.PrintInRed("Provide inputs for Reminders:");
                    int maxTable = ConsoleReader.GetUserInputInt("Max Table");

                    challengeInputs.AddReminderModule(questionsForReminder, maxTable);
                }


                _sm.PushInNextFrame(new ChallengeSessionState().Initialize(_sm), ChallengeSessionState.GetContext(levelNumber, challengeInputs));
            }),


                                  new ConsoleUtils.ActionParams("b", "b. Go back", delegate(ConsoleUtils.ActionParamsContext context)
            {
                Exit();
            })
                                  );
        }