/*    int[][] grid = {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  *     {0, 0, 0, 0, 0, 0, 0, 0, 0, 0},{0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  *      {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0},{0, 0, 0, 0, 0, 0, 0, 0, 0, 0},{0, 0, 0, 0, 0, 0, 0, 0, 0, 0}};
  */
 public void setShips()
 {
     Boat[] ship;
     ship    = new Boat[10];
     ship[0] = new Portaviones();
     ship[1] = new Crucero();
     ship[2] = new Crucero();
     ship[3] = new Destroyer();
     ship[4] = new Destroyer();
     ship[5] = new Destroyer();
     ship[6] = new Submarine();
     ship[7] = new Submarine();
     ship[8] = new Submarine();
     ship[9] = new Submarine();
 }
Пример #2
0
        private void createBoat(int size, int qty)
        {
            for (int i = 0; i < qty; i++)
            {
                ShipLocation shipLocation = getEmptyPoint(size);
                Barco        barco;

                if (size == SUBMARINO)
                {
                    barco = new Submarine();
                }
                else if (size == DESTRUCTOR)
                {
                    barco = new Destroyer();
                }
                else if (size == CRUCERO)
                {
                    barco = new Crucero();
                }
                else
                {
                    barco = new Portaviones();
                }


                for (int j = 0; j < size; j++)
                {
                    if (shipLocation.Orientation == UP)
                    {
                        matrix[shipLocation.Row - j, shipLocation.Col] = barco;
                    }
                    else if (shipLocation.Orientation == DOWN)
                    {
                        matrix[shipLocation.Row + j, shipLocation.Col] = barco;
                    }
                    else if (shipLocation.Orientation == LEFT)
                    {
                        matrix[shipLocation.Row, shipLocation.Col - j] = barco;
                    }
                    else if (shipLocation.Orientation == RIGHT)
                    {
                        matrix[shipLocation.Row, shipLocation.Col + j] = barco;
                    }
                }
                rodearConAgua(shipLocation);
            }
        }