/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package garten.model; import java.util.ArrayList; /** * * @author Jan */ class Pflanzengruppe { private int alter; private int pflanzentyp; private int startlaenge; private ArrayList pflanzen; private Beet beet; Pflanze pfl; Pflanzengruppe(int pflanzentyp, int alter, int startlaenge, Beet beet) { System.out.println("Konstruktor Pflanzengruppe"); this.alter = alter; this.pflanzentyp = pflanzentyp; this.startlaenge = startlaenge; pflanzen = new ArrayList<>(); this.beet = beet; beginnebepflanzung(); } public void beginnebepflanzung() { Boolean bepflanzung = true; Boolean versetzt = true; int[] temp = beet.getKoordinaten(); int tempx = temp[0] + 10; int tempy = temp[1] + 20; int tempxrand = temp[2] + temp[0]; int tempyrand = temp[3] + temp[1]; try { int deltax = (temp[2] - 40) / ((temp[2] - 40) / 40); int deltay = (temp[3] - 40) / ((temp[3] - 40) / 50); do { if (pflanzentyp == 1) { pfl = new Pflanze1(tempx, tempy, alter,startlaenge); } else if (pflanzentyp == 2) { pfl = new Pflanze2(tempx, tempy, alter,startlaenge); } else if (pflanzentyp == 3) { pfl = new Pflanze3(tempx, tempy, alter,startlaenge); } pflanzen.add(pfl); tempx += deltax; if (tempx > tempxrand) { if (versetzt) { tempx = temp[0] + 30; versetzt = false; } else { tempx = temp[0] + 20; versetzt = true; } tempy += deltay; } if (tempy > tempyrand) { bepflanzung = false; } } while (bepflanzung); beet.setPflanzengruppeBeet(this); } catch (ArithmeticException e) { System.out.println("Beet zu klein"); } } public ArrayList getPflanzeninGruppe() { return pflanzen; } public void beginnebepflbox() { int[] randKoordinaten = beet.getKoordinaten();//großes Rechteck aufspannen welche Position schon vergeben sind boolean platzimBeet = true; System.out.println("Folgendes Beet bekommen: " + beet); System.out.println("Beet hat folgende Koordinaten " +randKoordinaten[0] + " "+ randKoordinaten[1] + " " +randKoordinaten[2] + " " +randKoordinaten[3]); int tempxstart = randKoordinaten[0]+20; int tempystart = randKoordinaten[1]+20; int xmin = randKoordinaten[0]; int xmax = randKoordinaten[2]+randKoordinaten[0]; int ymax = randKoordinaten[3]+randKoordinaten[1]; int[] temprechteck = new int[4]; temprechteck[0] = randKoordinaten[0]; temprechteck[1] = randKoordinaten[1]; temprechteck[2] = randKoordinaten[0]; temprechteck[3] = randKoordinaten[1]; do { float[] koordvergleich; if (pflanzentyp == 1) { pfl = new Pflanze1(tempxstart, tempystart, alter, startlaenge); } else if (pflanzentyp == 2) { pfl = new Pflanze2(tempxstart, tempystart, alter, startlaenge); } else if (pflanzentyp == 3) { pfl = new Pflanze3(tempxstart, tempystart, alter, startlaenge); } koordvergleich = pfl.getBoundingBoxes(); // System.out.println("Pflanze hat folgende Koordinaten " + koordvergleich[0] + " "+ koordvergleich[1] + " "+ xmax + " "+ ymax); //System.out.println("Temprechteck 2: " + temprechteck[2] + " Koordvergleich 2: " + koordvergleich[2] + " Xmax : " + xmax); if(temprechteck[2]< koordvergleich[2] && koordvergleich[2] xmax && koordvergleich[3]< ymax) { temprechteck[0] = xmin; temprechteck[2] = xmin; tempxstart = temprechteck[0]+20; tempystart = temprechteck[3]+temprechteck[3]-temprechteck[0]+20; System.out.println("Y-Achse wert erhöhen"); } if(ymax < koordvergleich[3] && xmax < koordvergleich[2]) { platzimBeet = false; } } while (platzimBeet); System.out.println("Pflanzengruppe erstellt und folgenden Pflanzen hinzugefügt"); System.out.println(pflanzen); beet.setPflanzengruppeBeet(this); } }