diff --git a/ProjectCleaningCar/.idea/uiDesigner.xml b/ProjectCleaningCar/.idea/uiDesigner.xml
new file mode 100644
index 0000000..2b63946
--- /dev/null
+++ b/ProjectCleaningCar/.idea/uiDesigner.xml
@@ -0,0 +1,124 @@
+
+
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+
+
+
+ -
+
+
+
+
+
+ -
+
+
+
+
+
+ -
+
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+
+
+ -
+
+
+ -
+
+
+
+
+
\ No newline at end of file
diff --git a/ProjectCleaningCar/ProjectCleaningCar.iml b/ProjectCleaningCar/ProjectCleaningCar.iml
index c90834f..d5b343a 100644
--- a/ProjectCleaningCar/ProjectCleaningCar.iml
+++ b/ProjectCleaningCar/ProjectCleaningCar.iml
@@ -3,6 +3,7 @@
+
diff --git a/ProjectCleaningCar/Resources/Arrow_Down.png b/ProjectCleaningCar/Resources/Arrow_Down.png
new file mode 100644
index 0000000..4c2c5d9
Binary files /dev/null and b/ProjectCleaningCar/Resources/Arrow_Down.png differ
diff --git a/ProjectCleaningCar/Resources/Arrow_Left.png b/ProjectCleaningCar/Resources/Arrow_Left.png
new file mode 100644
index 0000000..c37001b
Binary files /dev/null and b/ProjectCleaningCar/Resources/Arrow_Left.png differ
diff --git a/ProjectCleaningCar/Resources/Arrow_Right.png b/ProjectCleaningCar/Resources/Arrow_Right.png
new file mode 100644
index 0000000..af23f23
Binary files /dev/null and b/ProjectCleaningCar/Resources/Arrow_Right.png differ
diff --git a/ProjectCleaningCar/Resources/Arrow_Up.png b/ProjectCleaningCar/Resources/Arrow_Up.png
new file mode 100644
index 0000000..0d7fa85
Binary files /dev/null and b/ProjectCleaningCar/Resources/Arrow_Up.png differ
diff --git a/ProjectCleaningCar/src/CountWheels.java b/ProjectCleaningCar/src/CountWheels.java
new file mode 100644
index 0000000..0b4114c
--- /dev/null
+++ b/ProjectCleaningCar/src/CountWheels.java
@@ -0,0 +1,12 @@
+public enum CountWheels {
+ One(1),
+ Two(2),
+ Three(3);
+ public final int count;
+ CountWheels(int count) {
+ this.count = count;
+ }
+ public int getCountWheels() {
+ return count;
+ }
+}
diff --git a/ProjectCleaningCar/src/DirectionType.java b/ProjectCleaningCar/src/DirectionType.java
new file mode 100644
index 0000000..35657f0
--- /dev/null
+++ b/ProjectCleaningCar/src/DirectionType.java
@@ -0,0 +1,6 @@
+public enum DirectionType {
+ Up,
+ Down,
+ Left,
+ Right
+}
diff --git a/ProjectCleaningCar/src/DrawningCleaningCar.java b/ProjectCleaningCar/src/DrawningCleaningCar.java
new file mode 100644
index 0000000..486434c
--- /dev/null
+++ b/ProjectCleaningCar/src/DrawningCleaningCar.java
@@ -0,0 +1,140 @@
+import java.awt.*;
+import java.util.Random;
+
+public class DrawningCleaningCar {
+ private EntityCleaningCar EntityCleaningCar;
+ public EntityCleaningCar getEntityCleaningCar() {
+ return EntityCleaningCar;
+ }
+ private Integer _pictureWidth;
+ private Integer _pictureHeight;
+ private Integer _startPosX;
+ private Integer _startPosY;
+ private final Integer _drawningCarWidth = 138;
+ private final Integer _drawningCarHeight = 68;
+ public DrawningWheels drawningWheels;
+
+ public void Init(int speed, double weight, Color bodyColor, Color additionalColor, boolean tank, boolean sweepingBrush, boolean flashlight) {
+ EntityCleaningCar = new EntityCleaningCar();
+ EntityCleaningCar.Init(speed, weight, bodyColor, additionalColor, tank, sweepingBrush, flashlight);
+ _pictureWidth = null;
+ _pictureHeight = null;
+ _startPosX = null;
+ _startPosY = null;
+
+ drawningWheels = new DrawningWheels();
+ Random random = new Random();
+ drawningWheels.setCountWheels(random.nextInt(1, 4));
+ }
+ public boolean SetPictureSize(int width, int height) {
+ if (width < _drawningCarWidth || height < _drawningCarHeight) {return false;}
+ _pictureWidth = width;
+ _pictureHeight = height;
+ if (_startPosX != null && _startPosY != null)
+ {
+ if (_startPosX + _drawningCarWidth > _pictureWidth)
+ {
+ _startPosX = -_drawningCarWidth + _pictureWidth;
+ }
+ else if (_startPosX < 0)
+ {
+ _startPosX = 0;
+ }
+ if (_startPosY + _drawningCarHeight > _pictureHeight)
+ {
+ _startPosY = -_drawningCarHeight + _pictureHeight;
+ }
+ else if (_startPosY < 0)
+ {
+ _startPosY = 0;
+ }
+ }
+ return true;
+ }
+ public void SetPosition(int x, int y) {
+ if (_pictureHeight == null || _pictureWidth == null) return;
+ if (x + _drawningCarWidth > _pictureWidth) {
+ _startPosX = _pictureWidth - _drawningCarWidth;
+ } else if (x < 0) {
+ _startPosX = 0;
+ }
+ else {
+ _startPosX = x;
+ }
+ if (y + _drawningCarHeight > _pictureHeight) {
+ _startPosY = _pictureHeight - _drawningCarHeight;
+ } else if (y < 0) {
+ _startPosY = 0;
+ } else {
+ _startPosY = y;
+ }
+ }
+ public boolean MoveTransport(DirectionType directionType) {
+ if (EntityCleaningCar == null || _startPosX == null || _startPosY == null) {
+ return false;
+ }
+ switch (directionType) {
+ case Left:
+ if (_startPosX - EntityCleaningCar.Step() > 0) {
+ _startPosX -= (int) EntityCleaningCar.Step();
+ }
+ return true;
+ case Right:
+ if (_startPosX + _drawningCarWidth + EntityCleaningCar.Step() < _pictureWidth) {
+ _startPosX += (int) EntityCleaningCar.Step();
+ }
+ return true;
+ case Up:
+ if (_startPosY - EntityCleaningCar.Step() > 0) {
+ _startPosY -= (int) EntityCleaningCar.Step();
+ }
+ return true;
+ case Down:
+ if (_startPosY + _drawningCarHeight + EntityCleaningCar.Step() < _pictureHeight) {
+ _startPosY += (int) EntityCleaningCar.Step();
+ }
+ return true;
+ default:
+ return false;
+ }
+ }
+ public void DrawTransport(Graphics g) {
+ if (EntityCleaningCar == null || _startPosX == null || _startPosY == null) {
+ return;
+ }
+ Graphics2D g2d = (Graphics2D) g;
+ if (EntityCleaningCar.getTank()) {
+ g2d.setColor(EntityCleaningCar.getAdditionalColor());
+ g2d.fillRect(_startPosX, _startPosY, 100, 38);
+ g2d.setColor(Color.black);
+ g2d.drawRect(_startPosX, _startPosY, 100, 38);
+ g2d.setColor(EntityCleaningCar.getBodyColor());
+ g2d.fillRect(_startPosX, _startPosY + 20, 100, 10);
+ }
+ if (EntityCleaningCar.getSweepingBrush()) {
+ g2d.setColor(EntityCleaningCar.getAdditionalColor());
+ g2d.fillOval(_startPosX + 120, _startPosY + 50, 20, 20);
+ g2d.setColor(EntityCleaningCar.getBodyColor());
+ g2d.fillOval(_startPosX + 125, _startPosY + 55, 10, 10);
+ g2d.setColor(Color.black);
+ g2d.drawOval(_startPosX + 120, _startPosY + 50, 19, 19);
+ g2d.drawOval(_startPosX + 125, _startPosY + 55, 9, 9);
+ g2d.drawLine(_startPosX + 122, _startPosY + 48, _startPosX + 130, _startPosY + 60);
+ }
+ if (EntityCleaningCar.getFlashLight()) {
+ g2d.setColor(EntityCleaningCar.getAdditionalColor());
+ g2d.fillRect(_startPosX + 108, _startPosY + 3, 5, 8);
+ }
+ g2d.setColor(EntityCleaningCar.getBodyColor());
+ g2d.fillRect(_startPosX, _startPosY + 40, 122, 10);
+ g2d.fillRect(_startPosX + 102, _startPosY + 10, 20, 30);
+
+ drawningWheels.DrawCleaningCarWheels(g, EntityCleaningCar.getBodyColor(), EntityCleaningCar.getAdditionalColor(), _startPosX, _startPosY);
+ g2d.setColor(Color.black);
+
+ g2d.drawRect(_startPosX, _startPosY + 40, 122, 10);
+ g2d.drawRect(_startPosX + 102, _startPosY + 10, 20, 30);
+
+ g2d.fillRect(_startPosX + 112, _startPosY + 15, 10, 12);
+ }
+}
diff --git a/ProjectCleaningCar/src/DrawningWheels.java b/ProjectCleaningCar/src/DrawningWheels.java
new file mode 100644
index 0000000..652b97c
--- /dev/null
+++ b/ProjectCleaningCar/src/DrawningWheels.java
@@ -0,0 +1,25 @@
+import java.awt.*;
+
+public class DrawningWheels {
+ private CountWheels countWheels;
+ public void setCountWheels(int numWheels) {
+ for (CountWheels value : CountWheels.values()) {
+ if (value.getCountWheels() == numWheels) {
+ countWheels = value;
+ return;
+ }
+ }
+ }
+ public void DrawCleaningCarWheels(Graphics g, Color bodyColor, Color additionalColor, int startPosX, int startPosY) {
+ Graphics2D g2d = (Graphics2D) g;
+ for (int i = 0; i < countWheels.getCountWheels(); i++) {
+ g2d.setColor(bodyColor);
+ g2d.fillOval(startPosX + 10 + 40 * i, startPosY + 50, 20, 20);
+ g2d.setColor(additionalColor);
+ g2d.fillOval(startPosX + 15 + 40 * i, startPosY + 55, 10, 10);
+ g2d.setColor(Color.black);
+ g2d.drawOval(startPosX + 10 + 40 * i, startPosY + 50, 19, 19);
+ g2d.drawOval(startPosX + 15 + 40 * i, startPosY + 55, 9, 9);
+ }
+ }
+}
diff --git a/ProjectCleaningCar/src/EntityCleaningCar.java b/ProjectCleaningCar/src/EntityCleaningCar.java
new file mode 100644
index 0000000..34e84cf
--- /dev/null
+++ b/ProjectCleaningCar/src/EntityCleaningCar.java
@@ -0,0 +1,45 @@
+import java.awt.*;
+
+public class EntityCleaningCar {
+ 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;
+ }
+ private boolean Tank;
+ public boolean getTank() {
+ return Tank;
+ }
+ private boolean SweepingBrush;
+ public boolean getSweepingBrush() {
+ return SweepingBrush;
+ }
+ private boolean FlashLight;
+ public boolean getFlashLight() {
+ return FlashLight;
+ }
+ public double Step() {
+ return Speed * 200 / Weight;
+ }
+ public void Init(int speed, double weight, Color bodyColor, Color additionalColor, boolean tank, boolean sweepingBrush, boolean flashLight) {
+ Speed = speed;
+ Weight = weight;
+ BodyColor = bodyColor;
+ AdditionalColor = additionalColor;
+ Tank = tank;
+ SweepingBrush = sweepingBrush;
+ FlashLight = flashLight;
+ }
+
+}
diff --git a/ProjectCleaningCar/src/FormCleaningCar.form b/ProjectCleaningCar/src/FormCleaningCar.form
new file mode 100644
index 0000000..55e2f3f
--- /dev/null
+++ b/ProjectCleaningCar/src/FormCleaningCar.form
@@ -0,0 +1,84 @@
+
+
diff --git a/ProjectCleaningCar/src/FormCleaningCar.java b/ProjectCleaningCar/src/FormCleaningCar.java
new file mode 100644
index 0000000..17e1600
--- /dev/null
+++ b/ProjectCleaningCar/src/FormCleaningCar.java
@@ -0,0 +1,101 @@
+import javax.swing.*;
+import java.awt.*;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.util.Random;
+import java.util.List;
+import java.util.LinkedList;
+
+public class FormCleaningCar extends JFrame {
+ protected DrawningCleaningCar _drawningCleaningCar = new DrawningCleaningCar();
+ JPanel pictureBox;
+ private JButton buttonCreate;
+ private JButton buttonRight;
+ private JButton buttonLeft;
+ private JButton buttonDown;
+ private JButton buttonUp;
+ private List controls;
+
+ public FormCleaningCar() {
+ buttonUp.setName("buttonUp");
+ buttonDown.setName("buttonDown");
+ buttonLeft.setName("buttonLeft");
+ buttonRight.setName("buttonRight");
+ InitializeControlsRepaintList();
+
+ buttonCreate.addActionListener(new ActionListener() {
+ @Override
+ public void actionPerformed(ActionEvent e) {
+ Random random = new Random();
+ _drawningCleaningCar.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(),
+ random.nextBoolean());
+ _drawningCleaningCar.SetPictureSize(pictureBox.getWidth(), pictureBox.getHeight());
+ _drawningCleaningCar.SetPosition(random.nextInt(0, 200), random.nextInt(0, 200));
+ 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 = _drawningCleaningCar.MoveTransport(DirectionType.Up);
+ }
+ break;
+ case "buttonDown": {
+ result = _drawningCleaningCar.MoveTransport(DirectionType.Down);
+ }
+ break;
+ case "buttonLeft": {
+ result = _drawningCleaningCar.MoveTransport(DirectionType.Left);
+ }
+ break;
+ case "buttonRight": {
+ result = _drawningCleaningCar.MoveTransport(DirectionType.Right);
+ }
+ break;
+
+ }
+ if (result)
+ Draw();
+
+ }
+ };
+ buttonRight.addActionListener(buttonMoveClickedListener);
+ buttonDown.addActionListener(buttonMoveClickedListener);
+ buttonLeft.addActionListener(buttonMoveClickedListener);
+ buttonUp.addActionListener(buttonMoveClickedListener);
+ }
+ private void Draw() {
+ if (_drawningCleaningCar.getEntityCleaningCar() == null ||
+ pictureBox.getWidth() == 0 || pictureBox.getHeight() == 0)
+ return;
+ Graphics g = pictureBox.getGraphics();
+ g.setColor(pictureBox.getBackground());
+ g.fillRect(0,0, pictureBox.getWidth(), pictureBox.getHeight());
+ _drawningCleaningCar.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);
+ }
+}
\ No newline at end of file
diff --git a/ProjectCleaningCar/src/Main.java b/ProjectCleaningCar/src/Main.java
index 930198c..76b742d 100644
--- a/ProjectCleaningCar/src/Main.java
+++ b/ProjectCleaningCar/src/Main.java
@@ -1,15 +1,13 @@
-//TIP To Run code, press or
-// click the icon in the gutter.
-public class Main {
+import javax.swing.*;
+class Main {
public static void main(String[] args) {
- //TIP Press with your caret at the highlighted text
- // to see how IntelliJ IDEA suggests fixing it.
- System.out.printf("Hello and welcome!");
-
- for (int i = 1; i <= 5; i++) {
- //TIP Press to start debugging your code. We have set one breakpoint
- // for you, but you can always add more by pressing .
- System.out.println("i = " + i);
- }
+ JFrame.setDefaultLookAndFeelDecorated(false);
+ JFrame frame = new JFrame("Project Cleaning Car");
+ frame.setContentPane(new FormCleaningCar().pictureBox);
+ frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
+ frame.setLocation(200, 200);
+ frame.pack();
+ frame.setSize(1000, 600);
+ frame.setVisible(true);
}
}
\ No newline at end of file