Ejemplo n.º 1
0
        // enum metod som skriver ut huvudmenyn och kollar felhantering
        // Convertar choice som blir inputen till en enum switch casen i MainMenu metoden
        // retunerar choice till Main och skickar in de som användaren skrev in.
        public enumMainMenu GetUserInputForMainMenu()
        {
            do
            {
                Console.WriteLine("Main menu\n");
                Console.WriteLine("1 | Register Training");
                Console.WriteLine("2 | Goals");
                Console.WriteLine("3 | Completed Workouts");
                Console.WriteLine("4 | Quit\n");

                Console.Write("Select a number");
                try
                {
                    Console.Write(": ");
                    int userInput = Convert.ToInt32(Console.ReadLine());

                    if (userInput > 4 || userInput < 1)
                    {
                        Console.Clear();
                        throw new Exception();
                    }

                    enumMainMenu choice = (enumMainMenu)userInput;
                    return(choice);
                }
                catch
                {
                    Console.WriteLine("Only numbers between 1-4!");
                }
            } while (true);
        }
Ejemplo n.º 2
0
        // Här skickas choice in från enummetoden GetUserInputMainMenuSwitch och valet görs beroende på vad användaren skrev in i inputen i den föregående motoden.
        public void MainMenu(enumMainMenu Choice)
        {
            switch (Choice)
            {
            case enumMainMenu.Registertraining:
                Console.Clear();
                Console.WriteLine("Register Training\n");
                // tar input från användaren och convertar till enum
                Menu.enumSportMenu Choice1 = enumTryCatchForSportMenu();
                //går till chooseTypOfTraining metoden och använder sedan choice1 från GetInputFromUser Metoden och skickar in valet i chooseTypOfTraining metoden och gör de valet som användaren skrivit
                chooseTypOfTraining(Choice1);
                break;

            case enumMainMenu.Goals:
                bool doWhileLoop = true;
                // enum switch i en enum switch för goals menyn
                do
                {
                    Console.Clear();
                    Console.WriteLine("1 | Set a goal");
                    Console.WriteLine("2 | Remove a goal");
                    Console.WriteLine("3 | See your goals");
                    Console.WriteLine("4 | Go back to main menu");

                    Console.Write("Select a number");

                    int inputForGoal = IntUserInputTryCatch();

                    Console.Clear();
                    switch (inputForGoal)
                    {
                    case (int)enumGoalMenu.Setgoal:
                        ChooseTypeOfGoal();
                        break;

                    case (int)enumGoalMenu.removeGoal:
                        Printclass.PrintGoalsInProgress();
                        Console.Write("Select the number of the goal you want to remove");

                        do
                        {
                            if (Goals.goalsInProgress.Count == 0)
                            {
                                Console.Clear();
                                Console.WriteLine("You dont have any goals at the moment, please set one first");
                                return;
                            }

                            int removeGoalChoice = IntUserInputTryCatch();

                            if (removeGoalChoice > Goals.goalsInProgress.Count)
                            {
                                Console.Clear();
                                Console.WriteLine("You don't have a goal matching that index");
                                return;
                            }

                            else
                            {
                                Goals.RemoveGoal(removeGoalChoice - 1);
                                return;
                            }
                        } while (true);

                    case (int)enumGoalMenu.seeAllGoals:
                        Printclass.PrintCompletedGoals();
                        Printclass.PrintGoalsInProgress();
                        break;

                    case (int)enumGoalMenu.goBackToMainMenu:
                        return;

                    default:
                        doWhileLoop = true;
                        Console.WriteLine("1-4 only");
                        Console.ReadLine();
                        break;
                    }
                } while (doWhileLoop == true);
                break;

            case enumMainMenu.Completedworkouts:
                Printclass.PrintCompletedWorkouts();
                break;

            case enumMainMenu.quit:
                return;
            }
        }