From 2022df66824dadc1083f2f2926b377de53ecdc1e Mon Sep 17 00:00:00 2001 From: Max Wenzel Date: Fri, 14 Jan 2022 17:05:19 +0100 Subject: [PATCH] restrucered logic-Class --- .../java/de/tims/fleetstorm/ai/Logic.java | 108 +++++++----------- 1 file changed, 44 insertions(+), 64 deletions(-) diff --git a/src/main/java/de/tims/fleetstorm/ai/Logic.java b/src/main/java/de/tims/fleetstorm/ai/Logic.java index d65227b..36a3cc4 100644 --- a/src/main/java/de/tims/fleetstorm/ai/Logic.java +++ b/src/main/java/de/tims/fleetstorm/ai/Logic.java @@ -68,7 +68,8 @@ public class Logic { } } - // If ship is sinked + sinkShip(); + ArrayList possibleFields = new ArrayList(); for (int i = 0; i < coordinates.size(); i++) { if (coordinates.get(i).getState() != Coordinate.SHOT && coordinates.get(i).getState() != Coordinate.HIT) { @@ -93,137 +94,116 @@ public class Logic { } } } - 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() { if (lastShot.getState() == Coordinate.HIT) { - 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) { target = matchfield.getAbove(shot); - if (target.getState() == Coordinate.EMPTY) { clearedAbove = true; } } - private void shot() { - // TODO Auto-generated method stub - - } - public void clearBelow(Coordinate shot) { target = matchfield.getBelow(shot); - if (target.getState() == Coordinate.EMPTY) { clearedBelow = true; } - } public void clearRight(Coordinate shot) { target = matchfield.getRight(shot); - if (target.getState() == Coordinate.EMPTY) { clearedRight = true; } - } public void clearLeft(Coordinate shot) { target = matchfield.getLeft(shot); - if (target.getState() == Coordinate.EMPTY) { 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) { this.clearedAbove = b; } + public boolean getClearedAbove() { + return this.clearedAbove; + } + public void setClearedBelow(boolean b) { this.clearedBelow = b; } + public boolean getClearedBelow() { + return this.clearedBelow; + } + public void setClearedRight(boolean b) { this.clearedRight = b; } + public boolean getClearedRight() { + return this.clearedRight; + } + public void setClearedLeft(boolean b) { this.clearedLeft = b; } - public Coordinate getTarget() { - return target; + public boolean getClearedLeft() { + return this.clearedLeft; } public void setTarget(Coordinate target) { this.target = target; } + public Coordinate getTarget() { + return target; + } + + public void setMatchfield(Matchfield matchfield) { + this.matchfield = matchfield; + } + + public Matchfield getMatchfield() { + return matchfield; + } }