https://pastein.ru/t/_T

  скопируйте уникальную ссылку для отправки

Загрузка данных


	private void createFour(int array[][], int number) {
	    while (true) {
	    boolean flag = false;
	    int i=0,j=0;
	    i = (int)(Math.random()*10);
	    j = (int)(Math.random()*10);
	    int direction = (int)(Math.random()*4);
	    if (shipCheckAvailable(array,i,j)==true) {
	    if (direction==0) // вверх 
	    {
	        if (shipCheckAvailable(array,i-(number-1),j)==true) flag = true;
	    }
	    else if (direction==1) // вправо
	    {
	        if (shipCheckAvailable(array,i,j+(number-1))==true) flag = true;
	    }
	    else if (direction==2) // вниз
	    {
	        if (shipCheckAvailable(array,i+(number-1),j)==true) flag = true;
	    }
	    else if (direction==3) // влево 
	    {
	        if (shipCheckAvailable(array,i,j-(number-1))==true) flag = true;
	    }
	    }
	     if (flag == true) {
	         array[i][j] = number;
	         surroundCreating(array,i,j,-2);
	         if (direction==0) {
	             for (int k = number-1;k>=1;k--) {
	                 array[i-k][j]=number;
	                 surroundCreating(array,i-k,j,-2);
	             }
	         }
	         else if (direction==1) {
	             for (int k = number-1;k>=1;k--) {
	                 array[i][j+k]=number;
	                 surroundCreating(array,i,j+k,-2);
	             }
	         }
	         else if (direction==2) {
	             for (int k = number-1;k>=1;k--) {
	                 array[i+k][j]=number;
	                 surroundCreating(array,i+k,j,-2);
	             }
	         }
	         else if (direction==3) {
	             for (int k = number-1;k>=1;k--) {
	                 array[i][j-k]=number;
	                 surroundCreating(array,i,j-k,-2);
	             }
	         }
	         break;
	         }
	     }
	         surroundFinal(array);
	     }