Extra task completed
This commit is contained in:
parent
d30a086f9d
commit
0a29f09918
@ -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)
|
||||
|
48
ExtraWheelsDraw.java
Normal file
48
ExtraWheelsDraw.java
Normal file
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -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();
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
3
WheelsCount.java
Normal file
3
WheelsCount.java
Normal file
@ -0,0 +1,3 @@
|
||||
public enum WheelsCount {
|
||||
Two, Three, Four
|
||||
}
|
Loading…
Reference in New Issue
Block a user