Java Schleife Schachbrett?

2 Antworten

public class mainclass {

private static int Lustig;

public static void main(String[] args) {

setLustig(60);

ZEICHENFENSTER.gibFenster();

for (int i = 0; i < 8; i++) {

  for (int j = 0; j < 8; j++) {

    if (((i % 2 == 0) && (j % 2 == 0)) || ((i % 2 != 0) && (j % 2 != 0))) {

    ZEICHENFENSTER.gibFenster().fuelleRechteck(i * getLustig(), j * getLustig(), getLustig(), getLustig(), 2);

    } else {

    ZEICHENFENSTER.gibFenster().fuelleRechteck(i * getLustig(), j * getLustig(), getLustig(), getLustig(), 1);

    }

  }

}

}

public static int getLustig() {

return Lustig;

}

public static void setLustig(int lustig) {

Lustig = lustig;

}

}

So geht das, mein Kollege! :)

Btw du brauchst noch "Zeichenfenster". Kann man sich kostenlos runterladen.

for (int i = 0; i < 64; i++) {
for (int j = 0; j < 64; j++) {
int farbe;
if (((i % 2 == 0) && (j % 2 == 0)) || ((i % 2 != 0) && (j % 2 != 0))) {
farbe = 255;
} else {
farbe = 0;
}
zeichneRechteck(i * 40, j * 40, 40, 40, (farbe, farbe, farbe));
}
}

Die Funktion "zeichneRechteck" musst du entsprechend anpassen, in meiner Variante sind die Parameter folgende:

  1.  Entfernung vom linken Rand
  2. Entfernung vom oberen Rand
  3. Breite
  4. Höhe
  5. Farbe (drei Werte für RGB)