Wie lösche ich die 0 (Null), ohne dass die Ausrichtung des Felds abstürzt?Java

Java-Forum
Anonymous
 Wie lösche ich die 0 (Null), ohne dass die Ausrichtung des Felds abstürzt?

Post by Anonymous »

Für die Verteidigung von Consolas (Spielerhandbuch / Java) versuche ich, ein Gitter/Feld zu erstellen, in dem der Turm verteidigt werden muss.
Die Ausrichtung des Codes funktioniert soweit, aber ich versuche, die Null oben links zu löschen, wo die Spalten und Zeilen beginnen. Hat jemand von euch einen Trick, wie man es löscht und auch dafür sorgt, dass das Feld gleich bleibt?
Gr. Stefan
Code:

Code: Select all

package PlayersGuide.Opdracht11;

public class TowerDefenseField {
public static void main(String[] args) {
int size = 21;
String[][] field = new String[21][21];

/*
make the grid :
make a for loop that uses a dot "." as placeholder
This for-loop makes the blueprint for the grid :
for : int variable for 20 rows, condition : if number of rows is smaller then 20,
row increment/+ 1
inner for loop : int var for columns, condition : if num of col is smaller then 20,
col increment/+ 1.
*/
for(int row = 0; row < 21; row++) { // print 20 rows
for (int col = 0; col < 21; col++) { // print 20 columns
field[row][col] = "."; // this prints the dot on every column / row
}
}
System.out.println("   "); // ruimte voor rijnummers! deze worden geprint,
//zowel als de nummer die "eroverheen"worden geprint.
for (int col = 0; col < 21; col++){
System.out.printf("%4s", col);
}
System.out.println("   ");
for(int row = 1; row < 21; row++){
System.out.printf("%4d | ", row);
for (int col = 0; col < 20; col++){
System.out.printf("%3s",field[row][col] + "   ");
}
System.out.println();
}
}
}

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post