diff --git a/ProjectAirFighter/src/CollectionGenericObjects/AbstractCompany.java b/ProjectAirFighter/src/CollectionGenericObjects/AbstractCompany.java new file mode 100644 index 0000000..c5eb4b3 --- /dev/null +++ b/ProjectAirFighter/src/CollectionGenericObjects/AbstractCompany.java @@ -0,0 +1,58 @@ +package CollectionGenericObjects; + +import Drawnings.DrawningAirCraft; + +import java.awt.*; +import java.util.Random; + +public abstract class AbstractCompany { + protected final int _placeSizeWidth = 100; + protected final int _placeSizeHeight = 86; + protected final int _pictureWidth; + protected final int _pictureHeight; + protected ICollectionGenericObjects _collection = null; + public int getMaxCount() { + return _pictureWidth * _pictureHeight / (_placeSizeWidth * _placeSizeHeight); + } + public AbstractCompany(int picWidth, int picHeight, ICollectionGenericObjects collection) { + this._pictureWidth = picWidth; + this._pictureHeight = picHeight; + this._collection = collection; + int maxCount = getMaxCount(); + _collection.setMaxCount(maxCount); + } + public static int add(AbstractCompany company ,DrawningAirCraft airCraft) { + if (company._collection == null) { + return -1; + } + return company._collection.insert(airCraft); + } + + public static DrawningAirCraft remove(AbstractCompany company, int position) { + if (company._collection == null) { + return null; + } + return company._collection.remove(position); + } + public DrawningAirCraft getRandomObject() { + if (_collection == null) { + return null; + } + Random rnd = new Random(); + return _collection.get(rnd.nextInt(0, _collection.getCount() + 1)); + } + public void show(Graphics g) { + drawBackground(g); + setObjectsPosition(); + if (_collection == null) { + return; + } + for(int i = 0; i < _collection.getCount(); i++) { + if(_collection.get(i) != null) { + _collection.get(i).drawAirCraft(g); + } + } + } + protected abstract void drawBackground(Graphics g); + protected abstract void setObjectsPosition(); +} \ No newline at end of file diff --git a/ProjectAirFighter/src/CollectionGenericObjects/AirCraftAngar.java b/ProjectAirFighter/src/CollectionGenericObjects/AirCraftAngar.java new file mode 100644 index 0000000..159a01c --- /dev/null +++ b/ProjectAirFighter/src/CollectionGenericObjects/AirCraftAngar.java @@ -0,0 +1,53 @@ +package CollectionGenericObjects; + +import Drawnings.DrawningAirCraft; + +import java.awt.*; +import java.util.ArrayList; +import java.util.List; + +public class AirCraftAngar extends AbstractCompany { + private final List locCoord = new ArrayList<>(); + int pamat_i = 0; + int pamat_j = 0; + + public AirCraftAngar(int picWidth, int picHeight, ICollectionGenericObjects collection) { + super(picWidth, picHeight, collection); + _collection.setMaxCount(30); + } + + @Override + protected void drawBackground(Graphics g) { + Color backgroundColor = new Color(255, 255, 255); + g.setColor(backgroundColor); + g.fillRect(0, 0, _pictureWidth, _pictureHeight); + g.setColor(Color.black); + ((Graphics2D) g).setStroke(new BasicStroke(4)); + for (int i = 0; i < _pictureWidth / _placeSizeWidth; i++) { + pamat_i = i; + for (int j = 0; j < _pictureHeight / _placeSizeHeight; j++) { + pamat_j = j; + g.drawLine(i * _placeSizeWidth, j * _placeSizeHeight, (int) (_placeSizeWidth * (i + 0.5f)), _placeSizeHeight * j); + g.drawLine(i * _placeSizeWidth, j * _placeSizeHeight, i * _placeSizeWidth, _placeSizeHeight * (j + 1)); + } + g.drawLine(i * _placeSizeWidth, _placeSizeHeight * (_pictureHeight / _placeSizeHeight), (int) (_placeSizeWidth * (i + 0.5f)), _placeSizeHeight * (_pictureHeight / _placeSizeHeight)); + } + } + + @Override + protected void setObjectsPosition() { + if (locCoord == null || _collection == null) { + return; + } + int currentIndex = -1; + for (int j = pamat_j; j >= 0; j--) { + for (int i = pamat_i; i >= 0; i--) { + currentIndex++; + if (_collection.get(currentIndex) == null) continue; + + _collection.get(currentIndex).setPictureSize(_pictureWidth, _pictureHeight); + _collection.get(currentIndex).setPosition(i * _placeSizeWidth + 5, j * _placeSizeHeight + 5); + } + } + } +} diff --git a/ProjectAirFighter/src/CollectionGenericObjects/Constructor.java b/ProjectAirFighter/src/CollectionGenericObjects/Constructor.java new file mode 100644 index 0000000..f8bbd80 --- /dev/null +++ b/ProjectAirFighter/src/CollectionGenericObjects/Constructor.java @@ -0,0 +1,53 @@ +package CollectionGenericObjects; + +import Drawnings.DrawningAirCraft; +import Drawnings.DrawningAirFighter; +import Drawnings.IDrawEngine; +import Entities.EntityAirCraft; +import Entities.EntityAirFighter; + +import java.util.ArrayList; +import java.util.Random; + +public class Constructor { + private ArrayList entitiesList = new ArrayList<>(); + private ArrayList engineList = new ArrayList<>(); + public void addAirCraft(T obj) { + entitiesList.add(obj); + } + public void addAirCraft(U obj) { + engineList.add(obj); + } + + public DrawningAirCraft getRandomAirCraft() { + Random rnd = new Random(); + + int entityIndex = rnd.nextInt(0, 3); + int engineIndex = rnd.nextInt(0, 3); + + T entity = entitiesList.get(entityIndex); + U engine = engineList.get(engineIndex); + + return (entity instanceof EntityAirFighter) ? + new DrawningAirFighter((EntityAirFighter) entity, engine) : + new DrawningAirCraft(entity, engine); + } + + public String getEntityDescription(int index) { + if (index < 0 || index >= entitiesList.size()) { + return null; + } + + T entity = entitiesList.get(index); + String entityClassName = (entity instanceof EntityAirFighter) ? "EntityAirFighter" : "EntityAirCraft"; + + return String.format("%s = %s", entityClassName, entity); + } + + public String getEngineDescription(int index) { + if (index < 0 || index >= engineList.size()) { + return null; + } + return engineList.get(index).toString(); + } +} \ No newline at end of file diff --git a/ProjectAirFighter/src/CollectionGenericObjects/ICollectionGenericObjects.java b/ProjectAirFighter/src/CollectionGenericObjects/ICollectionGenericObjects.java new file mode 100644 index 0000000..6320149 --- /dev/null +++ b/ProjectAirFighter/src/CollectionGenericObjects/ICollectionGenericObjects.java @@ -0,0 +1,17 @@ +package CollectionGenericObjects; + +import Drawnings.DrawningAirCraft; + +public interface ICollectionGenericObjects { + int getCount(); + + void setMaxCount(int count); + + int insert(T obj); + + int insert(T obj, int index); + + T remove(int index); + + T get(int index); +} \ No newline at end of file diff --git a/ProjectAirFighter/src/CollectionGenericObjects/MassiveGenericObjects.java b/ProjectAirFighter/src/CollectionGenericObjects/MassiveGenericObjects.java new file mode 100644 index 0000000..2475788 --- /dev/null +++ b/ProjectAirFighter/src/CollectionGenericObjects/MassiveGenericObjects.java @@ -0,0 +1,90 @@ +package CollectionGenericObjects; + +import Drawnings.DrawningAirCraft; +import java.util.ArrayList; + +public class MassiveGenericObjects implements ICollectionGenericObjects { + private ArrayList _collection; + public MassiveGenericObjects() { + _collection = new ArrayList<>(); + + } + int maxCount = 0; + int realSize = 0; + @Override + public int getCount() { + return _collection.size(); + } + @Override + public int insert(T obj) { + return insert(obj, 0); + } + + @Override + public int insert(T obj, int position) { + if (position > maxCount|| position < 0) { + return -1; + } + + for (int i = position; i < maxCount; i++) { + if (_collection.get(i) == null) { + _collection.set(i, obj); + realSize++; + return i; + } + } + for (int i = position; i > 0; i--) { + if (_collection.get(i) == null) { + _collection.set(i, obj); + realSize++; + return i; + } + } + return -1; + } + + @Override + public T remove(int position) { + if (position < 0 || position >= maxCount) { + return null; + } + if (_collection.get(position) != null) { + T bf = _collection.get(position); + _collection.set(position, null); + --realSize; + return bf; + } + return null; + } + + @Override + public T get(int position) { + if (position >= 0 && position < _collection.size()) { + return _collection.get(position); + } + else { + return null; + } + } + + @Override + public void setMaxCount(int count) { + if (count > 0) { + if (!_collection.isEmpty()) { + ArrayList bfLoc = new ArrayList<>(count); + bfLoc.addAll(0, _collection); + _collection = bfLoc; + for (int i = 0; i < count - maxCount; i++) { + _collection.add(null); + } + } else { + _collection = new ArrayList<>(count); + for (int i = 0; i < count; i++) { + _collection.add(null); + } + + } + maxCount = count; + } + } +} \ No newline at end of file diff --git a/ProjectAirFighter/src/Drawnings/DrawningAbstractCompany.java b/ProjectAirFighter/src/Drawnings/DrawningAbstractCompany.java new file mode 100644 index 0000000..4a34f66 --- /dev/null +++ b/ProjectAirFighter/src/Drawnings/DrawningAbstractCompany.java @@ -0,0 +1,125 @@ +package Drawnings; + +import CollectionGenericObjects.AbstractCompany; +import CollectionGenericObjects.AirCraftAngar; +import CollectionGenericObjects.MassiveGenericObjects; +import Forms.FormAirFighter; +import Forms.FormConstructor; + +import javax.swing.*; +import java.awt.*; +import java.awt.event.WindowEvent; +import java.util.Random; + +public class DrawningAbstractCompany extends JComponent { + private AbstractCompany _company = null; + public void collectionComboBox_SelectedIndexChanged(JComboBox obj, int width, int height) { + switch (obj.getSelectedIndex()) { + case 1: + _company = new AirCraftAngar(width, height, new MassiveGenericObjects()); + break; + default: + break; + } + } + public void createObject(int type, JFrame obj) { + if (_company == null) { + return; + } + DrawningAirCraft _drawningAirCraft; + Random random = new Random(); + switch (type) { + case 0: + _drawningAirCraft = new DrawningAirCraft(random.nextInt(30, 100), random.nextInt(100,500), + getColorR(obj, random), random.nextInt(3)); + break; + case 1: + _drawningAirCraft = new DrawningAirFighter(random.nextInt(30, 100), random.nextInt(100,500), + getColorR(obj, random), random.nextInt(3), + getColorR(obj, random), + random.nextBoolean(), random.nextBoolean()); + break; + default: + return; + } + if (AbstractCompany.add(_company, _drawningAirCraft) != -1) { + JOptionPane.showMessageDialog(obj, "Объект добавлен"); + } + else { + JOptionPane.showMessageDialog(obj, "Не удалось добавить объект"); + } + } + Color getColorR(JFrame obj, Random rnd) { + Color color = new Color(rnd.nextInt(0, 256), rnd.nextInt(0, 256), rnd.nextInt(0, 256)); + if (obj == null) { + return color; + } + JColorChooser colorChooser = new JColorChooser(); + colorChooser.setColor(color); + return JColorChooser.showDialog(obj, "Выберите цвет", color); + } + + public void deleteButtonAction(int val, Frame obj) { + if (_company == null) { + return; + } + int result = JOptionPane.showConfirmDialog( + obj, + "Удалить объект?", + "Подтверждение", + JOptionPane.YES_NO_OPTION); + if (result == JOptionPane.YES_OPTION) { + if (AbstractCompany.remove(_company, val) != null) { + JOptionPane.showMessageDialog(obj, "Выполнено"); + } else { + JOptionPane.showMessageDialog(obj, "Удаление не удалось"); + } + } + } + public void goToCheckButtonAction() { + if (_company == null) { + return; + } + DrawningAirCraft airCraft = null; + int counter = 100; + while (airCraft == null && counter > 0) { + airCraft = _company.getRandomObject(); + --counter; + } + if (airCraft == null) { + return; + } + FormAirFighter formAirFighter = new FormAirFighter(); + formAirFighter.setDrawningAirCraft(airCraft); + formAirFighter.OpenFrame(); + } + + private DrawningAirCraft createObject; + public void getObjFromConstructor(JFrame obj) { + if (_company == null) { + return; + } + FormConstructor formConstructor = new FormConstructor(); + formConstructor.OpenFrame(); + + formConstructor.getAddButton().addActionListener(e -> { + createObject = formConstructor.getConstructor().getObj(); + if (AbstractCompany.add(_company, createObject) != -1) { + JOptionPane.showMessageDialog(obj, "Выполнено"); + + } else { + JOptionPane.showMessageDialog(obj, "Добавление не удалось"); + } + obj.repaint(); + formConstructor.getjFrameConstructor().dispatchEvent(new WindowEvent(formConstructor.getjFrameConstructor(), WindowEvent.WINDOW_CLOSING)); + }); + } + @Override + public void paintComponent(Graphics g) { + super.paintComponent(g); + if (_company == null) { + return; + } + _company.show(g); + } +} \ No newline at end of file diff --git a/ProjectAirFighter/src/Drawnings/DrawningAirCraft.java b/ProjectAirFighter/src/Drawnings/DrawningAirCraft.java index 3bb5bcd..0fa1dca 100644 --- a/ProjectAirFighter/src/Drawnings/DrawningAirCraft.java +++ b/ProjectAirFighter/src/Drawnings/DrawningAirCraft.java @@ -1,13 +1,13 @@ package Drawnings; -import Entities.EntityAirCraft; -import MovementStrategy.MovementDirection; +import Entities.*; +import MovementStrategy.*; 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; @@ -131,10 +136,10 @@ public class DrawningAirCraft { Graphics2D g2d = (Graphics2D) g; Point[] rtail = new Point[]{ + new Point(_startPosX+2, _startPosY + 25), + new Point(_startPosX+2, _startPosY + 8), + new Point(_startPosX + 10, _startPosY + 17), new Point(_startPosX + 10, _startPosY + 25), - new Point(_startPosX + 10, _startPosY + 8), - new Point(_startPosX + 20, _startPosY + 17), - new Point(_startPosX + 20, _startPosY + 25), }; Polygon rtailPolygon = new Polygon(); for (Point point : rtail) @@ -144,10 +149,10 @@ public class DrawningAirCraft { g2d.fillPolygon(rtailPolygon); Point[] ltail = new Point[]{ + new Point(_startPosX+2, _startPosY + 49), + new Point(_startPosX+2, _startPosY + 66), + new Point(_startPosX + 10, _startPosY + 57), new Point(_startPosX + 10, _startPosY + 49), - new Point(_startPosX + 10, _startPosY + 66), - new Point(_startPosX + 20, _startPosY + 57), - new Point(_startPosX + 20, _startPosY + 49), }; Polygon ltailPolygon = new Polygon(); for (Point point : ltail) @@ -157,10 +162,10 @@ public class DrawningAirCraft { g2d.fillPolygon(ltailPolygon); Point[] rwing = new Point[]{ - new Point(_startPosX + 45, _startPosY + 49), - new Point(_startPosX + 45, _startPosY + 74), - new Point(_startPosX + 37, _startPosY + 74), - new Point(_startPosX + 30, _startPosY + 49), + new Point(_startPosX + 35, _startPosY + 49), + new Point(_startPosX + 35, _startPosY + 74), + new Point(_startPosX + 27, _startPosY + 74), + new Point(_startPosX + 20, _startPosY + 49), }; Polygon rwingPolygon = new Polygon(); for (Point point : rwing) @@ -170,10 +175,10 @@ public class DrawningAirCraft { g2d.fillPolygon(rwingPolygon); Point[] lwing = new Point[]{ - new Point(_startPosX + 45, _startPosY + 25), - new Point(_startPosX + 45, _startPosY), - new Point(_startPosX + 37, _startPosY), - new Point(_startPosX + 30, _startPosY + 25), + new Point(_startPosX + 35, _startPosY + 25), + new Point(_startPosX + 35, _startPosY), + new Point(_startPosX + 27, _startPosY), + new Point(_startPosX + 20, _startPosY + 25), }; Polygon lwingPolygon = new Polygon(); for (Point point : lwing) @@ -182,13 +187,13 @@ public class DrawningAirCraft { g2d.setColor(entityAirCraft.getBodyColor()); g2d.fillPolygon(lwingPolygon); - g2d.drawRect(_startPosX + 10, _startPosY + 25, 50, 24); - g2d.fillRect(_startPosX + 10, _startPosY + 25, 50, 24); + g2d.drawRect(_startPosX , _startPosY + 24, 50, 25); + g2d.fillRect(_startPosX , _startPosY + 24, 50, 25); Point[] nose = new Point[]{ - new Point(_startPosX + 60, _startPosY + 25), - new Point(_startPosX + 76, _startPosY + 37), - new Point(_startPosX + 60, _startPosY + 49), + new Point(_startPosX + 50, _startPosY + 26), + new Point(_startPosX + 66, _startPosY + 37), + new Point(_startPosX + 50, _startPosY + 48), }; Polygon nosePolygon = new Polygon(); for (Point point : nose) diff --git a/ProjectAirFighter/src/Drawnings/DrawningAirFighter.java b/ProjectAirFighter/src/Drawnings/DrawningAirFighter.java index aa62b56..bf173d0 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); @@ -21,9 +22,9 @@ public class DrawningAirFighter extends DrawningAirCraft { if (entityAirFighter.getPgo()) { Point[] pgo1 = new Point[]{ - new Point(_startPosX + 50, _startPosY + 25), - new Point(_startPosX + 50, _startPosY + 15), - new Point(_startPosX + 55, _startPosY + 25), + new Point(_startPosX + 40, _startPosY + 25), + new Point(_startPosX + 40, _startPosY + 15), + new Point(_startPosX + 45, _startPosY + 25), }; Polygon pgo1Polygon = new Polygon(); for (Point point : pgo1) @@ -33,9 +34,9 @@ public class DrawningAirFighter extends DrawningAirCraft { g2d.fillPolygon(pgo1Polygon); Point[] pgo2 = new Point[]{ - new Point(_startPosX + 50, _startPosY + 49), - new Point(_startPosX + 50, _startPosY + 59), - new Point(_startPosX + 55, _startPosY + 49), + new Point(_startPosX + 40, _startPosY + 49), + new Point(_startPosX + 40, _startPosY + 59), + new Point(_startPosX + 45, _startPosY + 49), }; Polygon pgo2Polygon = new Polygon(); for (Point point : pgo2) @@ -47,10 +48,10 @@ public class DrawningAirFighter extends DrawningAirCraft { if (entityAirFighter.getRockets()) { Point[] rocket1 = new Point[]{ - new Point(_startPosX + 50, _startPosY + 71), - new Point(_startPosX + 50, _startPosY + 74), - new Point(_startPosX + 55, _startPosY + 69), - new Point(_startPosX + 50, _startPosY + 64), + new Point(_startPosX + 40, _startPosY + 71), + new Point(_startPosX + 40, _startPosY + 74), + new Point(_startPosX + 45, _startPosY + 69), + new Point(_startPosX + 40, _startPosY + 64), }; Polygon rocket1Polygon = new Polygon(); for (Point point : rocket1) @@ -59,14 +60,14 @@ public class DrawningAirFighter extends DrawningAirCraft { g2d.setColor(entityAirFighter.getAdditionalColor()); g2d.fillPolygon(rocket1Polygon); - g.drawRect(_startPosX + 45, _startPosY + 67, 5, 4); - g.fillRect(_startPosX + 45, _startPosY + 67, 5, 4); + g.drawRect(_startPosX + 35, _startPosY + 67, 5, 4); + g.fillRect(_startPosX + 35, _startPosY + 67, 5, 4); Point[] rocket2 = new Point[]{ - new Point(_startPosX + 50, _startPosY + 7), - new Point(_startPosX + 50, _startPosY + 10), - new Point(_startPosX + 55, _startPosY + 5), - new Point(_startPosX + 50, _startPosY), + new Point(_startPosX + 40, _startPosY + 7), + new Point(_startPosX + 40, _startPosY + 10), + new Point(_startPosX + 45, _startPosY + 5), + new Point(_startPosX + 40, _startPosY), }; Polygon rocket2Polygon = new Polygon(); for (Point point : rocket2) @@ -75,8 +76,8 @@ public class DrawningAirFighter extends DrawningAirCraft { g2d.setColor(entityAirFighter.getAdditionalColor()); g2d.fillPolygon(rocket2Polygon); - g.drawRect(_startPosX + 45, _startPosY + 3, 5, 4); - g.fillRect(_startPosX + 45, _startPosY + 3, 5, 4); + g.drawRect(_startPosX + 35, _startPosY + 3, 5, 4); + g.fillRect(_startPosX + 35, _startPosY + 3, 5, 4); } } } \ No newline at end of file diff --git a/ProjectAirFighter/src/Drawnings/DrawningConstructor.java b/ProjectAirFighter/src/Drawnings/DrawningConstructor.java new file mode 100644 index 0000000..1879c59 --- /dev/null +++ b/ProjectAirFighter/src/Drawnings/DrawningConstructor.java @@ -0,0 +1,78 @@ +package Drawnings; + +import CollectionGenericObjects.Constructor; +import Entities.EntityAirCraft; +import Entities.EntityAirFighter; + +import javax.swing.*; +import java.awt.*; +import java.util.Random; + +public class DrawningConstructor extends JComponent { + Constructor constructor = new Constructor<>(); + private DrawningAirCraft obj; + public DrawningAirCraft getObj() { + return obj; + } + public DrawningConstructor() { + for (int i = 0; i < 3; i++) { + EntityAirCraft _entityAirCraft = null; + IDrawEngine _drawEngine = null; + Random rnd = new Random(); + int Type = rnd.nextInt(3); + switch (Type) { + case 0: + _drawEngine = new DrawningEngine(); + break; + case 1: + _drawEngine = new DrawningOvalEngine(); + break; + case 2: + _drawEngine = new DrawningLongEngine(); + break; + } + int[] countengine = {2, 4, 6}; + int engineCount = countengine[rnd.nextInt(countengine.length)]; + _drawEngine.setNumber(engineCount); + + int typeAir = rnd.nextInt(0,2); + + switch (typeAir) { + case 0: + _entityAirCraft = new EntityAirCraft(rnd.nextInt(70 - 30) + 30, rnd.nextInt(500 - 100) + 100, + new Color(rnd.nextInt(0, 256), rnd.nextInt(0, 256), rnd.nextInt(0, 256))); + break; + case 1: + _entityAirCraft = new EntityAirFighter(rnd.nextInt(70 - 30) + 30, rnd.nextInt(500 - 100) + 100, + new Color(rnd.nextInt(0, 256), rnd.nextInt(0, 256), rnd.nextInt(0, 256)), + new Color(rnd.nextInt(0, 256), rnd.nextInt(0, 256), rnd.nextInt(0, 256)), + rnd.nextBoolean(), rnd.nextBoolean()); + break; + } + constructor.addAirCraft(_entityAirCraft); + constructor.addAirCraft(_drawEngine); + } + obj = constructor.getRandomAirCraft(); + + } + public void reCreateObj() { + obj = constructor.getRandomAirCraft(); + } + + public String getEntityString(int index) { + return constructor.getEntityDescription(index); + } + public String getEngineString(int index) { + return constructor.getEngineDescription(index); + } + @Override + public void paintComponent(Graphics g) { + super.paintComponent(g); + if (obj != null) { + obj.setPosition(10, 30); + obj.setPictureSize(350, 300); + obj.drawAirCraft(g); + } + super.repaint(); + } +} \ No newline at end of file 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/DrawningFormAirFighter.java b/ProjectAirFighter/src/Drawnings/DrawningFormAirFighter.java new file mode 100644 index 0000000..e502bb6 --- /dev/null +++ b/ProjectAirFighter/src/Drawnings/DrawningFormAirFighter.java @@ -0,0 +1,69 @@ +package Drawnings; + +import MovementStrategy.*; + +import javax.swing.*; +import java.awt.*; + +public class DrawningFormAirFighter extends JComponent { + DrawningAirCraft drawningAirCraft; + + private int _pictureHeight = -1; + private int _pictureWidth = -1; + private AbstractStrategy _strategy; + public void setDrawningAirCraft(DrawningAirCraft drawningAirCraft) { + this.drawningAirCraft = drawningAirCraft; + } + + public boolean setPictureSize(int width, int height) { + if (drawningAirCraft.GetHeight() > height || drawningAirCraft.GetWidth() > width) + return false; + _pictureHeight = height; + _pictureWidth = width; + return true; + } + public void buttonStrategyStep(JComboBox comboBox) { + if (drawningAirCraft == null) + return; + if (comboBox.isEnabled()) { + switch (comboBox.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), _pictureWidth, _pictureHeight); + } + if (_strategy == null) { + return; + } + comboBox.setEnabled(false); + _strategy.MakeStep(); + if (_strategy.GetStatus() == StrategyStatus.Finish) { + comboBox.setEnabled(true); + _strategy = null; + } + + } + public void MoveButtonsAction(MovementDirection direction) { + if (drawningAirCraft == null) + return; + drawningAirCraft.moveTransport(direction); + } + @Override + protected void paintComponent(Graphics g) { + super.paintComponent(g); + if (drawningAirCraft == null) { + return; + } + drawningAirCraft.drawAirCraft(g); + } +} \ 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/Forms/FormAirCraftCollection.java b/ProjectAirFighter/src/Forms/FormAirCraftCollection.java new file mode 100644 index 0000000..500f349 --- /dev/null +++ b/ProjectAirFighter/src/Forms/FormAirCraftCollection.java @@ -0,0 +1,161 @@ +package Forms; + +import Drawnings.DrawningAbstractCompany; +import javax.swing.*; +import javax.swing.text.NumberFormatter; +import java.awt.*; +import java.awt.event.ComponentAdapter; +import java.awt.event.ComponentEvent; +import java.text.NumberFormat; + +public class FormAirCraftCollection extends JFrame { + final private JFrame jFrameCollectionAirCraft = new JFrame(); + final private DrawningAbstractCompany _company = new DrawningAbstractCompany(); + final private JButton refreshButton = new JButton("Обновить"); + final private JPanel refreshPanel = new JPanel(); + final private String[] listOfComboBox = { + + "", + "Хранилище" + }; + final private JComboBox comboBoxSelectorCompany = new JComboBox<>(listOfComboBox); + final private JPanel comboBoxPanel = new JPanel(); + final private JPanel toolsPanel = new JPanel(); + final private JLabel toolsNameLabel = new JLabel("Инструменты"); + final private JPanel labelPanel = new JPanel(); + final private JButton buttonAddAirCraft = new JButton("Добавить самолёт"); + final private JButton buttonAddAirFighter = new JButton("Добавить истребитель"); + final private JPanel addAirCraftPanel = new JPanel(); + final private JPanel addAirFighterPanel = new JPanel(); + final private JButton buttonRemove = new JButton("Удалить самолёт"); + final private JPanel removePanel = new JPanel(); + final private JButton goToCheckButton = new JButton("Отправить на тесты"); + final private JPanel goToCheckPanel = new JPanel(); + final private JPanel addFromConstructorPanel = new JPanel(); + final private JButton addFromConstructorButton = new JButton("Добавить из конструктора"); + + public void OpenFrame() { + + jFrameCollectionAirCraft.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + Toolkit tolls = Toolkit.getDefaultToolkit(); + Dimension dimension = tolls.getScreenSize(); + jFrameCollectionAirCraft.setBounds(dimension.width / 2 - 250, dimension.height / 2 - 250, + 1200, 665); + jFrameCollectionAirCraft.setTitle("Коллекция самолётов"); + + toolsPanel.setBackground(Color.BLACK); + labelPanel.setSize(new Dimension(100, 20)); + labelPanel.add(toolsNameLabel); + + comboBoxPanel.setLayout(new BorderLayout()); + comboBoxPanel.setSize(new Dimension(130, 30)); + comboBoxPanel.add(comboBoxSelectorCompany, BorderLayout.CENTER); + + addAirCraftPanel.setLayout(new BorderLayout()); + addAirCraftPanel.setSize(170, 40); + addAirCraftPanel.add(buttonAddAirCraft, BorderLayout.CENTER); + + addAirFighterPanel.setLayout(new BorderLayout()); + addAirFighterPanel.setSize(170, 40); + addAirFighterPanel.add(buttonAddAirFighter, BorderLayout.CENTER); + + removePanel.setLayout(new BorderLayout()); + removePanel.setSize(170, 40); + removePanel.add(buttonRemove, BorderLayout.CENTER); + + goToCheckPanel.setLayout(new BorderLayout()); + goToCheckPanel.setSize(170, 40); + goToCheckPanel.add(goToCheckButton, BorderLayout.CENTER); + + refreshPanel.setLayout(new BorderLayout()); + refreshPanel.setSize(170, 40); + refreshPanel.add(refreshButton, BorderLayout.CENTER); + + addFromConstructorPanel.setLayout(new BorderLayout()); + addFromConstructorPanel.setSize(170, 40); + addFromConstructorPanel.add(addFromConstructorButton, BorderLayout.CENTER); + + NumberFormat format = NumberFormat.getInstance(); + NumberFormatter formatter = new NumberFormatter(format); + formatter.setValueClass(Integer.class); + formatter.setMinimum(0); + formatter.setMaximum(100); + formatter.setAllowsInvalid(true); + formatter.setCommitsOnValidEdit(true); + + JTextField textBoxPosition = new JFormattedTextField(formatter); + JPanel textBoxPanel = new JPanel(); + textBoxPanel.setLayout(new BorderLayout()); + textBoxPanel.setSize(170, 40); + textBoxPanel.add(textBoxPosition, BorderLayout.CENTER); + + jFrameCollectionAirCraft.add(toolsPanel); + jFrameCollectionAirCraft.add(labelPanel); + jFrameCollectionAirCraft.add(comboBoxPanel); + jFrameCollectionAirCraft.add(addAirCraftPanel); + jFrameCollectionAirCraft.add(addAirFighterPanel); + jFrameCollectionAirCraft.add(textBoxPanel); + jFrameCollectionAirCraft.add(removePanel); + jFrameCollectionAirCraft.add(goToCheckPanel); + jFrameCollectionAirCraft.add(refreshPanel); + jFrameCollectionAirCraft.add(addFromConstructorPanel); + jFrameCollectionAirCraft.add(_company); + + jFrameCollectionAirCraft.addComponentListener(new ComponentAdapter() { + public void componentResized(ComponentEvent componentEvent) { + labelPanel.setLocation(jFrameCollectionAirCraft.getWidth() - 210, 0); + toolsPanel.setLocation(jFrameCollectionAirCraft.getWidth() - 233, 0); + comboBoxPanel.setLocation(jFrameCollectionAirCraft.getWidth() - 200, 30); + addAirCraftPanel.setLocation(jFrameCollectionAirCraft.getWidth() - 200, 70); + addAirFighterPanel.setLocation(jFrameCollectionAirCraft.getWidth() - 200, 120); + textBoxPanel.setLocation(jFrameCollectionAirCraft.getWidth() - 200, 220); + removePanel.setLocation(jFrameCollectionAirCraft.getWidth() - 200, 260); + goToCheckPanel.setLocation(jFrameCollectionAirCraft.getWidth() - 200, 300); + refreshPanel.setLocation(jFrameCollectionAirCraft.getWidth() - 200, 340); + addFromConstructorPanel.setLocation(jFrameCollectionAirCraft.getWidth() - 200, 170); + toolsPanel.setSize(new Dimension(10, jFrameCollectionAirCraft.getHeight())); + + jFrameCollectionAirCraft.repaint(); + } + }); + + comboBoxSelectorCompany.addActionListener(e -> { + + _company.collectionComboBox_SelectedIndexChanged(comboBoxSelectorCompany, + jFrameCollectionAirCraft.getWidth() - 233, jFrameCollectionAirCraft.getHeight()); + jFrameCollectionAirCraft.repaint(); + + }); + buttonAddAirCraft.addActionListener(e -> { + _company.createObject(0, jFrameCollectionAirCraft); + jFrameCollectionAirCraft.repaint(); + }); + buttonAddAirFighter.addActionListener(e -> { + _company.createObject(1, jFrameCollectionAirCraft); + jFrameCollectionAirCraft.repaint(); + }); + + buttonRemove.addActionListener(e -> { + if (!textBoxPosition.getText().isEmpty()) { + if (Integer.parseInt(textBoxPosition.getText()) <= 99 + && Integer.parseInt(textBoxPosition.getText()) >= 0) { + int pos = Integer.parseInt(textBoxPosition.getText()); + _company.deleteButtonAction(pos, jFrameCollectionAirCraft); + } + } + jFrameCollectionAirCraft.repaint(); + + }); + refreshButton.addActionListener(e -> { + jFrameCollectionAirCraft.repaint(); + }); + goToCheckButton.addActionListener(e -> { + _company.goToCheckButtonAction(); + jFrameCollectionAirCraft.repaint(); + }); + addFromConstructorButton.addActionListener(e -> { + _company.getObjFromConstructor(jFrameCollectionAirCraft); + }); + jFrameCollectionAirCraft.setVisible(true); + } +} \ No newline at end of file diff --git a/ProjectAirFighter/src/Forms/FormAirFighter.java b/ProjectAirFighter/src/Forms/FormAirFighter.java new file mode 100644 index 0000000..e2352ae --- /dev/null +++ b/ProjectAirFighter/src/Forms/FormAirFighter.java @@ -0,0 +1,112 @@ +package Forms; + +import Drawnings.*; +import MovementStrategy.*; +import javax.swing.*; +import java.awt.*; +import java.awt.event.ComponentAdapter; +import java.awt.event.ComponentEvent; + + +public class FormAirFighter extends JFrame { + final private JFrame JFrameAirFighter = new JFrame(); + final private JButton buttonRight = new JButton(new ImageIcon("ProjectAirFighter\\Resources\\arrowRight.png")); + final private JPanel RightPanel = new JPanel(); + final private JButton buttonDown = new JButton(new ImageIcon("ProjectAirFighter\\Resources\\arrowDown.png")); + final private JPanel DownPanel = new JPanel(); + final private JButton buttonLeft = new JButton(new ImageIcon("ProjectAirFighter\\Resources\\arrowLeft.png")); + final private JPanel LeftPanel = new JPanel(); + final private JButton buttonUp = new JButton(new ImageIcon("ProjectAirFighter\\Resources\\arrowUp.png")); + + final private JPanel UpPanel = new JPanel(); + final private String [] itemsComboBox = { + "К центру", + "К краю" + }; + final private JComboBox comboBoxStrategy =new JComboBox<>(itemsComboBox); + final private JButton buttonStrategyStep = new JButton("Шаг"); + final private JPanel StrategyPanel = new JPanel(new BorderLayout()); + + final private DrawningFormAirFighter form = new DrawningFormAirFighter(); + public void setDrawningAirCraft(DrawningAirCraft airCraft) {form.setDrawningAirCraft(airCraft);} + public void OpenFrame() { + JFrameAirFighter.setVisible(true); + Toolkit tolls = Toolkit.getDefaultToolkit(); + Dimension dimension = tolls.getScreenSize(); + JFrameAirFighter.setBounds(dimension.width / 2 - 250, dimension.height / 2 - 250, + 970, 700); + JFrameAirFighter.setTitle("Истребитель"); + + comboBoxStrategy.setPreferredSize(new Dimension(100, 35)); + buttonStrategyStep.setPreferredSize(new Dimension(100, 35)); + StrategyPanel.setSize(100, 70); + StrategyPanel.add(comboBoxStrategy, BorderLayout.NORTH); + StrategyPanel.add(buttonStrategyStep, BorderLayout.SOUTH); + + + UpPanel.setSize(30, 30); + buttonUp.setPreferredSize(new Dimension(30, 30)); + UpPanel.add(buttonUp, BorderLayout.CENTER); + + DownPanel.setSize(30, 30); + buttonDown.setPreferredSize(new Dimension(30, 30)); + DownPanel.add(buttonDown, BorderLayout.CENTER); + + RightPanel.setSize(30, 30); + buttonRight.setPreferredSize(new Dimension(30, 30)); + RightPanel.add(buttonRight, BorderLayout.CENTER); + + LeftPanel.setSize(30, 30); + buttonLeft.setPreferredSize(new Dimension(30, 30)); + LeftPanel.add(buttonLeft, BorderLayout.CENTER); + + JFrameAirFighter.add(StrategyPanel); + JFrameAirFighter.add(UpPanel); + JFrameAirFighter.add(DownPanel); + JFrameAirFighter.add(RightPanel); + JFrameAirFighter.add(LeftPanel); + JFrameAirFighter.add(form); + + JFrameAirFighter.addComponentListener(new ComponentAdapter() { + public void componentResized(ComponentEvent e) { + StrategyPanel.setLocation(JFrameAirFighter.getWidth() - 100, 0); + UpPanel.setLocation(JFrameAirFighter.getWidth() - 80, JFrameAirFighter.getHeight()-100); + DownPanel.setLocation(JFrameAirFighter.getWidth() - 80, JFrameAirFighter.getHeight()-70); + RightPanel.setLocation(JFrameAirFighter.getWidth() - 45, JFrameAirFighter.getHeight()-70); + LeftPanel.setLocation(JFrameAirFighter.getWidth() - 115, JFrameAirFighter.getHeight()-70); + + form.setPictureSize(JFrameAirFighter.getWidth(), JFrameAirFighter.getHeight()); + JFrameAirFighter.repaint(); + + } + + }); + + buttonUp.addActionListener(e -> { + form.setPictureSize(JFrameAirFighter.getWidth(), JFrameAirFighter.getHeight()); + form.MoveButtonsAction(MovementDirection.Up); + JFrameAirFighter.repaint(); + }); + + buttonDown.addActionListener(e -> { + form.setPictureSize(JFrameAirFighter.getWidth(), JFrameAirFighter.getHeight()); + form.MoveButtonsAction(MovementDirection.Down); + JFrameAirFighter.repaint(); + }); + buttonLeft.addActionListener(e -> { + form.setPictureSize(JFrameAirFighter.getWidth(), JFrameAirFighter.getHeight()); + form.MoveButtonsAction(MovementDirection.Left); + JFrameAirFighter.repaint(); + }); + buttonRight.addActionListener(e -> { + form.setPictureSize(JFrameAirFighter.getWidth(), JFrameAirFighter.getHeight()); + form.MoveButtonsAction(MovementDirection.Right); + JFrameAirFighter.repaint(); + }); + buttonStrategyStep.addActionListener(e -> { + form.setPictureSize(JFrameAirFighter.getWidth(), JFrameAirFighter.getHeight()); + form.buttonStrategyStep(comboBoxStrategy); + JFrameAirFighter.repaint(); + }); + } +} \ No newline at end of file diff --git a/ProjectAirFighter/src/Forms/FormConstructor.java b/ProjectAirFighter/src/Forms/FormConstructor.java new file mode 100644 index 0000000..4977bfe --- /dev/null +++ b/ProjectAirFighter/src/Forms/FormConstructor.java @@ -0,0 +1,90 @@ +package Forms; + +import Drawnings.DrawningConstructor; + +import javax.swing.*; +import java.awt.*; +import java.awt.event.ComponentAdapter; +import java.awt.event.ComponentEvent; + +public class FormConstructor extends JFrame { + private JFrame jFrameConstructor = new JFrame(); + public JFrame getjFrameConstructor() { + return jFrameConstructor; + } + private JButton addButton = new JButton("Добавить объект"); + public JButton getAddButton() { + return addButton; + } + public JButton reCreateButton = new JButton("Пересоздать"); + private final DrawningConstructor constructor = new DrawningConstructor(); + public DrawningConstructor getConstructor() { + return constructor; + } + JPanel entitiesInfoPanel = new JPanel(); + JLabel firstEntityLabel = new JLabel(); + JLabel secondEntityLabel = new JLabel(); + JLabel thirdEntityLabel = new JLabel(); + + JPanel engineInfoPanel = new JPanel(); + JLabel firstEngineLabel = new JLabel(); + JLabel secondEngineLabel = new JLabel(); + JLabel thirdEngineLabel = new JLabel(); + + public void OpenFrame() { + + Toolkit tolls = Toolkit.getDefaultToolkit(); + Dimension dimension = tolls.getScreenSize(); + jFrameConstructor.setBounds(dimension.width / 2 - 250, dimension.height / 2 - 250, + 800, 300); + jFrameConstructor.setLayout(new BorderLayout()); + + firstEntityLabel.setText(constructor.getEntityString(0)); + secondEntityLabel.setText(constructor.getEntityString(1)); + thirdEntityLabel.setText(constructor.getEntityString(2)); + + entitiesInfoPanel.setLayout(new BoxLayout(entitiesInfoPanel, BoxLayout.Y_AXIS)); + entitiesInfoPanel.setBorder(BorderFactory.createTitledBorder("Entities")); + entitiesInfoPanel.setSize(500, 130); + entitiesInfoPanel.setLocation(150, 10); + entitiesInfoPanel.add(firstEntityLabel); + entitiesInfoPanel.add(secondEntityLabel); + entitiesInfoPanel.add(thirdEntityLabel); + + firstEngineLabel.setText(constructor.getEngineString(0)); + secondEngineLabel.setText(constructor.getEngineString(1)); + thirdEngineLabel.setText(constructor.getEngineString(2)); + + + engineInfoPanel.setLayout(new BoxLayout(engineInfoPanel, BoxLayout.Y_AXIS)); + engineInfoPanel.setBorder(BorderFactory.createTitledBorder("Engine")); + engineInfoPanel.setSize(500, 130); + engineInfoPanel.setLocation(150, 150); + engineInfoPanel.add(firstEngineLabel); + engineInfoPanel.add(secondEngineLabel); + engineInfoPanel.add(thirdEngineLabel); + + addButton.setBounds(0, jFrameConstructor.getHeight() - 105, 150, 50); + reCreateButton.setBounds(0, jFrameConstructor.getHeight() - 135, 150, 30); + + jFrameConstructor.add(engineInfoPanel); + jFrameConstructor.add(entitiesInfoPanel); + jFrameConstructor.add(addButton); + jFrameConstructor.add(reCreateButton); + jFrameConstructor.add(constructor); + jFrameConstructor.revalidate(); + jFrameConstructor.repaint(); + + jFrameConstructor.addComponentListener(new ComponentAdapter() { + public void componentResized(ComponentEvent componentEvent) { + addButton.setLocation(0, jFrameConstructor.getSize().height - 105); + reCreateButton.setLocation(0, jFrameConstructor.getSize().height - 135); + } + }); + reCreateButton.addActionListener(e -> { + constructor.reCreateObj(); + jFrameConstructor.repaint(); + }); + jFrameConstructor.setVisible(true); + } +} \ 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