Jan 4 years ago
parent
commit
aff2d12f1b

+ 15
- 1
Garten/src/garten/model/Beet.java View File

@@ -6,6 +6,8 @@

package garten.model;

import java.util.ArrayList;

/**
*
* @author Jan
@@ -14,18 +16,30 @@ public class Beet extends Gartenkomponente
{
int laenge;
int breite;
Pflanzengruppe pflgruppe;
public Beet(int x, int y,int laenge, int breite)
{
positionx = x;
positiony = y;
this.laenge = laenge;
this.breite = breite;
pflgruppe = null;
}
public int [] getKoordinaten()
{
int[] temp = {positionx,positiony,laenge,breite};
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();
}

}

+ 8
- 45
Garten/src/garten/model/Gaertner.java View File

@@ -6,8 +6,6 @@
package garten.model;

import garten.view.Fenster;
import garten.view.GUI;
import java.awt.MouseInfo;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
@@ -37,15 +35,11 @@ public class Gaertner implements MouseMotionListener, MouseListener,ActionListen
Pflanze3 pfl3;
int height;
int width;
GUI gui;

public Gaertner(Fenster fenster)
{
this.fenster = fenster;
meinGarten = new Garten(fenster.getFlbeet(), fenster.getFlweg(), fenster.getFlpfl());
//this.gui = gui;
//meinGarten = new Garten(gui.getFlaecheBeet2(), gui.getFlaecheWeg1(), gui.getFlaechePflanzen1());

pflanzebewegt = false;
gartenexistiert = false;
bepflanzungexistiert = false;
@@ -58,10 +52,6 @@ public class Gaertner implements MouseMotionListener, MouseListener,ActionListen
{
fenster.addMouseListener(this);
fenster.addMouseMotionListener(this);

//fenster.getFlbeet().addMouseListener(this);
//fenster.getFlpfl().addMouseListener(this);
//fenster.getFlweg().addMouseListener(this);
fenster.getMnGartenanlegen().addActionListener(this);
fenster.getMnRandomPflanzenanlegen().addActionListener(this);

@@ -86,45 +76,16 @@ public class Gaertner implements MouseMotionListener, MouseListener,ActionListen

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
public void mouseClicked(MouseEvent e)
{
System.out.println("MouseEvent");
if (SwingUtilities.isRightMouseButton(e))//Bei Rechtsklick Popup Menü
{
//Zwischenspeichern der Koordinaten der Maus um Beet zu finden
aktuellesBeet[0] = MouseInfo.getPointerInfo().getLocation().x;
System.out.println("Beet x: " + aktuellesBeet[0]);
aktuellesBeet[1] = MouseInfo.getPointerInfo().getLocation().y;
System.out.println("Beet y: " + aktuellesBeet[1]);
fenster.showPoPup(e);
}
else
{
fenster.hidePopup();
aktuellesBeet[0] = e.getX();
aktuellesBeet[1] = e.getY();
}
}

@@ -255,11 +216,13 @@ public class Gaertner implements MouseMotionListener, MouseListener,ActionListen
konfig.alter(alter);
konfig.pflanzenTyp(pflanzentyp);
konfig.startlaenge(laenge);
konfig.beet(meinGarten.getBeet(aktuellesBeet));
konfig.erstellen();

System.out.println("Das gefundene Beet : " + meinGarten.getBeet(aktuellesBeet));
System.out.println("Alle beete" + meinGarten.getBeete());

for(Pflanze pf : meinGarten.getBeet(aktuellesBeet).getPflanzenausgruppe())
{
meinGarten.hinzufuegenPflanze(pf);
}
meinGarten.zeichnePflanzen();
System.out.println("Pflanze konfiguriert");
bepflanzungexistiert = true;
}

+ 32
- 70
Garten/src/garten/model/Garten.java View File

@@ -22,9 +22,6 @@ public class Garten extends Kompositum
private ArrayList<Pflanze> pflanzen;

private Pflanze pfl;
private Pflanze1 pfl1;
private Pflanze2 pfl2;
private Pflanze3 pfl3;
int intmovePflanze;
FlaecheBeet flbeet;
FlaecheWeg flweg;
@@ -57,24 +54,21 @@ public class Garten extends Kompositum
{
flbeet.zeichneBeete(beete);
}
public Beet getBeet(int[] mausposition)
{
System.out.println("Suche richtiges Beet");
Beet tempBeet = null;
for (Beet b : beete)
{
int[] koordinvergleich = b.getKoordinaten();
System.out.println("Maus: " +mausposition[0] +" " + 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] )
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;
}
}
}
return tempBeet;
}

//Funktionen Wege
public void hinzufuegenWeg(int sx, int sy, int ex, int ey)
{
@@ -100,69 +94,33 @@ public class Garten extends Kompositum

public Boolean randomBepflanzung()
{

for (Beet b : beete)
{
try
{
PflanzengruppenKonfigurator konfig = new PflanzengruppenKonfigurator();
int randomAlter = (int) (Math.random() * 3 + 1);
int randomTyp = (int) (Math.random() * 3 + 1);

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);
int[] temp = b.getKoordinaten();
int laenge;

konfig.alter(randomAlter);
konfig.pflanzenTyp(randomTyp);
if (randomTyp == 1)
{
laenge = 30;
}
catch (ArithmeticException e)
else
{
laenge = 15;
}
konfig.startlaenge(laenge);
konfig.beet(b);
konfig.erstellen();

for (Pflanze pf : b.getPflanzenausgruppe())
{
pflanzen.removeAll(pflanzen);
return false;
hinzufuegenPflanze(pf);
}
}
zeichnePflanzen();
@@ -186,10 +144,14 @@ public class Garten extends Kompositum
randomwertex[3] = width - 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
{
int wegendex = (int) (Math.random() * (170 * i) + (200 * i));
int wegendey = (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 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;
randomwertey[i] = wegendey;
}

+ 1
- 0
Garten/src/garten/model/Pflanze.java View File

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

+ 144
- 32
Garten/src/garten/model/Pflanzengruppe.java View File

@@ -3,59 +3,171 @@
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/

package garten.model;

import java.util.ArrayList;

/**
*
* @author Jan
* @author Jan
*/
class Pflanzengruppe
{
private int alter;
private int pflanzentyp;
private int startlaenge;
private ArrayList<Pflanze> pflanzen;
private Beet beet;
Pflanze1 pfl1;
Pflanze2 pfl2;
Pflanze3 pfl3;
Pflanzengruppe(int pflanzenTyp,int alter, int startlaenge, 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;
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 void anzeigen()


public ArrayList<Pflanze> getPflanzeninGruppe()
{
return pflanzen;
}
public ArrayList<Pflanze> beginnebepflanzung()
public void beginnebepflbox()
{
beet.getKoordinaten();
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;
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)
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
{
pfl3 = new Pflanze3(alter, alter, alter, startlaenge);
pflanzen.add(pfl1);
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;
}

}
return pflanzen;
while (platzimBeet);
System.out.println("Pflanzengruppe erstellt und folgenden Pflanzen hinzugefügt");
System.out.println(pflanzen);
beet.setPflanzengruppeBeet(this);
}
}
}

+ 1
- 5
Garten/src/garten/view/Fenster.java View File

@@ -143,10 +143,6 @@ public class Fenster extends JFrame
popup.addSeparator();
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.pack();
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
@@ -162,7 +158,7 @@ public class Fenster extends JFrame
});
this.add(popup);
//this.add(popup);
}

Loading…
Cancel
Save