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 +}