mirror of
https://github.com/jokerx3/HeatUp
synced 2026-07-27 11:39:45 +02:00
Kreuzungs erkennung hinzugefügt.
This commit is contained in:
@@ -9,6 +9,7 @@ import javax.imageio.ImageIO;
|
|||||||
import de.heatup.cfg.Config;
|
import de.heatup.cfg.Config;
|
||||||
import de.heatup.logging.Logger;
|
import de.heatup.logging.Logger;
|
||||||
import de.heatup.mapengine.MapGrid;
|
import de.heatup.mapengine.MapGrid;
|
||||||
|
import de.heatup.mapengine.MapGridCell;
|
||||||
|
|
||||||
public class Opponent extends Player {
|
public class Opponent extends Player {
|
||||||
|
|
||||||
@@ -26,6 +27,7 @@ public class Opponent extends Player {
|
|||||||
private int prevX;
|
private int prevX;
|
||||||
private int prevY;
|
private int prevY;
|
||||||
private boolean blocked = false;
|
private boolean blocked = false;
|
||||||
|
private boolean move = false;
|
||||||
private int blockedCounter = 0;
|
private int blockedCounter = 0;
|
||||||
|
|
||||||
@Override protected void loadBufferedImage() {
|
@Override protected void loadBufferedImage() {
|
||||||
@@ -37,17 +39,9 @@ public class Opponent extends Player {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override public void tick() {
|
@Override public void tick() {
|
||||||
|
|
||||||
if ( redecide ) {
|
if ( redecide ) {
|
||||||
while ( true ) {
|
while ( true ) {
|
||||||
|
|
||||||
this.d = (rand.nextInt(10) <= 4) ? 'x' : 'y';
|
|
||||||
this.i = (rand.nextInt(10) <= 4) ? 1 : -1;
|
|
||||||
|
|
||||||
// Sicher stellen das man nicht in die Richtung geht aus der man gekommen ist.
|
|
||||||
if ( redecide && this.d == this.prevd && this.i != this.previ ) {
|
|
||||||
this.i *= -1;
|
|
||||||
}
|
|
||||||
// Blockade Erkennung
|
// Blockade Erkennung
|
||||||
if ( this.prevX == this.getGridLocation().x & this.prevY == this.getGridLocation().y ) {
|
if ( this.prevX == this.getGridLocation().x & this.prevY == this.getGridLocation().y ) {
|
||||||
this.blockedCounter++;
|
this.blockedCounter++;
|
||||||
@@ -58,12 +52,46 @@ public class Opponent extends Player {
|
|||||||
this.prevX = this.getGridLocation().x;
|
this.prevX = this.getGridLocation().x;
|
||||||
this.prevY = this.getGridLocation().y;
|
this.prevY = this.getGridLocation().y;
|
||||||
|
|
||||||
//TODO: Bei Kreuzung umentscheiden
|
// Kreuzung erkennen
|
||||||
|
if ( d == 'x' ) {
|
||||||
|
if ( MapGrid.getGridCell(this.getGridLocation().x, this.getGridLocation().y+1).isPath() ) {
|
||||||
|
this.move = false;
|
||||||
|
}
|
||||||
|
if ( MapGrid.getGridCell(this.getGridLocation().x, this.getGridLocation().y-1).isPath() ) {
|
||||||
|
this.move = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ( d == 'y' ) {
|
||||||
|
if ( MapGrid.getGridCell(this.getGridLocation().x-1, this.getGridLocation().y).isPath() ) {
|
||||||
|
this.move = false;
|
||||||
|
}
|
||||||
|
if ( MapGrid.getGridCell(this.getGridLocation().x+1, this.getGridLocation().y).isPath() ) {
|
||||||
|
this.move = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Umentscheiden oder weiter in die vorgegeben Richtung
|
||||||
|
if ( ! this.move ) {
|
||||||
|
Logger.write("Redeciding...");
|
||||||
|
this.d = (rand.nextInt(10) <= 4) ? 'x' : 'y';
|
||||||
|
this.i = (rand.nextInt(10) <= 4) ? 1 : -1;
|
||||||
|
// Sicher stellen das man nicht in die Richtung geht aus der man gekommen ist.
|
||||||
|
if ( redecide && this.d == this.prevd && this.i != this.previ ) {
|
||||||
|
this.i *= -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
Logger.write("Moving...");
|
||||||
|
}
|
||||||
|
|
||||||
|
this.move = true;
|
||||||
|
|
||||||
// Blockade auflösen, gehe doch in die Richtung aus man gekommen ist
|
// Blockade auflösen, gehe doch in die Richtung aus man gekommen ist
|
||||||
if ( this.blocked ) {
|
if ( this.blocked ) {
|
||||||
Logger.write("Warning: Block detected!");
|
Logger.write("Warning: Block detected!");
|
||||||
this.i *= -1;
|
this.i *= -1;
|
||||||
|
this.move = false;
|
||||||
this.blocked = false;
|
this.blocked = false;
|
||||||
this.blockedCounter = 0;
|
this.blockedCounter = 0;
|
||||||
}
|
}
|
||||||
@@ -86,7 +114,6 @@ public class Opponent extends Player {
|
|||||||
animate = true;
|
animate = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -94,7 +121,8 @@ public class Opponent extends Player {
|
|||||||
int newx = this.getX();
|
int newx = this.getX();
|
||||||
int newy = this.getY();
|
int newy = this.getY();
|
||||||
|
|
||||||
for (int s = 0; s < this.speedMultiplicator; s++) { // speed multiplikator
|
// Speed Multiplikator
|
||||||
|
for (int s = 0; s < this.speedMultiplicator; s++) {
|
||||||
if (d == 'x' && i == -1) {
|
if (d == 'x' && i == -1) {
|
||||||
newx = newx - 1;
|
newx = newx - 1;
|
||||||
} else if (d == 'x' && i == 1) {
|
} else if (d == 'x' && i == 1) {
|
||||||
@@ -111,13 +139,21 @@ public class Opponent extends Player {
|
|||||||
animate = false;
|
animate = false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
if (stepCounter <= 0) {
|
if (stepCounter <= 0) {
|
||||||
stepCounter = 25;
|
stepCounter = 25;
|
||||||
|
if ( ! MapGrid.getGridCell(newx,newy).isPath()) {
|
||||||
redecide = true;
|
redecide = true;
|
||||||
|
animate = false;
|
||||||
|
} else {
|
||||||
|
animate = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user