Created
June 11, 2021 20:34
-
-
Save markxoe/66694122694b167824147d365b0936a7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class GENERATOR{ | |
private int all[][]; | |
private int bombe; // Der Wert einer Bombe ... | |
public GENERATOR(){ | |
bombe = Integer.MAX_VALUE; // ... ist sehr speziell | |
int groesse = 5; // Groesse für Feld, x und y | |
int anzahl_bomben = 10; // Anzahl der Bomben, verteilt auf das Feld | |
all = new int[groesse][groesse]; // Naja initialisierung und so lol | |
// Generiere Bomben... | |
for(int i = 0;i<anzahl_bomben;i++){ | |
int x = Math.round((int) (Math.random()*((float) groesse))); // Zufaellige Nummer und so | |
int y = Math.round((int) (Math.random()*((float) groesse))); | |
all[x][y] = bombe; // Setze dings bei dings auf Bombe | |
} | |
// Generiere Zahlen oder wie man die nennt... | |
for(int x = 0;x<groesse;x++){ | |
for(int y = 0;y<groesse;y++){ | |
// Wenns keine Bombe ist... | |
if(all[x][y] != bombe){ | |
int count = 0; | |
// ...dann zaehle die Bomben im Umkreis... | |
for(int countx = x-1; countx <= x+1; countx++){ | |
for(int county = y-1; county <= y+1; county++){ | |
boolean countxInBoundry = (countx < groesse) && (countx >= 0); | |
boolean countyInBoundry = (county < groesse) && (county >= 0); | |
if(countyInBoundry && countxInBoundry){ | |
if(all[countx][county] == bombe) count++; | |
} | |
} | |
} | |
// .. und speicher sie sonst sind se wech | |
all[x][y] = count; | |
} | |
} | |
} | |
// Gib den Kack noch aus damit man das so sehen kann und so | |
this.ausgeben(); | |
} | |
public void ausgeben(){ | |
String delimiter = ""; | |
for(int i = 0;i<all.length*2;i++) delimiter += "-"; | |
System.out.println(delimiter); | |
for(int i = 0;i<all.length;i++){ | |
for(int j = 0;j<all.length;j++){ | |
String out = ""; | |
if(all[i][j] == bombe) { | |
out = "X"; | |
} else{ | |
out = String.valueOf(all[i][j]); | |
} | |
System.out.print(out+" "); | |
} | |
System.out.println(); | |
} | |
System.out.println(delimiter); | |
} | |
public int[][] arr(){ | |
return all; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment