From f40d57044201ec8708dbe8937ceab43f698be2b3 Mon Sep 17 00:00:00 2001 From: "yu.shlyapin" Date: Sat, 8 Feb 2025 16:10:16 +0400 Subject: [PATCH] lab2 v 0.2 --- .../AircraftCarrierController.java | 76 +++++++++++-- .../Logic/Drawing/DrawingAircraftCarrier.java | 97 ++++------------ .../Drawing/DrawingSimpleAircraftCarrier.java | 104 ++++++++++++++++++ .../Logic/Entity/EntityAircraftCarrier.java | 29 +---- .../Entity/EntitySimpleAircraftCarrier.java | 35 ++++++ .../MovementStategy/AbstractStrategy.java | 72 ++++++++++++ .../MovementStategy/IMoveableObject.java | 7 ++ .../Logic/MovementStategy/MoveToCenter.java | 32 ++++++ .../Logic/MovementStategy/MoveToCorner.java | 25 +++++ .../MovementStategy/MoveableCarrier.java | 42 +++++++ .../MovementStategy/MovementDirection.java | 8 ++ .../MovementStategy/ObjectParameters.java | 43 ++++++++ .../Logic/MovementStategy/StrategyStatus.java | 7 ++ .../aircraftcarrier/AircraftCarrierView.fxml | 5 +- 14 files changed, 470 insertions(+), 112 deletions(-) create mode 100644 src/main/java/com/example/aircraftcarrier/Logic/Drawing/DrawingSimpleAircraftCarrier.java create mode 100644 src/main/java/com/example/aircraftcarrier/Logic/Entity/EntitySimpleAircraftCarrier.java create mode 100644 src/main/java/com/example/aircraftcarrier/Logic/MovementStategy/AbstractStrategy.java create mode 100644 src/main/java/com/example/aircraftcarrier/Logic/MovementStategy/IMoveableObject.java create mode 100644 src/main/java/com/example/aircraftcarrier/Logic/MovementStategy/MoveToCenter.java create mode 100644 src/main/java/com/example/aircraftcarrier/Logic/MovementStategy/MoveToCorner.java create mode 100644 src/main/java/com/example/aircraftcarrier/Logic/MovementStategy/MoveableCarrier.java create mode 100644 src/main/java/com/example/aircraftcarrier/Logic/MovementStategy/MovementDirection.java create mode 100644 src/main/java/com/example/aircraftcarrier/Logic/MovementStategy/ObjectParameters.java create mode 100644 src/main/java/com/example/aircraftcarrier/Logic/MovementStategy/StrategyStatus.java diff --git a/src/main/java/com/example/aircraftcarrier/AircraftCarrierController.java b/src/main/java/com/example/aircraftcarrier/AircraftCarrierController.java index 43358ed..7605608 100644 --- a/src/main/java/com/example/aircraftcarrier/AircraftCarrierController.java +++ b/src/main/java/com/example/aircraftcarrier/AircraftCarrierController.java @@ -1,12 +1,15 @@ package com.example.aircraftcarrier; +import com.example.aircraftcarrier.Logic.Drawing.DrawingSimpleAircraftCarrier; import com.example.aircraftcarrier.Logic.Enum.DirectionType; import com.example.aircraftcarrier.Logic.Drawing.DrawingAircraftCarrier; +import com.example.aircraftcarrier.Logic.MovementStategy.*; import javafx.event.Event; import javafx.fxml.FXML; import javafx.fxml.Initializable; import javafx.scene.canvas.Canvas; import javafx.scene.control.Button; +import javafx.scene.control.ChoiceBox; import javafx.scene.control.TextField; import javafx.scene.input.KeyCode; import javafx.scene.input.KeyEvent; @@ -20,7 +23,8 @@ import java.util.ResourceBundle; public class AircraftCarrierController implements Initializable { Random random = new Random(); - DrawingAircraftCarrier drawingAircraftCarrier; + DrawingSimpleAircraftCarrier drawingAircraftCarrier; + AbstractStrategy strategy; @FXML private AnchorPane Root; @@ -29,17 +33,62 @@ public class AircraftCarrierController implements Initializable { @FXML private TextField inputCountBlocks; @FXML - protected void buttonCreate_Click() { - drawingAircraftCarrier = new DrawingAircraftCarrier(); - int inputCountBlock; + private ChoiceBox choiceBoxStrategy; + private String[] strategyText = new String[]{"к центру", "к углу"}; - try { - inputCountBlock = Integer.parseInt(inputCountBlocks.getCharacters().toString()); - } catch (NumberFormatException ignored) { - inputCountBlock = 0; + @FXML + protected void ButtonStrategy_Click() { + if (drawingAircraftCarrier == null) return; + if (!choiceBoxStrategy.isDisable()) { + strategy = switch (choiceBoxStrategy.getValue()) { + case "к центру" -> new MoveToCenter(); + case "к углу" -> new MoveToCorner(); + default -> null; + }; + if (strategy == null) return; + strategy.SetDate(new MoveableCarrier(drawingAircraftCarrier), + (int)Root.getWidth(), + (int)Root.getHeight() + ); } + if (strategy==null) return; - drawingAircraftCarrier.Init( + choiceBoxStrategy.setDisable(true); + strategy.MakeStep(); + drawingAircraftCarrier.Draw(canvas.getGraphicsContext2D()); + if (strategy.GetStatus() == StrategyStatus.Finish) { + choiceBoxStrategy.setDisable(false); + strategy = null; + } + } + + @FXML + protected void ButtonCreateSimple_Click() { + drawingAircraftCarrier = new DrawingSimpleAircraftCarrier( + random.nextInt(100) + 100, + random.nextInt(1000) + 1000, + Color.rgb( + random.nextInt(256), + random.nextInt(256), + random.nextInt(256) + ) + ); + + drawingAircraftCarrier.setCanvasWidth((int) canvas.getWidth()); + drawingAircraftCarrier.setCanvasHeight((int) canvas.getHeight()); + if ( + drawingAircraftCarrier.setPosition( + random.nextInt(50) + 10, + random.nextInt(50) + 10 + ) + ) { + drawingAircraftCarrier.Draw(canvas.getGraphicsContext2D()); + } + } + + @FXML + protected void ButtonCreateAdvanced_Click() { + drawingAircraftCarrier = new DrawingAircraftCarrier( random.nextInt(100) + 100, random.nextInt(1000) + 1000, Color.rgb( @@ -53,10 +102,14 @@ public class AircraftCarrierController implements Initializable { random.nextInt(256) ), random.nextBoolean(), - random.nextBoolean(), - inputCountBlock + random.nextBoolean() ); + try { + DrawingAircraftCarrier a = (DrawingAircraftCarrier) drawingAircraftCarrier; + a.setDrawingBlock(Integer.parseInt(inputCountBlocks.getCharacters().toString())); + } catch (NumberFormatException ignored) {} + drawingAircraftCarrier.setCanvasWidth((int) canvas.getWidth()); drawingAircraftCarrier.setCanvasHeight((int) canvas.getHeight()); if ( @@ -105,5 +158,6 @@ public class AircraftCarrierController implements Initializable { System.out.println("start"); canvas.widthProperty().bind(Root.widthProperty()); canvas.heightProperty().bind(Root.heightProperty()); + choiceBoxStrategy.getItems().addAll(strategyText); } } \ No newline at end of file diff --git a/src/main/java/com/example/aircraftcarrier/Logic/Drawing/DrawingAircraftCarrier.java b/src/main/java/com/example/aircraftcarrier/Logic/Drawing/DrawingAircraftCarrier.java index babc02c..aaf44a8 100644 --- a/src/main/java/com/example/aircraftcarrier/Logic/Drawing/DrawingAircraftCarrier.java +++ b/src/main/java/com/example/aircraftcarrier/Logic/Drawing/DrawingAircraftCarrier.java @@ -1,107 +1,52 @@ package com.example.aircraftcarrier.Logic.Drawing; -import com.example.aircraftcarrier.Logic.Enum.BlockCount; -import com.example.aircraftcarrier.Logic.Enum.DirectionType; import com.example.aircraftcarrier.Logic.Entity.EntityAircraftCarrier; import javafx.scene.canvas.GraphicsContext; import javafx.scene.paint.Color; -public class DrawingAircraftCarrier { - public EntityAircraftCarrier aircraftCarrier; +public class DrawingAircraftCarrier extends DrawingSimpleAircraftCarrier { public DrawingBlock drawingBlock; - private int x; - private int y; - private int widthCanvas; - private int heightCanvas; - private static final int widthPicture = 250; - private static final int heightPicture = 100; - - public void Init( + public DrawingAircraftCarrier( int speed, int weight, Color primaryColor, Color secondaryColor, boolean hasDeck, - boolean hasСabin, - int countBlock + boolean hasСabin ) { - aircraftCarrier = new EntityAircraftCarrier(); - aircraftCarrier.Init(speed, + super(); + aircraftCarrier = new EntityAircraftCarrier(speed, weight, primaryColor, secondaryColor, hasDeck, - hasСabin - ); - drawingBlock = new DrawingBlock(); - drawingBlock.setBlockCount(countBlock); + hasСabin); } public void setDrawingBlock(int count) { + drawingBlock = new DrawingBlock(); drawingBlock.setBlockCount(count); } - public void setCanvasWidth(int width) { - if (x+widthPicture > width) return; - widthCanvas = width; - } - - public void setCanvasHeight(int height) { - if (y+heightPicture > height) return; - heightCanvas = height; - } - - public boolean setPosition(int newX, int newY) { - if (newX < 0 || newY < 0 || newX + widthPicture > widthCanvas || newY + heightPicture > heightCanvas) return false; - x = newX; - y = newY; - return true; - } - + @Override public void Draw(GraphicsContext gc) { - gc.clearRect(0,0,widthCanvas,heightCanvas); + if (aircraftCarrier == null) return; - double[] X = new double[]{x,x+200,x+250,x+200,x}; - double[] Y = new double[]{y,y,y+50,y+100,y+100}; - gc.strokePolygon(X, Y,5); + if (aircraftCarrier instanceof EntityAircraftCarrier entityAircraftCarrier) { - gc.strokeOval(x+175,y+35,30,30); + super.Draw(gc); - if (aircraftCarrier.isHasDeck()) { - gc.setFill(aircraftCarrier.getPrimaryColor()); - gc.fillRect(x + 50, y + 40, 55, 20); - } - if (aircraftCarrier.isHasСabin()) { - gc.setFill(aircraftCarrier.getSecondaryColor()); - gc.fillRect(x + 105, y + 25, 30, 50); - } + if (entityAircraftCarrier.isHasDeck()) { + gc.setFill(aircraftCarrier.getPrimaryColor()); + gc.fillRect(x + 50, y + 40, 55, 20); + } + if (entityAircraftCarrier.isHasСabin()) { + gc.setFill(entityAircraftCarrier.getSecondaryColor()); + gc.fillRect(x + 105, y + 25, 30, 50); + } - if (drawingBlock == null) return; - drawingBlock.Draw(gc,x,y,aircraftCarrier.getSecondaryColor()); - } - - public void Move(DirectionType direction) { - switch (direction) { - case Up: - if (y - aircraftCarrier.Step > 0) { - y -= aircraftCarrier.Step; - } - break; - case Down: - if (y + aircraftCarrier.Step + heightPicture < heightCanvas) { - y += aircraftCarrier.Step; - } - break; - case Right: - if (x + aircraftCarrier.Step + widthPicture < widthCanvas) { - x += aircraftCarrier.Step; - } - break; - case Left: - if (x - aircraftCarrier.Step > 0) { - x -= aircraftCarrier.Step; - } - break; + if (drawingBlock == null) return; + drawingBlock.Draw(gc, x, y, entityAircraftCarrier.getSecondaryColor()); } } } diff --git a/src/main/java/com/example/aircraftcarrier/Logic/Drawing/DrawingSimpleAircraftCarrier.java b/src/main/java/com/example/aircraftcarrier/Logic/Drawing/DrawingSimpleAircraftCarrier.java new file mode 100644 index 0000000..7457876 --- /dev/null +++ b/src/main/java/com/example/aircraftcarrier/Logic/Drawing/DrawingSimpleAircraftCarrier.java @@ -0,0 +1,104 @@ +package com.example.aircraftcarrier.Logic.Drawing; + +import com.example.aircraftcarrier.Logic.Entity.EntityAircraftCarrier; +import com.example.aircraftcarrier.Logic.Entity.EntitySimpleAircraftCarrier; +import com.example.aircraftcarrier.Logic.Enum.DirectionType; +import javafx.scene.canvas.GraphicsContext; +import javafx.scene.paint.Color; + +public class DrawingSimpleAircraftCarrier { + public EntitySimpleAircraftCarrier aircraftCarrier; + protected int x; + protected int y; + private int widthCanvas; + private int heightCanvas; + private static final int widthPicture = 250; + private static final int heightPicture = 100; + + public DrawingSimpleAircraftCarrier() {} + + public DrawingSimpleAircraftCarrier( + int speed, + int weight, + Color primaryColor + ) { + aircraftCarrier = new EntitySimpleAircraftCarrier( + speed, + weight, + primaryColor + ); + } + + public void setCanvasWidth(int width) { + if (x+widthPicture > width); + widthCanvas = width; + } + + public void setCanvasHeight(int height) { + if (y+heightPicture > height) return; + heightCanvas = height; + } + + public boolean setPosition(int newX, int newY) { + if (newX < 0 || newY < 0 || newX + widthPicture > widthCanvas || newY + heightPicture > heightCanvas) return false; + x = newX; + y = newY; + return true; + } + + public int getX() { + return x; + } + + public int getY() { + return y; + } + + public int getWidthPicture() { + return widthPicture; + } + + public int getHeightPicture() { + return heightPicture; + } + + public void Draw(GraphicsContext gc) { + gc.clearRect(0,0,widthCanvas,heightCanvas); + + double[] X = new double[]{x,x+200,x+250,x+200,x}; + double[] Y = new double[]{y,y,y+50,y+100,y+100}; + gc.strokePolygon(X, Y,5); + + gc.strokeOval(x+175,y+35,30,30); + } + + public boolean Move(DirectionType direction) { + switch (direction) { + case Up: + if (y - aircraftCarrier.getStep() > 0) { + y -= aircraftCarrier.getStep(); + return true; + } + return false; + case Down: + if (y + aircraftCarrier.getStep() + heightPicture < heightCanvas) { + y += aircraftCarrier.getStep(); + return true; + } + return false; + case Right: + if (x + aircraftCarrier.getStep() + widthPicture < widthCanvas) { + x += aircraftCarrier.getStep(); + return true; + } + return false; + case Left: + if (x - aircraftCarrier.getStep() > 0) { + x -= aircraftCarrier.getStep(); + return true; + } + return false; + default: return false; + } + } +} diff --git a/src/main/java/com/example/aircraftcarrier/Logic/Entity/EntityAircraftCarrier.java b/src/main/java/com/example/aircraftcarrier/Logic/Entity/EntityAircraftCarrier.java index 114c9c5..d625fdd 100644 --- a/src/main/java/com/example/aircraftcarrier/Logic/Entity/EntityAircraftCarrier.java +++ b/src/main/java/com/example/aircraftcarrier/Logic/Entity/EntityAircraftCarrier.java @@ -2,43 +2,24 @@ package com.example.aircraftcarrier.Logic.Entity; import javafx.scene.paint.Color; -public class EntityAircraftCarrier { - private int Speed; - private double Weight; - public int Step; - private Color PrimaryColor; +public class EntityAircraftCarrier extends EntitySimpleAircraftCarrier { private Color SecondaryColor; private boolean HasDeck; private boolean HasСabin; - public void Init( + public EntityAircraftCarrier( int speed, - double weight, + int weight, Color primaryColor, Color secondaryColor, boolean hasDeck, boolean hasСabin - ) { - this.Speed = speed; - this.Weight = weight; - this.PrimaryColor = primaryColor; + ){ + super(speed,weight,primaryColor); this.SecondaryColor = secondaryColor; this.HasDeck = hasDeck; this.HasСabin = hasСabin; - this.Step = (int) (Speed * 100 / Weight); - } - - public int getSpeed() { - return Speed; - } - - public double getWeight() { - return Weight; - } - - public Color getPrimaryColor() { - return PrimaryColor; } public Color getSecondaryColor() { diff --git a/src/main/java/com/example/aircraftcarrier/Logic/Entity/EntitySimpleAircraftCarrier.java b/src/main/java/com/example/aircraftcarrier/Logic/Entity/EntitySimpleAircraftCarrier.java new file mode 100644 index 0000000..d621f1b --- /dev/null +++ b/src/main/java/com/example/aircraftcarrier/Logic/Entity/EntitySimpleAircraftCarrier.java @@ -0,0 +1,35 @@ +package com.example.aircraftcarrier.Logic.Entity; + +import javafx.scene.paint.Color; + +public class EntitySimpleAircraftCarrier { + private int Speed; + private double Weight; + private Color PrimaryColor; + + public EntitySimpleAircraftCarrier( + int speed, + double weight, + Color primaryColor + ) { + this.Speed = speed; + this.Weight = weight; + this.PrimaryColor = primaryColor; + } + + public int getSpeed() { + return Speed; + } + + public double getWeight() { + return Weight; + } + + public Color getPrimaryColor() { + return PrimaryColor; + } + + public int getStep() { + return (int) (Speed * 100 / Weight); + } +} diff --git a/src/main/java/com/example/aircraftcarrier/Logic/MovementStategy/AbstractStrategy.java b/src/main/java/com/example/aircraftcarrier/Logic/MovementStategy/AbstractStrategy.java new file mode 100644 index 0000000..0f5c325 --- /dev/null +++ b/src/main/java/com/example/aircraftcarrier/Logic/MovementStategy/AbstractStrategy.java @@ -0,0 +1,72 @@ +package com.example.aircraftcarrier.Logic.MovementStategy; + +public abstract class AbstractStrategy { + private IMoveableObject moveableObject; + private StrategyStatus status = StrategyStatus.NotInit; + protected int FieldWidth; + protected int FieldHeight; + + public int getFieldWidth() { + return FieldWidth; + } + + public int getFieldHeight() { + return FieldHeight; + } + + public StrategyStatus GetStatus() { + return status; + } + + public void SetDate(IMoveableObject moveableObject, + int width, + int height) { + if (moveableObject == null) { + status = StrategyStatus.NotInit; + return; + } + status = StrategyStatus.InProgress; + this.moveableObject = moveableObject; + this.FieldWidth = width; + this.FieldHeight = height; + } + + public void MakeStep() { + if(status != StrategyStatus.InProgress) return; + if (IsTargetDestination()) { + status = StrategyStatus.Finish; + return; + } + MoveToTarget(); + } + + protected abstract void MoveToTarget(); + protected abstract boolean IsTargetDestination(); + + protected boolean MoveLeft() { + return MoveTo(MovementDirection.Left); + } + protected boolean MoveRight() { + return MoveTo(MovementDirection.Right); + } + protected boolean MoveUp() { + return MoveTo(MovementDirection.Up); + } + protected boolean MoveDown() { + return MoveTo(MovementDirection.Down); + } + + protected ObjectParameters GetObjectParameters() { + return moveableObject.GetObjectPosition(); + } + + protected Integer GetStep() { + if (status != StrategyStatus.InProgress) return null; + return moveableObject.GetStep(); + } + + private boolean MoveTo(MovementDirection direction) { + if (moveableObject==null || status != StrategyStatus.InProgress) return false; + return moveableObject.TryMoveObject(direction); + } +} diff --git a/src/main/java/com/example/aircraftcarrier/Logic/MovementStategy/IMoveableObject.java b/src/main/java/com/example/aircraftcarrier/Logic/MovementStategy/IMoveableObject.java new file mode 100644 index 0000000..d6accb2 --- /dev/null +++ b/src/main/java/com/example/aircraftcarrier/Logic/MovementStategy/IMoveableObject.java @@ -0,0 +1,7 @@ +package com.example.aircraftcarrier.Logic.MovementStategy; + +public interface IMoveableObject { + ObjectParameters GetObjectPosition(); + int GetStep(); + boolean TryMoveObject(MovementDirection direction); +} diff --git a/src/main/java/com/example/aircraftcarrier/Logic/MovementStategy/MoveToCenter.java b/src/main/java/com/example/aircraftcarrier/Logic/MovementStategy/MoveToCenter.java new file mode 100644 index 0000000..1293a51 --- /dev/null +++ b/src/main/java/com/example/aircraftcarrier/Logic/MovementStategy/MoveToCenter.java @@ -0,0 +1,32 @@ +package com.example.aircraftcarrier.Logic.MovementStategy; + +public class MoveToCenter extends AbstractStrategy { + @Override + protected void MoveToTarget() { + ObjectParameters objectParameters = GetObjectParameters(); + if (objectParameters == null) return; + int diffX = objectParameters.CenterX() - getFieldWidth()/2; + if (Math.abs(diffX) > GetStep()) { + if (diffX > 0) { + MoveLeft(); + } else { MoveRight(); } + } + + int diffY = objectParameters.CenterY() - getFieldHeight()/2; + if (Math.abs(diffY) > GetStep()) { + if (diffY > 0) { + MoveUp(); + } else { MoveDown(); } + } + } + + @Override + protected boolean IsTargetDestination() { + ObjectParameters objectParameters = GetObjectParameters(); + if (objectParameters == null) return false; + return objectParameters.CenterX() - GetStep() <= getFieldWidth()/2 && + objectParameters.CenterX() + GetStep() >= getFieldWidth()/2 && + objectParameters.CenterY() - GetStep() <= getFieldHeight()/2 && + objectParameters.CenterY() + GetStep() >= getFieldHeight()/2; + } +} diff --git a/src/main/java/com/example/aircraftcarrier/Logic/MovementStategy/MoveToCorner.java b/src/main/java/com/example/aircraftcarrier/Logic/MovementStategy/MoveToCorner.java new file mode 100644 index 0000000..6883806 --- /dev/null +++ b/src/main/java/com/example/aircraftcarrier/Logic/MovementStategy/MoveToCorner.java @@ -0,0 +1,25 @@ +package com.example.aircraftcarrier.Logic.MovementStategy; + +public class MoveToCorner extends AbstractStrategy { + @Override + protected void MoveToTarget() { + ObjectParameters objectParameters = GetObjectParameters(); + if (objectParameters == null) return; + int diffX = objectParameters.RightBorder() - getFieldWidth(); + if (Math.abs(diffX) > GetStep()) { + MoveRight(); + } + + int diffY = objectParameters.BottomBorder() - getFieldHeight(); + if (Math.abs(diffY) > GetStep()) { + MoveDown(); + } + } + @Override + protected boolean IsTargetDestination() { + ObjectParameters objectParameters = GetObjectParameters(); + if (objectParameters == null) return false; + return objectParameters.RightBorder() + GetStep() >= getFieldWidth() && + objectParameters.RightBorder() + GetStep() >= getFieldHeight(); + } +} diff --git a/src/main/java/com/example/aircraftcarrier/Logic/MovementStategy/MoveableCarrier.java b/src/main/java/com/example/aircraftcarrier/Logic/MovementStategy/MoveableCarrier.java new file mode 100644 index 0000000..e7e8c88 --- /dev/null +++ b/src/main/java/com/example/aircraftcarrier/Logic/MovementStategy/MoveableCarrier.java @@ -0,0 +1,42 @@ +package com.example.aircraftcarrier.Logic.MovementStategy; + +import com.example.aircraftcarrier.Logic.Drawing.DrawingSimpleAircraftCarrier; +import com.example.aircraftcarrier.Logic.Enum.DirectionType; + +public class MoveableCarrier implements IMoveableObject { + private final DrawingSimpleAircraftCarrier drawingSimpleAircraftCarrier; + + public MoveableCarrier(DrawingSimpleAircraftCarrier drawingSimpleAircraftCarrier) { + this.drawingSimpleAircraftCarrier = drawingSimpleAircraftCarrier; + } + + @Override + public ObjectParameters GetObjectPosition() { + if (drawingSimpleAircraftCarrier == null || drawingSimpleAircraftCarrier.aircraftCarrier == null) { + return null; + } + return new ObjectParameters(drawingSimpleAircraftCarrier); + } + + @Override + public int GetStep() { + return drawingSimpleAircraftCarrier.aircraftCarrier.getStep(); + } + + @Override + public boolean TryMoveObject(MovementDirection direction) { + if (drawingSimpleAircraftCarrier == null || drawingSimpleAircraftCarrier.aircraftCarrier == null) + return false; + return drawingSimpleAircraftCarrier.Move(GetDirectionType(direction)); + } + + private static DirectionType GetDirectionType(MovementDirection direction) { + return switch (direction) { + case Up -> DirectionType.Up; + case Down -> DirectionType.Down; + case Left -> DirectionType.Left; + case Right -> DirectionType.Right; + default -> DirectionType.Unknown; + }; + } +} \ No newline at end of file diff --git a/src/main/java/com/example/aircraftcarrier/Logic/MovementStategy/MovementDirection.java b/src/main/java/com/example/aircraftcarrier/Logic/MovementStategy/MovementDirection.java new file mode 100644 index 0000000..77255df --- /dev/null +++ b/src/main/java/com/example/aircraftcarrier/Logic/MovementStategy/MovementDirection.java @@ -0,0 +1,8 @@ +package com.example.aircraftcarrier.Logic.MovementStategy; + +public enum MovementDirection { + Up, + Down, + Left, + Right +} diff --git a/src/main/java/com/example/aircraftcarrier/Logic/MovementStategy/ObjectParameters.java b/src/main/java/com/example/aircraftcarrier/Logic/MovementStategy/ObjectParameters.java new file mode 100644 index 0000000..e54e1b2 --- /dev/null +++ b/src/main/java/com/example/aircraftcarrier/Logic/MovementStategy/ObjectParameters.java @@ -0,0 +1,43 @@ +package com.example.aircraftcarrier.Logic.MovementStategy; + +import com.example.aircraftcarrier.Logic.Drawing.DrawingSimpleAircraftCarrier; + +public class ObjectParameters { + private final int x; + private final int y; + private final int width; + private final int height; + + public ObjectParameters(int x, int y, int width, int height) { + this.x = x; + this.y = y; + this.width = width; + this.height = height; + } + + public ObjectParameters(DrawingSimpleAircraftCarrier drawingSimpleAircraftCarrier) { + this.x = drawingSimpleAircraftCarrier.getX(); + this.y = drawingSimpleAircraftCarrier.getY(); + this.width = drawingSimpleAircraftCarrier.getWidthPicture(); + this.height = drawingSimpleAircraftCarrier.getHeightPicture(); + } + + public int LeftBorder() { + return x; + } + public int RightBorder() { + return x+width; + } + public int TopBorder() { + return y; + } + public int BottomBorder() { + return y+height; + } + public int CenterX() { + return x+width / 2; + } + public int CenterY() { + return y+height/2; + } +} diff --git a/src/main/java/com/example/aircraftcarrier/Logic/MovementStategy/StrategyStatus.java b/src/main/java/com/example/aircraftcarrier/Logic/MovementStategy/StrategyStatus.java new file mode 100644 index 0000000..f8d7da7 --- /dev/null +++ b/src/main/java/com/example/aircraftcarrier/Logic/MovementStategy/StrategyStatus.java @@ -0,0 +1,7 @@ +package com.example.aircraftcarrier.Logic.MovementStategy; + +public enum StrategyStatus { + NotInit, + InProgress, + Finish +} diff --git a/src/main/resources/com/example/aircraftcarrier/AircraftCarrierView.fxml b/src/main/resources/com/example/aircraftcarrier/AircraftCarrierView.fxml index 313e711..d69e822 100644 --- a/src/main/resources/com/example/aircraftcarrier/AircraftCarrierView.fxml +++ b/src/main/resources/com/example/aircraftcarrier/AircraftCarrierView.fxml @@ -7,11 +7,14 @@ -