Compare commits

...

2 Commits

Author SHA1 Message Date
artur-kalimullin
23058f6672 Готово 2024-06-16 00:33:20 +04:00
artur-kalimullin
e714e00fdb Почти готово 2024-06-15 20:40:11 +04:00
8 changed files with 101 additions and 107 deletions

View File

@ -6,8 +6,8 @@ import java.awt.*;
import java.util.Random;
public abstract class AbstractCompany {
protected final int _placeSizeWidth = 210;
protected final int _placeSizeHeight = 120;
protected final int _placeSizeWidth = 100;
protected final int _placeSizeHeight = 86;
protected final int _pictureWidth;
protected final int _pictureHeight;
protected ICollectionGenericObjects<DrawningAirCraft> _collection = null;

View File

@ -9,35 +9,31 @@ import java.util.List;
public class AirCraftAngar extends AbstractCompany {
private final List<Point> locCoord = new ArrayList<>();
private int numRows, numCols;
public AirCraftAngar(int picWidth, int picHeight, ICollectionGenericObjects<DrawningAirCraft> collection) {
super(picWidth, picHeight, collection);
_collection.setMaxCount(30);
}
int pamat_i = 0;
int pamat_j = 0;
@Override
protected void drawBackground(Graphics g) {
Color backgroundColor = new Color(255, 255, 255);
g.setColor(backgroundColor);
g.fillRect(0, 0, _pictureWidth, _pictureHeight);
g.setColor(new Color(165, 42, 42)); // Brown
int offsetX = 10, offsetY = -5;
int x = 1 + offsetX, y = _pictureHeight - _placeSizeHeight + offsetY;
numRows = 0;
while (y >= 0) {
int numCols = 0;
while (x + _placeSizeWidth <= _pictureWidth) {
numCols++;
g.drawLine(x, y, x + _placeSizeWidth / 2, y);
g.drawLine(x, y, x, y + _placeSizeHeight + 4);
locCoord.add(new Point(x, y));
x += _placeSizeWidth + 2;
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));
}
numRows++;
x = 1 + offsetX;
y -= _placeSizeHeight + 5 + offsetY;
g.drawLine(i * _placeSizeWidth, _placeSizeHeight * (_pictureHeight / _placeSizeHeight), (int) (_placeSizeWidth * (i + 0.5f)), _placeSizeHeight * (_pictureHeight / _placeSizeHeight));
}
}
@Override
@ -45,18 +41,15 @@ public class AirCraftAngar extends AbstractCompany {
if (locCoord == null || _collection == null) {
return;
}
int row = numRows - 1, col = numCols;
for (int i=0;i< _collection.getCount(); i++, col--) {
if (_collection.get(i) != null) {
_collection.get(i).setPictureSize(_pictureWidth, _pictureHeight);
_collection.get(i).setPosition((int)locCoord.get(row*numCols - col).getX() + 5,
(int)locCoord.get(row*numCols - col).getY() + 9);
if (col == 1) {
col = numCols + 1;
row--;
}
}
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);
}
}
}
}

View File

@ -21,7 +21,7 @@ public class Constructor<T extends EntityAirCraft, U extends IDrawEngine> {
public DrawningAirCraft getRandomAirCraft() {
Random rnd = new Random();
int entityIndex = rnd.nextInt(0, 3);
int entityIndex = rnd.nextInt(0, 2);
int engineIndex = rnd.nextInt(0, 3);
T entity = entitiesList.get(entityIndex);

View File

@ -1,7 +1,7 @@
package Drawnings;
import Entities.EntityAirCraft;
import MovementStrategy.MovementDirection;
import Entities.*;
import MovementStrategy.*;
import java.awt.*;
import java.util.Random;
@ -79,7 +79,7 @@ public class DrawningAirCraft {
_startPosX = x;
_startPosY = y;
if (_drawingAirCraftWidth + x > _pictureWidth || x < 0) {
if (x > _pictureWidth - _drawingAirCraftWidth) {
_startPosX = 0;
}
if (_drawingAirCraftHeight + y > _pictureHeight || y < 0) {
@ -136,10 +136,10 @@ public class DrawningAirCraft {
Graphics2D g2d = (Graphics2D) g;
Point[] rtail = new Point[]{
new Point(_startPosX , _startPosY + 25),
new Point(_startPosX , _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)
@ -149,10 +149,10 @@ public class DrawningAirCraft {
g2d.fillPolygon(rtailPolygon);
Point[] ltail = new Point[]{
new Point(_startPosX, _startPosY + 49),
new Point(_startPosX , _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)
@ -162,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)
@ -175,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)
@ -187,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 + 25, 50, 24);
g2d.fillRect(_startPosX , _startPosY + 25, 50, 24);
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 + 25),
new Point(_startPosX + 66, _startPosY + 37),
new Point(_startPosX + 50, _startPosY + 49),
};
Polygon nosePolygon = new Polygon();
for (Point point : nose)

View File

@ -1,12 +1,12 @@
package Drawnings;
import Entities.EntityAirFighter;
import Entities.*;
import java.awt.*;
public class DrawningAirFighter extends DrawningAirCraft {
public DrawningAirFighter(int speed, float weight, Color bodyColor, int engineType, Color additionalColor, boolean pgo, boolean rockets) {
super(speed, weight, bodyColor, engineType, 76, 80);
super(speed, weight, bodyColor, engineType, 66, 74);
entityAirCraft = new EntityAirFighter(speed, weight, bodyColor, additionalColor, pgo, rockets);
}
@ -22,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)
@ -34,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)
@ -48,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)
@ -60,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)
@ -76,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);
}
}
}

View File

@ -31,18 +31,19 @@ public class DrawningConstructor extends JComponent {
_drawEngine = new DrawningLongEngine();
break;
}
int engineCount = rnd.nextInt(1,4);
int[] countengine = {2, 4, 6};
int engineCount = countengine[rnd.nextInt(countengine.length)];
_drawEngine.setNumber(engineCount);
int typeBoat = rnd.nextInt(0,2);
switch (typeBoat) {
case 0:
_entityAirCraft = new EntityAirCraft(rnd.nextInt(30,100), rnd.nextInt(100,500),
_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(30,100), rnd.nextInt(100,500),
_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());
@ -69,7 +70,7 @@ public class DrawningConstructor extends JComponent {
super.paintComponent(g);
if (obj != null) {
obj.setPosition(10, 30);
obj.setPictureSize(400, 300);
obj.setPictureSize(350, 300);
obj.drawAirCraft(g);
}
super.repaint();

View File

@ -25,8 +25,8 @@ public class FormAirCraftCollection extends JFrame {
final private JPanel labelPanel = new JPanel();
final private JButton buttonAddAirCraft = new JButton("Добавить самолёт");
final private JButton buttonAddAirFighter = new JButton("Добавить истребитель");
final private JPanel addBoatPanel = new JPanel();
final private JPanel addCatamaranPanel = new JPanel();
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("Отправить на тесты");
@ -51,13 +51,13 @@ public class FormAirCraftCollection extends JFrame {
comboBoxPanel.setSize(new Dimension(130, 30));
comboBoxPanel.add(comboBoxSelectorCompany, BorderLayout.CENTER);
addBoatPanel.setLayout(new BorderLayout());
addBoatPanel.setSize(170, 40);
addBoatPanel.add(buttonAddAirCraft, BorderLayout.CENTER);
addAirCraftPanel.setLayout(new BorderLayout());
addAirCraftPanel.setSize(170, 40);
addAirCraftPanel.add(buttonAddAirCraft, BorderLayout.CENTER);
addCatamaranPanel.setLayout(new BorderLayout());
addCatamaranPanel.setSize(170, 40);
addCatamaranPanel.add(buttonAddAirFighter, BorderLayout.CENTER);
addAirFighterPanel.setLayout(new BorderLayout());
addAirFighterPanel.setSize(170, 40);
addAirFighterPanel.add(buttonAddAirFighter, BorderLayout.CENTER);
removePanel.setLayout(new BorderLayout());
removePanel.setSize(170, 40);
@ -92,8 +92,8 @@ public class FormAirCraftCollection extends JFrame {
jFrameCollectionAirCraft.add(toolsPanel);
jFrameCollectionAirCraft.add(labelPanel);
jFrameCollectionAirCraft.add(comboBoxPanel);
jFrameCollectionAirCraft.add(addBoatPanel);
jFrameCollectionAirCraft.add(addCatamaranPanel);
jFrameCollectionAirCraft.add(addAirCraftPanel);
jFrameCollectionAirCraft.add(addAirFighterPanel);
jFrameCollectionAirCraft.add(textBoxPanel);
jFrameCollectionAirCraft.add(removePanel);
jFrameCollectionAirCraft.add(goToCheckPanel);
@ -106,8 +106,8 @@ public class FormAirCraftCollection extends JFrame {
labelPanel.setLocation(jFrameCollectionAirCraft.getWidth() - 210, 0);
toolsPanel.setLocation(jFrameCollectionAirCraft.getWidth() - 233, 0);
comboBoxPanel.setLocation(jFrameCollectionAirCraft.getWidth() - 200, 30);
addBoatPanel.setLocation(jFrameCollectionAirCraft.getWidth() - 200, 70);
addCatamaranPanel.setLocation(jFrameCollectionAirCraft.getWidth() - 200, 120);
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);

View File

@ -26,10 +26,10 @@ public class FormConstructor extends JFrame {
JLabel secondEntityLabel = new JLabel();
JLabel thirdEntityLabel = new JLabel();
JPanel paddlesInfoPanel = new JPanel();
JLabel firstPaddlesLabel = new JLabel();
JLabel secondPaddlesLabel = new JLabel();
JLabel thirdPaddlesLabel = new JLabel();
JPanel engineInfoPanel = new JPanel();
JLabel firstEngineLabel = new JLabel();
JLabel secondEngineLabel = new JLabel();
JLabel thirdEngineLabel = new JLabel();
public void OpenFrame() {
@ -51,23 +51,23 @@ public class FormConstructor extends JFrame {
entitiesInfoPanel.add(secondEntityLabel);
entitiesInfoPanel.add(thirdEntityLabel);
firstPaddlesLabel.setText(constructor.getEngineString(0));
secondPaddlesLabel.setText(constructor.getEngineString(1));
thirdPaddlesLabel.setText(constructor.getEngineString(2));
firstEngineLabel.setText(constructor.getEngineString(0));
secondEngineLabel.setText(constructor.getEngineString(1));
thirdEngineLabel.setText(constructor.getEngineString(2));
paddlesInfoPanel.setLayout(new BoxLayout(paddlesInfoPanel, BoxLayout.Y_AXIS));
paddlesInfoPanel.setBorder(BorderFactory.createTitledBorder("Engine"));
paddlesInfoPanel.setSize(500, 130);
paddlesInfoPanel.setLocation(150, 150);
paddlesInfoPanel.add(firstPaddlesLabel);
paddlesInfoPanel.add(secondPaddlesLabel);
paddlesInfoPanel.add(thirdPaddlesLabel);
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(paddlesInfoPanel);
jFrameConstructor.add(engineInfoPanel);
jFrameConstructor.add(entitiesInfoPanel);
jFrameConstructor.add(addButton);
jFrameConstructor.add(reCreateButton);