Fixed Problems.

This commit is contained in:
Данила Мочалов 2022-10-11 16:29:28 +04:00
parent 400672b6dd
commit 2920306b70
2 changed files with 21 additions and 11 deletions

View File

@ -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);

View File

@ -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();