From 6b03a65d8f6ff07ad07f472d2338803722d0f94a Mon Sep 17 00:00:00 2001 From: Danila_Mochalov Date: Sat, 24 Sep 2022 16:48:31 +0400 Subject: [PATCH 1/7] First Commit. Project Created. --- EntityLocomotive.java | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 EntityLocomotive.java diff --git a/EntityLocomotive.java b/EntityLocomotive.java new file mode 100644 index 0000000..88bcfdf --- /dev/null +++ b/EntityLocomotive.java @@ -0,0 +1,8 @@ +import java.awt.*; + +public class EntityLocomotive { + public int Speed; + public int Weight; + public Color BodyColor; + +} From 9c05e95a9b532dc4c1d6978668d80c7d564e25cd Mon Sep 17 00:00:00 2001 From: Danila_Mochalov Date: Sat, 24 Sep 2022 17:19:00 +0400 Subject: [PATCH 2/7] Base copied. --- Direction.java | 3 ++ DrawningLocomotive.java | 106 ++++++++++++++++++++++++++++++++++++++++ EntityLocomotive.java | 44 +++++++++++++++-- 3 files changed, 150 insertions(+), 3 deletions(-) create mode 100644 Direction.java create mode 100644 DrawningLocomotive.java diff --git a/Direction.java b/Direction.java new file mode 100644 index 0000000..cc121e9 --- /dev/null +++ b/Direction.java @@ -0,0 +1,3 @@ +public enum Direction { + Up, Down, Left, Right +} diff --git a/DrawningLocomotive.java b/DrawningLocomotive.java new file mode 100644 index 0000000..cf537eb --- /dev/null +++ b/DrawningLocomotive.java @@ -0,0 +1,106 @@ +import java.awt.*; + +class DrawningLocomotive { + public EntityLocomotive Locomotive; + /// Левая координата отрисовки локомотива + private float _startPosX; + /// Верхняя координата отрисовки локомотива + private float _startPosY; + /// Ширина окна отрисовки + private Integer _pictureWidth = null; + /// Высота окна отрисовки + private Integer _pictureHeight = null; + /// Ширина отрисовки локомотива + private final int _locomotiveWidth = 110; + /// Высота отрисовки локомотива + private final int _locomotiveHeight = 50; + /// Инициализация свойств + public void Init(int speed, float weight, Color bodyColor, EntityLocomotive entity) + { + Locomotive = entity; + Locomotive.Init(speed, weight, bodyColor); + } + /// Установка позиции локомотива + public void SetPosition(int x, int y, int width, int height) + { + if (x < 0 || x + _locomotiveWidth >= width) + { + return; + } + if (y < 0 || y + _locomotiveHeight >= height) + { + return; + } + _startPosX = x; + _startPosY = y; + _pictureWidth = width; + _pictureHeight = height; + } + + public void MoveTransport(Direction direction) + { + if (_pictureWidth == null || _pictureHeight == null) + { + return; + } + switch (direction) + { + // вправо + case Right: + if (_startPosX + _locomotiveWidth + Locomotive.Step() < _pictureWidth) + { + _startPosX += Locomotive.Step(); + } + else _startPosX = _pictureWidth - _locomotiveWidth; + break; + //влево + case Left: + if (_startPosX - Locomotive.Step() >= 0) + { + _startPosX -= Locomotive.Step(); + } + else _startPosX = 0; + break; + //вверх + case Up: + if (_startPosY - Locomotive.Step() >= 0) + { + _startPosY -= Locomotive.Step(); + } + else _startPosY = 0; + break; + //вниз + case Down: + if (_startPosY + _locomotiveHeight + Locomotive.Step() < _pictureHeight) + { + _startPosY += Locomotive.Step(); + } + else _startPosY = _pictureHeight - _locomotiveHeight; + break; + } + } + + public void DrawTransport() { + //TODO: do! + } + + public void ChangeBorders(int width, int height) + { + _pictureWidth = width; + _pictureHeight = height; + if (_pictureWidth <= _locomotiveWidth || _pictureHeight <= _locomotiveHeight) + { + _pictureWidth = null; + _pictureHeight = null; + return; + } + if (_startPosX + _locomotiveWidth > _pictureWidth) + { + _startPosX = _pictureWidth - _locomotiveWidth; + } + if (_startPosY + _locomotiveHeight > _pictureHeight) + { + _startPosY = _pictureHeight - _locomotiveHeight; + } + } +} diff --git a/EntityLocomotive.java b/EntityLocomotive.java index 88bcfdf..7d58451 100644 --- a/EntityLocomotive.java +++ b/EntityLocomotive.java @@ -1,8 +1,46 @@ import java.awt.*; +import java.util.Random; public class EntityLocomotive { - public int Speed; - public int Weight; - public Color BodyColor; + private int Speed; + public int getSpeed() { + return Speed; + } + private float Weight; + public float getWeight() { + return Weight; + } + private Color BodyColor; + public Color getBodyColor() { + return BodyColor; + } + + public float Step () { + return Speed * 100 / Weight; + } + + public void Init(int speed, float weight, Color bodyColor) + { + Random rnd = new Random(); + if (speed <= 0) { + Speed = 50 + rnd.nextInt(100); + } + else { + Speed = speed; + } + + if (weight <= 0) { + Weight = 40 + rnd.nextInt(30); + } + else { + Weight = weight; + } + BodyColor = bodyColor; + } + + + + + } From 0f8658bfeb53d99cc96a9e4351b0f92775bdbd49 Mon Sep 17 00:00:00 2001 From: Danila_Mochalov Date: Sat, 24 Sep 2022 18:00:56 +0400 Subject: [PATCH 3/7] DrawTransport method added --- DrawningLocomotive.java | 28 ++++++++++++++++++++++++++-- EntityLocomotive.java | 6 ------ 2 files changed, 26 insertions(+), 8 deletions(-) diff --git a/DrawningLocomotive.java b/DrawningLocomotive.java index cf537eb..19497c3 100644 --- a/DrawningLocomotive.java +++ b/DrawningLocomotive.java @@ -80,8 +80,32 @@ class DrawningLocomotive { } } - public void DrawTransport() { - //TODO: do! + public void DrawTransport(Graphics g) { + if (_startPosX < 0 || _startPosY < 0 + || _pictureHeight == null || _pictureWidth == null) + { + return; + } + //тело + g.setColor(Color.BLACK); + g.drawRect((int)_startPosX , (int)_startPosY, _locomotiveWidth - 10, _locomotiveHeight - 10); + //окна + g.setColor(Locomotive.getBodyColor()); + g.fillRect((int)_startPosX + 10, (int)_startPosY + 10, 10, 10); + g.fillRect((int)_startPosX + 30, (int)_startPosY + 10, 10, 10); + g.fillRect((int)_startPosX + 80, (int)_startPosY + 10, 10, 10); + //дверь + g.setColor(Color.BLACK); + g.drawRect( (int)_startPosX + 50, (int)_startPosY + 10, 10, 20); + //колеса + g.drawOval((int) _startPosX, (int)_startPosY + 40, 10, 10); + g.drawOval((int) _startPosX + 20, (int)_startPosY + 40, 10, 10); + g.drawOval((int) _startPosX + 70, (int)_startPosY + 40, 10, 10); + g.drawOval((int) _startPosX + 90, (int)_startPosY + 40, 10, 10); + //движок + g.setColor(Locomotive.getBodyColor()); + g.fillRect((int)_startPosX + 100, (int)_startPosY + 10, 10, 30); + } public void ChangeBorders(int width, int height) diff --git a/EntityLocomotive.java b/EntityLocomotive.java index 7d58451..440b8a1 100644 --- a/EntityLocomotive.java +++ b/EntityLocomotive.java @@ -37,10 +37,4 @@ public class EntityLocomotive { } BodyColor = bodyColor; } - - - - - - } From fefd0e637ef98498a6be7708d61e7b1b15545428 Mon Sep 17 00:00:00 2001 From: Danila_Mochalov Date: Sat, 24 Sep 2022 19:51:41 +0400 Subject: [PATCH 4/7] Create Button added --- DrawningLocomotive.java | 2 +- FormLocomotive.java | 55 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+), 1 deletion(-) create mode 100644 FormLocomotive.java diff --git a/DrawningLocomotive.java b/DrawningLocomotive.java index 19497c3..a12110e 100644 --- a/DrawningLocomotive.java +++ b/DrawningLocomotive.java @@ -80,7 +80,7 @@ class DrawningLocomotive { } } - public void DrawTransport(Graphics g) { + public void DrawTransport(Graphics2D g) { if (_startPosX < 0 || _startPosY < 0 || _pictureHeight == null || _pictureWidth == null) { diff --git a/FormLocomotive.java b/FormLocomotive.java new file mode 100644 index 0000000..ea3c141 --- /dev/null +++ b/FormLocomotive.java @@ -0,0 +1,55 @@ +import javax.swing.*; +import java.awt.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.util.Random; + +public class FormLocomotive extends JComponent{ + private DrawningLocomotive _locomotive; + private EntityLocomotive _entity; + public FormLocomotive() { + JFrame formFrame = new JFrame("Locomotive"); + formFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + formFrame.setSize(800, 500); + formFrame.setVisible(true); + formFrame.setLocationRelativeTo(null); + + Panel southPanel = new Panel(); + setLayout(new BorderLayout()); + add(southPanel, BorderLayout.SOUTH); + + JButton createButton = new JButton("Create"); + createButton.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + Random rnd = new Random(); + _locomotive = new DrawningLocomotive(); + _entity = new EntityLocomotive(); + _locomotive.Init(100 + rnd.nextInt(200), 1000 + rnd.nextInt(1000), Color.getHSBColor(rnd.nextInt(256), rnd.nextInt(256), rnd.nextInt(256)), _entity); + _locomotive.SetPosition(10 + rnd.nextInt(90), 10 + rnd.nextInt(90), formFrame.getWidth(), formFrame.getHeight()); +// toolStripStatusLabelSpeed.Text = $"Speed: {_locomotive.Locomotive.Speed}"; +// toolStripStatusLabelWeight.Text = $"Weight: {_locomotive.Locomotive.Weight}"; +// toolStripStatusLabelColor.Text = $"Color: {_locomotive.Locomotive.BodyColor.Name}"; + repaint(); + } + }); + + southPanel.add(createButton); + + formFrame.getContentPane().add(this); + } + + @Override + protected void paintComponent(Graphics g) { + super.paintComponent(g); + Graphics2D g2 = (Graphics2D)g; + if (_locomotive != null) _locomotive.DrawTransport(g2); + super.repaint(); + } + + public static void main(String[] args) { + FormLocomotive formLocomotive = new FormLocomotive(); + + + } +} From d30a086f9d802944cfbdfcc0556879c8a3907f68 Mon Sep 17 00:00:00 2001 From: Danila_Mochalov Date: Sat, 24 Sep 2022 21:33:44 +0400 Subject: [PATCH 5/7] Base Logic copied --- DrawningLocomotive.java | 2 +- FormLocomotive.java | 93 +++++++++++++++++++++++++++++++++-------- 2 files changed, 76 insertions(+), 19 deletions(-) diff --git a/DrawningLocomotive.java b/DrawningLocomotive.java index a12110e..a1b710f 100644 --- a/DrawningLocomotive.java +++ b/DrawningLocomotive.java @@ -111,7 +111,7 @@ class DrawningLocomotive { public void ChangeBorders(int width, int height) { _pictureWidth = width; - _pictureHeight = height; + _pictureHeight = height - 75; if (_pictureWidth <= _locomotiveWidth || _pictureHeight <= _locomotiveHeight) { _pictureWidth = null; diff --git a/FormLocomotive.java b/FormLocomotive.java index ea3c141..6b6d139 100644 --- a/FormLocomotive.java +++ b/FormLocomotive.java @@ -1,7 +1,6 @@ import javax.swing.*; import java.awt.*; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; +import java.awt.event.*; import java.util.Random; public class FormLocomotive extends JComponent{ @@ -14,27 +13,85 @@ public class FormLocomotive extends JComponent{ formFrame.setVisible(true); formFrame.setLocationRelativeTo(null); - Panel southPanel = new Panel(); - setLayout(new BorderLayout()); - add(southPanel, BorderLayout.SOUTH); - - JButton createButton = new JButton("Create"); - createButton.addActionListener(new ActionListener() { + formFrame.addComponentListener(new ComponentListener() { @Override - public void actionPerformed(ActionEvent e) { - Random rnd = new Random(); - _locomotive = new DrawningLocomotive(); - _entity = new EntityLocomotive(); - _locomotive.Init(100 + rnd.nextInt(200), 1000 + rnd.nextInt(1000), Color.getHSBColor(rnd.nextInt(256), rnd.nextInt(256), rnd.nextInt(256)), _entity); - _locomotive.SetPosition(10 + rnd.nextInt(90), 10 + rnd.nextInt(90), formFrame.getWidth(), formFrame.getHeight()); -// toolStripStatusLabelSpeed.Text = $"Speed: {_locomotive.Locomotive.Speed}"; -// toolStripStatusLabelWeight.Text = $"Weight: {_locomotive.Locomotive.Weight}"; -// toolStripStatusLabelColor.Text = $"Color: {_locomotive.Locomotive.BodyColor.Name}"; + public void componentResized(ComponentEvent e) { + if (_locomotive != null) _locomotive.ChangeBorders(formFrame.getWidth(), formFrame.getHeight()); repaint(); } + + @Override + public void componentMoved(ComponentEvent e) { + + } + + @Override + public void componentShown(ComponentEvent e) { + + } + + @Override + public void componentHidden(ComponentEvent e) { + + } }); - southPanel.add(createButton); + Panel statusPanel = new Panel(); + statusPanel.setBackground(Color.WHITE); + statusPanel.setLayout(new FlowLayout()); + setLayout(new BorderLayout()); + add(statusPanel, BorderLayout.SOUTH); + + Label speedLabel = new Label("Speed: "); + Label weightLabel = new Label("Weight: "); + Label colorLabel = new Label("Color: "); + + JButton createButton = new JButton("Create"); + createButton.addActionListener(e -> { + Random rnd = new Random(); + _locomotive = new DrawningLocomotive(); + _entity = new EntityLocomotive(); + _locomotive.Init(100 + rnd.nextInt(200), 1000 + rnd.nextInt(1000), Color.getHSBColor(rnd.nextInt(256), rnd.nextInt(256), rnd.nextInt(256)), _entity); + _locomotive.SetPosition(10 + rnd.nextInt(90), 10 + rnd.nextInt(90), formFrame.getWidth(), formFrame.getHeight() - 75); + speedLabel.setText("Speed: " + _locomotive.Locomotive.getSpeed()); + weightLabel.setText("Weight: " + (int)_locomotive.Locomotive.getWeight()); + colorLabel.setText("Color: " + _locomotive.Locomotive.getBodyColor().getRed() + " " + _locomotive.Locomotive.getBodyColor().getGreen() + " " + _locomotive.Locomotive.getBodyColor().getBlue() ); + repaint(); + }); + + statusPanel.add(createButton); + statusPanel.add(speedLabel); + statusPanel.add(weightLabel); + statusPanel.add(colorLabel); + + JButton moveDownButton = new JButton("Down"); + moveDownButton.addActionListener(e -> { + if (_locomotive != null) _locomotive.MoveTransport(Direction.Down); + repaint(); + }); + + JButton moveUpButton = new JButton("Up"); + moveUpButton.addActionListener(e -> { + if (_locomotive != null) _locomotive.MoveTransport(Direction.Up); + repaint(); + }); + + JButton moveLeftButton = new JButton("Left"); + moveLeftButton.addActionListener(e -> { + if (_locomotive != null) _locomotive.MoveTransport(Direction.Left); + repaint(); + }); + + JButton moveRightButton = new JButton("Right"); + moveRightButton.addActionListener(e -> { + if (_locomotive != null) _locomotive.MoveTransport(Direction.Right); + repaint(); + }); + + statusPanel.add(moveUpButton); + statusPanel.add(moveDownButton); + statusPanel.add(moveLeftButton); + statusPanel.add(moveRightButton); formFrame.getContentPane().add(this); } From 0a29f09918d7d221c254a8c2d4f64067fac24f58 Mon Sep 17 00:00:00 2001 From: Danila_Mochalov Date: Sun, 25 Sep 2022 13:45:19 +0400 Subject: [PATCH 6/7] Extra task completed --- DrawningLocomotive.java | 10 ++++----- ExtraWheelsDraw.java | 48 +++++++++++++++++++++++++++++++++++++++++ FormLocomotive.java | 19 ++++------------ WheelsCount.java | 3 +++ 4 files changed, 59 insertions(+), 21 deletions(-) create mode 100644 ExtraWheelsDraw.java create mode 100644 WheelsCount.java diff --git a/DrawningLocomotive.java b/DrawningLocomotive.java index a1b710f..c39e0e1 100644 --- a/DrawningLocomotive.java +++ b/DrawningLocomotive.java @@ -2,6 +2,7 @@ import java.awt.*; class DrawningLocomotive { public EntityLocomotive Locomotive; + public ExtraWheelsDraw extraWheelsDraw; /// Левая координата отрисовки локомотива private float _startPosX; /// Верхняя координата отрисовки локомотива @@ -15,9 +16,10 @@ class DrawningLocomotive { /// Высота отрисовки локомотива private final int _locomotiveHeight = 50; /// Инициализация свойств - public void Init(int speed, float weight, Color bodyColor, EntityLocomotive entity) + public void Init(int speed, float weight, Color bodyColor, int wheelsNum, EntityLocomotive entity) { Locomotive = entity; + extraWheelsDraw = new ExtraWheelsDraw(wheelsNum, bodyColor); Locomotive.Init(speed, weight, bodyColor); } /// Установка позиции локомотива @@ -98,14 +100,10 @@ class DrawningLocomotive { g.setColor(Color.BLACK); g.drawRect( (int)_startPosX + 50, (int)_startPosY + 10, 10, 20); //колеса - g.drawOval((int) _startPosX, (int)_startPosY + 40, 10, 10); - g.drawOval((int) _startPosX + 20, (int)_startPosY + 40, 10, 10); - g.drawOval((int) _startPosX + 70, (int)_startPosY + 40, 10, 10); - g.drawOval((int) _startPosX + 90, (int)_startPosY + 40, 10, 10); + extraWheelsDraw.DrawWheels((int)_startPosX, (int)_startPosY, g); //движок g.setColor(Locomotive.getBodyColor()); g.fillRect((int)_startPosX + 100, (int)_startPosY + 10, 10, 30); - } public void ChangeBorders(int width, int height) diff --git a/ExtraWheelsDraw.java b/ExtraWheelsDraw.java new file mode 100644 index 0000000..3bad278 --- /dev/null +++ b/ExtraWheelsDraw.java @@ -0,0 +1,48 @@ +import java.awt.*; + +public class ExtraWheelsDraw { + private WheelsCount wheelsCount; + private int wheelsNum; + public void setWheelsNum(int num) { + wheelsNum = num; + switch (wheelsNum) { + case 0: { + wheelsCount = WheelsCount.Two; + break; + } + case 1: { + wheelsCount = WheelsCount.Three; + break; + } + case 2: { + wheelsCount = WheelsCount.Four; + break; + } + } + } + private final Color color; + + public ExtraWheelsDraw(int num, Color color) { + setWheelsNum(num); + this.color = color; + } + + public void DrawWheels(int startPosX, int startPosY, Graphics2D g) { + g.setColor(color); + g.drawOval(startPosX, startPosY + 40, 10, 10); + g.drawOval(startPosX + 90, startPosY + 40, 10, 10); + switch (wheelsCount) { + case Two: { + break; + } + case Three: { + g.drawOval(startPosX + 20, startPosY + 40, 10, 10); + break; + } + case Four: { + g.drawOval(startPosX + 20, startPosY + 40, 10, 10); + g.drawOval(startPosX + 70, startPosY + 40, 10, 10); + } + } + } +} diff --git a/FormLocomotive.java b/FormLocomotive.java index 6b6d139..fe6d577 100644 --- a/FormLocomotive.java +++ b/FormLocomotive.java @@ -19,21 +19,12 @@ public class FormLocomotive extends JComponent{ if (_locomotive != null) _locomotive.ChangeBorders(formFrame.getWidth(), formFrame.getHeight()); repaint(); } - @Override - public void componentMoved(ComponentEvent e) { - - } - + public void componentMoved(ComponentEvent e) {} @Override - public void componentShown(ComponentEvent e) { - - } - + public void componentShown(ComponentEvent e) {} @Override - public void componentHidden(ComponentEvent e) { - - } + public void componentHidden(ComponentEvent e) {} }); Panel statusPanel = new Panel(); @@ -51,7 +42,7 @@ public class FormLocomotive extends JComponent{ Random rnd = new Random(); _locomotive = new DrawningLocomotive(); _entity = new EntityLocomotive(); - _locomotive.Init(100 + rnd.nextInt(200), 1000 + rnd.nextInt(1000), Color.getHSBColor(rnd.nextInt(256), rnd.nextInt(256), rnd.nextInt(256)), _entity); + _locomotive.Init(100 + rnd.nextInt(200), 1000 + rnd.nextInt(1000), Color.getHSBColor(rnd.nextInt(256), rnd.nextInt(256), rnd.nextInt(256)), rnd.nextInt(3), _entity); _locomotive.SetPosition(10 + rnd.nextInt(90), 10 + rnd.nextInt(90), formFrame.getWidth(), formFrame.getHeight() - 75); speedLabel.setText("Speed: " + _locomotive.Locomotive.getSpeed()); weightLabel.setText("Weight: " + (int)_locomotive.Locomotive.getWeight()); @@ -106,7 +97,5 @@ public class FormLocomotive extends JComponent{ public static void main(String[] args) { FormLocomotive formLocomotive = new FormLocomotive(); - - } } diff --git a/WheelsCount.java b/WheelsCount.java new file mode 100644 index 0000000..411b442 --- /dev/null +++ b/WheelsCount.java @@ -0,0 +1,3 @@ +public enum WheelsCount { + Two, Three, Four +} From ac9d6db704630075751e78705176ec678c476076 Mon Sep 17 00:00:00 2001 From: Danila_Mochalov Date: Tue, 27 Sep 2022 16:26:05 +0400 Subject: [PATCH 7/7] =?UTF-8?q?=D0=A1=D0=B4=D0=B0=D0=BD=D0=BD=D0=B0=D1=8F?= =?UTF-8?q?=20=D1=81=D0=BB=D0=BE=D0=B6=D0=BD=D0=B0=D1=8F=20=D0=BB=D0=B0?= =?UTF-8?q?=D0=B1=201?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- DrawningLocomotive.java | 7 ++++--- ExtraWheelsDraw.java | 29 ++++++++++++----------------- 2 files changed, 16 insertions(+), 20 deletions(-) diff --git a/DrawningLocomotive.java b/DrawningLocomotive.java index c39e0e1..7baf701 100644 --- a/DrawningLocomotive.java +++ b/DrawningLocomotive.java @@ -12,14 +12,15 @@ class DrawningLocomotive { /// Высота окна отрисовки private Integer _pictureHeight = null; /// Ширина отрисовки локомотива - private final int _locomotiveWidth = 110; + private final int _locomotiveWidth = 120; /// Высота отрисовки локомотива private final int _locomotiveHeight = 50; /// Инициализация свойств public void Init(int speed, float weight, Color bodyColor, int wheelsNum, EntityLocomotive entity) { Locomotive = entity; - extraWheelsDraw = new ExtraWheelsDraw(wheelsNum, bodyColor); + extraWheelsDraw = new ExtraWheelsDraw(); + extraWheelsDraw.Init(wheelsNum, bodyColor); Locomotive.Init(speed, weight, bodyColor); } /// Установка позиции локомотива @@ -90,7 +91,7 @@ class DrawningLocomotive { } //тело g.setColor(Color.BLACK); - g.drawRect((int)_startPosX , (int)_startPosY, _locomotiveWidth - 10, _locomotiveHeight - 10); + g.drawRect((int)_startPosX , (int)_startPosY, _locomotiveWidth - 20, _locomotiveHeight - 10); //окна g.setColor(Locomotive.getBodyColor()); g.fillRect((int)_startPosX + 10, (int)_startPosY + 10, 10, 10); diff --git a/ExtraWheelsDraw.java b/ExtraWheelsDraw.java index 3bad278..4a19792 100644 --- a/ExtraWheelsDraw.java +++ b/ExtraWheelsDraw.java @@ -1,28 +1,24 @@ import java.awt.*; public class ExtraWheelsDraw { - private WheelsCount wheelsCount; - private int wheelsNum; + private WheelsCount wheelsCount = WheelsCount.Two; public void setWheelsNum(int num) { - wheelsNum = num; - switch (wheelsNum) { + switch (num) { case 0: { - wheelsCount = WheelsCount.Two; - break; - } - case 1: { wheelsCount = WheelsCount.Three; break; } - case 2: { + case 1: { wheelsCount = WheelsCount.Four; break; } + default: + break; } } - private final Color color; + private Color color; - public ExtraWheelsDraw(int num, Color color) { + public void Init(int num, Color color) { setWheelsNum(num); this.color = color; } @@ -32,17 +28,16 @@ public class ExtraWheelsDraw { g.drawOval(startPosX, startPosY + 40, 10, 10); g.drawOval(startPosX + 90, startPosY + 40, 10, 10); switch (wheelsCount) { - case Two: { - break; + case Four: { + g.drawOval(startPosX + 70, startPosY + 40, 10, 10); } case Three: { g.drawOval(startPosX + 20, startPosY + 40, 10, 10); break; } - case Four: { - g.drawOval(startPosX + 20, startPosY + 40, 10, 10); - g.drawOval(startPosX + 70, startPosY + 40, 10, 10); - } + default: + break; } } + }