public void setShiffAtRandomPosition(Schiff schiff) { Random rand = new Random(); int direction = rand.nextInt(2); int maxWidth = this.width; int maxHeight = this.height; if (direction == 0) { maxWidth -= (schiff.getPunkte().size() - 1); } else { maxHeight -= (schiff.getPunkte().size() - 1); } int col = rand.nextInt(maxWidth); int row = rand.nextInt(maxHeight); SchiffName typ = schiff.getName(); switch (typ) { case KREUZER: schiff = new Kreuzer(row, col, direction); break; case SCHLACHTSCHIFF: schiff = new Schlachtschiff(row, col, direction); break; case UBOOT: schiff = new UBoot(row, col, direction); break; case ZERSTOERER: schiff = new Zerstoerer(row, col, direction); break; default: schiff = null; break; } boolean kolidiert = false; for (Schiff s : schiffListe) { if (s.kolidiertMitSchiff(schiff)) { kolidiert = true; } } if (!kolidiert) { addSchiff(schiff); } else { setShiffAtRandomPosition(schiff); } }