Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Main {
- public static void main(String[] args) {
- int tab[][] = new int[23][23];
- int ileProcent = (int)((Math.random()*91+10)*0.01*23*23);
- int licznikZapelnienia=0;
- while(licznikZapelnienia != ileProcent){
- int x = (int) (Math.random()*23);
- int y = (int) (Math.random()*23);
- if(tab[x][y] == 0) {
- tab[x][y] = 1;
- licznikZapelnienia++;
- }
- }
- int x = (int) (Math.random()*23);
- int y = (int) (Math.random()*23);
- tab[x][y] = 2;
- int liczPetla = 0;
- while(liczPetla < licznikZapelnienia){
- int ruch = (int) (Math.random() * 4);
- tab[x][y] = 3;
- if (ruch == 0 && x > 0) {
- // if(tab[x-1][y] == 3) ruch++;
- x = x - 1; // W górę
- }
- if (ruch == 1 && x < 22) {
- //if(tab[x+1][y] != 3) ruch++;
- x = x + 1; // W dół
- }
- if (ruch == 2 && y < 22) {
- //if(tab[x][y+1] != 3) ruch++;
- y = y + 1; // W prawo
- }
- if (ruch == 3 && y > 0) {
- y = y - 1; // W lewo
- }
- if(tab[x][y] == 1) liczPetla++;
- }
- tab[x][y]=2;
- for (int i = 0; i < 23; i++) {
- for (int j = 0; j < 23; j++) {
- System.out.print(tab[i][j]);
- }
- System.out.println();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement