Внес поправки в структуру классов

This commit is contained in:
ShipilovNikita 2024-02-19 11:24:47 +04:00
parent e20c8d5209
commit 1578c07887
2 changed files with 50 additions and 52 deletions

View File

@ -9,7 +9,6 @@ public class DrawingSeaplane {
private Integer _startPosY;
private final int drawingSeaplaneWidth = 190;
private final int drawingSeaplaneHeight = 90;
private final int drawingKeelHeight = 35;
private DrawingSeaplanePortholes _drawingSeaplanePortholes;
public EntitySeaplane EntitySeaplane() {
return entitySeaplane;
@ -24,7 +23,7 @@ public class DrawingSeaplane {
_drawingSeaplanePortholes = new DrawingSeaplanePortholes(entitySeaplane);
Random random = new Random();
int paddlesCount = random.nextInt(1,4);
_drawingSeaplanePortholes.setEnumNumber(paddlesCount * 10);
_drawingSeaplanePortholes.setPortholesCount(paddlesCount * 10);
}
public void setPictureSize(int width, int height) {
@ -43,8 +42,8 @@ public class DrawingSeaplane {
x = pictureWidth - drawingSeaplaneWidth - drawingSeaplaneWidth;
}
if (y - drawingKeelHeight < 0) {
y = drawingKeelHeight;
if (y < 0) {
y = 0;
} else if (y - drawingSeaplaneHeight >= pictureHeight) {
y = pictureHeight - drawingSeaplaneHeight - drawingSeaplaneHeight;
}
@ -66,7 +65,7 @@ public class DrawingSeaplane {
yield true;
}
case Up -> {
if (_startPosY - drawingKeelHeight - entitySeaplane.getStep() >= 0) {
if (_startPosY - entitySeaplane.getStep() >= 0) {
_startPosY -= (int) entitySeaplane.getStep();
}
yield true;
@ -78,7 +77,7 @@ public class DrawingSeaplane {
yield true;
}
case Down -> {
if (_startPosY + entitySeaplane.getStep() <= pictureHeight - drawingSeaplaneHeight + drawingKeelHeight) {
if (_startPosY + entitySeaplane.getStep() <= pictureHeight - drawingSeaplaneHeight) {
_startPosY += (int) entitySeaplane.getStep();
}
yield true;
@ -95,49 +94,49 @@ public class DrawingSeaplane {
Graphics2D g2d = (Graphics2D) g;
g2d.setColor(Color.BLACK);
// Отрисовка корпуса
g2d.drawOval(_startPosX, _startPosY + 4, 20, 20);
g2d.drawOval(_startPosX, _startPosY + 14, 20, 20);
g2d.drawRect(_startPosX, _startPosY + 15, 10, 10);
g2d.drawRect(_startPosX + 170, _startPosY + 15, 10, 10);
g2d.drawRect(_startPosX + 10, _startPosY + 4, 160, 30);
g2d.drawOval(_startPosX, _startPosY + 34, 20, 20);
g2d.drawOval(_startPosX, _startPosY + 44, 20, 20);
g2d.drawRect(_startPosX, _startPosY + 45, 10, 10);
g2d.drawRect(_startPosX + 170, _startPosY + 45, 10, 10);
g2d.drawRect(_startPosX + 10, _startPosY + 34, 160, 30);
// Отрисовка верхней части
int[] xPointsTop = {_startPosX + 170, _startPosX + 170, _startPosX + 190};
int[] yPointsTop = {_startPosY, _startPosY + 20, _startPosY + 20};
int[] yPointsTop = {_startPosY+30, _startPosY + 50, _startPosY + 50};
g2d.drawPolygon(xPointsTop, yPointsTop, 3);
// Отрисовка нижней части
int[] xPointsBottom = {_startPosX + 170, _startPosX + 170, _startPosX + 190};
int[] yPointsBottom = {_startPosY + 40, _startPosY + 20, _startPosY + 20};
int[] yPointsBottom = {_startPosY + 70, _startPosY + 50, _startPosY + 50};
g2d.drawPolygon(xPointsBottom, yPointsBottom, 3);
// Отрисовка киля
int[] xPointsKeel = {_startPosX + 10, _startPosX + 10, _startPosX + 50};
int[] yPointsKeel = {_startPosY - 30, _startPosY + 5, _startPosY + 5};
int[] yPointsKeel = {_startPosY, _startPosY + 35, _startPosY + 35};
g2d.drawPolygon(xPointsKeel, yPointsKeel, 3);
if (!entitySeaplane.getFloats())
{
// Рисуем переднее шасси с одним колесом
g2d.drawOval( _startPosX + 140, _startPosY + 45, 10, 10);
g2d.drawOval( _startPosX + 140, _startPosY + 75, 10, 10);
// Рисуем задние шасси с двумя колесами
g2d.drawOval( _startPosX + 20, _startPosY + 45, 10, 10);
g2d.drawOval( _startPosX + 30, _startPosY + 45, 10, 10);
g2d.drawOval( _startPosX + 20, _startPosY + 75, 10, 10);
g2d.drawOval( _startPosX + 30, _startPosY + 75, 10, 10);
// Рисуем ногу переднего шасси
g2d.drawLine( _startPosX + 145, _startPosY + 35, _startPosX + 145, _startPosY + 50);
g2d.drawLine( _startPosX + 145, _startPosY + 75, _startPosX + 145, _startPosY + 50);
// Рисуем ноги заднего шасси
g2d.drawLine( _startPosX + 30, _startPosY + 35, _startPosX + 30, _startPosY + 50);
g2d.drawLine( _startPosX + 30, _startPosY + 75, _startPosX + 30, _startPosY + 50);
}
g2d.setColor(entitySeaplane.getBodyColor());
// Закрашиваем корпус
g2d.fillOval(_startPosX, _startPosY + 4, 20, 20);
g2d.fillOval(_startPosX, _startPosY + 14, 20, 20);
g2d.fillOval(_startPosX, _startPosY + 15, 10, 10);
g2d.fillRect(_startPosX + 10, _startPosY + 4, 160, 30);
g2d.fillOval(_startPosX, _startPosY + 34, 20, 20);
g2d.fillOval(_startPosX, _startPosY + 44, 20, 20);
g2d.fillOval(_startPosX, _startPosY + 45, 10, 10);
g2d.fillRect(_startPosX + 10, _startPosY + 34, 160, 30);
g2d.setColor(entitySeaplane.getAdditionalColor());
// Закрашиваем дополнительные элементы
@ -145,43 +144,43 @@ public class DrawingSeaplane {
g2d.fillPolygon(xPointsBottom, yPointsBottom, 3);
g2d.fillPolygon(xPointsKeel, yPointsKeel, 3);
_drawingSeaplanePortholes.drawSeaplanePortholes(g, Color.CYAN, _startPosX, _startPosY);
_drawingSeaplanePortholes.drawSeaplanePortholes(g, Color.CYAN, _startPosX + 10, _startPosY + 41);
g2d.setColor(Color.BLACK);
// Рисуем триммера
g2d.drawOval( _startPosX, _startPosY, 10, 10);
g2d.drawOval( _startPosX+30, _startPosY, 10, 10);
g2d.drawRect( _startPosX+5, _startPosY, 30, 10);
g2d.drawOval( _startPosX, _startPosY+30, 10, 10);
g2d.drawOval( _startPosX+30, _startPosY+30, 10, 10);
g2d.drawRect( _startPosX+5, _startPosY+30, 30, 10);
// Рисуем крыло
g2d.drawOval( _startPosX + 70, _startPosY + 15, 6, 6);
g2d.drawOval( _startPosX + 130, _startPosY + 15, 6, 6);
g2d.drawRect( _startPosX + 75, _startPosY + 15, 60, 6);
g2d.drawOval( _startPosX + 70, _startPosY + 45, 6, 6);
g2d.drawOval( _startPosX + 130, _startPosY + 45, 6, 6);
g2d.drawRect( _startPosX + 75, _startPosY + 45, 60, 6);
// Закрашиваем триммера
g2d.fillOval( _startPosX, _startPosY, 10, 10);
g2d.fillOval( _startPosX+30, _startPosY, 10, 10);
g2d.fillRect( _startPosX+5, _startPosY, 30, 10);
g2d.fillOval( _startPosX, _startPosY+30, 10, 10);
g2d.fillOval( _startPosX+30, _startPosY+30, 10, 10);
g2d.fillRect( _startPosX+5, _startPosY+30, 30, 10);
// Закрашиваем крыло
g2d.fillOval( _startPosX + 70, _startPosY + 15, 6, 6);
g2d.fillOval( _startPosX + 130, _startPosY + 15, 6, 6);
g2d.fillRect( _startPosX + 75, _startPosY + 15, 60, 6);
g2d.fillOval( _startPosX + 70, _startPosY + 45, 6, 6);
g2d.fillOval( _startPosX + 130, _startPosY + 45, 6, 6);
g2d.fillRect( _startPosX + 75, _startPosY + 45, 60, 6);
// Поплавки
if (entitySeaplane.getFloats()) {
g2d.drawLine(_startPosX + 125, _startPosY + 35, _startPosX + 125, _startPosY + 50);
g2d.drawLine(_startPosX + 50, _startPosY + 35, _startPosX + 50, _startPosY + 50);
g2d.fillOval(_startPosX + 40, _startPosY + 45, 10, 10);
g2d.fillOval(_startPosX + 125, _startPosY + 45, 10, 10);
g2d.fillRect(_startPosX + 45, _startPosY + 45, 85, 10);
g2d.drawLine(_startPosX + 125, _startPosY + 65, _startPosX + 125, _startPosY + 80);
g2d.drawLine(_startPosX + 50, _startPosY + 65, _startPosX + 50, _startPosY + 80);
g2d.fillOval(_startPosX + 40, _startPosY + 75, 10, 10);
g2d.fillOval(_startPosX + 125, _startPosY + 75, 10, 10);
g2d.fillRect(_startPosX + 45, _startPosY + 75, 85, 10);
}
g2d.setColor(Color.RED);
// Надувная лодка
if (entitySeaplane.getInflatableBoat()) {
g2d.fillOval(_startPosX, _startPosY + 30, 8, 8);
g2d.fillOval(_startPosX + 165, _startPosY + 30, 8, 8);
g2d.fillRect(_startPosX + 4, _startPosY + 30, 165, 8);
g2d.fillOval(_startPosX, _startPosY + 60, 8, 8);
g2d.fillOval(_startPosX + 165, _startPosY + 60, 8, 8);
g2d.fillRect(_startPosX + 4, _startPosY + 60, 165, 8);
}
}
}

View File

@ -3,11 +3,7 @@ import java.awt.*;
public class DrawingSeaplanePortholes {
private PortholesCount _portholesCount;
private final EntitySeaplane _entitySeaplane;
public DrawingSeaplanePortholes(EntitySeaplane entitySeaplane) {
_entitySeaplane = entitySeaplane;
}
public void setEnumNumber(int portholesCount) {
public void setPortholesCount(int portholesCount) {
for (PortholesCount value : PortholesCount.values()) {
if (value.enumNumber == portholesCount) {
_portholesCount = value;
@ -15,6 +11,9 @@ public class DrawingSeaplanePortholes {
}
}
}
public DrawingSeaplanePortholes(EntitySeaplane entitySeaplane) {
_entitySeaplane = entitySeaplane;
}
public void drawSeaplanePortholes(Graphics g, Color color, float startPosX, float startPosY) {
Graphics2D g2d = (Graphics2D) g;
@ -24,13 +23,13 @@ public class DrawingSeaplanePortholes {
for (int i = 0; i < _portholesCount.enumNumber; i++) {
g2d.setColor(color);
int posX = (int)(startPosX + i * distanceBetweenPortholes);
drawPortholeBundle(g2d, posX, (int)startPosY + 5);
drawPortholeBundle(g2d, posX, (int)startPosY);
}
}
private void drawPortholeBundle(Graphics2D g2d, int posX, int posY) {
g2d.fillOval(posX + 10, posY + 6, 5, 5); // Рисуем иллюминатор
g2d.fillOval(posX, posY, 5, 5); // Рисуем иллюминатор
g2d.setColor(Color.BLACK);
g2d.drawOval(posX + 10, posY + 6, 5, 5); // Рисуем границу иллюминатора
g2d.drawOval(posX, posY, 5, 5); // Рисуем границу иллюминатора
}
}