закончил labwork02

This commit is contained in:
BoiledMilk123 2024-05-22 20:32:42 +04:00
parent 352e557d37
commit cc59420fbf
6 changed files with 110 additions and 33 deletions

View File

@ -20,22 +20,28 @@ public class DrawingElectricLocomotive extends DrawingLocomotive
switch (varOrnament) switch (varOrnament)
{ {
case 0: case 0:
_ornament = new DrawingWheels();
break;
case 1:
_ornament = new DrawingOrnamentWheels(); _ornament = new DrawingOrnamentWheels();
break; break;
case 1:
_ornament = new DrawningSecondOrnamentWheels();
break;
default: default:
_ornament = new DrawingOrnamentSecondWheels(); _ornament = new DrawingWheels();
break; break;
} }
_ornament.SetCountWheels(rnd.nextInt(1,3)); _ornament.SetCountWheels(rnd.nextInt(1,5));
} }
@Override @Override
public void DrawTransport(Graphics g) public void DrawTransport(Graphics g)
{ {
if (!(_entityLocomotive instanceof EntityElectricLocomotive _entityElectricLocomotive) || _startPosX == null) return; if (!(_entityLocomotive instanceof EntityElectricLocomotive _entityElectricLocomotive) || _startPosX == null) return;
super.DrawTransport(g);
g.setColor(Color.white);
g.fillRect(_startPosX + 48, _startPosY + 38, 20, 10);
g.fillRect(_startPosX + 9, _startPosY + 38, 20, 10);
// Создание перьев и кистей для прорисовки электровоза // Создание перьев и кистей для прорисовки электровоза
Color blackColor = Color.BLACK; Color blackColor = Color.BLACK;
Color deepSkyBlueColor = new Color(0, 191, 255); Color deepSkyBlueColor = new Color(0, 191, 255);
@ -67,14 +73,14 @@ public class DrawingElectricLocomotive extends DrawingLocomotive
// Прорисовка "хранилища батарей" электровоза // Прорисовка "хранилища батарей" электровоза
g.fillRect(_startPosX.intValue() + 36, _startPosY + 37, 8, 4); g.fillRect(_startPosX.intValue() + 36, _startPosY + 37, 8, 4);
g.setColor(yellowColor); g.setColor(yellowColor);
g.drawLine(pointLightning1.x, pointLightning1.y, pointLightning2.x, pointLightning2.y); g.drawLine(pointLightning1.x, pointLightning1.y, pointLightning2.x, pointLightning2.y);
g.drawLine(pointLightning2.x, pointLightning2.y, pointLightning3.x, pointLightning3.y); g.drawLine(pointLightning2.x, pointLightning2.y, pointLightning3.x, pointLightning3.y);
g.drawLine(pointLightning3.x, pointLightning3.y, pointLightning4.x, pointLightning4.y); g.drawLine(pointLightning3.x, pointLightning3.y, pointLightning4.x, pointLightning4.y);
g.setColor(blackColor);
} }
_ornament.DrawWheels(g, _startPosX, _startPosY); _ornament.DrawWheels(g, _startPosX, _startPosY);
} }

View File

@ -6,6 +6,7 @@ import ProjectElectricLocomotive.src.DirectionType;
import ProjectElectricLocomotive.src.Entities.EntityLocomotive; import ProjectElectricLocomotive.src.Entities.EntityLocomotive;
import java.awt.*; import java.awt.*;
import java.util.Random;
public class DrawingLocomotive { public class DrawingLocomotive {
public EntityLocomotive _entityLocomotive; public EntityLocomotive _entityLocomotive;
@ -13,7 +14,6 @@ public class DrawingLocomotive {
{ {
return _entityLocomotive; return _entityLocomotive;
} }
public DrawingWheels _wheels;
protected Integer _startPosX = null; protected Integer _startPosX = null;
public Integer getPosX() { public Integer getPosX() {
return _startPosX; return _startPosX;
@ -147,6 +147,16 @@ public class DrawingLocomotive {
// Совокупность точек полигона уголка второй "юбки" // Совокупность точек полигона уголка второй "юбки"
Point[] secondTrianglePoints = { point6, point7, point8 }; Point[] secondTrianglePoints = { point6, point7, point8 };
g.setColor(blackColor);
g.fillOval(_startPosX + 58, _startPosY + 37, 10, 10);
g.drawOval(_startPosX + 58, _startPosY + 37, 8, 8);
g.fillOval(_startPosX + 48, _startPosY + 37, 10, 10);
g.drawOval(_startPosX + 48, _startPosY + 37, 8, 8);
g.fillOval(_startPosX + 19, _startPosY + 37, 10, 10);
g.drawOval(_startPosX + 19, _startPosY + 37, 8, 8);
g.fillOval(_startPosX + 9, _startPosY + 37, 10, 10);
g.drawOval(_startPosX + 9, _startPosY + 37, 8, 8);
// Прорисовка уголков "юбок" // Прорисовка уголков "юбок"
g.setColor(_entityLocomotive.GetBodyColor()); g.setColor(_entityLocomotive.GetBodyColor());
g.fillPolygon(new Polygon(new int[]{ point3.x, point4.x, point5.x }, new int[]{ point3.y, point4.y, point5.y }, 3)); g.fillPolygon(new Polygon(new int[]{ point3.x, point4.x, point5.x }, new int[]{ point3.y, point4.y, point5.y }, 3));
@ -163,8 +173,5 @@ public class DrawingLocomotive {
g.setColor(deepSkyBlueColor); g.setColor(deepSkyBlueColor);
g.drawRect(_startPosX + 12, _startPosY + 9, 8, 8); g.drawRect(_startPosX + 12, _startPosY + 9, 8, 8);
g.drawRect(_startPosX+ 63, _startPosY + 9, 8, 8); g.drawRect(_startPosX+ 63, _startPosY + 9, 8, 8);
_wheels.DrawWheels(g, _startPosX, _startPosY);
} }
} }

View File

@ -1,17 +1,48 @@
package ProjectElectricLocomotive.src.Drawnings; package ProjectElectricLocomotive.src.Drawnings;
import ProjectElectricLocomotive.src.CountWheels;
import java.awt.*; import java.awt.*;
public class DrawingOrnamentWheels implements IDrawingOrnament public class DrawingOrnamentWheels implements IDrawingOrnament
{ {
private CountWheels _wheels;
@Override @Override
public void SetCountWheels(int count) { public void SetCountWheels(int count)
{
for(CountWheels temp : CountWheels.values())
{
if(temp.GetCountWheels() >= count)
{
_wheels = temp;
return;
}
}
} }
@Override @Override
public void DrawWheels(Graphics g, int _startPosX, int _startPosY) { public void DrawWheels(Graphics g,int _startPosX, int _startPosY)
{
g.setColor(Color.BLACK);
switch (_wheels.GetCountWheels())
{
case 4:
g.drawOval(_startPosX + 58, _startPosY + 37, 8, 8);
g.drawLine(_startPosX + 62,_startPosY + 38, _startPosX + 62, _startPosY + 38 + 6 );
case 3:
g.drawOval(_startPosX + 48, _startPosY + 37, 8, 8);
g.drawLine(_startPosX + 52,_startPosY + 38, _startPosX + 52, _startPosY + 38 + 6 );
case 2:
g.drawOval(_startPosX + 19, _startPosY + 37, 8, 8);
g.drawLine(_startPosX + 23,_startPosY + 38, _startPosX + 23, _startPosY + 38 + 6 );
case 1:
g.drawOval(_startPosX + 9, _startPosY + 37, 8, 8);
g.drawLine(_startPosX + 13,_startPosY + 38, _startPosX + 13, _startPosY + 38 + 6 );
break;
}
} }
} }

View File

@ -0,0 +1,48 @@
package ProjectElectricLocomotive.src.Drawnings;
import ProjectElectricLocomotive.src.CountWheels;
import java.awt.*;
public class DrawningSecondOrnamentWheels implements IDrawingOrnament
{
private CountWheels _wheels;
@Override
public void SetCountWheels(int count)
{
for(CountWheels temp : CountWheels.values())
{
if(temp.GetCountWheels() >= count)
{
_wheels = temp;
return;
}
}
}
@Override
public void DrawWheels(Graphics g,int _startPosX, int _startPosY)
{
g.setColor(Color.BLACK);
switch (_wheels.GetCountWheels())
{
case 4:
g.drawOval(_startPosX + 58, _startPosY + 37, 8, 8);
g.drawLine(_startPosX + 58,_startPosY + 38, _startPosX + 58 + 6, _startPosY + 37 + 6 );
g.drawLine(_startPosX + 64,_startPosY + 38, _startPosX + 58, _startPosY + 37 + 6 );
case 3:
g.drawOval(_startPosX + 48, _startPosY + 37, 8, 8);
g.drawLine(_startPosX + 48,_startPosY + 38, _startPosX + 48 + 6, _startPosY + 37 + 6 );
g.drawLine(_startPosX + 54,_startPosY + 38, _startPosX + 48, _startPosY + 37 + 6 );
case 2:
g.drawOval(_startPosX + 19, _startPosY + 37, 8, 8);
g.drawLine(_startPosX + 19,_startPosY + 38, _startPosX + 19 + 6, _startPosY + 37 + 6 );
g.drawLine(_startPosX + 25,_startPosY + 38, _startPosX + 19, _startPosY + 37 + 6 );
case 1:
g.drawOval(_startPosX + 9, _startPosY + 37, 8, 8);
g.drawLine(_startPosX + 9,_startPosY + 38, _startPosX + 9 + 6, _startPosY + 37 + 6 );
g.drawLine(_startPosX + 15,_startPosY + 38, _startPosX + 9, _startPosY + 37 + 6 );
break;
}
}
}

View File

@ -4,13 +4,7 @@ import java.awt.*;
import java.util.Random; import java.util.Random;
public class EntityElectricLocomotive extends EntityLocomotive { public class EntityElectricLocomotive extends EntityLocomotive {
private int Speed;
private float Weight;
private Color BodyColor;
public Color GetBodyColor()
{
return BodyColor;
}
private Color AdditionalColor; private Color AdditionalColor;
public Color GetAdditionalColor() public Color GetAdditionalColor()
{ {
@ -33,15 +27,5 @@ public class EntityElectricLocomotive extends EntityLocomotive {
ElectricHorns = electricHorns; ElectricHorns = electricHorns;
BatteryPlacement = batteryPlacement; BatteryPlacement = batteryPlacement;
} }
public void Init(int speed, float weight, Color bodyColor, Color additionalcolor, boolean electricHorns, boolean batteryPlacement)
{
Random rnd = new Random();
Speed = speed;
Weight = weight;
BodyColor = bodyColor;
AdditionalColor = additionalcolor;
ElectricHorns = electricHorns;
BatteryPlacement = batteryPlacement;
Step = Speed * 100 / Weight;
}
} }

View File

@ -45,6 +45,7 @@ public class FormElectricLocomotive extends JFrame{
setSize(900,500); setSize(900,500);
Width = getWidth(); Width = getWidth();
Height = getHeight(); Height = getHeight();
setBackground(Color.WHITE);
ShowWindow(); ShowWindow();
RefreshWindow(); RefreshWindow();
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);