Ejemplo n.º 1
0
        void ProcessTankControls()
        {
            if (controllableTank == null || !game)
            {
                return;
            }

            controllableTank.Move(Input.GetAxis("Vertical"));
            controllableTank.Rotate(Input.GetAxis("Horizontal"));
            controllableTank.ProcessTowerRotation(Camera.main.ScreenToWorldPoint(Input.mousePosition));
            if (Input.GetMouseButtonDown(0))
            {
                controllableTank.Shoot();
            }
            else if (Input.GetKeyDown(KeyCode.E))
            {
                controllableTank.NextWeapon();
            }
            else if (Input.GetKeyDown(KeyCode.Q))
            {
                controllableTank.PreviousWeapon();
            }
            if (Input.GetMouseButton(0))
            {
                controllableTank.ShootAutomatically();
            }
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            Console.WriteLine("Игра Перестрелка ");
            Tank   player = new Tank("Танк игрока", 5, 100, 25);     // танк игрока
            Tank   ai     = new Tank("Танк противника", 5, 100, 25); // танк компьютера
            int    i      = 1;
            string key;
            int    amount = 10; // величина починки

            key = Console.ReadLine();
            Random rnd = new Random();

            while (player.GetHealth() > 0 && ai.GetHealth() > 0) // условие победы
            {
                Console.WriteLine($"Раунд {i}");                 // вывод номера раунда

                {
                    do                   // начало валидации пользовательского ввода
                    {
                        player.PrintInfo();
                        ai.PrintInfo();
                        Console.WriteLine();
                        Console.WriteLine("Выберите действие");
                        Console.WriteLine("1. Выстрелить");
                        Console.WriteLine("2. Починка");
                        Console.WriteLine();
                        key = Console.ReadLine();
                        if (key != "1" && key != "2")
                        {
                            Console.WriteLine("Неизвестное действие, введите номер действия из списка");
                        }
                    }while (key != "1" && key != "2"); // конец пользовательского ввода
                }
                if (key == "1")
                {
                    player.Shoot(ref ai);
                }
                else if (key == "2")
                {
                    player.Repair(amount);
                }
                if (ai.GetHealth() <= 0)
                {
                    break;
                }
                int aim = rnd.Next(1, 3);
                if (aim == 1)
                {
                    ai.Shoot(ref player);
                    Console.WriteLine("Противник стреляет");
                }
                else if (aim == 2)
                {
                    ai.Repair(amount);
                    Console.WriteLine("Противник чинится");
                }
                i++;
            }
            if (player.GetHealth() > 0 || ai.GetHealth() <= 0)
            {
                Console.WriteLine("Игрок победил");
            }
            else if (player.GetHealth() <= 0 || ai.GetHealth() > 0)
            {
                Console.WriteLine("Противник победил");
            }
            Console.ReadKey();
        }