Added and Fixed EntityWarmlyLocomotive & DrawningWarmlyLocomotive

This commit is contained in:
Данила Мочалов 2022-10-08 18:36:19 +04:00
parent 673ba65efe
commit 4526388454
3 changed files with 63 additions and 0 deletions

View File

@ -0,0 +1,30 @@
import java.awt.*;
public class DrawningWarmlyLocomotive extends DrawningLocomotive{
public DrawningWarmlyLocomotive(int speed, float weight, Color bodyColor, Color extraColor, boolean pipe, boolean storage)
{
super(speed, weight, bodyColor, 110, 50);
Locomotive = new EntityWarmlyLocomotive(speed, weight, bodyColor, extraColor, pipe, storage);
}
public void DrawTransport(Graphics g)
{
if (Locomotive instanceof EntityWarmlyLocomotive)
{
EntityWarmlyLocomotive warmlyLocomotive = (EntityWarmlyLocomotive) Locomotive;
//Pen pen = new(Color.Black);
//Brush extraBrush = new SolidBrush(warmlyLocomotive.ExtraColor);
super.DrawTransport((Graphics2D)g);
if (warmlyLocomotive.Pipe)
{
//TODO
}
if (warmlyLocomotive.FuelStorage)
{
//TODO
}
}
}
}

View File

@ -0,0 +1,15 @@
import java.awt.*;
public class EntityWarmlyLocomotive extends EntityLocomotive{
public final Color ExtraColor;
public final boolean Pipe;
public final boolean FuelStorage;
public EntityWarmlyLocomotive (int speed, float weight, Color bodyColor, Color extraColor, boolean pipe, boolean fuelStorage)
{
super(speed, weight, bodyColor);
ExtraColor = extraColor;
Pipe = pipe;
FuelStorage = fuelStorage;
}
}

View File

@ -47,7 +47,23 @@ public class FormLocomotive extends JComponent{
repaint();
});
JButton modifiedButton = new JButton("Modified");
modifiedButton.addActionListener(e -> {
Random rnd = new Random();
_locomotive = new DrawningWarmlyLocomotive(rnd.nextInt(200) + 100, rnd.nextInt(1000) + 1000,
new Color(rnd.nextInt(256), rnd.nextInt(256), rnd.nextInt(256)),
new Color(rnd.nextInt(256), rnd.nextInt(256), rnd.nextInt(256)),
rnd.nextBoolean(),
rnd.nextBoolean());
_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(modifiedButton);
statusPanel.add(speedLabel);
statusPanel.add(weightLabel);
statusPanel.add(colorLabel);
@ -84,6 +100,8 @@ public class FormLocomotive extends JComponent{
formFrame.getContentPane().add(this);
}
@Override
protected void paintComponent(Graphics g) {
super.paintComponent(g);