示例#1
0
        /// <summary>
        ///     Let user select a gun of their choice
        /// </summary>
        private void GunSelection()
        {
            Console.WriteLine("Select a gun: \n" +
                              "1: Rifle\n" +
                              "2: Pistol\n");
            try
            {
                var selection = int.Parse(Console.ReadLine());

                //Ninjects returns an instace of the selected gun
                switch (selection)
                {
                    case 1:
                        _selectedGun = _kernel.Get<M16>();

                        break;
                    case 2:
                        _selectedGun = _kernel.Get<PipeHandGun>();
                        break;

                    default:
                        GunSelection();
                        break;
                }
                Console.WriteLine(_selectedGun.GetName() + " selected.");
            }
            catch (FormatException)
            {
                Console.WriteLine("Please select a valid gun.");
                GunSelection();
            }
        }