diff --git a/ProjectContainerShip/.idea/misc.xml b/ProjectContainerShip/.idea/misc.xml new file mode 100644 index 0000000..12f22af --- /dev/null +++ b/ProjectContainerShip/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/ProjectContainerShip/.idea/modules.xml b/ProjectContainerShip/.idea/modules.xml new file mode 100644 index 0000000..74373b3 --- /dev/null +++ b/ProjectContainerShip/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/ProjectContainerShip/.idea/vcs.xml b/ProjectContainerShip/.idea/vcs.xml new file mode 100644 index 0000000..6c0b863 --- /dev/null +++ b/ProjectContainerShip/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/ProjectContainerShip/Resources/30px_arrow_down.png b/ProjectContainerShip/Resources/30px_arrow_down.png new file mode 100644 index 0000000..7aa3255 Binary files /dev/null and b/ProjectContainerShip/Resources/30px_arrow_down.png differ diff --git a/ProjectContainerShip/Resources/30px_arrow_left.png b/ProjectContainerShip/Resources/30px_arrow_left.png new file mode 100644 index 0000000..9a3dfa2 Binary files /dev/null and b/ProjectContainerShip/Resources/30px_arrow_left.png differ diff --git a/ProjectContainerShip/Resources/30px_arrow_right.png b/ProjectContainerShip/Resources/30px_arrow_right.png new file mode 100644 index 0000000..0f06fd0 Binary files /dev/null and b/ProjectContainerShip/Resources/30px_arrow_right.png differ diff --git a/ProjectContainerShip/Resources/30px_arrow_up.png b/ProjectContainerShip/Resources/30px_arrow_up.png new file mode 100644 index 0000000..67ae4bc Binary files /dev/null and b/ProjectContainerShip/Resources/30px_arrow_up.png differ diff --git a/ProjectContainerShip/src/DeckCount.java b/ProjectContainerShip/src/DeckCount.java new file mode 100644 index 0000000..d8ceff9 --- /dev/null +++ b/ProjectContainerShip/src/DeckCount.java @@ -0,0 +1,15 @@ +package ProjectContainerShip.src; + +public enum DeckCount { + One(1), + Two(2), + Three(3); + + final private int EnumNumber; + DeckCount(int enumNumber) { + EnumNumber = enumNumber; + } + public int getEnumNumber() { + return EnumNumber; + } +} diff --git a/ProjectContainerShip/src/DirectionType.java b/ProjectContainerShip/src/DirectionType.java new file mode 100644 index 0000000..523ac1b --- /dev/null +++ b/ProjectContainerShip/src/DirectionType.java @@ -0,0 +1,8 @@ +package ProjectContainerShip.src; + +public enum DirectionType { + Up, + Down, + Left, + Right +} diff --git a/ProjectContainerShip/src/DrawningContainerShip.java b/ProjectContainerShip/src/DrawningContainerShip.java new file mode 100644 index 0000000..6a712f0 --- /dev/null +++ b/ProjectContainerShip/src/DrawningContainerShip.java @@ -0,0 +1,188 @@ +package ProjectContainerShip.src; + +import java.awt.*; +import java.util.Random; + +public class DrawningContainerShip { + private EntityContainerShip entityContainerShip; + public EntityContainerShip getEntityContainerShip() { + return entityContainerShip; + } + private Integer _pictureWidth; + private Integer _pictureHeight; + private Integer _startPosX; + private Integer _startPosY; + private final int _drawingContainerShipWidth = 130; + private final int _drawingContainerShipHeight = 60; + public DrawningContainerShipDeck _drawingContainerShipDeck; + + public void Init(int speed, float weight, Color bodyColor, Color additionalColor, boolean crane, boolean container) { + entityContainerShip = new EntityContainerShip(); + entityContainerShip.Init(speed, weight, bodyColor, additionalColor, crane, container); + _startPosY = null; + _startPosX = null; + _pictureWidth = null; + _pictureHeight = null; + + _drawingContainerShipDeck = new DrawningContainerShipDeck(); + Random random = new Random(); + int deckCount = random.nextInt(1,4); + _drawingContainerShipDeck.setEnumNumber(deckCount); + + } + + + public void setPosition(int x, int y) { + if (_pictureHeight == null || _pictureWidth == null) + return; + _startPosX = x; + _startPosY = y; + + if (_drawingContainerShipWidth + x > _pictureWidth || x < 0) { + _startPosX = 0; + } + if (_drawingContainerShipHeight + y > _pictureHeight || y < 0) { + _startPosY = 0; + } + } + public boolean setPictureSize(int width, int height) { + + if (_drawingContainerShipHeight > height || _drawingContainerShipWidth > width) + return false; + _pictureHeight = height; + _pictureWidth = width; + + if (_startPosX != null && _startPosY != null) + { + if (_startPosX + _drawingContainerShipWidth > width) + _startPosX = width - _drawingContainerShipWidth; + if (_startPosY + _drawingContainerShipHeight > height) + _startPosY = height - _drawingContainerShipHeight; + } + + return true; + + + } + + public boolean moveTransport(DirectionType direction) { + if (entityContainerShip == null || _pictureWidth == null || _pictureHeight == null) + return false; + switch (direction) { + case Left: + if (_startPosX - entityContainerShip.Step() > 0) + _startPosX -= (int) entityContainerShip.Step(); + return true; + case Up: + if (_startPosY - entityContainerShip.Step() > 0) + _startPosY -= (int) entityContainerShip.Step(); + return true; + case Right: + if (_startPosX + entityContainerShip.Step() < _pictureWidth - _drawingContainerShipWidth) + _startPosX += (int) entityContainerShip.Step(); + return true; + case Down: + if (_startPosY + entityContainerShip.Step() < _pictureHeight - _drawingContainerShipHeight) + _startPosY += (int) entityContainerShip.Step(); + return true; + default: + return false; + + + } + } + + + // тут рисовашки + + private void drawCrane(Color additionalColor, Graphics g2d) + { + g2d.setColor(additionalColor); + Point[] crane = new Point[] + { + new Point(_startPosX + 75, _startPosY + 50), + new Point(_startPosX + 85, _startPosY+ 50), + new Point(_startPosX + 85, _startPosY + 20), + new Point(_startPosX + 105, _startPosY + 20), + new Point(_startPosX + 105, _startPosY + 15), + new Point(_startPosX + 75, _startPosY + 15), + + }; + Polygon cranePolygon = new Polygon(); + for (Point point: crane) { + cranePolygon.addPoint(point.x, point.y); + } + g2d.fillPolygon(cranePolygon); + g2d.drawPolygon(cranePolygon); + } + + private void drawContainer(Color additionalColor, Graphics g2d) + { + g2d.setColor(Color.BLACK); + + Point[] container1 = new Point[] { + new Point(_startPosX + 90, _startPosY + 50), + new Point(_startPosX + 120, _startPosY + 50), + new Point(_startPosX + 120, _startPosY + 40), + new Point(_startPosX + 90, _startPosY + 40) + }; + Polygon container1Polygon = new Polygon(); + for(Point point: container1) { + container1Polygon.addPoint(point.x, point.y); + } + + Point[] container2 = new Point[] { + new Point(_startPosX + 90, _startPosY + 40), + new Point(_startPosX + 90, _startPosY + 30), + new Point(_startPosX + 120, _startPosY + 30), + new Point(_startPosX + 120, _startPosY + 40) + }; + Polygon container2Polygon = new Polygon(); + for(Point point: container1) { + container2Polygon.addPoint(point.x, point.y); + } + + g2d.drawPolygon(container1Polygon); + g2d.drawPolygon(container2Polygon); + g2d.setColor(entityContainerShip.getAdditionalColor()); + g2d.fillPolygon(container1Polygon); + g2d.fillPolygon(container2Polygon); + } + + public void drawContainerShip(Graphics g) { + if (entityContainerShip == null || _startPosX == null || _startPosY == null) { + return; + } + + Graphics2D g2d = (Graphics2D) g; + + Point[] containerShipBorders = new Point[] { + new Point(_startPosX, _startPosY + 50), + new Point(_startPosX + 20, _startPosY + 70), + new Point(_startPosX + 110, _startPosY + 70), + new Point(_startPosX + 130, _startPosY + 50) + }; + Polygon containerShipPolygon = new Polygon(); + for(Point point : containerShipBorders) + containerShipPolygon.addPoint(point.x, point.y); + g2d.setColor(Color.BLACK); + g2d.draw(containerShipPolygon); + g2d.setColor(entityContainerShip.getBodyColor()); + g2d.fill(containerShipPolygon); + + if (entityContainerShip.getCrane()) { + drawCrane( entityContainerShip.getAdditionalColor(), g2d); + + } + if (entityContainerShip.getContainer()) { + drawContainer( entityContainerShip.getAdditionalColor(), g2d); + } + + _drawingContainerShipDeck.drawContainerShipDeck(g, entityContainerShip.getBodyColor(), _startPosX, _startPosY); + + + } + + + +} \ No newline at end of file diff --git a/ProjectContainerShip/src/DrawningContainerShipDeck.java b/ProjectContainerShip/src/DrawningContainerShipDeck.java new file mode 100644 index 0000000..ced31af --- /dev/null +++ b/ProjectContainerShip/src/DrawningContainerShipDeck.java @@ -0,0 +1,32 @@ +package ProjectContainerShip.src; + +import java.awt.*; +public class DrawningContainerShipDeck { + private DeckCount _deckCount; + + public void setEnumNumber(int deckCount) { + for (DeckCount value : DeckCount.values()) { + if (value.getEnumNumber() == deckCount) { + _deckCount = value; + return; + } + } + } + + public void drawContainerShipDeck(Graphics g, Color color, float startPosX, float startPosY) + { + Graphics2D g2d = (Graphics2D) g; + g2d.setColor(color); + g2d.setStroke(new BasicStroke(4)); + for (int i = 0; i < _deckCount.getEnumNumber(); i++) { + drawDeck(g2d, (int) startPosX, (int)startPosY); + startPosY-=10; + } + } + private void drawDeck(Graphics2D g2d, int posX, int posY) { + g2d.drawLine(posX + 10, posY + 50, posX + 60, posY + 50); + g2d.drawLine(posX + 60, posY + 50, posX + 60, posY + 40); + g2d.drawLine(posX + 60, posY + 40, posX + 10, posY + 40); + g2d.drawLine(posX + 10, posY + 40, posX + 10, posY + 50); + } +} diff --git a/ProjectContainerShip/src/EntityContainerShip.java b/ProjectContainerShip/src/EntityContainerShip.java new file mode 100644 index 0000000..ba315a3 --- /dev/null +++ b/ProjectContainerShip/src/EntityContainerShip.java @@ -0,0 +1,55 @@ +package ProjectContainerShip.src; +import java.awt.*; +public class EntityContainerShip { + + // скорость + 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 Crane; + public boolean getCrane() { + return Crane; + } + + // доп опция контейнер + private boolean Container; + public boolean getContainer() { + return Container; + } + + // инициализация полей обьекта + public void Init(int speed, double weight, Color bodyColor, Color additionalColor, boolean crane, boolean container) { + Speed = speed; + Weight = weight; + BodyColor = bodyColor; + AdditionalColor = additionalColor; + Crane = crane; + Container = container; + } +} diff --git a/ProjectContainerShip/src/FormContainerShip.form b/ProjectContainerShip/src/FormContainerShip.form new file mode 100644 index 0000000..9eeb0b1 --- /dev/null +++ b/ProjectContainerShip/src/FormContainerShip.form @@ -0,0 +1,93 @@ + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
diff --git a/ProjectContainerShip/src/FormContainerShip.java b/ProjectContainerShip/src/FormContainerShip.java new file mode 100644 index 0000000..2d7b289 --- /dev/null +++ b/ProjectContainerShip/src/FormContainerShip.java @@ -0,0 +1,116 @@ +package ProjectContainerShip.src; + +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 FormContainerShip extends JFrame { + protected DrawningContainerShip _drawningContainerShip = new DrawningContainerShip(); + JPanel PanelWrapper; + private JPanel PictureBox; + private JButton buttonCreate; + private JButton buttonRight; + private JButton buttonDown; + private JButton buttonLeft; + private JButton buttonUp; + + private List controls; + public FormContainerShip() { + buttonUp.setName("buttonUp"); + buttonDown.setName("buttonDown"); + buttonLeft.setName("buttonLeft"); + buttonRight.setName("buttonRight"); + + InitializeControlsRepaintList(); + + buttonCreate.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + _drawningContainerShip = new DrawningContainerShip(); + Random random = new Random(); + + _drawningContainerShip.Init(random.nextInt(30, 100), + random.nextInt(100, 500), + 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() ); + _drawningContainerShip.setPictureSize(PictureBox.getWidth(), PictureBox.getHeight()); + _drawningContainerShip.setPosition(random.nextInt(25, 100), + random.nextInt(25, 100)); + + Draw(); + + } + }); + ActionListener buttonMoveClickedListener = new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + String buttonName = ((JButton) e.getSource()).getName(); + boolean result = false; + + switch (buttonName) { + case "buttonUp": { + result = _drawningContainerShip.moveTransport(DirectionType.Up); + } + break; + case "buttonDown": { + result = _drawningContainerShip.moveTransport(DirectionType.Down); + } + break; + case "buttonLeft": { + result = _drawningContainerShip.moveTransport(DirectionType.Left); + } + break; + case "buttonRight": { + result = _drawningContainerShip.moveTransport(DirectionType.Right); + } + break; + + } + if (result) + Draw(); + + } + }; + buttonRight.addActionListener(buttonMoveClickedListener); + buttonDown.addActionListener(buttonMoveClickedListener); + buttonLeft.addActionListener(buttonMoveClickedListener); + buttonUp.addActionListener(buttonMoveClickedListener); + + } + private void Draw() { + if (_drawningContainerShip.getEntityContainerShip() == 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()); + _drawningContainerShip.drawContainerShip(g); + + RepaintControls(); + + } + private void RepaintControls() { + for (JComponent control : controls) { + control.repaint(); + } + } + + + private void InitializeControlsRepaintList() { + controls = new LinkedList<>(); + controls.add(buttonCreate); + controls.add(buttonUp); + controls.add(buttonDown); + controls.add(buttonLeft); + controls.add(buttonRight); + } + + +} diff --git a/ProjectContainerShip/src/Main.java b/ProjectContainerShip/src/Main.java index debcd5b..b8b303e 100644 --- a/ProjectContainerShip/src/Main.java +++ b/ProjectContainerShip/src/Main.java @@ -11,5 +11,6 @@ public class Main { frame.pack(); frame.setSize(700, 500); frame.setVisible(true); + } } diff --git a/out/production/Lab(HARD)/.gitignore b/out/production/Lab(HARD)/.gitignore new file mode 100644 index 0000000..9154f4c --- /dev/null +++ b/out/production/Lab(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/Lab(HARD)/.idea/.gitignore b/out/production/Lab(HARD)/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/out/production/Lab(HARD)/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/out/production/Lab(HARD)/.idea/Lab(HARD).iml b/out/production/Lab(HARD)/.idea/Lab(HARD).iml new file mode 100644 index 0000000..17c20fa --- /dev/null +++ b/out/production/Lab(HARD)/.idea/Lab(HARD).iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/out/production/Lab(HARD)/.idea/misc.xml b/out/production/Lab(HARD)/.idea/misc.xml new file mode 100644 index 0000000..bcb5da6 --- /dev/null +++ b/out/production/Lab(HARD)/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/out/production/Lab(HARD)/.idea/modules.xml b/out/production/Lab(HARD)/.idea/modules.xml new file mode 100644 index 0000000..7f25830 --- /dev/null +++ b/out/production/Lab(HARD)/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/out/production/Lab(HARD)/.idea/uiDesigner.xml b/out/production/Lab(HARD)/.idea/uiDesigner.xml new file mode 100644 index 0000000..2b63946 --- /dev/null +++ b/out/production/Lab(HARD)/.idea/uiDesigner.xml @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/out/production/Lab(HARD)/.idea/vcs.xml b/out/production/Lab(HARD)/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/out/production/Lab(HARD)/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/out/production/Lab(HARD)/ProjectContainerShip/.gitignore b/out/production/Lab(HARD)/ProjectContainerShip/.gitignore new file mode 100644 index 0000000..f68d109 --- /dev/null +++ b/out/production/Lab(HARD)/ProjectContainerShip/.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/out/production/Lab(HARD)/ProjectContainerShip/.idea/.gitignore b/out/production/Lab(HARD)/ProjectContainerShip/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/out/production/Lab(HARD)/ProjectContainerShip/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/out/production/Lab(HARD)/ProjectContainerShip/.idea/misc.xml b/out/production/Lab(HARD)/ProjectContainerShip/.idea/misc.xml new file mode 100644 index 0000000..12f22af --- /dev/null +++ b/out/production/Lab(HARD)/ProjectContainerShip/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/out/production/Lab(HARD)/ProjectContainerShip/.idea/modules.xml b/out/production/Lab(HARD)/ProjectContainerShip/.idea/modules.xml new file mode 100644 index 0000000..74373b3 --- /dev/null +++ b/out/production/Lab(HARD)/ProjectContainerShip/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/out/production/Lab(HARD)/ProjectContainerShip/.idea/vcs.xml b/out/production/Lab(HARD)/ProjectContainerShip/.idea/vcs.xml new file mode 100644 index 0000000..6c0b863 --- /dev/null +++ b/out/production/Lab(HARD)/ProjectContainerShip/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/out/production/Lab(HARD)/ProjectContainerShip/Resources/30px_arrow_down.png b/out/production/Lab(HARD)/ProjectContainerShip/Resources/30px_arrow_down.png new file mode 100644 index 0000000..7aa3255 Binary files /dev/null and b/out/production/Lab(HARD)/ProjectContainerShip/Resources/30px_arrow_down.png differ diff --git a/out/production/Lab(HARD)/ProjectContainerShip/Resources/30px_arrow_left.png b/out/production/Lab(HARD)/ProjectContainerShip/Resources/30px_arrow_left.png new file mode 100644 index 0000000..9a3dfa2 Binary files /dev/null and b/out/production/Lab(HARD)/ProjectContainerShip/Resources/30px_arrow_left.png differ diff --git a/out/production/Lab(HARD)/ProjectContainerShip/Resources/30px_arrow_right.png b/out/production/Lab(HARD)/ProjectContainerShip/Resources/30px_arrow_right.png new file mode 100644 index 0000000..0f06fd0 Binary files /dev/null and b/out/production/Lab(HARD)/ProjectContainerShip/Resources/30px_arrow_right.png differ diff --git a/out/production/Lab(HARD)/ProjectContainerShip/Resources/30px_arrow_up.png b/out/production/Lab(HARD)/ProjectContainerShip/Resources/30px_arrow_up.png new file mode 100644 index 0000000..67ae4bc Binary files /dev/null and b/out/production/Lab(HARD)/ProjectContainerShip/Resources/30px_arrow_up.png differ diff --git a/out/production/Lab(HARD)/README.md b/out/production/Lab(HARD)/README.md new file mode 100644 index 0000000..04b018f --- /dev/null +++ b/out/production/Lab(HARD)/README.md @@ -0,0 +1,2 @@ +# PIBD-12_Morozov_D.V._Hard +