コード例 #1
0
        private bool UseItem()
        {
            var c = 0;

            ui.WriteLine(hero.Backpack.Select(i => $"{c++}: {i}"));
            var pos = ui.AskForInt("Select item to use");

            log.Add(hero.Use(hero.Backpack[pos]));
            return(true);
        }
コード例 #2
0
        private void SerchOnVechicleFeatures()
        {
            String regNum = "", color = "", manufacturer = "";
            int    wheels = 0;

            GarageHandler.StringPredicate regNumPredicate = null, colorPredicate = null, manufacturerPredicate = null;
            Console.Clear();
            Console.WriteLine("Find a vehicle by features");
            Console.WriteLine("To search on registration number press Y");

            if (Console.ReadKey(intercept: true).Key == ConsoleKey.Y)
            {
                regNum          = manufacturer = Ui.AskForString("Enter the registration number to search on", 5, 8);
                regNumPredicate = GetStringPredicate("Registration Number", regNum);
            }

            Console.WriteLine("To search on color press Y");
            if (Console.ReadKey(intercept: true).Key == ConsoleKey.Y)
            {
                Console.WriteLine("What Color do want to search on");
                color          = Console.ReadLine();
                colorPredicate = GetStringPredicate("Color", color);
            }

            Console.WriteLine("To search on wheels press Y");
            if (Console.ReadKey(intercept: true).Key == ConsoleKey.Y)
            {
                wheels = Ui.AskForInt("How many wheels should the vehicle have");
            }
            Console.WriteLine("To search on manufacturer press Y");

            if (Console.ReadKey(intercept: true).Key == ConsoleKey.Y)
            {
                Console.WriteLine("What manufacturer do want to search on");
                manufacturer          = Console.ReadLine();
                manufacturerPredicate = GetStringPredicate("Manufacturer", manufacturer);
            }

            var matchingVehicles = GarageHandler.GetVehicles(regNum, regNumPredicate, color, colorPredicate, wheels, manufacturer, manufacturerPredicate);

            Console.WriteLine($"Found {matchingVehicles.Count()} matching vehicles");
            foreach (var vehicle in matchingVehicles)
            {
                Console.WriteLine(vehicle);
            }
            Console.WriteLine("Press space to go back to main menu");
            do
            {
            } while (Console.ReadKey(intercept: true).KeyChar != ' ');
            this.Start();
        }
コード例 #3
0
        private Result InteractWithItem(string question, string failText, Func <Item, Result> action)
        {
            //log.Add("Backpack contents:");
            log.Add("");
            log.Add(question);
            log.Add($"  {0:#0}: Nothing");
            for (var i = 0; i < hero.Backpack.Count; i++)
            {
                log.Add($"  {i + 1:#0}: {hero.Backpack[i]}");
            }
            log.Flush();


            var index = ui.AskForInt("> ");

            try {
                var itemToUse = hero.Backpack[index - 1];
                return(action(itemToUse));
            } catch {
                return(Result.NoAction(failText));
            }
        }