From 2920306b706be1f72aa6535c7b147c881dcac788 Mon Sep 17 00:00:00 2001 From: Danila_Mochalov Date: Tue, 11 Oct 2022 16:29:28 +0400 Subject: [PATCH] Fixed Problems. --- DrawningLocomotive.java | 24 +++++++++++++++++------- FormMap.java | 8 ++++---- 2 files changed, 21 insertions(+), 11 deletions(-) diff --git a/DrawningLocomotive.java b/DrawningLocomotive.java index 7e3054c..5a4e57b 100644 --- a/DrawningLocomotive.java +++ b/DrawningLocomotive.java @@ -3,7 +3,8 @@ import java.util.Random; class DrawningLocomotive { public EntityLocomotive Locomotive; - public IDrawningExtra[] drawningExtra; + public ExtraWheelsDraw extraWheelsDraw; + public IDrawningExtra drawningExtra; /// Левая координата отрисовки локомотива protected float _startPosX; /// Верхняя координата отрисовки локомотива @@ -20,10 +21,19 @@ class DrawningLocomotive { private final Random random = new Random(); public DrawningLocomotive(int speed, float weight, Color bodyColor) { - int randExtra = random.nextInt(3); - drawningExtra = new IDrawningExtra[2]; - drawningExtra[0] = new ExtraWheelsDraw(randExtra, bodyColor); - drawningExtra[1] = random.nextBoolean() ? new ExtraRoundWheelDraw(randExtra) : new ExtraStarWheelDraw(randExtra); + int randExtra = random.nextInt(2); + extraWheelsDraw = new ExtraWheelsDraw(randExtra, bodyColor); + switch (random.nextInt(3)){ + case 0: + drawningExtra = new ExtraStarWheelDraw(randExtra); + break; + case 1: + drawningExtra = new ExtraRoundWheelDraw(randExtra); + break; + case 2: + drawningExtra = new ExtraWheelsDraw(randExtra, bodyColor); + break; + } Locomotive = new EntityLocomotive(speed, weight, bodyColor); } @@ -113,9 +123,9 @@ class DrawningLocomotive { g.setColor(Color.BLACK); g.fillRect( (int)_startPosX + 50, (int)_startPosY + 10, 10, 20); //колеса - drawningExtra[0].DrawExtra((int)_startPosX, (int)_startPosY, g); + extraWheelsDraw.DrawExtra((int)_startPosX, (int)_startPosY, g); //extra - drawningExtra[1].DrawExtra((int)_startPosX, (int)_startPosY, g); + drawningExtra.DrawExtra((int)_startPosX, (int)_startPosY, g); //движок g.setColor(Locomotive.getBodyColor()); g.fillRect((int)_startPosX + 100, (int)_startPosY + 10, 10, 30); diff --git a/FormMap.java b/FormMap.java index 1e42c4b..4b0064d 100644 --- a/FormMap.java +++ b/FormMap.java @@ -85,25 +85,25 @@ public class FormMap extends JComponent { statusPanel.add(weightLabel); statusPanel.add(colorLabel); - JButton moveDownButton = new JButton("D"); + JButton moveDownButton = new JButton("Down"); moveDownButton.addActionListener(e -> { if(bufferImg != null) bufferImg = _abstractMap.MoveObject(Direction.Down); repaint(); }); - JButton moveUpButton = new JButton("U"); + JButton moveUpButton = new JButton("Up"); moveUpButton.addActionListener(e -> { if(bufferImg != null) bufferImg = _abstractMap.MoveObject(Direction.Up); repaint(); }); - JButton moveLeftButton = new JButton("L"); + JButton moveLeftButton = new JButton("Left"); moveLeftButton.addActionListener(e -> { if(bufferImg != null) bufferImg = _abstractMap.MoveObject(Direction.Left); repaint(); }); - JButton moveRightButton = new JButton("R"); + JButton moveRightButton = new JButton("Right"); moveRightButton.addActionListener(e -> { if(bufferImg != null) bufferImg = _abstractMap.MoveObject(Direction.Right); repaint();