Beispiel #1
0
        static void Main(string[] args)
        {
            uint    a, ammo, K = 1;
            bool    exit = false;
            Firearm Gun  = new Firearm();

            while (true)
            {
                Console.WriteLine("1.Create a new firearm" +
                                  "\n2.Shoot a firearm" +
                                  "\n3.Realod a firearm" +
                                  "\n4.Info about firearm" +
                                  "\n5.Switch the safety" +
                                  "\n6.Switch mode" +
                                  "\n7.Change info" +
                                  "\n8.Exit the program");
                if (!UInt32.TryParse(Console.ReadLine(), out K))
                {
                    Console.WriteLine("Error");
                    break;
                }
                Console.Clear();
                switch (K)
                {
                case 1:
                {
                    uint maxAmmo, ammoInClip;
                    Console.Write("Write model of your weapon: ");
                    string model = Console.ReadLine();
                    Console.Write("Write caliber of your weapon: ");
                    string caliber = Console.ReadLine();
                    Console.Write("Write max ammo in a clip: ");
                    if (!UInt32.TryParse(Console.ReadLine(), out maxAmmo))
                    {
                        Console.WriteLine("Error");
                        break;
                    }
                    Console.Write("Write current ammo in a clip: ");
                    if (!UInt32.TryParse(Console.ReadLine(), out ammoInClip))
                    {
                        Console.WriteLine("Error");
                        break;
                    }
                    Gun = new Firearm(model, caliber, maxAmmo, ammoInClip);
                    break;
                }

                case 2:
                {
                    if (Gun.IsSafetyOn)
                    {
                        Console.WriteLine("Turn the safety off before shooting");
                    }
                    else
                    {
                        while (Gun.IsReloaded)
                        {
                            Gun.Shoot();
                        }
                    }
                    break;
                }

                case 3:
                {
                    Console.WriteLine("How many ammo do you want to reload?" +
                                      "\n1.Full clip" +
                                      "\n2.My number");
                    if (!UInt32.TryParse(Console.ReadLine(), out a))
                    {
                        Console.WriteLine("Error");
                        break;
                    }
                    if (a == 1)
                    {
                        Gun.ReloadFirearm(Gun.MaxAmmo);
                    }
                    else if (a == 2)
                    {
                        Console.WriteLine("What number?");
                        if (!UInt32.TryParse(Console.ReadLine(), out ammo))
                        {
                            Console.WriteLine("Error");
                            break;
                        }
                        Gun.ReloadFirearm(ammo);
                    }
                    break;
                }

                case 4:
                {
                    Firearm.GetGeneralInfo();
                    Gun.GetInfo();
                    break;
                }

                case 5:
                {
                    Console.WriteLine("1.Turn the safety off" +
                                      "\n2.Turn the safety on");
                    if (!UInt32.TryParse(Console.ReadLine(), out a))
                    {
                        Console.WriteLine("Error");
                        break;
                    }
                    switch (a)
                    {
                    case 1:
                    {
                        Gun.IsSafetyOn = false;
                        Console.WriteLine("You've got the safety off");
                        break;
                    }

                    case 2:
                    {
                        Gun.IsSafetyOn = true;
                        Console.WriteLine("You've got the safety on");
                        break;
                    }
                    }
                    break;
                }

                case 6:
                {
                    Console.WriteLine("1.Single" +
                                      "\n2.Burst" +
                                      "\n3.Auto");
                    if (!UInt32.TryParse(Console.ReadLine(), out a))
                    {
                        Console.WriteLine("Error");
                        break;
                    }
                    switch (a)
                    {
                    case 1:
                    {
                        Gun["Single"] = true;
                        break;
                    }

                    case 2:
                    {
                        Gun["Birst"] = true;
                        break;
                    }

                    case 3:
                    {
                        Gun["Auto"] = true;
                        break;
                    }
                    }
                    break;
                }

                case 7:
                {
                    Console.Write("Write new model of your weapon: ");
                    Gun.Model = Console.ReadLine();
                    Console.Write("Write new caliber of your weapon: ");
                    Gun.Caliber = Console.ReadLine();
                    Console.Write("Write new max ammo in a clip: ");
                    if (!UInt32.TryParse(Console.ReadLine(), out ammo))
                    {
                        Console.WriteLine("Error");
                        break;
                    }
                    Gun.MaxAmmo = ammo;
                    Console.Write("Write new current ammo in a clip: ");
                    if (!UInt32.TryParse(Console.ReadLine(), out ammo))
                    {
                        Console.WriteLine("Error");
                        break;
                    }
                    Gun.AmmoInClip = ammo > Gun.MaxAmmo ? Gun.MaxAmmo : ammo;
                    break;
                }

                case 8:
                {
                    exit = true;
                    break;
                }
                }
                if (exit == true)
                {
                    break;
                }
                Console.WriteLine("\nPress any button...");
                Console.ReadKey();
                Console.Clear();
            }
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            uint    K = 1;
            uint    a;
            bool    exit = false;
            Firearm Gun  = new Firearm();

            while (true)
            {
                Console.WriteLine("1.Create a new firearm" +
                                  "\n2.Shoot a firearm" +
                                  "\n3.Realod a firearm" +
                                  "\n4.Info about gun" +
                                  "\n5.Exit the program");
                if (!UInt32.TryParse(Console.ReadLine(), out K))
                {
                    Console.WriteLine("Error");
                    break;
                }
                Console.Clear();
                switch (K)
                {
                case 1:
                {
                    Console.Write("Write model of your weapon: ");
                    Gun.Model = Console.ReadLine();
                    Console.Write("Write caliber of your weapon: ");
                    Gun.Caliber = Console.ReadLine();
                    Console.Write("Write max ammo in a clip: ");
                    if (!UInt32.TryParse(Console.ReadLine(), out a))
                    {
                        Console.WriteLine("Error");
                        break;
                    }
                    Gun.MaxAmmo = a;
                    Console.Write("Write current ammo in a clip: ");
                    if (!UInt32.TryParse(Console.ReadLine(), out a))
                    {
                        Console.WriteLine("Error");
                        break;
                    }
                    Gun.AmmoInClip = a;
                    break;
                }

                case 2:
                {
                    while (!Gun.Reload)
                    {
                        Gun.Shoot();
                    }
                    break;
                }

                case 3:
                {
                    Console.WriteLine("How many ammo do you want to reload?" +
                                      "\n1.Full clip" +
                                      "\n2.My number");
                    uint k;
                    if (!UInt32.TryParse(Console.ReadLine(), out k))
                    {
                        Console.WriteLine("Error");
                        break;
                    }
                    if (k == 1)
                    {
                        Gun.Reload = false;
                    }
                    else if (k == 2)
                    {
                        Console.WriteLine("What number?");
                        if (!UInt32.TryParse(Console.ReadLine(), out k))
                        {
                            Console.WriteLine("Error");
                            break;
                        }
                        Gun.ReloadFirearm(k);
                    }
                    break;
                }

                case 4:
                {
                    Console.WriteLine(Firearm.GeneralInfo);
                    Console.WriteLine($"Model of your weapon: {Gun.Model}");
                    Console.WriteLine($"Caliber of your weapon: {Gun.Caliber}");
                    Console.WriteLine($"Max ammo in a clip: {Gun.MaxAmmo}");
                    Console.WriteLine($"Current ammo in a clip: {Gun.AmmoInClip}");
                    break;
                }

                case 5:
                {
                    exit = true;
                    break;
                }

                default:
                    break;
                }
                if (exit == true)
                {
                    break;
                }
                Console.WriteLine("\nPress any button...");
                Console.ReadKey();
                Console.Clear();
            }
        }