Исправил класс отрисовки ДопПер

This commit is contained in:
Никита Шипилов 2024-05-13 06:11:52 +04:00
parent 1578c07887
commit 1786de4b95
3 changed files with 32 additions and 16 deletions

View File

@ -20,7 +20,7 @@ public class DrawingSeaplane {
pictureWidth = null;
_startPosX = null;
_startPosY = null;
_drawingSeaplanePortholes = new DrawingSeaplanePortholes(entitySeaplane);
_drawingSeaplanePortholes = new DrawingSeaplanePortholes();
Random random = new Random();
int paddlesCount = random.nextInt(1,4);
_drawingSeaplanePortholes.setPortholesCount(paddlesCount * 10);

View File

@ -2,34 +2,31 @@ import java.awt.*;
public class DrawingSeaplanePortholes {
private PortholesCount _portholesCount;
private final EntitySeaplane _entitySeaplane;
public void setPortholesCount(int portholesCount) {
for (PortholesCount value : PortholesCount.values()) {
if (value.enumNumber == portholesCount) {
_portholesCount = value;
return;
}
}
public PortholesCount getPortholesCount() {
return _portholesCount;
}
public DrawingSeaplanePortholes(EntitySeaplane entitySeaplane) {
_entitySeaplane = entitySeaplane;
public void setPortholesCount(int amount){
if(PortholesCount.contains(amount)) {
_portholesCount = PortholesCount.getNumber(amount);
}
}
public void drawSeaplanePortholes(Graphics g, Color color, float startPosX, float startPosY) {
Graphics2D g2d = (Graphics2D) g;
g2d.setStroke(new BasicStroke(1));
int distanceBetweenPortholes = (_portholesCount.enumNumber == 20) ? 7 : 20 - _portholesCount.enumNumber / 2;
int distanceBetweenPortholes = (getPortholesCount().enumNumber == 20) ? 7 : 20 - getPortholesCount().enumNumber / 2;
for (int i = 0; i < _portholesCount.enumNumber; i++) {
for (int i = 0; i < getPortholesCount().enumNumber; i++) {
g2d.setColor(color);
int posX = (int)(startPosX + i * distanceBetweenPortholes);
drawPortholeBundle(g2d, posX, (int)startPosY);
drawPortholeBundle(g2d, posX, (int)startPosY + 5);
}
}
private void drawPortholeBundle(Graphics2D g2d, int posX, int posY) {
g2d.fillOval(posX, posY, 5, 5); // Рисуем иллюминатор
g2d.fillOval(posX + 10, posY + 6, 5, 5); // Рисуем иллюминатор
g2d.setColor(Color.BLACK);
g2d.drawOval(posX, posY, 5, 5); // Рисуем границу иллюминатора
g2d.drawOval(posX + 10, posY + 6, 5, 5); // Рисуем границу иллюминатора
}
}

View File

@ -5,4 +5,23 @@ public enum PortholesCount {
public final int enumNumber;
PortholesCount(int i) {this.enumNumber = i;}
public static PortholesCount getNumber(int amount){
PortholesCount [] num = PortholesCount.values();
for (PortholesCount portholesCount : num) {
if (amount == portholesCount.enumNumber) {
return portholesCount;
}
}
return null;
}
public static boolean contains(int amount){
PortholesCount [] num = PortholesCount.values();
for (PortholesCount portholesCount : num) {
if (amount == portholesCount.enumNumber) {
return true;
}
}
return false;
}
}