问题
I'm trying to make a grid made out of "." for a MineSweeper/Capture The Flag type game, but I've been having trouble. I'm trying to do a \n every 50 "." so it can start printing another column but my code prints a single dot every row. This is how the grid is supposed to look (ignore the % and the since that's another part of the project, pretend it is alll "."): https://imgur.com/a/3zWKyb8
This is my code:
String grid = ".";
int rows = 20;
int columns = 50;
int count = 0;
while(count <= 1000)
{
count++;
for(int c = 1; c <= columns; display(grid))
{
String nwln = "\n";
display(nwln);
c = 0;
}
}
My display method code per requested:
public static String display(String disp)
{
System.out.print(disp);
return(disp);
}
回答1:
First let's see a simple code to print the 20 X 50 grid:
public static void main(String[] args) {
final String point = ".";
final int rows = 20;
final int columns = 50;
for (int i = 0; i < rows; i++) {
for (int j = 0; j < columns; j++) {
System.out.print(point);
}
System.out.println();
}
}
From there you can implement your flags and bombs in between the points.
来源:https://stackoverflow.com/questions/54523029/how-to-make-a-20-rows-x-50-columns-grid-in-java