Beispiel #1
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;
                }
                }
            }
        }