示例#1
0
        public static int CoordY()
        {
again:
            Console.Write($"Введите");
            Console.ForegroundColor = ConsoleColor.Yellow;
            Console.Write(" букву ");
            Console.ResetColor();
            Console.WriteLine("в промежутке от А до К");

            bool correctEnter = Enum.TryParse <Letters>(Console.ReadLine(), out Letters buffer_y);

            if (correctEnter)
            {
                int coord_y = (int)buffer_y;
                if (coord_y < 11)
                {
                    return(coord_y);
                }
                else
                {
                    Printer.PrintPlaceError();
                    goto again;
                }
            }
            else
            {
                Printer.PrintPlaceError();
                goto again;
            }
        }
示例#2
0
        public static int CoordX()
        {
again:
            Console.Write($"Введите");
            Console.ForegroundColor = ConsoleColor.Yellow;
            Console.Write(" цифру ");
            Console.ResetColor();
            Console.WriteLine("в промежутке от 1 до 10");
            bool correctcoord_x = int.TryParse(Console.ReadLine(), out int coord_x);

            if (correctcoord_x & coord_x < 11)
            {
                return(coord_x);
            }
            else
            {
                Printer.PrintPlaceError();
                goto again;
            }
        }
示例#3
0
        public static void Spawn(int[,] field, int x, int y, int shipSize, int direct, ref byte oneship, ref byte twoship, ref byte threeship, ref byte fourship, ref int countConstruct)
        {
            if (shipSize == 1)
            {
                if (Vert.FreespaceCheck(field, x, y, shipSize,
                                        sign_x: 1, sign_y: -1, sign_vect_x: -1, sign_vect_y: 1))
                {
                    Vert.MakeShip(field, x, y, shipSize,
                                  sign_x: 1, sign_y: -1, sign_vect_x: -1, sign_vect_y: 1);
                    oneship--;
                    countConstruct++;
                }
                else
                {
                    Printer.PrintPlaceError();
                }
            }
            else
            {
                switch (direct)
                {
                case 1:                            // вверх
                {
                    if (Vert.FreespaceCheck(field, x, y, shipSize,
                                            sign_x: 1, sign_y: -1, sign_vect_x: -1, sign_vect_y: 1))
                    {
                        Vert.MakeShip(field, x, y, shipSize,
                                      sign_x: 1, sign_y: -1, sign_vect_x: -1, sign_vect_y: 1);
                        switch (shipSize)
                        {
                        case 2: { twoship--; break; }

                        case 3: { threeship--; break; }

                        case 4: { fourship--; break; }
                        }
                        countConstruct++;
                    }
                    else
                    {
                        Printer.PrintPlaceError();
                    }
                    break;
                }

                case 2:                         // вниз
                {
                    if (Vert.FreespaceCheck(field, x, y, shipSize,
                                            sign_x: -1, sign_y: -1, sign_vect_x: 1, sign_vect_y: 1))
                    {
                        Vert.MakeShip(field, x, y, shipSize,
                                      sign_x: -1, sign_y: -1, sign_vect_x: 1, sign_vect_y: 1);
                        switch (shipSize)
                        {
                        case 2: { twoship--; break; }

                        case 3: { threeship--; break; }

                        case 4: { fourship--; break; }
                        }
                        countConstruct++;
                    }
                    else
                    {
                        Printer.PrintPlaceError();
                    }
                    break;
                }

                case 3:                            // вправо
                {
                    if (Horiz.FreespaceCheck(field, x, y, shipSize,
                                             sign_x: -1, sign_y: -1, sign_vect_x: 1, sign_vect_y: 1))
                    {
                        Horiz.MakeShip(field, x, y, shipSize,
                                       sign_x: -1, sign_y: -1, sign_vect_x: 1, sign_vect_y: 1);
                        switch (shipSize)
                        {
                        case 2: { twoship--; break; }

                        case 3: { threeship--; break; }

                        case 4: { fourship--; break; }
                        }
                        countConstruct++;
                    }
                    else
                    {
                        Printer.PrintPlaceError();
                    }
                    break;
                }

                case 4:                         // влево
                {
                    if (Horiz.FreespaceCheck(field, x, y, shipSize,
                                             sign_x: -1, sign_y: 1, sign_vect_x: 1, sign_vect_y: -1))
                    {
                        Horiz.MakeShip(field, x, y, shipSize,
                                       sign_x: -1, sign_y: 1, sign_vect_x: 1, sign_vect_y: -1);
                        switch (shipSize)
                        {
                        case 2: { twoship--; break; }

                        case 3: { threeship--; break; }

                        case 4: { fourship--; break; }
                        }
                        countConstruct++;
                    }
                    else
                    {
                        Printer.PrintPlaceError();
                    }
                    break;
                }
                }
            }
        }