Advertisement
Guest User

Untitled

a guest
Apr 25th, 2019
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.69 KB | None | 0 0
  1. public class Main {
  2.  
  3.     public static void main(String[] args) {
  4.         int tab[][] = new int[23][23];
  5.  
  6.             int ileProcent = (int)((Math.random()*91+10)*0.01*23*23);
  7.             int licznikZapelnienia=0;
  8.             while(licznikZapelnienia != ileProcent){
  9.                 int x = (int) (Math.random()*23);
  10.                 int y = (int) (Math.random()*23);
  11.                 if(tab[x][y] == 0) {
  12.                     tab[x][y] = 1;
  13.                     licznikZapelnienia++;
  14.                 }
  15.             }
  16.  
  17.             int x = (int) (Math.random()*23);
  18.             int y = (int) (Math.random()*23);
  19.             tab[x][y] = 2;
  20.  
  21.             int liczPetla = 0;
  22.             while(liczPetla < licznikZapelnienia){
  23.             int ruch = (int) (Math.random() * 4);
  24.             tab[x][y] = 3;
  25.                 if (ruch == 0 && x > 0) {
  26.                     // if(tab[x-1][y] == 3) ruch++;
  27.                         x = x - 1;      // W górę
  28.                 }
  29.                 if (ruch == 1 && x < 22) {
  30.                    //if(tab[x+1][y] != 3) ruch++;
  31.                         x = x + 1;      // W dół
  32.                 }
  33.                 if (ruch == 2 && y < 22) {
  34.                     //if(tab[x][y+1] != 3) ruch++;
  35.                         y = y + 1;      // W prawo
  36.                 }
  37.                 if (ruch == 3 && y > 0) {
  38.                         y = y - 1;      // W lewo
  39.                 }
  40.                 if(tab[x][y] == 1) liczPetla++;
  41.             }
  42.             tab[x][y]=2;
  43.  
  44.         for (int i = 0; i < 23; i++) {
  45.             for (int j = 0; j < 23; j++) {
  46.                 System.out.print(tab[i][j]);
  47.             }
  48.             System.out.println();
  49.         }
  50.  
  51.     }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement