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/ProjectMotorBoat/ProjectMotorBoat.iml b/ProjectMotorBoat/ProjectMotorBoat.iml
new file mode 100644
index 0000000..cbbcb79
--- /dev/null
+++ b/ProjectMotorBoat/ProjectMotorBoat.iml
@@ -0,0 +1,11 @@
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/ProjectMotorBoat/src/DirectionType.java b/ProjectMotorBoat/src/DirectionType.java
new file mode 100644
index 0000000..35657f0
--- /dev/null
+++ b/ProjectMotorBoat/src/DirectionType.java
@@ -0,0 +1,6 @@
+public enum DirectionType {
+ Up,
+ Down,
+ Left,
+ Right
+}
diff --git a/ProjectMotorBoat/src/DrawingMotorBoat.java b/ProjectMotorBoat/src/DrawingMotorBoat.java
new file mode 100644
index 0000000..d61d097
--- /dev/null
+++ b/ProjectMotorBoat/src/DrawingMotorBoat.java
@@ -0,0 +1,171 @@
+import java.awt.*;
+import java.util.Random;
+
+public class DrawingMotorBoat {
+ private EntityMotorBoat EntityMotorBoat;
+ private Integer _pictureWidth;
+ private Integer _pictureHeight;
+ private Integer _startPosX;
+ private Integer _startPosY;
+
+ private final int _drawingBoatWidth = 100;
+ private final int _drawingBoatHeight = 50;
+ public DrawingMotorBoatOar _drawingMotorBoatOar;
+
+ public void Init(int speed, double weight, Color bodyColor, Color additionalColor, boolean inboardEngine, boolean oar, boolean protectiveGlass) {
+ EntityMotorBoat = new EntityMotorBoat();
+ EntityMotorBoat.init(speed, weight, bodyColor, additionalColor, inboardEngine, oar, protectiveGlass);
+ _pictureWidth = null;
+ _pictureHeight = null;
+ _startPosX = null;
+ _startPosY = null;
+
+ _drawingMotorBoatOar = new DrawingMotorBoatOar();
+ Random random = new Random();
+ int[] oarsCount = {1, 2, 3};
+ int oarCount = oarsCount[random.nextInt(oarsCount.length)];
+ _drawingMotorBoatOar.setEnumNumber(oarCount);
+ }
+
+ public boolean SetPictureSize(int width, int height) {
+ if (_drawingBoatWidth < width && _drawingBoatHeight < height) {
+ this._pictureWidth = width;
+ this._pictureHeight = height;
+
+ if (_startPosX != null && _startPosX + _drawingBoatWidth > _pictureWidth) {
+ _startPosX = _pictureWidth - _drawingBoatWidth;
+ }
+ if (_startPosY != null && _startPosY + _drawingBoatHeight > _pictureHeight) {
+ _startPosY = _pictureHeight - _drawingBoatHeight;
+ }
+ return true;
+ }
+ return false;
+ }
+
+ public void SetPosition(int x, int y) {
+ if (_pictureHeight == null || _pictureWidth == null) {
+ return;
+ }
+
+ if (x + _drawingBoatWidth > _pictureWidth) {
+ x = _pictureWidth - _drawingBoatWidth;
+ }
+
+ if (y + _drawingBoatHeight > _pictureHeight) {
+ y = _pictureHeight - _drawingBoatHeight;
+ }
+
+ if (x < 0) x = 0;
+ if (y < 0) y = 0;
+
+ _startPosX = x;
+ _startPosY = y;
+ }
+
+ public boolean MoveTransport(DirectionType direction) {
+ if (EntityMotorBoat == null || _startPosX == null || _startPosY == null) {
+ return false;
+ }
+
+ switch (direction) {
+ case Left:
+ if (_startPosX - EntityMotorBoat.getStep() > 0) {
+ _startPosX -= (int) EntityMotorBoat.getStep();
+ }
+ return true;
+ case Up:
+ if (_startPosY - EntityMotorBoat.getStep() > 0) {
+ _startPosY -= (int) EntityMotorBoat.getStep();
+ }
+ return true;
+ case Right:
+ if (_startPosX + EntityMotorBoat.getStep() < _pictureWidth - _drawingBoatWidth) {
+ _startPosX += (int) EntityMotorBoat.getStep();
+ }
+ return true;
+ case Down:
+ if (_startPosY + EntityMotorBoat.getStep() < _pictureHeight - _drawingBoatHeight) {
+ _startPosY += (int) EntityMotorBoat.getStep();
+ }
+ return true;
+ default:
+ return false;
+ }
+ }
+
+ public void DrawTransport(Graphics g) {
+ if (EntityMotorBoat == null || _startPosX == null || _startPosY == null) {
+ return;
+ }
+
+ Graphics2D g2d = (Graphics2D) g;
+ g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
+
+
+ g2d.setColor(Color.BLACK);
+ g2d.setStroke(new BasicStroke(1));
+
+ // Границы катера
+ Polygon boatShape = new Polygon();
+ boatShape.addPoint(_startPosX, _startPosY + 10);
+ boatShape.addPoint(_startPosX + 70, _startPosY + 10);
+ boatShape.addPoint(_startPosX + 100, _startPosY + 25);
+ boatShape.addPoint(_startPosX + 70, _startPosY + 40);
+ boatShape.addPoint(_startPosX, _startPosY + 40);
+
+ g2d.draw(boatShape);
+ g2d.setColor(EntityMotorBoat.getBodyColor());
+ g2d.fillPolygon(boatShape);
+
+ // Палуба
+ g2d.setColor(Color.BLACK);
+ g2d.drawRect(_startPosX + 5, _startPosY + 20, 65, 10);
+ g2d.drawRect(_startPosX + 10, _startPosY + 15, 55, 20);
+
+ g2d.setColor(EntityMotorBoat.getBodyColor());
+ g2d.fillRect(_startPosX + 6, _startPosY + 20, 64, 11);
+ g2d.fillRect(_startPosX + 11, _startPosY + 16, 56, 19);
+
+ for (int i = 0; i < 2; i++) {
+ for (int j = 0; j < 2; j++) {
+ g2d.setColor(Color.BLACK);
+ g2d.drawOval(_startPosX + 5 + i * 55, _startPosY + 15 + j * 10, 10, 10);
+ g2d.setColor(EntityMotorBoat.getBodyColor());
+ g2d.fillOval(_startPosX + 5 + i * 55, _startPosY + 15 + j * 10, 11, 11);
+ }
+ }
+
+ // Мотор в корме
+ if (EntityMotorBoat.isInboardEngine()) {
+ g2d.setColor(Color.BLACK);
+ g2d.drawRect(_startPosX + 3, _startPosY + 13, 20, 24);
+ g2d.setColor(EntityMotorBoat.getAdditionalColor());
+ g2d.fillRect(_startPosX + 4, _startPosY + 14, 19, 23);
+
+ for (int i = 0; i < 2; i++) {
+ for (int j = 0; j < 2; j++) {
+ g2d.setColor(Color.BLACK);
+ g2d.drawOval(_startPosX + 5 + i * 9, _startPosY + 15 + j * 13, 6, 6);
+ g2d.setColor(EntityMotorBoat.getAdditionalColor());
+ g2d.fillOval(_startPosX + 6 + i * 9, _startPosY + 16 + j * 13, 4, 4);
+ }
+ }
+ }
+
+ // Вёсла
+ if (EntityMotorBoat.isOar()) {
+ _drawingMotorBoatOar.drawMotorBoatOar(g, EntityMotorBoat.getAdditionalColor(), _startPosX, _startPosY);
+ }
+
+ // Защитное стекло
+ if (EntityMotorBoat.isProtectiveGlass()) {
+ g2d.setColor(Color.CYAN);
+ g2d.fillRect(_startPosX + 45, _startPosY + 20, 25, 11);
+ g2d.fillRect(_startPosX + 45, _startPosY + 16, 17, 19);
+
+ g2d.fillOval(_startPosX + 59, _startPosY + 15, 11, 11);
+ g2d.fillOval(_startPosX + 59, _startPosY + 24, 11, 11);
+ }
+ }
+}
diff --git a/ProjectMotorBoat/src/DrawingMotorBoatOar.java b/ProjectMotorBoat/src/DrawingMotorBoatOar.java
new file mode 100644
index 0000000..972dfd0
--- /dev/null
+++ b/ProjectMotorBoat/src/DrawingMotorBoatOar.java
@@ -0,0 +1,54 @@
+import java.awt.*;
+
+public class DrawingMotorBoatOar {
+ private OarCount _oarCount;
+ public void setEnumNumber(int engineCount) {
+ for (OarCount value : OarCount.values()) {
+ if (value.getEnumNumber() == engineCount) {
+ _oarCount = value;
+ return;
+ }
+ }
+ }
+ public void drawMotorBoatOar(Graphics g, Color color, float startPosX, float startPosY) {
+ Graphics2D g2d = (Graphics2D) g;
+ g2d.setColor(color);
+ g2d.setStroke(new BasicStroke(1));
+
+ if (_oarCount.getEnumNumber() >= 1) {
+ g2d.setColor(Color.BLACK);
+ g2d.drawRect((int)startPosX + 32, (int)startPosY + 3, 2, 17);
+ g2d.setColor(color);
+ g2d.fillRect((int)startPosX + 33, (int)startPosY + 3, 1, 17);
+
+ g2d.setColor(Color.BLACK);
+ g2d.drawOval((int)startPosX + 30, (int)startPosY, 6, 8);
+ g2d.setColor(color);
+ g2d.fillOval((int)startPosX + 30, (int)startPosY, 6, 8);
+ }
+
+ if (_oarCount.getEnumNumber() >= 2) {
+ g2d.setColor(Color.BLACK);
+ g2d.drawRect((int)startPosX + 27, (int)startPosY + 3 + 27, 2, 17);
+ g2d.setColor(color);
+ g2d.fillRect((int)startPosX + 28, (int)startPosY + 3 + 27, 1, 17);
+
+ g2d.setColor(Color.BLACK);
+ g2d.drawOval((int)startPosX + 25, (int)startPosY + 27 + 17, 6, 8);
+ g2d.setColor(color);
+ g2d.fillOval((int)startPosX + 25, (int)startPosY + 27 + 17, 6, 8);
+ }
+
+ if (_oarCount.getEnumNumber() >= 3) {
+ g2d.setColor(Color.BLACK);
+ g2d.drawRect((int)startPosX + 36, (int)startPosY + 3 + 27, 2, 17);
+ g2d.setColor(color);
+ g2d.fillRect((int)startPosX + 37, (int)startPosY + 3 + 27, 1, 17);
+
+ g2d.setColor(Color.BLACK);
+ g2d.drawOval((int)startPosX + 34, (int)startPosY + 27 + 17, 6, 8);
+ g2d.setColor(color);
+ g2d.fillOval((int)startPosX + 34, (int)startPosY + 27 + 17, 6, 8);
+ }
+ }
+}
diff --git a/ProjectMotorBoat/src/EntityMotorBoat.java b/ProjectMotorBoat/src/EntityMotorBoat.java
new file mode 100644
index 0000000..1a53245
--- /dev/null
+++ b/ProjectMotorBoat/src/EntityMotorBoat.java
@@ -0,0 +1,92 @@
+import java.awt.Color;
+
+/**
+ * Класс-сущность "Катер"
+ */
+public class EntityMotorBoat {
+
+ /**
+ * Скорость
+ */
+ private int Speed;
+
+ /**
+ * Вес
+ */
+ private double Weight;
+
+ /**
+ * Основной цвет
+ */
+ private Color BodyColor;
+
+ /**
+ * Дополнительный цвет (для опциональных элементов)
+ */
+ private Color AdditionalColor;
+
+ /**
+ * Признак (опция) наличия внутреннего двигателя
+ */
+ private boolean InboardEngine;
+
+ /**
+ * Признак (опция) наличия весла
+ */
+ private boolean Oar;
+
+ /**
+ * Признак (опция) наличия защитного стекла
+ */
+ private boolean ProtectiveGlass;
+
+ /**
+ * Шаг перемещения катера
+ *
+ * @return Шаг перемещения
+ */
+ public double getStep() {
+ return Speed * 100 / Weight;
+ }
+
+ /**
+ * Инициализация полей объекта-класса катера
+ */
+ public void init(int speed, double weight, Color bodyColor, Color additionalColor, boolean inboardEngine, boolean oar, boolean protectiveGlass) {
+ this.Speed = speed;
+ this.Weight = weight;
+ this.BodyColor = bodyColor;
+ this.AdditionalColor = additionalColor;
+ this.InboardEngine = inboardEngine;
+ this.Oar = oar;
+ this.ProtectiveGlass = protectiveGlass;
+ }
+
+ public int getSpeed() {
+ return Speed;
+ }
+
+ public double getWeight() {
+ return Weight;
+ }
+
+ public Color getBodyColor() {
+ return BodyColor;
+ }
+
+ public Color getAdditionalColor() {
+ return AdditionalColor;
+ }
+
+ public boolean isInboardEngine() {
+ return InboardEngine;
+ }
+
+ public boolean isOar() {
+ return Oar;
+ }
+
+ public boolean isProtectiveGlass() {
+ return ProtectiveGlass;
+ }
+}
diff --git a/ProjectMotorBoat/src/FormMotorBoat.form b/ProjectMotorBoat/src/FormMotorBoat.form
new file mode 100644
index 0000000..0fb398f
--- /dev/null
+++ b/ProjectMotorBoat/src/FormMotorBoat.form
@@ -0,0 +1,98 @@
+
+
diff --git a/ProjectMotorBoat/src/FormMotorBoat.java b/ProjectMotorBoat/src/FormMotorBoat.java
new file mode 100644
index 0000000..d3f5181
--- /dev/null
+++ b/ProjectMotorBoat/src/FormMotorBoat.java
@@ -0,0 +1,114 @@
+import javax.swing.*;
+import java.awt.*;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Random;
+
+public class FormMotorBoat extends JFrame {
+ protected DrawingMotorBoat _drawingMotorBoat = new DrawingMotorBoat();
+ JPanel PanelWrapper;
+ private JPanel PictureBox;
+ private JButton buttonCreate;
+ private JButton buttonRight;
+ private JButton buttonDown;
+ private JButton buttonLeft;
+ private JButton buttonUp;
+
+ private List controls;
+
+ public FormMotorBoat() {
+ buttonUp.setName("buttonUp");
+ buttonDown.setName("buttonDown");
+ buttonLeft.setName("buttonLeft");
+ buttonRight.setName("buttonRight");
+
+ InitializeControlsRepaintList();
+
+ buttonCreate.addActionListener(new ActionListener() {
+ @Override
+ public void actionPerformed(ActionEvent e) {
+ _drawingMotorBoat = new DrawingMotorBoat();
+ Random r = new Random();
+
+ _drawingMotorBoat.Init(r.nextInt(30, 100),
+ r.nextInt(100, 500),
+ new Color(r.nextInt(256), r.nextInt(256), r.nextInt(256)),
+ new Color(r.nextInt(256), r.nextInt(256), r.nextInt(256)),
+ r.nextBoolean(), r.nextBoolean(), r.nextBoolean());
+ _drawingMotorBoat.SetPictureSize(PictureBox.getWidth(), PictureBox.getHeight());
+ _drawingMotorBoat.SetPosition(r.nextInt(25, 100),
+ r.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 = _drawingMotorBoat.MoveTransport(DirectionType.Up);
+ }
+ break;
+ case "buttonDown": {
+ result = _drawingMotorBoat.MoveTransport(DirectionType.Down);
+ }
+ break;
+ case "buttonLeft": {
+ result = _drawingMotorBoat.MoveTransport(DirectionType.Left);
+ }
+ break;
+ case "buttonRight": {
+ result = _drawingMotorBoat.MoveTransport(DirectionType.Right);
+ }
+ break;
+
+ }
+ if (result)
+ Draw();
+
+ }
+ };
+ buttonRight.addActionListener(buttonMoveClickedListener);
+ buttonDown.addActionListener(buttonMoveClickedListener);
+ buttonLeft.addActionListener(buttonMoveClickedListener);
+ buttonUp.addActionListener(buttonMoveClickedListener);
+
+ }
+
+ private void Draw() {
+ if (_drawingMotorBoat == 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());
+ _drawingMotorBoat.DrawTransport(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/ProjectMotorBoat/src/Main.java b/ProjectMotorBoat/src/Main.java
new file mode 100644
index 0000000..69a9ec7
--- /dev/null
+++ b/ProjectMotorBoat/src/Main.java
@@ -0,0 +1,14 @@
+import javax.swing.*;
+
+public class Main {
+ public static void main(String[] args) {
+ JFrame.setDefaultLookAndFeelDecorated(false);
+ JFrame frame = new JFrame("Моторная лодка");
+ frame.setContentPane(new FormMotorBoat().PanelWrapper);
+ frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
+ frame.setLocation(400, 200);
+ frame.pack();
+ frame.setSize(940, 540);
+ frame.setVisible(true);
+ }
+}
\ No newline at end of file
diff --git a/ProjectMotorBoat/src/OarCount.java b/ProjectMotorBoat/src/OarCount.java
new file mode 100644
index 0000000..29d034d
--- /dev/null
+++ b/ProjectMotorBoat/src/OarCount.java
@@ -0,0 +1,14 @@
+public enum OarCount {
+ One(1),
+ Two(2),
+ Three(3);
+
+ final private int EnumNumber;
+
+ OarCount(int enumNumber) {
+ EnumNumber = enumNumber;
+ }
+ public int getEnumNumber() {
+ return EnumNumber;
+ }
+}
\ No newline at end of file
diff --git a/ProjectMotorBoat/src/Resources/arrowDown.png b/ProjectMotorBoat/src/Resources/arrowDown.png
new file mode 100644
index 0000000..447b27a
Binary files /dev/null and b/ProjectMotorBoat/src/Resources/arrowDown.png differ
diff --git a/ProjectMotorBoat/src/Resources/arrowLeft.png b/ProjectMotorBoat/src/Resources/arrowLeft.png
new file mode 100644
index 0000000..35ab05f
Binary files /dev/null and b/ProjectMotorBoat/src/Resources/arrowLeft.png differ
diff --git a/ProjectMotorBoat/src/Resources/arrowRight.png b/ProjectMotorBoat/src/Resources/arrowRight.png
new file mode 100644
index 0000000..0c520dc
Binary files /dev/null and b/ProjectMotorBoat/src/Resources/arrowRight.png differ
diff --git a/ProjectMotorBoat/src/Resources/arrowUp.png b/ProjectMotorBoat/src/Resources/arrowUp.png
new file mode 100644
index 0000000..4256635
Binary files /dev/null and b/ProjectMotorBoat/src/Resources/arrowUp.png differ