diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/.idea/PIbd-21_Bakalskaya_E.D._ElectricLocomotive._HARD.iml b/.idea/PIbd-21_Bakalskaya_E.D._ElectricLocomotive._HARD.iml new file mode 100644 index 0000000..b107a2d --- /dev/null +++ b/.idea/PIbd-21_Bakalskaya_E.D._ElectricLocomotive._HARD.iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..4458232 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..561b3e5 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/uiDesigner.xml b/.idea/uiDesigner.xml new file mode 100644 index 0000000..2b63946 --- /dev/null +++ b/.idea/uiDesigner.xml @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/ProjectElectricLocomotive/DrawingElectricLocomotive.java b/ProjectElectricLocomotive/DrawingElectricLocomotive.java new file mode 100644 index 0000000..027745f --- /dev/null +++ b/ProjectElectricLocomotive/DrawingElectricLocomotive.java @@ -0,0 +1,173 @@ +package ProjectElectricLocomotive; +import java.awt.*; +public class DrawingElectricLocomotive { + public EntityElectricLocomotive EntityElectricLocomotive; + private DrawingWheel _drawingWheel; + private int _pictureWidth; + private int _pictureHeight; + private int _startPosX; + private int _startPosY; + private final int _locoWidth = 150; + private final int _locoHeight = 50; + + public boolean Init(int speed, double weight, Color bodyColor, Color additionalColor, + boolean horns, boolean seifbatteries, int width, int height) + { + + if (width < _locoWidth || height < _locoHeight) + { + return false; + } + _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) + { + x = 20; + } + if (y < 0 || y + _locoHeight > _pictureHeight) + { + y = 20; + } + _startPosX = x; + _startPosY = y; + } + + public void MoveTransport(DyrectionType direction){ + if(EntityElectricLocomotive == null) return; + switch(direction) + { + case Up -> { + if(_startPosY - EntityElectricLocomotive.Step() >= 0) + _startPosY -= (int) EntityElectricLocomotive.Step(); + } + case Down -> { + if(_startPosY + EntityElectricLocomotive.Step() + _locoHeight <= _pictureHeight) + _startPosY += (int) EntityElectricLocomotive.Step(); + } + case Left -> { + if(_startPosX - EntityElectricLocomotive.Step() >= 0) + _startPosX -= (int) EntityElectricLocomotive.Step(); + } + case Right -> { + if(_startPosX + EntityElectricLocomotive.Step() + _locoWidth <= _pictureWidth) + _startPosX += (int) EntityElectricLocomotive.Step(); + } + } + } + public void DrawTransport(Graphics g) { + if (EntityElectricLocomotive == null) { + return; + } + + Graphics2D g2d = (Graphics2D) g; + + Color bodyColor = EntityElectricLocomotive.BodyColor; + Color additionalColor = EntityElectricLocomotive.AdditionalColor; + 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); + g2d.drawLine(_startPosX + 40, _startPosY + 15, _startPosX + 50, _startPosY + 10); + g2d.drawLine(_startPosX + 50, _startPosY + 10, _startPosX + 45, _startPosY); + g2d.drawLine(_startPosX + 45, _startPosY + 15, _startPosX + 50, _startPosY + 10); + g2d.drawLine(_startPosX + 50, _startPosY + 10, _startPosX + 40, _startPosY); + g2d.setColor(blackBrush); + } + + //locomotive + Polygon loco = new Polygon(); + + loco.addPoint(_startPosX, _startPosY + 40); + loco.addPoint(_startPosX, _startPosY + 30); + loco.addPoint(_startPosX + 20, _startPosY + 20); + loco.addPoint(_startPosX + 70, _startPosY + 20); + loco.addPoint(_startPosX +80, _startPosY + 30); + loco.addPoint(_startPosX +80, _startPosY + 40); + loco.addPoint(_startPosX +75, _startPosY + 45); + loco.addPoint(_startPosX +5, _startPosY + 45); + loco.addPoint(_startPosX, _startPosY + 40); + + g2d.setColor(blackBrush); + g2d.drawPolygon(loco); + g2d.setColor(bodyColor); + g2d.fillPolygon(loco); + // windows + Polygon window = new Polygon(); + window.addPoint(_startPosX + 10, _startPosY + 30); + window.addPoint(_startPosX +15, _startPosY + 25); + window.addPoint(_startPosX + 20, _startPosY + 25); + window.addPoint(_startPosX + 20, _startPosY + 30); + window.addPoint(_startPosX +10, _startPosY + 30); + + g2d.setColor(blackBrush); + g2d.drawPolygon(window); + g2d.setColor(windowsColor); + g2d.fillPolygon(window); + + g2d.fillRect(_startPosX + 25, _startPosY + 25, 10, 5); + g2d.setColor(windowsColor); + g2d.drawRect(_startPosX + 25, _startPosY + 25, 10, 5); + g2d.setColor(blackBrush); + //locomotive + + if(EntityElectricLocomotive.SeifBatteries) + { + g2d.drawRect(_startPosX + 50, _startPosY + 25, 20, 10); + g2d.setColor(blackBrush); + } + + + //обязательные колеса + //loco + g2d.fillOval(_startPosX + 10, _startPosY + 45, 5, 5); + g2d.fillOval(_startPosX + 25, _startPosY + 45, 5, 5); + g2d.fillOval(_startPosX + 50, _startPosY + 45, 5, 5); + g2d.fillOval(_startPosX + 65, _startPosY + 45, 5, 5); + + + //telega + g2d.setColor(blackBrush); + g2d.fillOval(_startPosX + 95, _startPosY + 45, 5, 5); + g2d.fillOval(_startPosX + 140, _startPosY + 45, 5, 5); + + //telejka + Polygon telega = new Polygon(); + + telega.addPoint(_startPosX + 90, _startPosY + 25); + telega.addPoint(_startPosX + 95, _startPosY + 20); + telega.addPoint(_startPosX + 145, _startPosY + 20); + telega.addPoint(_startPosX + 150, _startPosY + 25); + telega.addPoint(_startPosX + 150, _startPosY + 45); + telega.addPoint(_startPosX + 90, _startPosY + 45); + telega.addPoint(_startPosX + 90, _startPosY + 25); + + g2d.setColor(additionalColor); + g2d.fillPolygon(telega); + g2d.setColor(blackBrush); + g2d.drawPolygon(telega); + //telejka + + //телега окна + g2d.setColor(blackBrush); + g.drawLine(_startPosX + 80, _startPosY + 40, _startPosX + 90, _startPosY + 40); + g2d.setColor(windowsColor); g.fillRect(_startPosX + 95, _startPosY + 30, 10, 5); + g.fillRect(_startPosX + 115, _startPosY + 30, 10, 5); + g.fillRect(_startPosX + 135, _startPosY + 30, 10, 5); + } +} diff --git a/ProjectElectricLocomotive/DrawingWheel.java b/ProjectElectricLocomotive/DrawingWheel.java new file mode 100644 index 0000000..f4ee669 --- /dev/null +++ b/ProjectElectricLocomotive/DrawingWheel.java @@ -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 + ); + } + } +} diff --git a/ProjectElectricLocomotive/DyrectionType.java b/ProjectElectricLocomotive/DyrectionType.java new file mode 100644 index 0000000..d833f54 --- /dev/null +++ b/ProjectElectricLocomotive/DyrectionType.java @@ -0,0 +1,5 @@ +package ProjectElectricLocomotive; + +public enum DyrectionType { + Up, Down, Left, Right +} diff --git a/ProjectElectricLocomotive/EntityElectricLocomotive.java b/ProjectElectricLocomotive/EntityElectricLocomotive.java new file mode 100644 index 0000000..492585f --- /dev/null +++ b/ProjectElectricLocomotive/EntityElectricLocomotive.java @@ -0,0 +1,26 @@ +package ProjectElectricLocomotive; + +import java.awt.*; + +public class EntityElectricLocomotive { + public int Speed; + public double Weight; + public Color BodyColor; + public Color AdditionalColor; + public boolean Horns; + public boolean SeifBatteries; + public double Step() + { + return (double) Speed * 100 / Weight; + } + public void Init(int speed, double weight, Color bodyColor, Color additionalColor, + boolean horns, boolean seifBatteries) + { + Speed = speed; + Weight = weight; + BodyColor = bodyColor; + AdditionalColor = additionalColor; + Horns = horns; + SeifBatteries = seifBatteries; + } +} diff --git a/ProjectElectricLocomotive/FormElectricLocomotive.form b/ProjectElectricLocomotive/FormElectricLocomotive.form new file mode 100644 index 0000000..9908b3b --- /dev/null +++ b/ProjectElectricLocomotive/FormElectricLocomotive.form @@ -0,0 +1,100 @@ + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/ProjectElectricLocomotive/FormElectricLocomotive.java b/ProjectElectricLocomotive/FormElectricLocomotive.java new file mode 100644 index 0000000..49f6cf2 --- /dev/null +++ b/ProjectElectricLocomotive/FormElectricLocomotive.java @@ -0,0 +1,79 @@ +package ProjectElectricLocomotive; +import javax.swing.*; +import java.awt.*; +import java.awt.event.ActionListener; +import java.util.Random; + +public class FormElectricLocomotive { + DrawingElectricLocomotive _drawingElectricLocomotive = new DrawingElectricLocomotive(); + private JButton buttonCreate; + private JPanel pictureBox; + private JButton buttonUp; + private JButton buttonDown; + private JButton buttonLeft; + private JButton buttonRight; + + public JPanel getPictureBox() { + return pictureBox; + } + public FormElectricLocomotive() + { + buttonUp.setName("buttonUp"); + buttonDown.setName("buttonDown"); + buttonLeft.setName("buttonLeft"); + buttonRight.setName("buttonRight"); + + buttonCreate.addActionListener(e -> { + _drawingElectricLocomotive = new DrawingElectricLocomotive(); + Random random = new Random(); + + _drawingElectricLocomotive.Init( + random.nextInt(100, 300), + random.nextInt(1000, 3000), + new Color(random.nextInt(256), random.nextInt(256), random.nextInt(256)), + new Color(random.nextInt(256), random.nextInt(256), random.nextInt(256)), + random.nextBoolean(), + random.nextBoolean(), + pictureBox.getWidth(), + pictureBox.getHeight() + ); + + _drawingElectricLocomotive.SetWheelsCount(random.nextInt(2, 5)); + _drawingElectricLocomotive.SetPosition(random.nextInt(10, 100), random.nextInt(10, 100)); + Draw(); + }); + + ActionListener buttonMoveClickedListener = e -> { + String buttonName = ((JButton) e.getSource()).getName(); + + switch (buttonName) { + case ("buttonUp") -> { + _drawingElectricLocomotive.MoveTransport(DyrectionType.Up); + } + case ("buttonDown") -> { + _drawingElectricLocomotive.MoveTransport(DyrectionType.Down); + } + case ("buttonLeft") -> { + _drawingElectricLocomotive.MoveTransport(DyrectionType.Left); + } + case ("buttonRight") -> { + _drawingElectricLocomotive.MoveTransport(DyrectionType.Right); + } + } + Draw(); + }; + buttonUp.addActionListener(buttonMoveClickedListener); + buttonDown.addActionListener(buttonMoveClickedListener); + buttonLeft.addActionListener(buttonMoveClickedListener); + buttonRight.addActionListener(buttonMoveClickedListener); + } + public void Draw() { + if (_drawingElectricLocomotive.EntityElectricLocomotive == null) { + return; + } + Graphics g = pictureBox.getGraphics(); + pictureBox.paint(g); + _drawingElectricLocomotive.DrawTransport(g); + } + +} diff --git a/ProjectElectricLocomotive/Main.java b/ProjectElectricLocomotive/Main.java new file mode 100644 index 0000000..2542503 --- /dev/null +++ b/ProjectElectricLocomotive/Main.java @@ -0,0 +1,8 @@ +package ProjectElectricLocomotive; + +public class Main { + public static void main(String[] args) + { + MainFrameElectricLocomotive mainFrameElectricLocomotive = new MainFrameElectricLocomotive(); + } +} diff --git a/ProjectElectricLocomotive/MainFrameElectricLocomotive.java b/ProjectElectricLocomotive/MainFrameElectricLocomotive.java new file mode 100644 index 0000000..629d685 --- /dev/null +++ b/ProjectElectricLocomotive/MainFrameElectricLocomotive.java @@ -0,0 +1,19 @@ +package ProjectElectricLocomotive; + +import javax.swing.*; + +public class MainFrameElectricLocomotive extends JFrame { + private FormElectricLocomotive _formElectricLocomotive; + + public MainFrameElectricLocomotive() { + super(); + setTitle("ElectroLoco"); + setDefaultCloseOperation(EXIT_ON_CLOSE); + _formElectricLocomotive = new FormElectricLocomotive(); + setContentPane(_formElectricLocomotive.getPictureBox()); + setDefaultLookAndFeelDecorated(false); + setLocation(500, 50); + pack(); + setVisible(true); + } +} diff --git a/ProjectElectricLocomotive/WheelsCount.java b/ProjectElectricLocomotive/WheelsCount.java new file mode 100644 index 0000000..08e4f6c --- /dev/null +++ b/ProjectElectricLocomotive/WheelsCount.java @@ -0,0 +1,9 @@ +package ProjectElectricLocomotive; + +public enum WheelsCount { + Two(2), Three(3), Four(4); + public final int count; + WheelsCount(int count) { + this.count = count; + } +} diff --git a/ProjectElectricLocomotive/img/arrowDown.jpg b/ProjectElectricLocomotive/img/arrowDown.jpg new file mode 100644 index 0000000..2d41e93 Binary files /dev/null and b/ProjectElectricLocomotive/img/arrowDown.jpg differ diff --git a/ProjectElectricLocomotive/img/arrowLeft.jpg b/ProjectElectricLocomotive/img/arrowLeft.jpg new file mode 100644 index 0000000..5f03da1 Binary files /dev/null and b/ProjectElectricLocomotive/img/arrowLeft.jpg differ diff --git a/ProjectElectricLocomotive/img/arrowRight.jpg b/ProjectElectricLocomotive/img/arrowRight.jpg new file mode 100644 index 0000000..41134aa Binary files /dev/null and b/ProjectElectricLocomotive/img/arrowRight.jpg differ diff --git a/ProjectElectricLocomotive/img/arrowUp.jpg b/ProjectElectricLocomotive/img/arrowUp.jpg new file mode 100644 index 0000000..74ea15e Binary files /dev/null and b/ProjectElectricLocomotive/img/arrowUp.jpg differ diff --git a/out/production/PIbd-21_Bakalskaya_E.D._ElectricLocomotive._HARD/.gitignore b/out/production/PIbd-21_Bakalskaya_E.D._ElectricLocomotive._HARD/.gitignore new file mode 100644 index 0000000..9154f4c --- /dev/null +++ b/out/production/PIbd-21_Bakalskaya_E.D._ElectricLocomotive._HARD/.gitignore @@ -0,0 +1,26 @@ +# ---> Java +# Compiled class file +*.class + +# Log file +*.log + +# BlueJ files +*.ctxt + +# Mobile Tools for Java (J2ME) +.mtj.tmp/ + +# Package Files # +*.jar +*.war +*.nar +*.ear +*.zip +*.tar.gz +*.rar + +# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml +hs_err_pid* +replay_pid* + diff --git a/out/production/PIbd-21_Bakalskaya_E.D._ElectricLocomotive._HARD/.idea/.gitignore b/out/production/PIbd-21_Bakalskaya_E.D._ElectricLocomotive._HARD/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/out/production/PIbd-21_Bakalskaya_E.D._ElectricLocomotive._HARD/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/out/production/PIbd-21_Bakalskaya_E.D._ElectricLocomotive._HARD/.idea/PIbd-21_Bakalskaya_E.D._ElectricLocomotive._HARD.iml b/out/production/PIbd-21_Bakalskaya_E.D._ElectricLocomotive._HARD/.idea/PIbd-21_Bakalskaya_E.D._ElectricLocomotive._HARD.iml new file mode 100644 index 0000000..b107a2d --- /dev/null +++ b/out/production/PIbd-21_Bakalskaya_E.D._ElectricLocomotive._HARD/.idea/PIbd-21_Bakalskaya_E.D._ElectricLocomotive._HARD.iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/out/production/PIbd-21_Bakalskaya_E.D._ElectricLocomotive._HARD/.idea/misc.xml b/out/production/PIbd-21_Bakalskaya_E.D._ElectricLocomotive._HARD/.idea/misc.xml new file mode 100644 index 0000000..4458232 --- /dev/null +++ b/out/production/PIbd-21_Bakalskaya_E.D._ElectricLocomotive._HARD/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/out/production/PIbd-21_Bakalskaya_E.D._ElectricLocomotive._HARD/.idea/modules.xml b/out/production/PIbd-21_Bakalskaya_E.D._ElectricLocomotive._HARD/.idea/modules.xml new file mode 100644 index 0000000..561b3e5 --- /dev/null +++ b/out/production/PIbd-21_Bakalskaya_E.D._ElectricLocomotive._HARD/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/out/production/PIbd-21_Bakalskaya_E.D._ElectricLocomotive._HARD/.idea/uiDesigner.xml b/out/production/PIbd-21_Bakalskaya_E.D._ElectricLocomotive._HARD/.idea/uiDesigner.xml new file mode 100644 index 0000000..2b63946 --- /dev/null +++ b/out/production/PIbd-21_Bakalskaya_E.D._ElectricLocomotive._HARD/.idea/uiDesigner.xml @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/out/production/PIbd-21_Bakalskaya_E.D._ElectricLocomotive._HARD/.idea/vcs.xml b/out/production/PIbd-21_Bakalskaya_E.D._ElectricLocomotive._HARD/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/out/production/PIbd-21_Bakalskaya_E.D._ElectricLocomotive._HARD/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/out/production/PIbd-21_Bakalskaya_E.D._ElectricLocomotive._HARD/README.md b/out/production/PIbd-21_Bakalskaya_E.D._ElectricLocomotive._HARD/README.md new file mode 100644 index 0000000..05af8c6 --- /dev/null +++ b/out/production/PIbd-21_Bakalskaya_E.D._ElectricLocomotive._HARD/README.md @@ -0,0 +1,2 @@ +# PIbd-21_Bakalskaya_E.D._ElectricLocomotive._HARD +