Реализована отрисовка доп. класса

This commit is contained in:
Никита Потапов 2023-09-13 14:19:11 +04:00
parent 6382b11542
commit 274f82bb70
3 changed files with 93 additions and 0 deletions

View File

@ -0,0 +1,84 @@
package ProjectStormtrooper;
import java.awt.*;
public class DrawingEngines {
private EnumEnginesCount _enumEnginesCount;
public void SetEnginesCount(int enginesCount) {
for (EnumEnginesCount val : EnumEnginesCount.values()) {
if (val.count == enginesCount) {
this._enumEnginesCount = val;
return;
}
}
}
private void DrawEngine(Graphics2D g2d, Color color, int x, int y, int w, int h) {
g2d.setColor(Color.WHITE);
g2d.fillRect(x, y, w, h);
g2d.setColor(Color.BLACK);
g2d.drawRect(x, y, w, h);
g2d.setColor(color);
g2d.fillRect(x, y, 6, h);
}
public void DrawEngines(Graphics g, Color color, int startPosX, int startPosY, int drawingWidth, int drawingHeight) {
if (_enumEnginesCount == null) {
return;
}
Graphics2D g2d = (Graphics2D) g;
int engineWidth = 20;
int engineHeight = 6;
if (_enumEnginesCount.count >= EnumEnginesCount.Two.count) {
DrawEngine(
g2d, color,
startPosX + drawingWidth - drawingWidth / 5,
startPosY + drawingHeight / 2 - drawingHeight / 6,
engineWidth,
engineHeight
);
DrawEngine(
g2d, color,
startPosX + drawingWidth - drawingWidth / 5,
startPosY + drawingHeight / 2 + drawingHeight / 6 - engineHeight,
engineWidth,
engineHeight
);
}
if (_enumEnginesCount.count >= EnumEnginesCount.Four.count) {
DrawEngine(
g2d, color,
startPosX + drawingWidth - drawingWidth / 5 + 5,
startPosY + drawingHeight / 2 - drawingHeight / 6 - 10,
engineWidth - 5,
engineHeight
);
DrawEngine(
g2d, color,
startPosX + drawingWidth - drawingWidth / 5 + 5,
startPosY + drawingHeight / 2 + drawingHeight / 6 - engineHeight + 10,
engineWidth - 5,
engineHeight
);
}
if (_enumEnginesCount.count >= EnumEnginesCount.Six.count) {
DrawEngine(
g2d, color,
startPosX + drawingWidth / 2 - 10,
startPosY + drawingHeight / 2 - drawingHeight / 6 - 10,
engineWidth,
engineHeight
);
DrawEngine(
g2d, color,
startPosX + drawingWidth / 2 - 10,
startPosY + drawingHeight / 2 + drawingHeight / 6 + 3,
engineWidth,
engineHeight
);
}
}
}

View File

@ -4,6 +4,7 @@ import java.awt.*;
public class DrawingStormtrooper {
public EntityStormtrooper EntityStormtrooper;
private DrawingEngines _drawingEngines;
private int _pictureWidth;
private int _pictureHeight;
private int _startPosX;
@ -19,11 +20,16 @@ public class DrawingStormtrooper {
}
_pictureWidth = width;
_pictureHeight = height;
_drawingEngines = new DrawingEngines();
EntityStormtrooper = new EntityStormtrooper();
EntityStormtrooper.Init(speed, weight, bodyColor, additionalColor, rockets, bombs);
return true;
}
public void SetEnginesCount(int enginesCount) {
_drawingEngines.SetEnginesCount(enginesCount);
}
public void SetPosition(int x, int y) {
if (x < 0) {
x = 0;
@ -80,6 +86,8 @@ public class DrawingStormtrooper {
Color blackColor = Color.BLACK;
Color redColor = Color.RED;
_drawingEngines.DrawEngines(g, additionalColor, _startPosX, _startPosY, _stormtrooperWidth, _stormtrooperHeight);
// Длина фюзеляжа
int bodyHeight = _stormtrooperHeight / 9;
int bodyWidth = _stormtrooperWidth - _stormtrooperWidth / 8;

View File

@ -39,6 +39,7 @@ public class FormStormtrooper {
pictureBox.getHeight()
);
_drawingStormtrooper.SetEnginesCount(random.nextInt(2, 7));
_drawingStormtrooper.SetPosition(random.nextInt(10, 100), random.nextInt(10, 100));
Draw();