I have been making a basic game of battleship and to get the CPU to choose ship locations on a 2d array I am making two random number generators to pick values from 1 to 8 on a separate method. For some reason, the random generators show up as unused and I don't know why. so far this is what I have. If anyone knows what I'm doing wrong please let me know.
public static String[][] CPUship(String[][]board3){
boolean valid2=false;
int rowGenerate=0;
int colGenerate=0;
int CPUships=0;
while (CPUships<=5){
while (valid2=false){
rowGenerate = (int) ( 9* Math.random() + 0);
colGenerate = (int) ( 9* Math.random() + 0);
if (!board3[rowGenerate][colGenerate].equalsIgnoreCase ("#")){
board3[rowGenerate][colGenerate]="#";
valid2=true;
}
}
CPUships++;
}
return board3;
}
Aucun commentaire:
Enregistrer un commentaire