Hallo.
ich versuche durch ein wenig Programmierung routine zu finden. Darum schreibe ich immer mal wider den ein oder anderen kleinen Mist
Momentan arbeite ich an folgendem sinnlosen Programm.
Es soll ein Feld ausgegeben werden:
das x symbolisiert eine Mine auf dem 4x4 gossen Feld.
Das Programm funktioniert soweit ohne Probleme, d.h die zufälligen Koordinaten(x,y) für die Mienen werden generiert.
Aber ich habe nun keine Ahnung wie ich anhand dieser Koordinaten die x-en auf das Feld bekomme.
Hat jemand eine Idee wie ich die das ganze visualisieren kann?
(Java 1.7)
ich versuche durch ein wenig Programmierung routine zu finden. Darum schreibe ich immer mal wider den ein oder anderen kleinen Mist
Momentan arbeite ich an folgendem sinnlosen Programm.
Es soll ein Feld ausgegeben werden:
Code:
.............
. .x . . .
.............
. . .x . .
.............
.x . . . .
.............
. . . . .
.............
Das Programm funktioniert soweit ohne Probleme, d.h die zufälligen Koordinaten(x,y) für die Mienen werden generiert.
Aber ich habe nun keine Ahnung wie ich anhand dieser Koordinaten die x-en auf das Feld bekomme.
Java:
public class main {
/**
* @param args
*/
public static void main(String[] args) {
java.awt.Point bomb1 = new java.awt.Point();
java.awt.Point bomb2 = new java.awt.Point();
java.awt.Point bomb3 = new java.awt.Point();
int count = 0;
while(count != 3){
int randx = 0;
int randy = 0;
do{
randx = (int) ((Math.random() * 4) + 1);
randy = (int) ((Math.random() * 4) + 1);
}while(randx == 1 || randy == randx);
switch(count)
{
case 0:
bomb1.setLocation(randx, randy);
break;
case 1:
bomb2.setLocation(randx, randy);
break;
case 2:
bomb3.setLocation(randx, randy);
break;
}
count++;
}
System.out.println(bomb1.getLocation());
System.out.println(bomb2.getLocation());
System.out.println(bomb3.getLocation());
System.out.println((int)bomb1.getX());
System.out.println((int)bomb1.getY());
printField(); //... die bombenkordinaten
//java.util.Scanner input = new java.util.Scanner(System.in);
}
public static void printField(int b1x, int b1y, int b2x, int b2y, int b3x, int b3y)
{
System.out.println(".............");
System.out.println(". . . . .");
System.out.println(".............");
System.out.println(". . . . .");
System.out.println(".............");
System.out.println(". . . . .");
System.out.println(".............");
System.out.println(". . . . .");
System.out.println(".............");
}
}
Hat jemand eine Idee wie ich die das ganze visualisieren kann?
(Java 1.7)
Zuletzt bearbeitet von einem Moderator: