示例#1
0
        public void shotResult(Position position, ShotStatus status)
        {
            Shots.Add(position, status);

            ConsoleGraphics.showShootedField(Shots, 90);

            string str = null;

            switch (status)
            {
            case ShotStatus.HIT:
                str = "Попадание";
                break;

            case ShotStatus.MISS:
                str = "Промах";
                break;

            case ShotStatus.SUNK:
                str = "Потопил";
                break;
            }
            Console.WriteLine($"{position.getX()},{position.getY()} {str}");
            Console.ReadLine();
        }
示例#2
0
        public Position chooseShot()
        {
            ConsoleGraphics.showShootedField(Shots, 90);

            Console.WriteLine($"Игрок {Name}, введите кординаты выстрела");

            Console.WriteLine("Введите X:");
            string answ = Console.ReadLine();

            if (answ == "пауза")
            {
                throw new PauseException();
            }

            int x, y;

            try
            {
                x = int.Parse(answ);
            }
            catch
            {
                Console.WriteLine("Введено неверное значение");
                return(chooseShot());
            }

            Console.WriteLine("Введите Y:");
            answ = Console.ReadLine();
            if (answ == "пауза")
            {
                throw new PauseException();
            }
            try
            {
                y = int.Parse(answ);
            }
            catch
            {
                Console.WriteLine("Введено неверное значение");
                return(chooseShot());
            }

            Position position = null;

            try
            {
                position = new Position(y, x);
            }
            catch
            {
                Console.WriteLine("Введены неверные кординаты, введите кординаты заново");
                return(chooseShot());
            }

            return(position);
        }