READY LabWork02 HARD

This commit is contained in:
ekallin 2023-10-10 13:30:54 +04:00
parent 4284b48c00
commit 37a3d7d8d2
10 changed files with 15 additions and 25 deletions

View File

@ -16,9 +16,6 @@ public class DrawingElectricLocomotive extends DrawingLocomotive {
if (EntityLocomotive instanceof EntityElectricLocomotive electricLocomotive) ///////// WARNING INSTANCEOF if (EntityLocomotive instanceof EntityElectricLocomotive electricLocomotive) ///////// WARNING INSTANCEOF
{ {
Color colorBlack = Color.BLACK; Color colorBlack = Color.BLACK;
Color windows = Color.BLUE;
Color bodyColor = EntityLocomotive.BodyColor;
Color additionalBrush = electricLocomotive.AdditionalColor;
if (electricLocomotive.Horns) { if (electricLocomotive.Horns) {
//horns //horns

View File

@ -56,7 +56,6 @@ public class DrawingLocomotive {
_pictureHeight = height; _pictureHeight = height;
_locoWidth = locoWidth; _locoWidth = locoWidth;
_locoHeight = locoHeight; _locoHeight = locoHeight;
// EntityLocomotive = new EntityLocomotive(speed, weight, bodyColor);
} }
public void SetWheelsCount(int wheelsCount){ public void SetWheelsCount(int wheelsCount){
@ -105,6 +104,7 @@ public class DrawingLocomotive {
break; break;
} }
} }
public void DrawTransport(Graphics g) public void DrawTransport(Graphics g)
{ {
{ {
@ -112,7 +112,6 @@ public class DrawingLocomotive {
} }
Color colorBlack = Color.BLACK; Color colorBlack = Color.BLACK;
/*Brush blackBrush = new SolidBrush(Color.Black);*/
Color windows = Color.BLUE; Color windows = Color.BLUE;
Color bodyColor = EntityLocomotive.BodyColor; Color bodyColor = EntityLocomotive.BodyColor;
@ -133,7 +132,6 @@ public class DrawingLocomotive {
g.setColor(colorBlack); g.setColor(colorBlack);
g.drawPolygon(locoP); g.drawPolygon(locoP);
//окошки //окошки
Polygon window = new Polygon(); Polygon window = new Polygon();
window.addPoint(_startPosX + 10, _startPosY + 30); window.addPoint(_startPosX + 10, _startPosY + 30);
@ -155,11 +153,6 @@ public class DrawingLocomotive {
g.fillOval(_startPosX + 50, _startPosY + 45, 9, 9); g.fillOval(_startPosX + 50, _startPosY + 45, 9, 9);
g.fillOval(_startPosX + 65, _startPosY + 45, 9, 9); g.fillOval(_startPosX + 65, _startPosY + 45, 9, 9);
//telega
g.setColor(colorBlack);
g.fillOval(_startPosX + 95, _startPosY + 45, 9, 9);
g.fillOval(_startPosX + 140, _startPosY + 45, 9, 9);
//telejka //telejka
Polygon telega = new Polygon(); Polygon telega = new Polygon();
@ -175,7 +168,6 @@ public class DrawingLocomotive {
g.fillPolygon(telega); g.fillPolygon(telega);
g.setColor(colorBlack); g.setColor(colorBlack);
g.drawPolygon(telega); g.drawPolygon(telega);
//telejka
//телега окна //телега окна
g.setColor(colorBlack); g.setColor(colorBlack);

View File

@ -2,7 +2,6 @@ package ProjectElectricLocomotive;
public class DrawingObjectLocomotive implements IMoveableObject { public class DrawingObjectLocomotive implements IMoveableObject {
private DrawingLocomotive _drawningLocomotive = null; private DrawingLocomotive _drawningLocomotive = null;
public DrawingObjectLocomotive(DrawingLocomotive drawningLocomotive) public DrawingObjectLocomotive(DrawingLocomotive drawningLocomotive)
{ {
_drawningLocomotive = drawningLocomotive; _drawningLocomotive = drawningLocomotive;

View File

@ -5,7 +5,6 @@ import java.awt.*;
public class EntityElectricLocomotive extends EntityLocomotive { public class EntityElectricLocomotive extends EntityLocomotive {
public Color AdditionalColor; public Color AdditionalColor;
public boolean Horns; public boolean Horns;
public boolean SeifBatteries; public boolean SeifBatteries;
public EntityElectricLocomotive(int speed, double weight, Color bodyColor, Color additionalColor, boolean horns, boolean seifBatteries) public EntityElectricLocomotive(int speed, double weight, Color bodyColor, Color additionalColor, boolean horns, boolean seifBatteries)
{ {

View File

@ -6,13 +6,11 @@ public class EntityLocomotive {
public int Speed; public int Speed;
public double Weight; public double Weight;
public Color BodyColor; public Color BodyColor;
public EntityLocomotive(int speed, double weight, Color bodyColor) { public EntityLocomotive(int speed, double weight, Color bodyColor) {
Speed = speed; Speed = speed;
Weight = weight; Weight = weight;
BodyColor = bodyColor; BodyColor = bodyColor;
} }
public double Step() public double Step()
{ {
return (double) Speed * 100 / Weight; return (double) Speed * 100 / Weight;

View File

@ -58,7 +58,6 @@ public class FormElectricLocomotive {
_drawingLocomotive.SetWheelsCount(random.nextInt(2, 5)); _drawingLocomotive.SetWheelsCount(random.nextInt(2, 5));
_drawingLocomotive.SetPosition(random.nextInt(10, 100), random.nextInt(10, 100)); _drawingLocomotive.SetPosition(random.nextInt(10, 100), random.nextInt(10, 100));
//drawingElectricLocomotive.SetWheelsCount(random.nextInt(2,5));
Draw(); Draw();
}); });

View File

@ -7,8 +7,6 @@ public interface IDrawingWheels {
WheelsCount GetWheelsCount(); WheelsCount GetWheelsCount();
// WheelsCount GetWheelsCount();
void DrawWheel(Graphics2D g2d, Color color, int x, int y, int w, int h); void DrawWheel(Graphics2D g2d, Color color, int x, int y, int w, int h);
default void DrawWheels(Graphics g, Color color, int startPosX, int startPosY, int drawingWidth, int drawingHeight){ default void DrawWheels(Graphics g, Color color, int startPosX, int startPosY, int drawingWidth, int drawingHeight){
@ -18,10 +16,21 @@ public interface IDrawingWheels {
int wheelWidth = 9; int wheelWidth = 9;
int wheelHeight = 9; int wheelHeight = 9;
if (wheelsCount.count >= wheelsCount.Three.count) { if(wheelsCount.count <= wheelsCount.Two.count){
DrawWheel(g2d, color, startPosX + 95, startPosY + 45, 9, 9);
DrawWheel(g2d, color, startPosX + 140, startPosY + 45, 9, 9);
}
if (wheelsCount.count == wheelsCount.Three.count) {
DrawWheel(g2d, color, startPosX + 95, startPosY + 45, 9, 9);
DrawWheel(g2d, color, startPosX + 140, startPosY + 45, 9, 9);
DrawWheel(g2d, color, startPosX + 105, startPosY + 45, wheelWidth, wheelHeight); DrawWheel(g2d, color, startPosX + 105, startPosY + 45, wheelWidth, wheelHeight);
} }
if (wheelsCount.count >= wheelsCount.Four.count) { if (wheelsCount.count == wheelsCount.Four.count) {
DrawWheel(g2d, color, startPosX + 95, startPosY + 45, 9, 9);
DrawWheel(g2d, color, startPosX + 140, startPosY + 45, 9, 9);
DrawWheel(g2d, color, startPosX + 105, startPosY + 45, wheelWidth, wheelHeight); DrawWheel(g2d, color, startPosX + 105, startPosY + 45, wheelWidth, wheelHeight);
DrawWheel(g2d, color, startPosX + 130, startPosY + 45, wheelWidth, wheelHeight); DrawWheel(g2d, color, startPosX + 130, startPosY + 45, wheelWidth, wheelHeight);
} }

View File

@ -4,7 +4,6 @@ import java.awt.*;
public interface IMoveableObject { public interface IMoveableObject {
ObjectParameters GetObjectPosition(); ObjectParameters GetObjectPosition();
int GetStep(); int GetStep();
boolean CheckCanMove(DyrectionType direction); boolean CheckCanMove(DyrectionType direction);
void MoveObject(DyrectionType direction); void MoveObject(DyrectionType direction);
} }

View File

@ -9,7 +9,6 @@ public class MoveToRigthCorner extends AbstractStrategy {
return objParams.RightBorder() >= FieldWidth - GetStep() && objParams.DownBorder() >= FieldHeight - GetStep(); return objParams.RightBorder() >= FieldWidth - GetStep() && objParams.DownBorder() >= FieldHeight - GetStep();
} }
@Override @Override
protected void MoveToTarget() protected void MoveToTarget()
{ {
@ -18,6 +17,5 @@ public class MoveToRigthCorner extends AbstractStrategy {
if (objParams.RightBorder() < FieldWidth - GetStep()) MoveRight(); if (objParams.RightBorder() < FieldWidth - GetStep()) MoveRight();
if (objParams.DownBorder() < FieldHeight - GetStep()) MoveDown(); if (objParams.DownBorder() < FieldHeight - GetStep()) MoveDown();
} }
} }

View File

@ -1,7 +1,7 @@
package ProjectElectricLocomotive; package ProjectElectricLocomotive;
public enum WheelsCount { public enum WheelsCount {
/* Two(2),*/ Three(3), Four(4); Two(2), Three(3), Four(4);
public final int count; public final int count;
WheelsCount(int count) { WheelsCount(int count) {
this.count = count; this.count = count;