From e34fca8784e14d29bbdafedd92195cb8073c1b16 Mon Sep 17 00:00:00 2001 From: Tonb73 Date: Sat, 8 Jun 2024 15:48:47 +0400 Subject: [PATCH 1/4] 1 --- OOP/.gitignore | 29 ++++ OOP/.idea/.gitignore | 3 + OOP/.idea/misc.xml | 6 + OOP/.idea/modules.xml | 8 + OOP/.idea/vcs.xml | 6 + OOP/OOP.iml | 11 ++ OOP/src/Main.java | 7 + ..._Checkout_at_08_06_2024_6_41__Changes_.xml | 4 + OOP_Hard/.idea/workspace.xml | 147 ++++++++++++++++++ 9 files changed, 221 insertions(+) create mode 100644 OOP/.gitignore create mode 100644 OOP/.idea/.gitignore create mode 100644 OOP/.idea/misc.xml create mode 100644 OOP/.idea/modules.xml create mode 100644 OOP/.idea/vcs.xml create mode 100644 OOP/OOP.iml create mode 100644 OOP/src/Main.java create mode 100644 OOP_Hard/.idea/shelf/Uncommitted_changes_before_Checkout_at_08_06_2024_6_41__Changes_.xml create mode 100644 OOP_Hard/.idea/workspace.xml diff --git a/OOP/.gitignore b/OOP/.gitignore new file mode 100644 index 0000000..f68d109 --- /dev/null +++ b/OOP/.gitignore @@ -0,0 +1,29 @@ +### IntelliJ IDEA ### +out/ +!**/src/main/**/out/ +!**/src/test/**/out/ + +### Eclipse ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache +bin/ +!**/src/main/**/bin/ +!**/src/test/**/bin/ + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ + +### VS Code ### +.vscode/ + +### Mac OS ### +.DS_Store \ No newline at end of file diff --git a/OOP/.idea/.gitignore b/OOP/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/OOP/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/OOP/.idea/misc.xml b/OOP/.idea/misc.xml new file mode 100644 index 0000000..0548357 --- /dev/null +++ b/OOP/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/OOP/.idea/modules.xml b/OOP/.idea/modules.xml new file mode 100644 index 0000000..98761a0 --- /dev/null +++ b/OOP/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/OOP/.idea/vcs.xml b/OOP/.idea/vcs.xml new file mode 100644 index 0000000..6c0b863 --- /dev/null +++ b/OOP/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/OOP/OOP.iml b/OOP/OOP.iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/OOP/OOP.iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/OOP/src/Main.java b/OOP/src/Main.java new file mode 100644 index 0000000..082a77f --- /dev/null +++ b/OOP/src/Main.java @@ -0,0 +1,7 @@ +//TIP To Run code, press or +// click the icon in the gutter. +public class Main { + public static void main(String[] args) { + + } + } \ No newline at end of file diff --git a/OOP_Hard/.idea/shelf/Uncommitted_changes_before_Checkout_at_08_06_2024_6_41__Changes_.xml b/OOP_Hard/.idea/shelf/Uncommitted_changes_before_Checkout_at_08_06_2024_6_41__Changes_.xml new file mode 100644 index 0000000..5c4f2fd --- /dev/null +++ b/OOP_Hard/.idea/shelf/Uncommitted_changes_before_Checkout_at_08_06_2024_6_41__Changes_.xml @@ -0,0 +1,4 @@ + + \ No newline at end of file diff --git a/OOP_Hard/.idea/workspace.xml b/OOP_Hard/.idea/workspace.xml new file mode 100644 index 0000000..c1b1ae4 --- /dev/null +++ b/OOP_Hard/.idea/workspace.xml @@ -0,0 +1,147 @@ + + + + + + + + + + + + + + { + "associatedIndex": 3 +} + + + + + + + + + + + + + + + + + + + + + + 1717656751523 + + + + + + + + + + + + + + + + + + + + + + + + file://$PROJECT_DIR$/src/Main.java + 14 + + + + + \ No newline at end of file -- 2.25.1 From 78d14ef13e73e1ae6ea90f35c16fedf2a1b736b0 Mon Sep 17 00:00:00 2001 From: Tonb73 Date: Sat, 8 Jun 2024 15:52:07 +0400 Subject: [PATCH 2/4] =?UTF-8?q?=D0=A7=D0=B0=D1=81=D1=82=D1=8C=20=D0=BF?= =?UTF-8?q?=D0=B5=D1=80=D0=B5=D0=BD=D0=B5=D1=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- OOP/.idea/uiDesigner.xml | 124 +++++++++++ OOP/src/DirectionType.java | 6 + OOP/src/DrawningElectricLocomotive.java | 193 ++++++++++++++++++ OOP/src/DrawningElectricLocomotiveWheels.java | 51 +++++ OOP/src/FormElectricLocomotive.form | 131 ++++++++++++ OOP/src/FormElectricLocomotive.java | 177 ++++++++++++++++ 6 files changed, 682 insertions(+) create mode 100644 OOP/.idea/uiDesigner.xml create mode 100644 OOP/src/DirectionType.java create mode 100644 OOP/src/DrawningElectricLocomotive.java create mode 100644 OOP/src/DrawningElectricLocomotiveWheels.java create mode 100644 OOP/src/FormElectricLocomotive.form create mode 100644 OOP/src/FormElectricLocomotive.java diff --git a/OOP/.idea/uiDesigner.xml b/OOP/.idea/uiDesigner.xml new file mode 100644 index 0000000..2b63946 --- /dev/null +++ b/OOP/.idea/uiDesigner.xml @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/OOP/src/DirectionType.java b/OOP/src/DirectionType.java new file mode 100644 index 0000000..d3a2058 --- /dev/null +++ b/OOP/src/DirectionType.java @@ -0,0 +1,6 @@ +public enum DirectionType { + Up, + Down, + Left, + Right +} \ No newline at end of file diff --git a/OOP/src/DrawningElectricLocomotive.java b/OOP/src/DrawningElectricLocomotive.java new file mode 100644 index 0000000..e560f86 --- /dev/null +++ b/OOP/src/DrawningElectricLocomotive.java @@ -0,0 +1,193 @@ +import java.awt.*; +import java.util.Random; + +public class DrawningElectricLocomotive { + private EntityElectricLocomotive entityElectricLocomotive; + public EntityElectricLocomotive getEntityElectricLocomotive() { + return entityElectricLocomotive; + } + private Integer _pictureWidth; + private Integer _pictureHeight; + private Integer _startPosX; + private Integer _startPosY; + private final int _drawingElectricLocomotiveWidth = 100; + private final int _drawingElectricLocomotiveHight = 100; + + public DrawningElectricLocomotiveWheels _drawningElectricLocomotiveWheels; + + public void Init(int speed, double weight, Color bodyColor, Color additionalColor, boolean pantograph, boolean batteryStorage) { + entityElectricLocomotive = new EntityElectricLocomotive(); + entityElectricLocomotive.Init(speed, weight, bodyColor, additionalColor, pantograph, batteryStorage); + _startPosY = null; + _startPosX = null; + _pictureWidth = null; + _pictureHeight = null; + + _drawningElectricLocomotiveWheels = new DrawningElectricLocomotiveWheels(); + Random random = new Random(); + int[] countwheels = {2, 3, 4}; + int wheelCount = countwheels[random.nextInt(countwheels.length)]; + _drawningElectricLocomotiveWheels.setEnumNumber(wheelCount); + + + } + + public void setPosition(int x, int y) { + if (_pictureHeight == null || _pictureWidth == null) + return; + _startPosX = x; + _startPosY = y; + + if (_drawingElectricLocomotiveWidth + x > _pictureWidth || x < 0) { + _startPosX = 0; + } + if (_drawingElectricLocomotiveHight + y > _pictureHeight || y < 0) { + _startPosY = 0; + } + } + + public boolean setPictureSize(int width, int height) { + + if (_drawingElectricLocomotiveHight > height || _drawingElectricLocomotiveWidth > width) + return false; + _pictureHeight = height; + _pictureWidth = width; + + if (_startPosX != null && _startPosY != null) { + if (_startPosX + _drawingElectricLocomotiveWidth > width) + _startPosX = width - _drawingElectricLocomotiveWidth; + if (_startPosY + _drawingElectricLocomotiveHight > height) + _startPosY = height - _drawingElectricLocomotiveHight; + } + return true; + } + + public boolean moveTransport(DirectionType direction) { + if (entityElectricLocomotive == null || _pictureWidth == null || _pictureHeight == null) + return false; + switch (direction) { + case Left: + if (_startPosX - entityElectricLocomotive.Step() > 0) + _startPosX -= (int) entityElectricLocomotive.Step(); + return true; + case Up: + if (_startPosY - entityElectricLocomotive.Step() > 0) + _startPosY -= (int) entityElectricLocomotive.Step(); + return true; + case Right: + if (_startPosX + entityElectricLocomotive.Step() < _pictureWidth - _drawingElectricLocomotiveWidth) + _startPosX += (int) entityElectricLocomotive.Step(); + return true; + case Down: + if (_startPosY + entityElectricLocomotive.Step() < _pictureHeight - _drawingElectricLocomotiveHight) + _startPosY += (int) entityElectricLocomotive.Step(); + return true; + default: + return false; + } + } + + public void DrawTransport(Graphics g){ + if (entityElectricLocomotive == null || _startPosX == null || _startPosY == null) { + return; + } + + Graphics2D g2d = (Graphics2D) g; + _drawningElectricLocomotiveWheels.drawElectricLocomotiveWheels(g, Color.BLACK, _startPosX, _startPosY); + Point[] Body = new Point[]{ + new Point(_startPosX + 20,_startPosY + 20), + new Point(_startPosX, _startPosY + 25 + 20), + new Point(_startPosX , _startPosY + 50 + 20), + new Point(_startPosX + 100 , _startPosY + 50 + 20), + new Point(_startPosX + 100, _startPosY + 25 + 20), + new Point(_startPosX + 105, _startPosY + 20), + }; + + Polygon BodyPolygon = new Polygon(); + for(Point point:Body){ + BodyPolygon.addPoint(point.x, point.y); + } + g2d.setColor(entityElectricLocomotive.getBodyColor()); + g2d.fillPolygon(BodyPolygon); + + + Point[] line = new Point[]{ + new Point(_startPosX, _startPosY + 25 + 20), + new Point(_startPosX, _startPosY + 30 + 20), + new Point(_startPosX + 100, _startPosY + 30 + 20), + new Point(_startPosX + 100, _startPosY + 25 + 20), + }; + Polygon linePolugon = new Polygon(); + for(Point point: line){ + linePolugon.addPoint(point.x, point.y); + } + g2d.setColor(entityElectricLocomotive.getAdditionalColor()); + g2d.fillPolygon(linePolugon); + + + Point[] glass = new Point[]{ + new Point(_startPosX + 20, _startPosY + 2 + 20), + new Point(_startPosX + 6 , _startPosY + 20 + 20), + new Point(_startPosX + 20, _startPosY + 20 + 20), + new Point(_startPosX + 20, _startPosY + 2 + 20) + }; + Polygon glassPolygon = new Polygon(); + for(Point point: glass){ + glassPolygon.addPoint(point.x, point.y); + } + g2d.setColor(Color.WHITE); + g2d.fillPolygon(glassPolygon); + + + if(entityElectricLocomotive.getBatteryStorage()){ + int mod = 50; + Point[] battery = new Point[]{ + new Point(_startPosX + 40/2 + mod, _startPosY + 2+ 20), + new Point(_startPosX + 40/2 + mod, _startPosY + 4+ 20), + new Point(_startPosX + 35/2 + mod , _startPosY + 4+ 20), + new Point(_startPosX + 35/2 + mod, _startPosY + 16+ 20), + new Point(_startPosX + 60/2 + mod, _startPosY + 16+ 20), + new Point(_startPosX + 60/2 + mod, _startPosY + 4+ 20), + new Point(_startPosX + 55/2 + mod, _startPosY + 4+ 20), + new Point(_startPosX + 55/2 + mod, _startPosY + 2+ 20), + }; + mod += 20; + Point[] battery2 = new Point[]{ + new Point(_startPosX + 40/2 + mod, _startPosY + 2+ 20), + new Point(_startPosX + 40/2 + mod, _startPosY + 4+ 20), + new Point(_startPosX + 35/2 + mod , _startPosY + 4+ 20), + new Point(_startPosX + 35/2 + mod, _startPosY + 16+ 20), + new Point(_startPosX + 60/2 + mod, _startPosY + 16+ 20), + new Point(_startPosX + 60/2 + mod, _startPosY + 4+ 20), + new Point(_startPosX + 55/2 + mod, _startPosY + 4+ 20), + new Point(_startPosX + 55/2 + mod, _startPosY + 2+ 20), + }; + + Polygon batteryPolygon = new Polygon(); + for(Point points : battery){ + batteryPolygon.addPoint(points.x, points.y); + } + Polygon battery2Polygon = new Polygon(); + for(Point points : battery2){ + battery2Polygon.addPoint(points.x, points.y); + } + g2d.setColor(Color.YELLOW); + g2d.fillPolygon(batteryPolygon); + g2d.fillPolygon(battery2Polygon); + } + if(entityElectricLocomotive.getPantograph()){ + g2d.setColor(Color.BLACK); + g.drawRect(_startPosX + 40,_startPosY,10,1); + g.drawRect(_startPosX + 5 + 40, _startPosY ,1,20); + + g.drawRect(_startPosX + 40 + 30,_startPosY,10,1); + g.drawRect(_startPosX + 5 + 40 + 30, _startPosY ,1,20); + + } + + + + } + + +} diff --git a/OOP/src/DrawningElectricLocomotiveWheels.java b/OOP/src/DrawningElectricLocomotiveWheels.java new file mode 100644 index 0000000..a403e62 --- /dev/null +++ b/OOP/src/DrawningElectricLocomotiveWheels.java @@ -0,0 +1,51 @@ +import java.awt.*; + +public class DrawningElectricLocomotiveWheels { + private WheelsCount _wheelCount; + public void setEnumNumber(int wheelCount) { + for (WheelsCount value : WheelsCount.values()) { + if (value.getEnumNumber() == wheelCount) { + _wheelCount = value; + return; + } + } + } + public void drawElectricLocomotiveWheels(Graphics g, Color color, int startPosX, int startPosY) { + Graphics2D g2d = (Graphics2D) g; + g2d.setColor(color); + g2d.setStroke(new BasicStroke(4)); + + if (_wheelCount.getEnumNumber() >= 2){ + g2d.drawOval(startPosX, startPosY + 70,10,10); + g2d.drawOval(startPosX+ 10, startPosY + 70,10,10); + + g2d.drawOval(startPosX + 50, startPosY + 70,10,10); + g2d.drawOval(startPosX+ 10 + 50, startPosY + 70,10,10); + + } + + if (_wheelCount.getEnumNumber() >= 3){ + g2d.drawOval(startPosX, startPosY + 70,10,10); + g2d.drawOval(startPosX+ 10, startPosY + 70,10,10); + g2d.drawOval(startPosX+ 10 +10, startPosY + 70,10,10); + + g2d.drawOval(startPosX + 50, startPosY + 70,10,10); + g2d.drawOval(startPosX + 10 + 50, startPosY + 70,10,10); + g2d.drawOval(startPosX + 10 + 10 + 50, startPosY + 70,10,10); + } + + if (_wheelCount.getEnumNumber() >= 4){ + g2d.drawOval(startPosX, startPosY + 70,10,10); + g2d.drawOval(startPosX+ 10, startPosY + 70,10,10); + g2d.drawOval(startPosX+ 10 +10, startPosY + 70,10,10); + g2d.drawOval(startPosX+ 10 +10 + 10, startPosY + 70,10,10); + + g2d.drawOval(startPosX + 50, startPosY + 70,10,10); + g2d.drawOval(startPosX + 10 + 50, startPosY + 70,10,10); + g2d.drawOval(startPosX + 10 + 10 + 50, startPosY + 70,10,10); + g2d.drawOval(startPosX + 10 + 10 + 10 + 50, startPosY + 70,10,10); + } + + } +} + diff --git a/OOP/src/FormElectricLocomotive.form b/OOP/src/FormElectricLocomotive.form new file mode 100644 index 0000000..137ff13 --- /dev/null +++ b/OOP/src/FormElectricLocomotive.form @@ -0,0 +1,131 @@ + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
diff --git a/OOP/src/FormElectricLocomotive.java b/OOP/src/FormElectricLocomotive.java new file mode 100644 index 0000000..1dd2a7d --- /dev/null +++ b/OOP/src/FormElectricLocomotive.java @@ -0,0 +1,177 @@ + +import Drawnings.DrawningElectricLocomotive; +import Drawnings.DrawningLocomotive; +import MovementStrategy.*; + +import javax.swing.*; +import java.awt.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.util.LinkedList; +import java.util.Random; +import java.util.List; + +public class FormElectricLocomotive extends JFrame { + protected DrawningLocomotive _drawningLocomotive; + JPanel PanelWrapper; + private JPanel PictureBox; + private JButton buttonCreateElectricLocomotive; + private JButton buttonCreateLocomotive; + private JButton buttonRight; + private JButton buttonDown; + private JButton buttonLeft; + private JButton buttonUp; + private JComboBox comboBoxStrategy; + private JButton buttonStrategyStep; + private AbstractStrategy _strategy; + private List controls; + + private void createObject(String type) { + Random random = new Random(); + switch (type) { + case "Drawnings.DrawningLocomotive": + _drawningLocomotive = new DrawningLocomotive(50, 100, + new Color(random.nextInt(256), random.nextInt(256), random.nextInt(256)), random.nextInt(3)); + break; + case "Drawnings.DrawningElectricLocomotive": + _drawningLocomotive = new DrawningElectricLocomotive(50, 100, + new Color(random.nextInt(256), random.nextInt(256), random.nextInt(256)),random.nextInt(3), + new Color(random.nextInt(256), random.nextInt(256), random.nextInt(256)), + random.nextBoolean(), random.nextBoolean()); + break; + default: + return; + } + _drawningLocomotive.setPictureSize(PictureBox.getWidth(), PictureBox.getHeight()); + _drawningLocomotive.setPosition(random.nextInt(100), + random.nextInt(100)); + _strategy = null; + comboBoxStrategy.setEnabled(true); + + Draw(); + } + + public FormElectricLocomotive() { + buttonUp.setName("buttonUp"); + buttonDown.setName("buttonDown"); + buttonLeft.setName("buttonLeft"); + buttonRight.setName("buttonRight"); + + InitializeControlsRepaintList(); + + buttonCreateElectricLocomotive.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + createObject("Drawnings.DrawningElectricLocomotive"); + + } + }); + buttonCreateLocomotive.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + createObject("Drawnings.DrawningLocomotive"); + } + }); + ActionListener buttonMoveClickedListener = new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + String buttonName = ((JButton) e.getSource()).getName(); + boolean result = false; + + switch (buttonName) { + case "buttonUp": { + result = _drawningLocomotive.moveTransport(MovementDirection.Up); + } + break; + case "buttonDown": { + result = _drawningLocomotive.moveTransport(MovementDirection.Down); + } + break; + case "buttonLeft": { + result = _drawningLocomotive.moveTransport(MovementDirection.Left); + } + break; + case "buttonRight": { + result = _drawningLocomotive.moveTransport(MovementDirection.Right); + } + break; + } + if (result) + Draw(); + } + }; + buttonRight.addActionListener(buttonMoveClickedListener); + buttonDown.addActionListener(buttonMoveClickedListener); + buttonLeft.addActionListener(buttonMoveClickedListener); + buttonUp.addActionListener(buttonMoveClickedListener); + comboBoxStrategy.addItem("К центру"); + comboBoxStrategy.addItem("К краю"); + buttonStrategyStep.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + if (_drawningLocomotive == null) + return; + if (comboBoxStrategy.isEnabled()) { + switch (comboBoxStrategy.getSelectedIndex()) { + case 0: + _strategy = new MoveToCenter(); + break; + case 1: + _strategy = new MoveToBorder(); + break; + + default: + _strategy = null; + break; + + } + if (_strategy == null) { + return; + } + _strategy.SetData(new MoveableLocomotive(_drawningLocomotive), PictureBox.getWidth(), PictureBox.getHeight()); + } + if (_strategy == null) { + return; + } + _strategy.MakeStep(); + Draw(); + comboBoxStrategy.setEnabled(false); + + if (_strategy.GetStatus() == StrategyStatus.Finish) { + comboBoxStrategy.setEnabled(true); + _strategy = null; + } + } + }); + } + private void Draw() { + if (_drawningLocomotive.getEntityLocomotive() == null) + return; + if (PictureBox.getWidth() == 0 || PictureBox.getHeight() == 0) { + return; + } + Graphics g = PictureBox.getGraphics(); + g.setColor(PictureBox.getBackground()); + g.fillRect(0,0, PictureBox.getWidth(), PictureBox.getHeight()); + _drawningLocomotive.DrawTransport(g); + + RepaintControls(); + } + private void RepaintControls() { + for (JComponent control : controls) { + control.repaint(); + } + } + + private void InitializeControlsRepaintList() { + controls = new LinkedList<>(); + controls.add(buttonCreateElectricLocomotive); + controls.add(buttonCreateLocomotive); + controls.add(buttonUp); + controls.add(buttonDown); + controls.add(buttonLeft); + controls.add(buttonRight); + controls.add(comboBoxStrategy); + controls.add(buttonStrategyStep); + } +} \ No newline at end of file -- 2.25.1 From e3f5feadb25456afeda8d511be7b0c7bdd612bbf Mon Sep 17 00:00:00 2001 From: Tonb73 Date: Sat, 8 Jun 2024 15:53:53 +0400 Subject: [PATCH 3/4] =?UTF-8?q?=D0=94=D0=BE=D0=BF=D1=83=D1=81=D1=82=D0=B8?= =?UTF-8?q?=D0=BC=20=D0=BF=D0=B5=D1=80=D0=B5=D0=BD=D0=B5=D1=81=20=D0=B2?= =?UTF-8?q?=D1=81=D0=B5=20=D1=84=D0=B0=D0=B9=D0=BB=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- OOP/src/EntityElectricLocomotive.java | 39 ++++++++ OOP/src/FormElectricLocomotive.form | 116 ++++++++--------------- OOP/src/FormElectricLocomotive.java | 127 +++++++------------------- OOP/src/Main.java | 15 ++- OOP/src/WheelsCount.java | 12 +++ 5 files changed, 134 insertions(+), 175 deletions(-) create mode 100644 OOP/src/EntityElectricLocomotive.java create mode 100644 OOP/src/WheelsCount.java diff --git a/OOP/src/EntityElectricLocomotive.java b/OOP/src/EntityElectricLocomotive.java new file mode 100644 index 0000000..c8f4f4b --- /dev/null +++ b/OOP/src/EntityElectricLocomotive.java @@ -0,0 +1,39 @@ +import java.awt.*; + +public class EntityElectricLocomotive { + private int Speed; + public int getSpeed() { + return Speed; + } + private double Weight; + public double getWeight() { + return Weight; + } + private Color BodyColor; + public Color getBodyColor() { + return BodyColor; + } + private Color AdditionalColor; + public Color getAdditionalColor() { + return AdditionalColor; + } + public double Step() { + return Speed*100/Weight; + } + private boolean BatteryStorage; + public boolean getBatteryStorage() { + return BatteryStorage; + } + private boolean Pantograph; + public boolean getPantograph() { + return Pantograph; + } + public void Init(int speed, double weight, Color bodyColor, Color additionalColor, boolean pantograph, boolean batteryStorage) { + Speed = speed; + Weight = weight; + BodyColor = bodyColor; + AdditionalColor = additionalColor; + Pantograph = pantograph; + BatteryStorage = batteryStorage; + } +} diff --git a/OOP/src/FormElectricLocomotive.form b/OOP/src/FormElectricLocomotive.form index 137ff13..5b13c84 100644 --- a/OOP/src/FormElectricLocomotive.form +++ b/OOP/src/FormElectricLocomotive.form @@ -8,89 +8,30 @@ - + - - - + + + + + + + + + - - - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + @@ -101,9 +42,14 @@ + + + + + - + @@ -114,14 +60,30 @@ - + - + + + + + - - - + + + + + + + + + + + + + + + diff --git a/OOP/src/FormElectricLocomotive.java b/OOP/src/FormElectricLocomotive.java index 1dd2a7d..2a90784 100644 --- a/OOP/src/FormElectricLocomotive.java +++ b/OOP/src/FormElectricLocomotive.java @@ -1,56 +1,22 @@ - -import Drawnings.DrawningElectricLocomotive; -import Drawnings.DrawningLocomotive; -import MovementStrategy.*; - import javax.swing.*; import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.util.LinkedList; -import java.util.Random; import java.util.List; +import java.util.Random; public class FormElectricLocomotive extends JFrame { - protected DrawningLocomotive _drawningLocomotive; + protected DrawningElectricLocomotive _drawningElectricLocomotive = new DrawningElectricLocomotive(); JPanel PanelWrapper; private JPanel PictureBox; - private JButton buttonCreateElectricLocomotive; - private JButton buttonCreateLocomotive; + private JButton buttonCreate; private JButton buttonRight; private JButton buttonDown; private JButton buttonLeft; private JButton buttonUp; - private JComboBox comboBoxStrategy; - private JButton buttonStrategyStep; - private AbstractStrategy _strategy; + private List controls; - - private void createObject(String type) { - Random random = new Random(); - switch (type) { - case "Drawnings.DrawningLocomotive": - _drawningLocomotive = new DrawningLocomotive(50, 100, - new Color(random.nextInt(256), random.nextInt(256), random.nextInt(256)), random.nextInt(3)); - break; - case "Drawnings.DrawningElectricLocomotive": - _drawningLocomotive = new DrawningElectricLocomotive(50, 100, - new Color(random.nextInt(256), random.nextInt(256), random.nextInt(256)),random.nextInt(3), - new Color(random.nextInt(256), random.nextInt(256), random.nextInt(256)), - random.nextBoolean(), random.nextBoolean()); - break; - default: - return; - } - _drawningLocomotive.setPictureSize(PictureBox.getWidth(), PictureBox.getHeight()); - _drawningLocomotive.setPosition(random.nextInt(100), - random.nextInt(100)); - _strategy = null; - comboBoxStrategy.setEnabled(true); - - Draw(); - } - public FormElectricLocomotive() { buttonUp.setName("buttonUp"); buttonDown.setName("buttonDown"); @@ -59,17 +25,23 @@ public class FormElectricLocomotive extends JFrame { InitializeControlsRepaintList(); - buttonCreateElectricLocomotive.addActionListener(new ActionListener() { + buttonCreate.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { - createObject("Drawnings.DrawningElectricLocomotive"); + _drawningElectricLocomotive = new DrawningElectricLocomotive(); + Random random = new Random(); + + _drawningElectricLocomotive.Init(25, + 200, + 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() ); + _drawningElectricLocomotive.setPictureSize(PictureBox.getWidth(), PictureBox.getHeight()); + _drawningElectricLocomotive.setPosition(random.nextInt(100), + random.nextInt(100)); + + Draw(); - } - }); - buttonCreateLocomotive.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - createObject("Drawnings.DrawningLocomotive"); } }); ActionListener buttonMoveClickedListener = new ActionListener() { @@ -80,72 +52,36 @@ public class FormElectricLocomotive extends JFrame { switch (buttonName) { case "buttonUp": { - result = _drawningLocomotive.moveTransport(MovementDirection.Up); + result = _drawningElectricLocomotive.moveTransport(DirectionType.Up); } break; case "buttonDown": { - result = _drawningLocomotive.moveTransport(MovementDirection.Down); + result = _drawningElectricLocomotive.moveTransport(DirectionType.Down); } break; case "buttonLeft": { - result = _drawningLocomotive.moveTransport(MovementDirection.Left); + result = _drawningElectricLocomotive.moveTransport(DirectionType.Left); } break; case "buttonRight": { - result = _drawningLocomotive.moveTransport(MovementDirection.Right); + result = _drawningElectricLocomotive.moveTransport(DirectionType.Right); } break; + } if (result) Draw(); + } }; buttonRight.addActionListener(buttonMoveClickedListener); buttonDown.addActionListener(buttonMoveClickedListener); buttonLeft.addActionListener(buttonMoveClickedListener); buttonUp.addActionListener(buttonMoveClickedListener); - comboBoxStrategy.addItem("К центру"); - comboBoxStrategy.addItem("К краю"); - buttonStrategyStep.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - if (_drawningLocomotive == null) - return; - if (comboBoxStrategy.isEnabled()) { - switch (comboBoxStrategy.getSelectedIndex()) { - case 0: - _strategy = new MoveToCenter(); - break; - case 1: - _strategy = new MoveToBorder(); - break; - default: - _strategy = null; - break; - - } - if (_strategy == null) { - return; - } - _strategy.SetData(new MoveableLocomotive(_drawningLocomotive), PictureBox.getWidth(), PictureBox.getHeight()); - } - if (_strategy == null) { - return; - } - _strategy.MakeStep(); - Draw(); - comboBoxStrategy.setEnabled(false); - - if (_strategy.GetStatus() == StrategyStatus.Finish) { - comboBoxStrategy.setEnabled(true); - _strategy = null; - } - } - }); } private void Draw() { - if (_drawningLocomotive.getEntityLocomotive() == null) + if (_drawningElectricLocomotive.getEntityElectricLocomotive() == null) return; if (PictureBox.getWidth() == 0 || PictureBox.getHeight() == 0) { return; @@ -153,9 +89,10 @@ public class FormElectricLocomotive extends JFrame { Graphics g = PictureBox.getGraphics(); g.setColor(PictureBox.getBackground()); g.fillRect(0,0, PictureBox.getWidth(), PictureBox.getHeight()); - _drawningLocomotive.DrawTransport(g); + _drawningElectricLocomotive.DrawTransport(g); RepaintControls(); + } private void RepaintControls() { for (JComponent control : controls) { @@ -163,15 +100,15 @@ public class FormElectricLocomotive extends JFrame { } } + private void InitializeControlsRepaintList() { controls = new LinkedList<>(); - controls.add(buttonCreateElectricLocomotive); - controls.add(buttonCreateLocomotive); + controls.add(buttonCreate); controls.add(buttonUp); controls.add(buttonDown); controls.add(buttonLeft); controls.add(buttonRight); - controls.add(comboBoxStrategy); - controls.add(buttonStrategyStep); } -} \ No newline at end of file + + +} diff --git a/OOP/src/Main.java b/OOP/src/Main.java index 082a77f..ca8fdc0 100644 --- a/OOP/src/Main.java +++ b/OOP/src/Main.java @@ -1,7 +1,16 @@ +import javax.swing.*; + //TIP To Run code, press or // click the icon in the gutter. public class Main { public static void main(String[] args) { - - } - } \ No newline at end of file + JFrame.setDefaultLookAndFeelDecorated(false); + JFrame frame = new JFrame("Поезд"); + frame.setContentPane(new FormElectricLocomotive().PanelWrapper); + frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + frame.setLocation(500, 200); + frame.pack(); + frame.setSize(700, 500); + frame.setVisible(true); + } +} \ No newline at end of file diff --git a/OOP/src/WheelsCount.java b/OOP/src/WheelsCount.java new file mode 100644 index 0000000..f86dd18 --- /dev/null +++ b/OOP/src/WheelsCount.java @@ -0,0 +1,12 @@ +public enum WheelsCount { + Two(2), + Three(3), + Four(4); + final private int EnumNumber; + WheelsCount(int enumNumber) { + EnumNumber = enumNumber; + } + public int getEnumNumber() { + return EnumNumber; + } +} -- 2.25.1 From ef856b41d21cc8841bdd846b88e6ae0c8aef9998 Mon Sep 17 00:00:00 2001 From: Tonb73 Date: Sat, 8 Jun 2024 15:56:34 +0400 Subject: [PATCH 4/4] =?UTF-8?q?=D0=92=D1=81=D0=B5=20=D0=BF=D1=80=D1=87?= =?UTF-8?q?=D0=B8=D0=BD=D0=B5=D0=BD=D0=BE,=20=D0=B2=D1=81=D0=B5=20=D1=80?= =?UTF-8?q?=D0=B0=D0=B1=D0=BE=D1=82=D0=B0=D0=B5=D1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- OOP/OOP.iml | 1 + OOP/Resources/arrowDown.png | Bin 0 -> 965 bytes OOP/Resources/arrowLeft.png | Bin 0 -> 1005 bytes OOP/Resources/arrowRight.png | Bin 0 -> 978 bytes OOP/Resources/arrowUp.png | Bin 0 -> 1012 bytes OOP/src/Main.java | 3 --- 6 files changed, 1 insertion(+), 3 deletions(-) create mode 100644 OOP/Resources/arrowDown.png create mode 100644 OOP/Resources/arrowLeft.png create mode 100644 OOP/Resources/arrowRight.png create mode 100644 OOP/Resources/arrowUp.png diff --git a/OOP/OOP.iml b/OOP/OOP.iml index c90834f..d5b343a 100644 --- a/OOP/OOP.iml +++ b/OOP/OOP.iml @@ -3,6 +3,7 @@ + diff --git a/OOP/Resources/arrowDown.png b/OOP/Resources/arrowDown.png new file mode 100644 index 0000000000000000000000000000000000000000..2d51306b4744a97dc0e59ef5af54c90401b042ab GIT binary patch literal 965 zcmeAS@N?(olHy`uVBq!ia0vp^av;nBBpBqPKh^;$rX+877l!}s{b%+Ad7K3vk;M!Q ze1}1p@p%4<6rdn`iKnkC`wM11HgV3Ed38EKA;$b7zYxari^^vKIdQ2Go@u_m3|c@o z2Ll_U5Cbzv2@o+Os=fURW#3jNzvTANa`edDA)u%t&?FXS*L))~ zQ!zu{>D|nm)w{pVsTM4{f1rBDoWnJnzr|IbJs`F}>-h;rMG+gr$aRnYA3ZxIU$T?i zDCn5p#-h2a1%w|Rd(KntX!l^_O5>-Gk1j1bf5)#;#QD>svrBd^bK1M5_wk-M9!<9+ z4a5)#LSlL`Bb!mi_OOBf~Y`RR5rG-K_ zZeZH+`QeTOuQ-bixp(dptoc|FtX`L^eIsX`zQxz?a@*D=O}793I8l0eWPV~;&bPeX&Zolj kR^9LWxcxrg)ur3_Pftwk{2Z#54U9_$Pgg&ebxsLQ07u_nH~;_u literal 0 HcmV?d00001 diff --git a/OOP/Resources/arrowLeft.png b/OOP/Resources/arrowLeft.png new file mode 100644 index 0000000000000000000000000000000000000000..2c406e851276b58c97852701a1cfdefe9432fda5 GIT binary patch literal 1005 zcmeAS@N?(olHy`uVBq!ia0vp^av;nBBpBqPKh^;$rX+877l!}s{b%+Ad7K3vk;M!Q ze1}1p@p%4<6rdn`iKnkC`wM11HgV3Ed38EKA;$b7zYxari^^vKIdQ2Go@u_m3|c@o z2Ll_U5Cbzv2@oe9Oqx+J-LZPkx|gGBUowGl|KxN z7Pvbxz3OO*z5PCQ-rk!Ykuxs8eOqbs`Pet(5~q-}PnByXTeWqby>(mpX0=yUvzV^b zs-#_Id&0z-WtD6%-HCaj8(FgDg!xsO*OTAP`!ezJvu8W|e;!xfv&J>;*_xf#56C|I zr&Ygjsf(n`{+x<6kG9TxZg*Tz;BukvCz;p-Oz)2s1U1aEtdDble1XY&zTKX9z5Z#U z7c>^t&pTMEdsFQ|<9$BmperRc=eO!Dco;A4ba~sob}qNye^nlcO`THd*8aWVUg(22 zM`gDxd!q5ioI!VW&zJM1_glQI_}@#-P6^doTX}tPGq3fh2KUQJM$ZlFZkOHDd3i7+ z_W9iRGtM6<{U3TWKH=!9brtPN294HU&GG$>w>RA2-?rUsyIfx10;|q>oppPimG^o$*ZF_e(#I7--~dMGxZL7 z#jZ_WpUs|<>Nox0t_$7okJi-jo-%#;|N6?E>(uyDm;T?u_O#DXeRk}po@tx*S>>*( a<#hX!T5R}r!CYXRGkCiCxvXdO-0aPLhR}zp}k(v{bS`?a>SrWluY;Iwoqp;Rn-V&#xNT{O3 zhw{sTiUd$i0vW@g_hQ~B8=#yNTrN1s-6<$FFD11oGcVmUuOu}OsA?n$LTp=Ew;{Kiamqs{|2T&C-z+)>WUuD?z8@| zOi@eK3JP4{p_pEsCh_~s-1iOJr~pUwiewF?vTeeyrP3Q6j@$&xR>;p?xnzj;f<{Ei>D z|H*KrhAmxfz1-f7+U`pKRS$+%ynl1xaP$GG#|`ECzr0D%is4&%O{!mR+3O2$KlW_f zASR`wdFAj=zSq}-rIxB$)UG+rX|=~j%6yCC#Vnz@U)kp8mE7OA=>3K{OZD`>oLduT z&|a2Yw#oeU)uZ)4wWny?uePwYmygX$UckL4{{O)_m;Nk#W!T?i?tMV7{Z@R3sN$WC zFQ!W5{5w|rJrh~xyNxOLOmdKI;Vst0Q-|& ABme*a literal 0 HcmV?d00001 diff --git a/OOP/Resources/arrowUp.png b/OOP/Resources/arrowUp.png new file mode 100644 index 0000000000000000000000000000000000000000..e3a03831d7aab179980ec7b6fd5d56167851a114 GIT binary patch literal 1012 zcmeAS@N?(olHy`uVBq!ia0vp^av;nBBpBqPKh^;$rX+877l!}s{b%+Ad7K3vk;M!Q ze1}1p@p%4<6rdn`iKnkC`wM11HZi_D!CU8mLX7!Eej$wK7nRQfa^g}WJkxxA8MJ_G z4hA+xAqHlU5+Gz?W@KOmvl$q|n3+K$V9XFG0AYg!0tFdZAmV&S0)-H4pcqhf+X4oL zjs06fO+ePFmbgZgq$HN4S|t~y0x1R~10xe%17lr7lMn+lD-0aPLhR}zp}k(v{bS`?a>SrWluY;Iwoqp;Rn-V&#xNT{O3hw{sT ziUd$i0vW@g_hQ~B8=#yNTrN1s-6<$FFD11oGcVmUuOu}OsA?||7Y9eAHH4MC} zwu%ck8Zf@I{cX7JW{f^t-GSP9GiRD^PCI)bZF$tQ*H3!v>(28%t3TN_wK{*f*@gM* zcTK)(T-|wl|C%W#-{Tj(PG}d}IPHbz^$SbIs(WUyvepUuKW%?WbX{|YT=(;%&Fgn; zmc7q)>0z6la)0)j?8>gVi=8Lpd_O-q8db1qeL!MaXVvwrwc=3+PK$i|_1o`_iGv7t zMWV2}vkJ#jKId3={|BOirT2?6GY`5Mc%}gufaO zLoG{VlIKmz^>}Z)xVgkHp#O#@=On3v>>akAu67MA7d^s?rFrKZcsZ#m?c=#Q(k!25 zeaQLnQEu<=KQA9Y+qA+-<;CZ<-{bB6e7F`>zet!J*gAB{3joJE-Dnp zDLA{#Z?e9R(`{aU-To;>1xp^z_IBbf-muZkmaTu~O#V49Ja6;6{n_l3%z1}3@A0>q e{Run code, press or -// click the icon in the gutter. public class Main { public static void main(String[] args) { JFrame.setDefaultLookAndFeelDecorated(false); -- 2.25.1