Готово

This commit is contained in:
artur-kalimullin 2024-06-16 00:33:20 +04:00
parent e714e00fdb
commit 23058f6672
6 changed files with 70 additions and 77 deletions

View File

@ -6,13 +6,13 @@ 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;
public int getMaxCount() {
return _pictureWidth * _pictureHeight / (_placeSizeWidth*_placeSizeHeight);
return _pictureWidth * _pictureHeight / (_placeSizeWidth * _placeSizeHeight);
}
public AbstractCompany(int picWidth, int picHeight, ICollectionGenericObjects<DrawningAirCraft> collection) {
this._pictureWidth = picWidth;

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

@ -70,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();