This commit is contained in:
Jan 2019-06-25 08:28:57 +02:00
parent 0ce7a928c8
commit aff2d12f1b
6 changed files with 202 additions and 154 deletions

View File

@ -6,6 +6,8 @@
package garten.model; package garten.model;
import java.util.ArrayList;
/** /**
* *
* @author Jan * @author Jan
@ -14,18 +16,30 @@ public class Beet extends Gartenkomponente
{ {
int laenge; int laenge;
int breite; int breite;
Pflanzengruppe pflgruppe;
public Beet(int x, int y,int laenge, int breite) public Beet(int x, int y,int laenge, int breite)
{ {
positionx = x; positionx = x;
positiony = y; positiony = y;
this.laenge = laenge; this.laenge = laenge;
this.breite = breite; this.breite = breite;
pflgruppe = null;
} }
public int [] getKoordinaten() public int [] getKoordinaten()
{ {
int[] temp = {positionx,positiony,laenge,breite}; int[] temp = {positionx,positiony,laenge,breite};
return temp; return temp;
} }
public void setPflanzengruppeBeet(Pflanzengruppe pflgruppe)
{
this.pflgruppe = pflgruppe;
}
public ArrayList<Pflanze> getPflanzenausgruppe()
{
System.out.println("Beet frägt nach seinen Pflanzen");
System.out.println(pflgruppe.getPflanzeninGruppe());
return pflgruppe.getPflanzeninGruppe();
}
} }

View File

@ -6,8 +6,6 @@
package garten.model; package garten.model;
import garten.view.Fenster; import garten.view.Fenster;
import garten.view.GUI;
import java.awt.MouseInfo;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
import java.awt.event.ActionListener; import java.awt.event.ActionListener;
import java.awt.event.MouseEvent; import java.awt.event.MouseEvent;
@ -37,15 +35,11 @@ public class Gaertner implements MouseMotionListener, MouseListener,ActionListen
Pflanze3 pfl3; Pflanze3 pfl3;
int height; int height;
int width; int width;
GUI gui;
public Gaertner(Fenster fenster) public Gaertner(Fenster fenster)
{ {
this.fenster = fenster; this.fenster = fenster;
meinGarten = new Garten(fenster.getFlbeet(), fenster.getFlweg(), fenster.getFlpfl()); meinGarten = new Garten(fenster.getFlbeet(), fenster.getFlweg(), fenster.getFlpfl());
//this.gui = gui;
//meinGarten = new Garten(gui.getFlaecheBeet2(), gui.getFlaecheWeg1(), gui.getFlaechePflanzen1());
pflanzebewegt = false; pflanzebewegt = false;
gartenexistiert = false; gartenexistiert = false;
bepflanzungexistiert = false; bepflanzungexistiert = false;
@ -58,10 +52,6 @@ public class Gaertner implements MouseMotionListener, MouseListener,ActionListen
{ {
fenster.addMouseListener(this); fenster.addMouseListener(this);
fenster.addMouseMotionListener(this); fenster.addMouseMotionListener(this);
//fenster.getFlbeet().addMouseListener(this);
//fenster.getFlpfl().addMouseListener(this);
//fenster.getFlweg().addMouseListener(this);
fenster.getMnGartenanlegen().addActionListener(this); fenster.getMnGartenanlegen().addActionListener(this);
fenster.getMnRandomPflanzenanlegen().addActionListener(this); fenster.getMnRandomPflanzenanlegen().addActionListener(this);
@ -86,45 +76,16 @@ public class Gaertner implements MouseMotionListener, MouseListener,ActionListen
fenster.getRadiobtn1pfl1().setVisible(true); fenster.getRadiobtn1pfl1().setVisible(true);
/*
gui.addMouseListener(this);
gui.addMouseMotionListener(this);
gui.getMnGartenanlegen().addActionListener(this);
gui.getMnRandomPflanzenanlegen().addActionListener(this);
gui.getBtnbepfl1().addActionListener(this);
gui.getBtnbepfl2().addActionListener(this);
gui.getBtnbepfl3().addActionListener(this);
gui.getRadiobtn1pfl1().addActionListener(this);
gui.getRadiobtn1pfl2().addActionListener(this);
gui.getRadiobtn1pfl3().addActionListener(this);
gui.getRadiobtn2pfl1().addActionListener(this);
gui.getRadiobtn2pfl2().addActionListener(this);
gui.getRadiobtn2pfl3().addActionListener(this);
gui.getRadiobtn3pfl1().addActionListener(this);
gui.getRadiobtn3pfl2().addActionListener(this);
gui.getRadiobtn3pfl3().addActionListener(this);
gui.getRadiobtn4pfl3().addActionListener(this);
*/
} }
@Override @Override
public void mouseClicked(MouseEvent e) public void mouseClicked(MouseEvent e)
{ {
System.out.println("MouseEvent");
if (SwingUtilities.isRightMouseButton(e))//Bei Rechtsklick Popup Menü if (SwingUtilities.isRightMouseButton(e))//Bei Rechtsklick Popup Menü
{ {
//Zwischenspeichern der Koordinaten der Maus um Beet zu finden //Zwischenspeichern der Koordinaten der Maus um Beet zu finden
aktuellesBeet[0] = MouseInfo.getPointerInfo().getLocation().x; aktuellesBeet[0] = e.getX();
System.out.println("Beet x: " + aktuellesBeet[0]); aktuellesBeet[1] = e.getY();
aktuellesBeet[1] = MouseInfo.getPointerInfo().getLocation().y;
System.out.println("Beet y: " + aktuellesBeet[1]);
fenster.showPoPup(e);
}
else
{
fenster.hidePopup();
} }
} }
@ -255,11 +216,13 @@ public class Gaertner implements MouseMotionListener, MouseListener,ActionListen
konfig.alter(alter); konfig.alter(alter);
konfig.pflanzenTyp(pflanzentyp); konfig.pflanzenTyp(pflanzentyp);
konfig.startlaenge(laenge); konfig.startlaenge(laenge);
konfig.beet(meinGarten.getBeet(aktuellesBeet));
konfig.erstellen(); konfig.erstellen();
for(Pflanze pf : meinGarten.getBeet(aktuellesBeet).getPflanzenausgruppe())
System.out.println("Das gefundene Beet : " + meinGarten.getBeet(aktuellesBeet)); {
System.out.println("Alle beete" + meinGarten.getBeete()); meinGarten.hinzufuegenPflanze(pf);
}
meinGarten.zeichnePflanzen();
System.out.println("Pflanze konfiguriert"); System.out.println("Pflanze konfiguriert");
bepflanzungexistiert = true; bepflanzungexistiert = true;
} }

View File

@ -22,9 +22,6 @@ public class Garten extends Kompositum
private ArrayList<Pflanze> pflanzen; private ArrayList<Pflanze> pflanzen;
private Pflanze pfl; private Pflanze pfl;
private Pflanze1 pfl1;
private Pflanze2 pfl2;
private Pflanze3 pfl3;
int intmovePflanze; int intmovePflanze;
FlaecheBeet flbeet; FlaecheBeet flbeet;
FlaecheWeg flweg; FlaecheWeg flweg;
@ -57,24 +54,21 @@ public class Garten extends Kompositum
{ {
flbeet.zeichneBeete(beete); flbeet.zeichneBeete(beete);
} }
public Beet getBeet(int[] mausposition) public Beet getBeet(int[] mausposition)
{ {
System.out.println("Suche richtiges Beet");
Beet tempBeet = null; Beet tempBeet = null;
for (Beet b : beete) for (Beet b : beete)
{ {
int[] koordinvergleich = b.getKoordinaten(); int[] koordinvergleich = b.getKoordinaten();
System.out.println("Maus: " +mausposition[0] +" " + mausposition[1]); if (koordinvergleich[0] < mausposition[0] && koordinvergleich[1] < mausposition[1] && (koordinvergleich[2] + koordinvergleich[0]) > mausposition[0] && (koordinvergleich[3] + koordinvergleich[1]) > mausposition[1])
System.out.println("Beet: " +koordinvergleich[0]+" " + koordinvergleich[1]+" " + koordinvergleich[2]+" " + koordinvergleich[3]);
if(koordinvergleich[0]<mausposition[0] && koordinvergleich[1]<mausposition[1] && (koordinvergleich[2]+koordinvergleich[0]) >mausposition[0] && (koordinvergleich[3]+koordinvergleich[1]) > mausposition[1] )
{ {
System.err.println("Kommt zum Vergleich?");
tempBeet = b; tempBeet = b;
} }
} }
return tempBeet; return tempBeet;
} }
//Funktionen Wege //Funktionen Wege
public void hinzufuegenWeg(int sx, int sy, int ex, int ey) public void hinzufuegenWeg(int sx, int sy, int ex, int ey)
{ {
@ -100,69 +94,33 @@ public class Garten extends Kompositum
public Boolean randomBepflanzung() public Boolean randomBepflanzung()
{ {
for (Beet b : beete) for (Beet b : beete)
{ {
try PflanzengruppenKonfigurator konfig = new PflanzengruppenKonfigurator();
int randomAlter = (int) (Math.random() * 3 + 1);
int randomTyp = (int) (Math.random() * 3 + 1);
int[] temp = b.getKoordinaten();
int laenge;
konfig.alter(randomAlter);
konfig.pflanzenTyp(randomTyp);
if (randomTyp == 1)
{ {
laenge = 30;
int randomAlter = (int) (Math.random() * 3 + 1);
int randomTyp = (int) (Math.random() * 3 + 1);
Boolean bepflanzung = true;
Boolean versetzt = true;
int[] temp = b.getKoordinaten();
int tempx = temp[0] + 10;
int tempy = temp[1] + 20;
int tempxrand = temp[2] + temp[0];
int tempyrand = temp[3] + temp[1];
int deltax = (temp[2] - 40) / ((temp[2] - 40) / 40);
int deltay = (temp[3] - 40) / ((temp[3] - 40) / 50);
do
{
if (randomTyp == 1)
{
pfl1 = new Pflanze1(tempx, tempy, randomAlter,20);
float[] tempbound = pfl1.getBoundingBoxes();
System.out.println("Bounding Boxes: " + tempbound[0] + " " + tempbound[1] + " " + tempbound[2] + " " + tempbound[3]);
hinzufuegenPflanze(pfl1);
}
else if (randomTyp == 2)
{
pfl2 = new Pflanze2(tempx, tempy, randomAlter,15);
hinzufuegenPflanze(pfl2);
}
else if (randomTyp == 3)
{
pfl3 = new Pflanze3(tempx, tempy, randomAlter,10);
hinzufuegenPflanze(pfl3);
}
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);
} }
catch (ArithmeticException e) else
{ {
pflanzen.removeAll(pflanzen); laenge = 15;
return false; }
konfig.startlaenge(laenge);
konfig.beet(b);
konfig.erstellen();
for (Pflanze pf : b.getPflanzenausgruppe())
{
hinzufuegenPflanze(pf);
} }
} }
zeichnePflanzen(); zeichnePflanzen();
@ -186,10 +144,14 @@ public class Garten extends Kompositum
randomwertex[3] = width - 50; randomwertex[3] = width - 50;
randomwertey[3] = height - 50; randomwertey[3] = height - 50;
int deltax = randomwertex[3] / 3;
int deltay = randomwertey[3] / 3;
for (int i = 1; i < 3; i++) //erstelle Random Punkte für Wege + Beete for (int i = 1; i < 3; i++) //erstelle Random Punkte für Wege + Beete
{ {
int wegendex = (int) (Math.random() * (170 * i) + (200 * i)); //int wegendex = (int) (Math.random() * (170 * i) + (200 * i));
int wegendey = (int) (Math.random() * (170 * i) + (200 * i)); //int wegendey = (int) (Math.random() * (170 * i) + (200 * i));
int wegendex = (int) (Math.random() * ((randomwertex[3] / 3 - 40 * i) * i) + (randomwertex[3] / 4 * i));
int wegendey = (int) (Math.random() * ((randomwertey[3] / 3 - 40 * i) * i) + (randomwertey[3] / 4 * i));
randomwertex[i] = wegendex; randomwertex[i] = wegendex;
randomwertey[i] = wegendey; randomwertey[i] = wegendey;
} }

View File

@ -18,5 +18,6 @@ public interface Pflanze extends Position
void setPosition(); void setPosition();
public ArrayList<float[]> getPoints(); public ArrayList<float[]> getPoints();
public void setAlgorithm(); public void setAlgorithm();
public float [] getBoundingBoxes();
} }

View File

@ -3,59 +3,171 @@
* To change this template file, choose Tools | Templates * To change this template file, choose Tools | Templates
* and open the template in the editor. * and open the template in the editor.
*/ */
package garten.model; package garten.model;
import java.util.ArrayList; import java.util.ArrayList;
/** /**
* *
* @author Jan * @author Jan
*/ */
class Pflanzengruppe class Pflanzengruppe
{ {
private int alter; private int alter;
private int pflanzentyp; private int pflanzentyp;
private int startlaenge; private int startlaenge;
private ArrayList<Pflanze> pflanzen; private ArrayList<Pflanze> pflanzen;
private Beet beet; private Beet beet;
Pflanze1 pfl1; Pflanze pfl;
Pflanze2 pfl2;
Pflanze3 pfl3; Pflanzengruppe(int pflanzentyp, int alter, int startlaenge, Beet beet)
{
System.out.println("Konstruktor Pflanzengruppe");
Pflanzengruppe(int pflanzenTyp,int alter, int startlaenge, Beet beet)
{
this.alter = alter; this.alter = alter;
this.pflanzentyp = pflanzenTyp; this.pflanzentyp = pflanzentyp;
this.startlaenge = startlaenge; this.startlaenge = startlaenge;
pflanzen = new ArrayList<>();
this.beet = beet; this.beet = beet;
beginnebepflanzung();
} }
public void anzeigen()
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<Pflanze> beginnebepflanzung()
public ArrayList<Pflanze> getPflanzeninGruppe()
{ {
beet.getKoordinaten();
if(pflanzentyp == 1)
{
pfl1 = new Pflanze1(alter, alter, alter, startlaenge);
pflanzen.add(pfl1);
}
else if (pflanzentyp ==2)
{
pfl2 = new Pflanze2(alter, alter, alter, startlaenge);
pflanzen.add(pfl1);
}
else if (pflanzentyp ==3)
{
pfl3 = new Pflanze3(alter, alter, alter, startlaenge);
pflanzen.add(pfl1);
}
return pflanzen; 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)
{
temprechteck[2] = (int) koordvergleich[2];
tempxstart =temprechteck[2]+20;
if(temprechteck[3]<koordvergleich[3])
{
temprechteck[3]= (int)koordvergleich[3];
}
pflanzen.add(pfl);
}
else
tempxstart +=40;
if(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);
}
}

View File

@ -143,10 +143,6 @@ public class Fenster extends JFrame
popup.addSeparator(); popup.addSeparator();
popup.add(mnbepflanzen3); popup.add(mnbepflanzen3);
popup.setLightWeightPopupEnabled(false);
//flbeet.setComponentPopupMenu(popup);
//popup.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
this.setTitle("Garten von Paul und Jan"); this.setTitle("Garten von Paul und Jan");
this.pack(); this.pack();
this.setDefaultCloseOperation(EXIT_ON_CLOSE); this.setDefaultCloseOperation(EXIT_ON_CLOSE);
@ -162,7 +158,7 @@ public class Fenster extends JFrame
}); });
this.add(popup); //this.add(popup);
} }