Browse Source

restrucered logic-Class

fleetstorm
Max Wenzel 3 years ago
committed by Lorenz Hohmann
parent
commit
2022df6682
  1. 108
      src/main/java/de/tims/fleetstorm/ai/Logic.java

108
src/main/java/de/tims/fleetstorm/ai/Logic.java

@ -68,7 +68,8 @@ public class Logic {
} }
} }
// If ship is sinked
sinkShip();
ArrayList<Coordinate> possibleFields = new ArrayList<Coordinate>(); ArrayList<Coordinate> possibleFields = new ArrayList<Coordinate>();
for (int i = 0; i < coordinates.size(); i++) { for (int i = 0; i < coordinates.size(); i++) {
if (coordinates.get(i).getState() != Coordinate.SHOT && coordinates.get(i).getState() != Coordinate.HIT) { if (coordinates.get(i).getState() != Coordinate.SHOT && coordinates.get(i).getState() != Coordinate.HIT) {
@ -93,137 +94,116 @@ public class Logic {
} }
} }
} }
return out; return out;
} }
public void setLastShot(Coordinate coordinate) {
lastShot = this.matchfield.getField(coordinate);
}
public Coordinate getLastShot() {
return lastShot;
}
public void setMatchfield(Matchfield matchfield) {
this.matchfield = matchfield;
}
public Matchfield getMatchfield() {
return matchfield;
}
public void findShip() { public void findShip() {
if (lastShot.getState() == Coordinate.HIT) { if (lastShot.getState() == Coordinate.HIT) {
foundShip = true; foundShip = true;
} }
} }
public void setFoundShip(boolean b) {
this.foundShip = b;
}
public boolean getFoundShip() {
// TODO Auto-generated method stub
return this.foundShip;
}
public void checkAround(Coordinate coordinate) {
// TODO Auto-generated method stub
public void sinkShip() {
if (foundShip && clearedAbove && clearedBelow && clearedLeft && clearedRight) {
this.foundShip = false;
this.clearedAbove = false;
this.clearedBelow = false;
this.clearedLeft = false;
this.clearedRight = false;
}
} }
public void clearAbove(Coordinate shot) { public void clearAbove(Coordinate shot) {
target = matchfield.getAbove(shot); target = matchfield.getAbove(shot);
if (target.getState() == Coordinate.EMPTY) { if (target.getState() == Coordinate.EMPTY) {
clearedAbove = true; clearedAbove = true;
} }
} }
private void shot() {
// TODO Auto-generated method stub
}
public void clearBelow(Coordinate shot) { public void clearBelow(Coordinate shot) {
target = matchfield.getBelow(shot); target = matchfield.getBelow(shot);
if (target.getState() == Coordinate.EMPTY) { if (target.getState() == Coordinate.EMPTY) {
clearedBelow = true; clearedBelow = true;
} }
} }
public void clearRight(Coordinate shot) { public void clearRight(Coordinate shot) {
target = matchfield.getRight(shot); target = matchfield.getRight(shot);
if (target.getState() == Coordinate.EMPTY) { if (target.getState() == Coordinate.EMPTY) {
clearedRight = true; clearedRight = true;
} }
} }
public void clearLeft(Coordinate shot) { public void clearLeft(Coordinate shot) {
target = matchfield.getLeft(shot); target = matchfield.getLeft(shot);
if (target.getState() == Coordinate.EMPTY) { if (target.getState() == Coordinate.EMPTY) {
clearedLeft = true; clearedLeft = true;
} }
} }
public boolean getClearedAbove() {
return this.clearedAbove;
}
// Getter And Setter
public boolean getClearedBelow() {
return this.clearedBelow;
public void setLastShot(Coordinate coordinate) {
lastShot = this.matchfield.getField(coordinate);
} }
public boolean getClearedRight() {
return this.clearedRight;
public Coordinate getLastShot() {
return lastShot;
} }
public boolean getClearedLeft() {
return this.clearedLeft;
public void setFoundShip(boolean b) {
this.foundShip = b;
} }
public void sinkShip() {
if (foundShip && clearedAbove && clearedBelow && clearedLeft && clearedRight) {
this.foundShip = false;
this.clearedAbove = false;
this.clearedBelow = false;
this.clearedLeft = false;
this.clearedRight = false;
}
public boolean getFoundShip() {
return this.foundShip;
} }
public void setClearedAbove(boolean b) { public void setClearedAbove(boolean b) {
this.clearedAbove = b; this.clearedAbove = b;
} }
public boolean getClearedAbove() {
return this.clearedAbove;
}
public void setClearedBelow(boolean b) { public void setClearedBelow(boolean b) {
this.clearedBelow = b; this.clearedBelow = b;
} }
public boolean getClearedBelow() {
return this.clearedBelow;
}
public void setClearedRight(boolean b) { public void setClearedRight(boolean b) {
this.clearedRight = b; this.clearedRight = b;
} }
public boolean getClearedRight() {
return this.clearedRight;
}
public void setClearedLeft(boolean b) { public void setClearedLeft(boolean b) {
this.clearedLeft = b; this.clearedLeft = b;
} }
public Coordinate getTarget() {
return target;
public boolean getClearedLeft() {
return this.clearedLeft;
} }
public void setTarget(Coordinate target) { public void setTarget(Coordinate target) {
this.target = target; this.target = target;
} }
public Coordinate getTarget() {
return target;
}
public void setMatchfield(Matchfield matchfield) {
this.matchfield = matchfield;
}
public Matchfield getMatchfield() {
return matchfield;
}
} }
Loading…
Cancel
Save