Лаба готовая к выгрузке (с допами)

This commit is contained in:
ekallin 2023-09-14 23:02:37 +04:00
parent 69b251691f
commit ba8bcf5f78
9 changed files with 53 additions and 8 deletions

View File

@ -2,7 +2,7 @@ package ProjectElectricLocomotive;
import java.awt.*;
public class DrawingElectricLocomotive {
public EntityElectricLocomotive EntityElectricLocomotive;
private DrawingWheel _drawingWheel;
private int _pictureWidth;
private int _pictureHeight;
private int _startPosX;
@ -21,10 +21,15 @@ public class DrawingElectricLocomotive {
_pictureWidth = width;
_pictureHeight = height;
EntityElectricLocomotive = new EntityElectricLocomotive();
_drawingWheel = new DrawingWheel();
EntityElectricLocomotive.Init(speed, weight, bodyColor, additionalColor, horns, seifbatteries);
return true;
}
public void SetWheelsCount(int weelsCount) {
_drawingWheel.SetWheelsCount(weelsCount);
}
public void SetPosition(int x, int y)
{
if (x < 0 || x + _locoWidth > _pictureWidth)
@ -73,6 +78,8 @@ public class DrawingElectricLocomotive {
Color blackBrush = Color.BLACK;
Color windowsColor = Color.BLUE;
_drawingWheel.DrawWheels(g, additionalColor, _startPosX, _startPosY, 5, 5);
if(EntityElectricLocomotive.Horns)
{
g2d.fillRect(_startPosX + 30, _startPosY + 15, 20, 5);
@ -133,9 +140,6 @@ public class DrawingElectricLocomotive {
g2d.fillOval(_startPosX + 50, _startPosY + 45, 5, 5);
g2d.fillOval(_startPosX + 65, _startPosY + 45, 5, 5);
// g2d.setColor(EntityElectricLocomotive.BodyColor);
// g2d.fillRect(_startPosX, _startPosY, _locoWidth, _locoHeight);
//telega
g2d.setColor(blackBrush);

View File

@ -0,0 +1,42 @@
package ProjectElectricLocomotive;
import java.awt.*;
public class DrawingWheel {
private WheelsCount _wheelsCount;
public void SetWheelsCount(int enginesCount) {
for (WheelsCount val : WheelsCount.values()) {
if (val.count == enginesCount) {
this._wheelsCount = val;
return;
}
}
}
private void DrawWheel(Graphics2D g2d, Color color, int x, int y, int w, int h) {
g2d.setColor(Color.BLACK);
g2d.fillOval(x, y, w, h);
}
public void DrawWheels(Graphics g, Color color, int startPosX, int startPosY, int drawingWidth, int drawingHeight) {
if (_wheelsCount == null) {
return;
}
Graphics2D g2d = (Graphics2D) g;
int wheelWidth = 5;
int wheelHeight = 5;
if (_wheelsCount.count >= _wheelsCount.Three.count) {
DrawWheel(g2d, color, startPosX + 105, startPosY + 45, wheelWidth, wheelHeight
);
}
if (_wheelsCount.count >= _wheelsCount.Four.count) {
DrawWheel(g2d, color, startPosX + 105, startPosY + 45, wheelWidth, wheelHeight
);
DrawWheel(g2d, color, startPosX + 130, startPosY + 45, wheelWidth, wheelHeight
);
}
}
}

View File

@ -3,7 +3,7 @@
<grid id="27dc6" binding="pictureBox" layout-manager="GridLayoutManager" row-count="3" column-count="5" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<xy x="20" y="20" width="639" height="400"/>
<xy x="24" y="37" width="635" height="383"/>
</constraints>
<properties/>
<border type="none">
@ -44,7 +44,7 @@
</grid>
</constraints>
<properties>
<hideActionText value="true"/>
<hideActionText value="false"/>
<horizontalTextPosition value="0"/>
<icon value="ProjectElectricLocomotive/img/arrowLeft.jpg"/>
<text value=""/>

View File

@ -38,7 +38,7 @@ public class FormElectricLocomotive {
pictureBox.getHeight()
);
//_drawingElectricLocomotive.SetEnginesCount(random.nextInt(2, 7));
_drawingElectricLocomotive.SetWheelsCount(random.nextInt(2, 5));
_drawingElectricLocomotive.SetPosition(random.nextInt(10, 100), random.nextInt(10, 100));
Draw();
});

View File

@ -6,5 +6,4 @@ public enum WheelsCount {
WheelsCount(int count) {
this.count = count;
}
}