From 3f28d330154287a1f7962ce33150963ea7a69e8c Mon Sep 17 00:00:00 2001 From: Extrimal Date: Sun, 24 Dec 2023 00:30:20 +0300 Subject: [PATCH] =?UTF-8?q?=D1=83=D0=B4=D0=B0=D0=BB=D0=B5=D0=BD=D0=B8?= =?UTF-8?q?=D0=B5=20=D0=B2=D1=81=D0=B5=D0=B3=D0=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AircraftCarrier/src/AbstractStrategy.java | 57 ------ AircraftCarrier/src/DirectionType.java | 6 - AircraftCarrier/src/DrawingAircraft.java | 120 ------------- .../src/DrawingAircraftCarrier.java | 33 ---- .../src/DrawingImprovementsCircle.java | 24 --- .../src/DrawingImprovementsSquare.java | 25 --- .../src/DrawingImprovementsTriangle.java | 36 ---- .../src/DrawingObjectAircraftCarrier.java | 27 --- AircraftCarrier/src/EntityAircraft.java | 24 --- .../src/EntityAircraftCarrier.java | 23 --- AircraftCarrier/src/FrameAircraftCarrier.java | 169 ------------------ AircraftCarrier/src/IDrawImprovements.java | 6 - AircraftCarrier/src/IMoveableObject.java | 6 - AircraftCarrier/src/Main.java | 7 - AircraftCarrier/src/MoveToBorder.java | 34 ---- AircraftCarrier/src/MoveToCenter.java | 32 ---- AircraftCarrier/src/NumberImprovement.java | 5 - AircraftCarrier/src/ObjectParameters.java | 19 -- AircraftCarrier/src/Status.java | 5 - 19 files changed, 658 deletions(-) delete mode 100644 AircraftCarrier/src/AbstractStrategy.java delete mode 100644 AircraftCarrier/src/DirectionType.java delete mode 100644 AircraftCarrier/src/DrawingAircraft.java delete mode 100644 AircraftCarrier/src/DrawingAircraftCarrier.java delete mode 100644 AircraftCarrier/src/DrawingImprovementsCircle.java delete mode 100644 AircraftCarrier/src/DrawingImprovementsSquare.java delete mode 100644 AircraftCarrier/src/DrawingImprovementsTriangle.java delete mode 100644 AircraftCarrier/src/DrawingObjectAircraftCarrier.java delete mode 100644 AircraftCarrier/src/EntityAircraft.java delete mode 100644 AircraftCarrier/src/EntityAircraftCarrier.java delete mode 100644 AircraftCarrier/src/FrameAircraftCarrier.java delete mode 100644 AircraftCarrier/src/IDrawImprovements.java delete mode 100644 AircraftCarrier/src/IMoveableObject.java delete mode 100644 AircraftCarrier/src/Main.java delete mode 100644 AircraftCarrier/src/MoveToBorder.java delete mode 100644 AircraftCarrier/src/MoveToCenter.java delete mode 100644 AircraftCarrier/src/NumberImprovement.java delete mode 100644 AircraftCarrier/src/ObjectParameters.java delete mode 100644 AircraftCarrier/src/Status.java diff --git a/AircraftCarrier/src/AbstractStrategy.java b/AircraftCarrier/src/AbstractStrategy.java deleted file mode 100644 index 4a70f71..0000000 --- a/AircraftCarrier/src/AbstractStrategy.java +++ /dev/null @@ -1,57 +0,0 @@ -import java.util.function.Supplier; - -public abstract class AbstractStrategy { - private IMoveableObject moveableObject; - private Status state = Status.NOTINIT; - private int FieldWidth; - protected int getFieldWidth(){return FieldWidth;} - private int FieldHeight; - protected int getFieldHeight(){return FieldHeight;} - public Status GetStatus() {return state;} - - public void SetData(IMoveableObject moveableObject, int width, int height){ - if(moveableObject == null){ - state = Status.NOTINIT; - return; - } - state = Status.INPROGRESS; - this.moveableObject = moveableObject; - FieldWidth = width; - FieldHeight = height; - } - - public void MakeStep(){ - if(state != Status.INPROGRESS) - return; - if(IsTargetDestination()){ - state = Status.FINISH; - return; - } - MoveToTarget(); - } - - protected boolean MoveLeft() {return MoveTo(DirectionType.LEFT);} - protected boolean MoveRight() {return MoveTo(DirectionType.RIGHT);} - protected boolean MoveUp() {return MoveTo(DirectionType.UP);} - protected boolean MoveDown() {return MoveTo(DirectionType.DOWN);} - protected Supplier getObjectParameters = () -> moveableObject.getObjectPosition(); - - protected Integer GetStep(){ - if(state != Status.INPROGRESS) - return null; - return moveableObject.getStep(); - } - - protected abstract void MoveToTarget(); - protected abstract boolean IsTargetDestination(); - - private boolean MoveTo(DirectionType direction){ - if(state != Status.INPROGRESS) - return false; - if(moveableObject.checkCanMove(direction)){ - moveableObject.moveObject(direction); - return true; - } - return false; - } -} diff --git a/AircraftCarrier/src/DirectionType.java b/AircraftCarrier/src/DirectionType.java deleted file mode 100644 index 0d664bb..0000000 --- a/AircraftCarrier/src/DirectionType.java +++ /dev/null @@ -1,6 +0,0 @@ -public enum DirectionType { - UP, - DOWN, - LEFT, - RIGHT -} \ No newline at end of file diff --git a/AircraftCarrier/src/DrawingAircraft.java b/AircraftCarrier/src/DrawingAircraft.java deleted file mode 100644 index 6c93614..0000000 --- a/AircraftCarrier/src/DrawingAircraft.java +++ /dev/null @@ -1,120 +0,0 @@ -import java.awt.*; - -public class DrawingAircraft { - protected EntityAircraft entityAircraft ; - protected void setEntityShip(EntityAircraft entityShip){ - this.entityAircraft = entityAircraft; - } - public EntityAircraft getEntityShip() { - return entityAircraft; - } - private IDrawImprovements drawingImprovements; - private int _pictureWidth; - private int _pictureHeight; - protected int _startPosX; - public int getPosX(){ - return _startPosX; - } - protected int _startPosY; - public int getPosY(){ - return _startPosY; - } - private final int _ShipWidth = 164; - public int getWidth() { - return _ShipWidth; - } - private final int _ShipHeight = 40; - public int getHeight(){ - return _ShipHeight; - } - public DrawingAircraft(int speed, double weight, Color bodyColor, int width, int height, int improvementsType, int improvementsNumber) { - if (width < _ShipWidth || height < _ShipHeight) - return; - _pictureWidth = width; - _pictureHeight = height; - entityAircraft = new EntityAircraft(speed, weight, bodyColor); - switch (improvementsType){ - case 1: - drawingImprovements = new DrawingImprovementsSquare(); - break; - case 2: - drawingImprovements = new DrawingImprovementsCircle(); - break; - default: - drawingImprovements = new DrawingImprovementsTriangle(); - break; - } - drawingImprovements.setNumber(improvementsNumber); - } - public void setPosition(int x, int y) - { - if (_startPosX > (_pictureWidth - _ShipWidth) || _startPosY>(_pictureHeight - _ShipHeight) || x <= 0 || y <= 0) - x = y = 2; - _startPosX = x; - _startPosY = y; - } - public void drawTransport(Graphics2D g) { - if (entityAircraft == null) - return; - Color penColor = Color.BLACK; - Color bodyColor = entityAircraft.getBodyColor(); - g.setColor(penColor); - g.drawLine(_startPosX+4, _startPosY, _startPosX + 124, _startPosY); - g.drawLine(_startPosX+124, _startPosY, _startPosX + 164, _startPosY+20); - g.drawLine(_startPosX + 164, _startPosY+20, _startPosX + 124, _startPosY + 40); - g.drawLine(_startPosX + 164, _startPosY + 20, _startPosX + 124, _startPosY + 40); - g.drawLine(_startPosX + 124, _startPosY + 40, _startPosX + 4, _startPosY + 40); - g.drawLine(_startPosX+4, _startPosY + 40, _startPosX + 4, _startPosY); - g.setColor(bodyColor); - g.fillRect(_startPosX, _startPosY + 6, 4, 12); - g.fillRect(_startPosX, _startPosY + 24, 4, 12); - g.setColor(penColor); - g.drawOval(_startPosX + 115, _startPosY + 13, 14, 14); - g.drawRect(_startPosX + 63, _startPosY + 13, 27, 14); - g.drawRect(_startPosX + 90, _startPosY + 9, 14, 22); - g.setColor(bodyColor); - drawingImprovements.drawImprovements(g, _startPosX, _startPosY); - } - public boolean canMove(DirectionType direction) { - if (entityAircraft == null) { - return false; - } - switch(direction) { - case LEFT: - return _startPosX - entityAircraft.step.get().intValue() > 0; - case UP: - return _startPosY - entityAircraft.step.get().intValue() > 0; - case RIGHT: - return _startPosX + entityAircraft.step.get().intValue() + _ShipWidth < _pictureWidth; - case DOWN: - return _startPosY + entityAircraft.step.get().intValue() + _ShipWidth < _pictureWidth; - default: - return false; - } - } - public void moveTransport(DirectionType direction) - { - if (entityAircraft == null) - return; - int step = entityAircraft.step.get().intValue(); - switch (direction) - { - case LEFT: - if (_startPosX - step > 0) - _startPosX -= step; - break; - case UP: - if (_startPosY - step > 0) - _startPosY -= step; - break; - case RIGHT: - if (_startPosX + _ShipWidth + step < _pictureWidth) - _startPosX += step; - break; - case DOWN: - if (_startPosY + _ShipHeight + step < _pictureHeight) - _startPosY += step; - break; - } - } -} diff --git a/AircraftCarrier/src/DrawingAircraftCarrier.java b/AircraftCarrier/src/DrawingAircraftCarrier.java deleted file mode 100644 index 10a2846..0000000 --- a/AircraftCarrier/src/DrawingAircraftCarrier.java +++ /dev/null @@ -1,33 +0,0 @@ - -import java.awt.*; - -public class DrawingAircraftCarrier extends DrawingAircraft { - public DrawingAircraftCarrier(int speed, double weight, Color bodyColor, - Color additionalColor, boolean cabin, boolean runway, int width, int height, int improvementsType, int improvementsNumber){ - super(speed, weight, bodyColor, width, height, improvementsType, improvementsNumber); - if(entityAircraft != null) - entityAircraft = new EntityAircraftCarrier(speed, weight, bodyColor, additionalColor,cabin, runway); - } - public void drawTransport(Graphics2D g) - { - if (!(entityAircraft instanceof EntityAircraftCarrier)) - return; - EntityAircraftCarrier entityAircraftCarrier = (EntityAircraftCarrier) entityAircraft; - Color additionalColor = entityAircraftCarrier.getAdditionalColor(); - super.drawTransport(g); - if(entityAircraftCarrier.getRunway()){ - g.setColor(additionalColor); - g.fillRect(_startPosX + 4, _startPosY + 13, 59, 14); - g.setColor(Color.WHITE); - g.drawLine(_startPosX + 62, _startPosY + 19, _startPosX + 52, _startPosY + 19); - g.drawLine(_startPosX + 47, _startPosY + 19, _startPosX + 37, _startPosY + 19); - g.drawLine(_startPosX + 32, _startPosY + 19, _startPosX + 22, _startPosY + 19); - g.drawLine(_startPosX + 17, _startPosY + 19, _startPosX + 7, _startPosY + 19); - } - if (entityAircraftCarrier.getCabin()) - { - g.setColor(additionalColor); - g.fillRect(_startPosX + 90, _startPosY, 15, 9); - } - } -} \ No newline at end of file diff --git a/AircraftCarrier/src/DrawingImprovementsCircle.java b/AircraftCarrier/src/DrawingImprovementsCircle.java deleted file mode 100644 index d0b5aa0..0000000 --- a/AircraftCarrier/src/DrawingImprovementsCircle.java +++ /dev/null @@ -1,24 +0,0 @@ -import java.awt.*; -public class DrawingImprovementsCircle implements IDrawImprovements{ - private NumberImprovement number; - public void setNumber(int x){ - if(x <= 2) - number = NumberImprovement.TWO; - if(x == 4) - number = NumberImprovement.FOUR; - if(x >= 6) - number = NumberImprovement.SIX; - } - public void drawImprovements(Graphics2D g, int _startPosX, int _startPosY){ - g.fillOval(_startPosX+5, _startPosY+1, 15, 12); - g.fillOval(_startPosX+5, _startPosY+27, 15, 13); - if (number == NumberImprovement.FOUR || number == NumberImprovement.SIX){ - g.fillOval(_startPosX+26, _startPosY+1, 15, 12); - g.fillOval(_startPosX+26, _startPosY+27, 15, 13); - } - if (number == NumberImprovement.SIX){ - g.fillOval(_startPosX+48, _startPosY+1, 15, 12); - g.fillOval(_startPosX+48, _startPosY+27, 15, 13); - } - } -} diff --git a/AircraftCarrier/src/DrawingImprovementsSquare.java b/AircraftCarrier/src/DrawingImprovementsSquare.java deleted file mode 100644 index 93a71c2..0000000 --- a/AircraftCarrier/src/DrawingImprovementsSquare.java +++ /dev/null @@ -1,25 +0,0 @@ -import java.awt.*; - -public class DrawingImprovementsSquare implements IDrawImprovements{ - private NumberImprovement number; - public void setNumber(int x){ - if(x <= 2) - number = NumberImprovement.TWO; - if(x == 4) - number = NumberImprovement.FOUR; - if(x >= 6) - number = NumberImprovement.SIX; - } - public void drawImprovements(Graphics2D g, int _startPosX, int _startPosY){ - g.fillRect(_startPosX+5, _startPosY+1, 15, 12); - g.fillRect(_startPosX+5, _startPosY+27, 15, 13); - if (number == NumberImprovement.FOUR || number == NumberImprovement.SIX){ - g.fillRect(_startPosX+26, _startPosY+1, 15, 12); - g.fillRect(_startPosX+26, _startPosY+27, 15, 13); - } - if (number == NumberImprovement.SIX){ - g.fillRect(_startPosX+48, _startPosY+1, 15, 12); - g.fillRect(_startPosX+48, _startPosY+27, 15, 13); - } - } -} \ No newline at end of file diff --git a/AircraftCarrier/src/DrawingImprovementsTriangle.java b/AircraftCarrier/src/DrawingImprovementsTriangle.java deleted file mode 100644 index 1f34d70..0000000 --- a/AircraftCarrier/src/DrawingImprovementsTriangle.java +++ /dev/null @@ -1,36 +0,0 @@ -import java.awt.*; -public class DrawingImprovementsTriangle implements IDrawImprovements{ - private NumberImprovement number; - public void setNumber(int x){ - if(x <= 2) - number = NumberImprovement.TWO; - if(x == 4) - number = NumberImprovement.FOUR; - if(x >= 6) - number = NumberImprovement.SIX; - } - public void drawImprovements(Graphics2D g, int _startPosX, int _startPosY){ - int[] pointX = new int[]{ _startPosX+5, _startPosX+13, _startPosX+ 21}; - int[] pointY = new int[]{ _startPosY + 1, _startPosY+13, _startPosY+1}; - g.fillPolygon(pointX, pointY, 3); - pointX = new int[]{ _startPosX+5, _startPosX+13, _startPosX+ 21}; - pointY = new int[]{ _startPosY + 40, _startPosY+27, _startPosY+40}; - g.fillPolygon(pointX, pointY, 3); - if (number == NumberImprovement.FOUR || number == NumberImprovement.SIX){ - pointX = new int[]{ _startPosX+26, _startPosX+34, _startPosX+ 42}; - pointY = new int[]{ _startPosY + 1, _startPosY+13, _startPosY+1}; - g.fillPolygon(pointX, pointY, 3); - pointX = new int[]{ _startPosX+26, _startPosX+34, _startPosX+ 42}; - pointY = new int[]{ _startPosY + 40, _startPosY+27, _startPosY+40}; - g.fillPolygon(pointX, pointY, 3); - } - if (number == NumberImprovement.SIX){ - pointX = new int[]{ _startPosX+47, _startPosX+55, _startPosX+ 63}; - pointY = new int[]{ _startPosY + 1, _startPosY+13, _startPosY+1}; - g.fillPolygon(pointX, pointY, 3); - pointX = new int[]{ _startPosX+47, _startPosX+55, _startPosX+ 63}; - pointY = new int[]{ _startPosY + 40, _startPosY+27, _startPosY+40}; - g.fillPolygon(pointX, pointY, 3); - } - } -} \ No newline at end of file diff --git a/AircraftCarrier/src/DrawingObjectAircraftCarrier.java b/AircraftCarrier/src/DrawingObjectAircraftCarrier.java deleted file mode 100644 index 51703f8..0000000 --- a/AircraftCarrier/src/DrawingObjectAircraftCarrier.java +++ /dev/null @@ -1,27 +0,0 @@ -public class DrawingObjectAircraftCarrier implements IMoveableObject{ - private final DrawingAircraft drawingAircraft; - - public DrawingObjectAircraftCarrier(DrawingAircraft drawingShip){ - this.drawingAircraft = drawingShip; - } - public ObjectParameters getObjectPosition(){ - if(drawingAircraft == null || drawingAircraft.getEntityShip() == null) - return null; - return new ObjectParameters(drawingAircraft.getPosX(), drawingAircraft.getPosY(), - drawingAircraft.getWidth(), drawingAircraft.getHeight()); - } - public int getStep(){ - if(drawingAircraft.getEntityShip() == null) - return 0; - return drawingAircraft.getEntityShip().step.get().intValue(); - } - public boolean checkCanMove(DirectionType direction){ - if(drawingAircraft == null) - return false; - return drawingAircraft.canMove(direction); - } - public void moveObject(DirectionType direction){ - drawingAircraft.moveTransport(direction); - } -} - diff --git a/AircraftCarrier/src/EntityAircraft.java b/AircraftCarrier/src/EntityAircraft.java deleted file mode 100644 index 36122ae..0000000 --- a/AircraftCarrier/src/EntityAircraft.java +++ /dev/null @@ -1,24 +0,0 @@ -import java.awt.*; -import java.util.function.Supplier; - -public class EntityAircraft { - private int speed; - public int getSpeed(){ - return speed; - } - private double weight; - public double getWeight(){ - return weight; - } - private Color bodyColor; - public Color getBodyColor(){ - return bodyColor; - } - public Supplier step = () ->(double) speed * 100 / weight; - - public EntityAircraft(int speed, double weight, Color bodyColor){ - this.speed = speed; - this.weight = weight; - this.bodyColor = bodyColor; - } -} diff --git a/AircraftCarrier/src/EntityAircraftCarrier.java b/AircraftCarrier/src/EntityAircraftCarrier.java deleted file mode 100644 index 85df120..0000000 --- a/AircraftCarrier/src/EntityAircraftCarrier.java +++ /dev/null @@ -1,23 +0,0 @@ -import java.awt.*; - -public class EntityAircraftCarrier extends EntityAircraft{ - private Color additionalColor; - public Color getAdditionalColor(){ - return additionalColor; - } - private boolean Cabin; - public boolean getCabin() { - return Cabin; - } - private boolean Runway; - public boolean getRunway() { - return Runway; - } - public EntityAircraftCarrier(int speed, double weight, Color bodyColor, Color - additionalColor, boolean Cabin, boolean Runway) { - super(speed, weight, bodyColor); - this.additionalColor = additionalColor; - this.Cabin = Cabin; - this.Runway = Runway; - } -} \ No newline at end of file diff --git a/AircraftCarrier/src/FrameAircraftCarrier.java b/AircraftCarrier/src/FrameAircraftCarrier.java deleted file mode 100644 index a01f62b..0000000 --- a/AircraftCarrier/src/FrameAircraftCarrier.java +++ /dev/null @@ -1,169 +0,0 @@ -import javax.imageio.ImageIO; -import javax.swing.*; -import java.awt.*; -import java.awt.event.ActionEvent; -import java.io.File; -import java.io.IOException; -import java.util.Random; -public class FrameAircraftCarrier extends JFrame { - private DrawingAircraft drawingAircraft; - private AbstractStrategy abstractStrategy; - private JComboBox comboBoxStrategy; - private final JComponent pictureBox; - public FrameAircraftCarrier() throws IOException { - super("Военный корабль"); - setSize(new Dimension(900,500)); - setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); - pictureBox = new JComponent(){ - public void paintComponent(Graphics graphics){ - super.paintComponent(graphics); - Graphics2D graphics2D = (Graphics2D) graphics; - if (drawingAircraft!= null) drawingAircraft.drawTransport(graphics2D); - super.repaint(); - } - }; - comboBoxStrategy = new JComboBox<>(new String[]{"К центру", "К границе"}); - JButton stepButton = new JButton("Шаг"); - JButton createShipButton = new JButton("Создать корабль"); - JButton createAircraftCarrierButton = new JButton("Создать Военный корабль"); - JButton rightButton = new JButton(new ImageIcon(ImageIO.read(new File("C:\\Users\\79962\\Desktop\\arrows\\right.png")))); - JButton leftButton = new JButton(new ImageIcon(ImageIO.read(new File("C:\\Users\\79962\\Desktop\\arrows\\left.png")))); - JButton upButton = new JButton(new ImageIcon(ImageIO.read(new File("C:\\Users\\79962\\Desktop\\arrows\\up.png")))); - JButton downButton = new JButton(new ImageIcon(ImageIO.read(new File("C:\\Users\\79962\\Desktop\\arrows\\down.png")))); - pictureBox.setBounds( 0, 0, getContentPane().getWidth(), getContentPane().getHeight()); - createShipButton.addActionListener(e -> buttonCreateShipClick()); - createAircraftCarrierButton.addActionListener(e -> buttonCreateAircraftCarrierClick()); - stepButton.addActionListener(e -> buttonStepClick()); - rightButton.setActionCommand("right"); - rightButton.addActionListener(this::buttonMoveClick); - leftButton.setActionCommand("left"); - leftButton.addActionListener(this::buttonMoveClick); - upButton.setActionCommand("up"); - upButton.addActionListener(this::buttonMoveClick); - downButton.setActionCommand("down"); - downButton.addActionListener(this::buttonMoveClick); - //component addition - setLayout(new BorderLayout()); - JPanel panelAircraftCarrier = new JPanel(new BorderLayout()); - JPanel rightPanel = new JPanel(new BorderLayout()); - JPanel leftPanel = new JPanel(new BorderLayout()); - GridBagConstraints constraints = new GridBagConstraints(); - constraints.insets.left = constraints.insets.top = constraints.insets.bottom = constraints.insets.right = 2; - JPanel createPanel = new JPanel(new GridBagLayout()); - constraints.gridx = 0; - constraints.gridy = 0; - createPanel.add(createShipButton, constraints); - constraints.gridx = 1; - constraints.gridy = 0; - createPanel.add(createAircraftCarrierButton, constraints); - JPanel movementPanel = new JPanel(new GridBagLayout()); - rightButton.setPreferredSize(new Dimension(30,30)); - constraints.gridx = 2; - constraints.gridy = 1; - movementPanel.add(rightButton, constraints); - leftButton.setPreferredSize(new Dimension(30,30)); - constraints.gridx = 0; - constraints.gridy = 1; - movementPanel.add(leftButton, constraints); - upButton.setPreferredSize(new Dimension(30,30)); - constraints.gridx = 1; - constraints.gridy = 0; - movementPanel.add(upButton, constraints); - downButton.setPreferredSize(new Dimension(30,30)); - constraints.gridx = 1; - constraints.gridy = 1; - movementPanel.add(downButton, constraints); - JPanel stepPanel = new JPanel(new GridBagLayout()); - constraints.gridx = 0; - constraints.gridy = 0; - stepPanel.add(comboBoxStrategy, constraints); - constraints.gridx = 0; - constraints.gridy = 1; - stepPanel.add(stepButton, constraints); - add(pictureBox); - rightPanel.add(movementPanel, BorderLayout.SOUTH); - rightPanel.add(stepPanel, BorderLayout.NORTH); - leftPanel.add(createPanel, BorderLayout.SOUTH); - panelAircraftCarrier.add(rightPanel, BorderLayout.EAST); - panelAircraftCarrier.add(leftPanel, BorderLayout.WEST); - add(panelAircraftCarrier,BorderLayout.CENTER); - setVisible(true); - } - private void buttonCreateAircraftCarrierClick() { - Random random = new Random(); - pictureBox.setBounds(0,0,getContentPane().getWidth(),getContentPane().getHeight()); - drawingAircraft = new DrawingAircraftCarrier(random.nextInt(200) + 100, random.nextInt(2000) + 1000, new Color(random.nextInt(256), random.nextInt(256), random.nextInt(256)), - new Color(random.nextInt(256), random.nextInt(256), random.nextInt(256)), random.nextBoolean(), random.nextBoolean(), pictureBox.getWidth(), pictureBox.getHeight(), random.nextInt(3),(random.nextInt(3)+1)*2); - drawingAircraft.setPosition(random.nextInt(90) + 10, random.nextInt(90) + 10); - draw(); - } - private void buttonCreateShipClick(){ - Random random = new Random(); - pictureBox.setBounds(0,0,getContentPane().getWidth(),getContentPane().getHeight()); - drawingAircraft = new DrawingAircraft(random.nextInt(200) + 100, random.nextInt(2000) + 1000, new Color(random.nextInt(256), random.nextInt(256), random.nextInt(256)), - pictureBox.getWidth(), pictureBox.getHeight(), random.nextInt(3),(random.nextInt(3)+1)*2); - drawingAircraft.setPosition(random.nextInt(90) + 10, random.nextInt(90) + 10); - draw(); - } - private void buttonStepClick() { - if (drawingAircraft == null) { - return; - } - if (comboBoxStrategy.isEnabled()) { - switch(comboBoxStrategy.getSelectedIndex()) { - case 0: - abstractStrategy = new MoveToCenter(); - break; - case 1: - abstractStrategy = new MoveToBorder(); - break; - default: - abstractStrategy = null; - break; - }; - if (abstractStrategy == null) - { - return; - } - abstractStrategy.SetData(new DrawingObjectAircraftCarrier(drawingAircraft), pictureBox.getWidth(), - pictureBox.getHeight()); - comboBoxStrategy.setEnabled(false); - } - if (abstractStrategy == null) - { - return; - } - abstractStrategy.MakeStep(); - draw(); - if (abstractStrategy.GetStatus() == Status.FINISH) - { - comboBoxStrategy.setEnabled(true); - abstractStrategy = null; - } - } - private void buttonMoveClick(ActionEvent event) { - if(drawingAircraft == null || drawingAircraft.getEntityShip() == null) - return; - switch (event.getActionCommand()) - { - case "left": - drawingAircraft.moveTransport(DirectionType.LEFT); - break; - case "right": - drawingAircraft.moveTransport(DirectionType.RIGHT); - break; - case "up": - drawingAircraft.moveTransport(DirectionType.UP); - break; - case "down": - drawingAircraft.moveTransport(DirectionType.DOWN); - break; - } - draw(); - } - private void draw() { - if (drawingAircraft == null) - return; - pictureBox.repaint(); - } -} \ No newline at end of file diff --git a/AircraftCarrier/src/IDrawImprovements.java b/AircraftCarrier/src/IDrawImprovements.java deleted file mode 100644 index c50d2dc..0000000 --- a/AircraftCarrier/src/IDrawImprovements.java +++ /dev/null @@ -1,6 +0,0 @@ -import java.awt.*; - -public interface IDrawImprovements { - public void setNumber(int x); - public void drawImprovements(Graphics2D graphics2D, int _startX, int _startY); -} diff --git a/AircraftCarrier/src/IMoveableObject.java b/AircraftCarrier/src/IMoveableObject.java deleted file mode 100644 index 329d7ad..0000000 --- a/AircraftCarrier/src/IMoveableObject.java +++ /dev/null @@ -1,6 +0,0 @@ -public interface IMoveableObject { - ObjectParameters getObjectPosition(); - int getStep(); - boolean checkCanMove(DirectionType direction); - void moveObject(DirectionType direction); -} diff --git a/AircraftCarrier/src/Main.java b/AircraftCarrier/src/Main.java deleted file mode 100644 index a0d4911..0000000 --- a/AircraftCarrier/src/Main.java +++ /dev/null @@ -1,7 +0,0 @@ -import java.io.IOException; - -public class Main { - public static void main(String[] args) throws IOException{ - new FrameAircraftCarrier(); - } -} diff --git a/AircraftCarrier/src/MoveToBorder.java b/AircraftCarrier/src/MoveToBorder.java deleted file mode 100644 index 07b0c19..0000000 --- a/AircraftCarrier/src/MoveToBorder.java +++ /dev/null @@ -1,34 +0,0 @@ -public class MoveToBorder extends AbstractStrategy{ - @Override - protected boolean IsTargetDestination() { - var objParams = getObjectParameters.get(); - if(objParams == null) - return false; - return objParams.getRightBorder() + GetStep() >= getFieldWidth() && - objParams.getDownBorder() + GetStep() >= getFieldHeight(); - } - @Override - protected void MoveToTarget() { - var objParams = getObjectParameters.get(); - if(objParams == null) - return; - var diffX = objParams.getRightBorder() - getFieldWidth(); - var diffY = objParams.getDownBorder() - getFieldHeight(); - if(diffX >= 0) - { - MoveDown(); - } - else if(diffY >= 0) - { - MoveRight(); - } - else if(Math.abs(diffX) > Math.abs(diffY)) - { - MoveRight(); - } - else - { - MoveDown(); - } - } -} diff --git a/AircraftCarrier/src/MoveToCenter.java b/AircraftCarrier/src/MoveToCenter.java deleted file mode 100644 index 18363f9..0000000 --- a/AircraftCarrier/src/MoveToCenter.java +++ /dev/null @@ -1,32 +0,0 @@ -public class MoveToCenter extends AbstractStrategy{ - @Override - protected boolean IsTargetDestination() { - var objParams = getObjectParameters.get(); - if(objParams == null) - return false; - return objParams.getObjectMiddleHorizontal() <= getFieldWidth() / 2 && - objParams.getObjectMiddleHorizontal()+GetStep() >= getFieldWidth() / 2 && - objParams.getObjectMiddleVertical() <= getFieldHeight() / 2 && - objParams.getObjectMiddleVertical() + GetStep() >= getFieldHeight() / 2; - } - @Override - protected void MoveToTarget() { - var objParams = getObjectParameters.get(); - if(objParams == null) - return; - var diffX = objParams.getObjectMiddleHorizontal() - getFieldWidth() / 2; - if(Math.abs(diffX) > GetStep()){ - if(diffX > 0) - MoveLeft(); - else - MoveRight(); - } - var diffY = objParams.getObjectMiddleVertical() - getFieldHeight() / 2; - if(Math.abs(diffY) > GetStep()){ - if(diffY > 0) - MoveUp(); - else - MoveDown(); - } - } -} diff --git a/AircraftCarrier/src/NumberImprovement.java b/AircraftCarrier/src/NumberImprovement.java deleted file mode 100644 index e7b419d..0000000 --- a/AircraftCarrier/src/NumberImprovement.java +++ /dev/null @@ -1,5 +0,0 @@ -public enum NumberImprovement { - TWO, - FOUR, - SIX -} \ No newline at end of file diff --git a/AircraftCarrier/src/ObjectParameters.java b/AircraftCarrier/src/ObjectParameters.java deleted file mode 100644 index 7b04f57..0000000 --- a/AircraftCarrier/src/ObjectParameters.java +++ /dev/null @@ -1,19 +0,0 @@ -public class ObjectParameters { - private final int _x; - private final int _y; - private final int _width; - private final int _height; - public int getLeftBorder() {return _x;} - public int getTopBorder() {return _y;} - public int getRightBorder() {return _x + _width;} - public int getDownBorder() {return _y + _height;} - public int getObjectMiddleHorizontal() {return _x + this._width / 2;} - public int getObjectMiddleVertical() {return _y + this._height / 2;} - public ObjectParameters(int x, int y, int width, int height) - { - _x = x; - _y = y; - _width = width; - _height = height; - } -} diff --git a/AircraftCarrier/src/Status.java b/AircraftCarrier/src/Status.java deleted file mode 100644 index 8fb12ef..0000000 --- a/AircraftCarrier/src/Status.java +++ /dev/null @@ -1,5 +0,0 @@ -public enum Status { - NOTINIT, - INPROGRESS, - FINISH -}