Ejemplo n.º 1
0
        public bool LeapCharge()
        {
            var leapRepo   = new LeapRepository();
            var currentBal = leapRepo.currentAvailableBudget();

            if (currentBal >= 1000)
            {
                var updatedBudget = currentBal - 1000;
                HasEnoughFunds = true;
                leapRepo.saveBudget(updatedBudget);
                Console.WriteLine();
                Console.WriteLine($"$1,000 has been deducted from your budget. Your new balance is ${updatedBudget}. You are good to leap!");
                Console.WriteLine();
                Console.WriteLine("Leap info:");
                Console.WriteLine();
            }
            else
            {
                Console.Clear();
                Console.BackgroundColor = ConsoleColor.Red;
                Console.WriteLine($"Your current balance of ${currentBal} is insufficient for the leap. Please add more funds!");
                Console.ResetColor();
                Console.WriteLine();
                var userMenu = new Menu();
                userMenu.MenuItems();
            }
            return(HasEnoughFunds);
        }
Ejemplo n.º 2
0
        public void MenuItems()
        {
            while (true)
            {
                var welcomeMessage = "  Welcome to Quantum Leap! Please enter a number to make your selection or type exit to end the game.";

                var option1TakeALeap       = "     1. Take your next leap";
                var option2FundMoreProject = "     2. Fund more projects";
                var option3LeapHistory     = "     3. List leap history";

                Console.WriteLine(welcomeMessage);
                Console.WriteLine();

                Console.WriteLine(option1TakeALeap);
                Console.WriteLine(option2FundMoreProject);
                Console.WriteLine(option3LeapHistory);

                var userInput = Console.ReadLine();
                Console.Clear();

                if (userInput == "1")
                {
                    var leap     = new Leap();
                    var leapRepo = new LeapRepository();

                    var leaperCanLeap = new LeaperCanLeap();
                    var canLeap       = leaperCanLeap.LeapCharge();

                    if (canLeap == true)
                    {
                        var quantumLeap = leap.createALeap();
                        Console.WriteLine($"{quantumLeap.Leaper} you have lept to, {quantumLeap.Date} {quantumLeap.Location}, you're apparently {quantumLeap.Host}");
                        leapRepo.SaveNewLeap(quantumLeap);
                        var menu = new Menu();
                        menu.MenuItems();
                    }
                }
                else if (userInput == "2")
                {
                    // Fund more project calls/method will be call here.
                    var currentAvailableFunds = new Budget();
                    var leapRepo       = new LeapRepository();
                    var currentBalance = leapRepo.currentAvailableBudget();



                    Console.WriteLine($"Your current available funds are ${currentBalance}. Add more funds y/n?");
                    var userResponse = Console.ReadLine().ToLower();

                    if (userResponse == "y")
                    {
                        Console.Clear();
                        Console.WriteLine("Please enter the amount of funds");
                        var enteredAmount = Console.ReadLine().ToCharArray();
                        foreach (var ea in enteredAmount)
                        {
                            if (!char.IsNumber(ea))
                            {
                                Console.WriteLine("Please enter numbers only");
                            }
                            else
                            {
                                string rebuilt = new string(enteredAmount);
                                var    currentBudgetBalance = Convert.ToInt32(rebuilt) + currentBalance;
                                Console.Clear();
                                Console.ForegroundColor = ConsoleColor.Green;
                                Console.WriteLine($"Your current available funds are ${currentBudgetBalance}");
                                Console.ResetColor();
                                Console.WriteLine();
                                leapRepo.saveBudget(currentBudgetBalance);
                                var menu = new Menu();

                                menu.MenuItems();
                            }
                        }
                    }
                    else if (userResponse == "n")
                    {
                        Console.WriteLine("You have chosen not to add funds");
                        var menu = new Menu();

                        menu.MenuItems();
                    }
                    else
                    {
                        Console.WriteLine("You have made an invalid selection.");
                        var menu = new Menu();

                        menu.MenuItems();
                    }

                    // Console.Clear();
                    break;
                }
                else if (userInput == "3")
                {
                    // Leap History class/method will be call here.
                    var leapRepo        = new LeapRepository();
                    var historicalLeaps = leapRepo.GetLeaps();
                    if (historicalLeaps.Count > 0)
                    {
                        for (var i = 0; i < historicalLeaps.Count; i++)
                        // foreach(Events Leap in historicalLeaps)
                        {
                            Console.ForegroundColor = ConsoleColor.Cyan;
                            Console.WriteLine($"Leap {i+1}: \n Leaper:{ historicalLeaps[i].Leaper},\n Date: { historicalLeaps[i].Date},\n Location: { historicalLeaps[i].Location},\n Host: { historicalLeaps[i].Host},\n IsPutRight: { historicalLeaps[i].isPutRight}\n\n");
                            Console.ResetColor();
                        }
                        //Console.WriteLine("List leap history class/method will be called.");
                        break;
                    }
                    else
                    {
                        Console.Clear();
                        Console.ForegroundColor = ConsoleColor.Red;
                        Console.WriteLine("Cannot show history of leaps because no one has lept yet.");
                        Console.ResetColor();
                        Console.WriteLine();
                    }
                }
                else if (userInput.ToLower() == "exit")
                {
                    Environment.Exit(0);
                }
                else
                {
                    Console.Clear();
                    Console.BackgroundColor = ConsoleColor.Red;
                    Console.WriteLine();
                    Console.WriteLine("Please enter a number or type exit to end the game!");
                    Console.ResetColor();
                    Console.WriteLine();
                }
            }
        }
Ejemplo n.º 3
0
        public void saveCurrentBudgetBalanceToRepo(int newBalance)
        {
            var leapRepoInstance = new LeapRepository();

            leapRepoInstance.saveBudget(newBalance);
        }