diff --git a/ProjectAirFighter/src/Drawnings/DrawningAirCraft.java b/ProjectAirFighter/src/Drawnings/DrawningAirCraft.java
index 3bb5bcd..9f102ac 100644
--- a/ProjectAirFighter/src/Drawnings/DrawningAirCraft.java
+++ b/ProjectAirFighter/src/Drawnings/DrawningAirCraft.java
@@ -7,7 +7,7 @@ import java.awt.*;
import java.util.Random;
public class DrawningAirCraft {
- private final EntityAirCraft entityAirCraft;
+ public Entities.EntityAirCraft entityAirCraft;
public EntityAirCraft getEntityAirCraft() {
return entityAirCraft;
@@ -20,11 +20,11 @@ public class DrawningAirCraft {
private int _drawingAirCraftWidth = 66;
private int _drawingAirCraftHeight = 74;
- public int GetPosX() {
+ public Integer GetPosX() {
return _startPosX;
}
- public int GetPosY() {
+ public Integer GetPosY() {
return _startPosY;
}
@@ -36,7 +36,7 @@ public class DrawningAirCraft {
return _drawingAirCraftHeight;
}
- private IDrawEngine drawEngine;
+ public IDrawEngine drawEngine;
public DrawningAirCraft(int speed, float weight, Color bodyColor, int engineType) {
entityAirCraft = new EntityAirCraft(speed, weight, bodyColor);
@@ -68,6 +68,11 @@ public class DrawningAirCraft {
_drawingAirCraftWidth = aircraftWidth;
}
+ public DrawningAirCraft(EntityAirCraft _entityAirCraft, IDrawEngine _drawEngine) {
+ entityAirCraft = _entityAirCraft;
+ drawEngine = _drawEngine;
+ }
+
public void setPosition(int x, int y) {
if (_pictureHeight == null || _pictureWidth == null)
return;
diff --git a/ProjectAirFighter/src/Drawnings/DrawningAirFighter.java b/ProjectAirFighter/src/Drawnings/DrawningAirFighter.java
index aa62b56..9f44440 100644
--- a/ProjectAirFighter/src/Drawnings/DrawningAirFighter.java
+++ b/ProjectAirFighter/src/Drawnings/DrawningAirFighter.java
@@ -5,15 +5,16 @@ import Entities.EntityAirFighter;
import java.awt.*;
public class DrawningAirFighter extends DrawningAirCraft {
- private EntityAirFighter entityAirFighter;
-
public DrawningAirFighter(int speed, float weight, Color bodyColor, int engineType, Color additionalColor, boolean pgo, boolean rockets) {
super(speed, weight, bodyColor, engineType, 76, 80);
- entityAirFighter = new EntityAirFighter(speed, weight, bodyColor, additionalColor, pgo, rockets);
+ entityAirCraft = new EntityAirFighter(speed, weight, bodyColor, additionalColor, pgo, rockets);
}
+ public DrawningAirFighter(EntityAirFighter entity, IDrawEngine engine) {
+ super(entity, engine);
+ }
public void drawAirCraft(Graphics g) {
- if (entityAirFighter == null || _startPosX == null || _startPosY == null) {
+ if (entityAirCraft == null|| !(entityAirCraft instanceof EntityAirFighter entityAirFighter) || _startPosX == null || _startPosY == null) {
return;
}
super.drawAirCraft(g);
diff --git a/ProjectAirFighter/src/Drawnings/DrawningEngine.java b/ProjectAirFighter/src/Drawnings/DrawningEngine.java
index ded7e3f..acb4f6b 100644
--- a/ProjectAirFighter/src/Drawnings/DrawningEngine.java
+++ b/ProjectAirFighter/src/Drawnings/DrawningEngine.java
@@ -35,4 +35,10 @@ public class DrawningEngine implements IDrawEngine {
g2d.drawRect(_startX + 30, _startY + 17, 10, 2 );
}
}
+ @Override
+ public String toString() {
+ String buffer = "";
+ buffer += "Тип: обычные, Количество двигателей: " + _engineCount.getEnumNumber();
+ return buffer;
+ }
}
\ No newline at end of file
diff --git a/ProjectAirFighter/src/Drawnings/DrawningLongEngine.java b/ProjectAirFighter/src/Drawnings/DrawningLongEngine.java
index cbf1dc9..3a31622 100644
--- a/ProjectAirFighter/src/Drawnings/DrawningLongEngine.java
+++ b/ProjectAirFighter/src/Drawnings/DrawningLongEngine.java
@@ -35,4 +35,10 @@ public class DrawningLongEngine implements IDrawEngine {
g2d.drawRoundRect(_startX + 25, _startY + 17, 15, 2, 5, 5);
}
}
+ @Override
+ public String toString() {
+ String buffer = "";
+ buffer += "Тип: длиные, Количество двигателей: " + _engineCount.getEnumNumber();
+ return buffer;
+ }
}
\ No newline at end of file
diff --git a/ProjectAirFighter/src/Drawnings/DrawningOvalEngine.java b/ProjectAirFighter/src/Drawnings/DrawningOvalEngine.java
index 066274b..2bed099 100644
--- a/ProjectAirFighter/src/Drawnings/DrawningOvalEngine.java
+++ b/ProjectAirFighter/src/Drawnings/DrawningOvalEngine.java
@@ -35,4 +35,10 @@ public class DrawningOvalEngine implements IDrawEngine {
g2d.drawOval(_startX + 30, _startY + 17, 10, 2);
}
}
+ @Override
+ public String toString() {
+ String buffer = "";
+ buffer += "Тип: овальные, Количество двигателей: " + _engineCount.getEnumNumber();
+ return buffer;
+ }
}
\ No newline at end of file
diff --git a/ProjectAirFighter/src/Entities/EntityAirCraft.java b/ProjectAirFighter/src/Entities/EntityAirCraft.java
index ae2634c..7313e3f 100644
--- a/ProjectAirFighter/src/Entities/EntityAirCraft.java
+++ b/ProjectAirFighter/src/Entities/EntityAirCraft.java
@@ -25,4 +25,14 @@ public class EntityAirCraft {
Weight = weight;
BodyColor = bodyColor;
}
+
+ @Override
+ public String toString() {
+ String buffer = "";
+ buffer += "Скорость: " + this.Speed;
+ buffer += ", Вес: " + this.Weight;
+ buffer += String.format(", Основной цвет : RGB{%d, %d, %d}",
+ this.BodyColor.getRed(), this.BodyColor.getGreen(), this.BodyColor.getBlue());
+ return buffer;
+ }
}
\ No newline at end of file
diff --git a/ProjectAirFighter/src/Entities/EntityAirFighter.java b/ProjectAirFighter/src/Entities/EntityAirFighter.java
index 2098795..250ee19 100644
--- a/ProjectAirFighter/src/Entities/EntityAirFighter.java
+++ b/ProjectAirFighter/src/Entities/EntityAirFighter.java
@@ -21,4 +21,14 @@ public class EntityAirFighter extends EntityAirCraft {
Pgo = pgo;
Rockets = rockets;
}
+
+ @Override
+ public String toString() {
+ String buffer = super.toString();
+ buffer += String.format(", Дополнительный цвет : RGB{%d, %d, %d}",
+ this.AdditionalColor.getRed(), this.AdditionalColor.getGreen(), this.AdditionalColor.getBlue());
+ buffer += ", ПГО: " + this.Pgo;
+ buffer += ", Ракеты: " + this.Rockets;
+ return buffer;
+ }
}
\ No newline at end of file
diff --git a/ProjectAirFighter/src/FormAirFighter.form b/ProjectAirFighter/src/FormAirFighter.form
deleted file mode 100644
index fd0549c..0000000
--- a/ProjectAirFighter/src/FormAirFighter.form
+++ /dev/null
@@ -1,131 +0,0 @@
-
-
diff --git a/ProjectAirFighter/src/FormAirFighter.java b/ProjectAirFighter/src/FormAirFighter.java
deleted file mode 100644
index cf00e67..0000000
--- a/ProjectAirFighter/src/FormAirFighter.java
+++ /dev/null
@@ -1,176 +0,0 @@
-import Drawnings.DrawningAirCraft;
-import Drawnings.DrawningAirFighter;
-import MovementStrategy.*;
-
-import javax.swing.*;
-import java.awt.*;
-import java.awt.event.ActionEvent;
-import java.awt.event.ActionListener;
-import java.util.LinkedList;
-import java.util.Random;
-import java.util.List;
-
-public class FormAirFighter extends JFrame {
- protected DrawningAirCraft _drawningAirCraft;
- JPanel PanelWrapper;
- private JPanel PictureBox;
- private JButton buttonCreateAirFighter;
- private JButton buttonCreateAirCraft;
- private JButton buttonRight;
- private JButton buttonDown;
- private JButton buttonLeft;
- private JButton buttonUp;
- private JComboBox comboBoxStrategy;
- private JButton buttonStrategyStep;
- private AbstractStrategy _strategy;
- private List controls;
-
- private void createObject(String type) {
- Random random = new Random();
- switch (type) {
- case "Drawnings.DrawningAirCraft":
- _drawningAirCraft = new DrawningAirCraft(random.nextInt(30,100), random.nextInt(100,500),
- new Color(random.nextInt(256), random.nextInt(256), random.nextInt(256)), random.nextInt(3));
- break;
- case "Drawnings.DrawningAirFighter":
- _drawningAirCraft = new DrawningAirFighter(random.nextInt(30,100), random.nextInt(100,500),
- new Color(random.nextInt(256), random.nextInt(256), random.nextInt(256)), random.nextInt(3),
- new Color(random.nextInt(256), random.nextInt(256), random.nextInt(256)),
- random.nextBoolean(), random.nextBoolean());
- break;
- default:
- return;
- }
- _drawningAirCraft.setPictureSize(PictureBox.getWidth(), PictureBox.getHeight());
- _drawningAirCraft.setPosition(random.nextInt(25, 100),
- random.nextInt(25, 100));
- _strategy = null;
- comboBoxStrategy.setEnabled(true);
-
- Draw();
- }
-
- public FormAirFighter() {
- buttonUp.setName("buttonUp");
- buttonDown.setName("buttonDown");
- buttonLeft.setName("buttonLeft");
- buttonRight.setName("buttonRight");
-
- InitializeControlsRepaintList();
-
- buttonCreateAirFighter.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- createObject("Drawnings.DrawningAirFighter");
-
- }
- });
- buttonCreateAirCraft.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- createObject("Drawnings.DrawningAirCraft");
- }
- });
- ActionListener buttonMoveClickedListener = new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- String buttonName = ((JButton) e.getSource()).getName();
- boolean result = false;
-
- switch (buttonName) {
- case "buttonUp": {
- result = _drawningAirCraft.moveTransport(MovementDirection.Up);
- }
- break;
- case "buttonDown": {
- result = _drawningAirCraft.moveTransport(MovementDirection.Down);
- }
- break;
- case "buttonLeft": {
- result = _drawningAirCraft.moveTransport(MovementDirection.Left);
- }
- break;
- case "buttonRight": {
- result = _drawningAirCraft.moveTransport(MovementDirection.Right);
- }
- break;
- }
- if (result)
- Draw();
- }
- };
- buttonRight.addActionListener(buttonMoveClickedListener);
- buttonDown.addActionListener(buttonMoveClickedListener);
- buttonLeft.addActionListener(buttonMoveClickedListener);
- buttonUp.addActionListener(buttonMoveClickedListener);
- comboBoxStrategy.addItem("К центру");
- comboBoxStrategy.addItem("К краю");
- buttonStrategyStep.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- if (_drawningAirCraft == null)
- return;
- if (comboBoxStrategy.isEnabled()) {
- switch (comboBoxStrategy.getSelectedIndex()) {
- case 0:
- _strategy = new MoveToCenter();
- break;
- case 1:
- _strategy = new MoveToBorder();
- break;
-
- default:
- _strategy = null;
- break;
-
- }
- if (_strategy == null) {
- return;
- }
- _strategy.SetData(new MoveableAirCraft(_drawningAirCraft), PictureBox.getWidth(), PictureBox.getHeight());
- }
- if (_strategy == null) {
- return;
- }
- _strategy.MakeStep();
- Draw();
- comboBoxStrategy.setEnabled(false);
-
- if (_strategy.GetStatus() == StrategyStatus.Finish) {
- comboBoxStrategy.setEnabled(true);
- _strategy = null;
- }
- }
- });
- }
- private void Draw() {
- if (_drawningAirCraft.getEntityAirCraft() == null)
- return;
- if (PictureBox.getWidth() == 0 || PictureBox.getHeight() == 0) {
- return;
- }
- Graphics g = PictureBox.getGraphics();
- g.setColor(PictureBox.getBackground());
- g.fillRect(0,0, PictureBox.getWidth(), PictureBox.getHeight());
- _drawningAirCraft.drawAirCraft(g);
-
- RepaintControls();
- }
- private void RepaintControls() {
- for (JComponent control : controls) {
- control.repaint();
- }
- }
-
- private void InitializeControlsRepaintList() {
- controls = new LinkedList<>();
- controls.add(buttonCreateAirFighter);
- controls.add(buttonCreateAirCraft);
- controls.add(buttonUp);
- controls.add(buttonDown);
- controls.add(buttonLeft);
- controls.add(buttonRight);
- controls.add(comboBoxStrategy);
- controls.add(buttonStrategyStep);
- }
-}
\ No newline at end of file
diff --git a/ProjectAirFighter/src/Main.java b/ProjectAirFighter/src/Main.java
index e514ca2..d97dbd3 100644
--- a/ProjectAirFighter/src/Main.java
+++ b/ProjectAirFighter/src/Main.java
@@ -1,13 +1,7 @@
-import javax.swing.*;
+import Forms.FormAirCraftCollection;
public class Main {
public static void main(String[] args) {
- JFrame.setDefaultLookAndFeelDecorated(false);
- JFrame frame = new JFrame("Истребитель");
- frame.setContentPane(new FormAirFighter().PanelWrapper);
- frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- frame.setLocation(500, 200);
- frame.pack();
- frame.setSize(700, 500);
- frame.setVisible(true);
+ FormAirCraftCollection formAirCraftCollection = new FormAirCraftCollection();
+ formAirCraftCollection.OpenFrame();
}
}
\ No newline at end of file
diff --git a/ProjectAirFighter/src/MovementStrategy/MoveToBorder.java b/ProjectAirFighter/src/MovementStrategy/MoveToBorder.java
index 52d6ad6..e6ce28b 100644
--- a/ProjectAirFighter/src/MovementStrategy/MoveToBorder.java
+++ b/ProjectAirFighter/src/MovementStrategy/MoveToBorder.java
@@ -1,18 +1,18 @@
package MovementStrategy;
public class MoveToBorder extends AbstractStrategy {
+ @Override
protected boolean IsTargetDestination()
{
var objParams = GetObjectParameters();
if (objParams == null) {
return false;
}
- return objParams.RightBorder() <= FieldWidth &&
- objParams.RightBorder() + GetStep() >= FieldWidth &&
- objParams.DownBorder() <= FieldHeight &&
+ return objParams.RightBorder() + GetStep() >= FieldWidth &&
objParams.DownBorder() + GetStep() >= FieldHeight;
}
+ @Override
protected void MoveToTarget()
{
var objParams = GetObjectParameters();
diff --git a/ProjectAirFighter/src/MovementStrategy/MoveToCenter.java b/ProjectAirFighter/src/MovementStrategy/MoveToCenter.java
index 8a314f8..0249179 100644
--- a/ProjectAirFighter/src/MovementStrategy/MoveToCenter.java
+++ b/ProjectAirFighter/src/MovementStrategy/MoveToCenter.java
@@ -1,6 +1,7 @@
package MovementStrategy;
public class MoveToCenter extends AbstractStrategy {
+ @Override
protected boolean IsTargetDestination()
{
var objParams = GetObjectParameters();
@@ -12,9 +13,9 @@ public class MoveToCenter extends AbstractStrategy {
objParams.ObjectMiddleVertical() - GetStep() <= FieldHeight / 2 &&
objParams.ObjectMiddleVertical() + GetStep() >= FieldHeight / 2);
}
+ @Override
protected void MoveToTarget()
{
-
var objParams = GetObjectParameters();
if (objParams == null) {
return;
diff --git a/out/production/PIbd-14_Calimullin_A.R._AirFighter_Hard/Drawnings/DrawningAirCraft$1.class b/out/production/PIbd-14_Calimullin_A.R._AirFighter_Hard/Drawnings/DrawningAirCraft$1.class
index edb7f7b..52b10a9 100644
Binary files a/out/production/PIbd-14_Calimullin_A.R._AirFighter_Hard/Drawnings/DrawningAirCraft$1.class and b/out/production/PIbd-14_Calimullin_A.R._AirFighter_Hard/Drawnings/DrawningAirCraft$1.class differ
diff --git a/out/production/PIbd-14_Calimullin_A.R._AirFighter_Hard/Drawnings/DrawningAirCraft.class b/out/production/PIbd-14_Calimullin_A.R._AirFighter_Hard/Drawnings/DrawningAirCraft.class
index 60add02..e2fa6d4 100644
Binary files a/out/production/PIbd-14_Calimullin_A.R._AirFighter_Hard/Drawnings/DrawningAirCraft.class and b/out/production/PIbd-14_Calimullin_A.R._AirFighter_Hard/Drawnings/DrawningAirCraft.class differ