133 lines
4.8 KiB
Java
133 lines
4.8 KiB
Java
package laba1Loco;
|
||
|
||
import java.awt.*;
|
||
import java.util.*;
|
||
import javax.swing.*;
|
||
import javax.swing.Timer;
|
||
import java.awt.event.*;
|
||
|
||
public class DrawingLoco extends DrawingTrain{
|
||
|
||
/// <summary>
|
||
/// Инициализация свойств
|
||
/// </summary>
|
||
/// <param name="speed">Скорость</param>
|
||
/// <param name="weight">Вес</param>
|
||
/// <param name="bodyColor">Цвет кузова</param>
|
||
/// <param name="additionalColor">Дополнительный цвет</param>
|
||
/// <param name="tube">Признак наличия трубы</param>
|
||
/// <param name="fuelTank">Признак наличия бака</param>
|
||
/// <param name="locoLine">Признак наличия паровозной полосы</param>
|
||
/// <param name="width">Ширина картинки</param>
|
||
/// <param name="height">Высота картинки</param>
|
||
public DrawingLoco(int speed, double weight, Color bodyColor, int _numWheel, Color additionalColor, boolean tube, boolean fuelTank, boolean locoLine, int width, int height)
|
||
{
|
||
super(speed, weight, bodyColor, _numWheel, width, height);
|
||
EntityTrain = new EntityLoco(speed, weight, bodyColor, _numWheel, additionalColor, tube, fuelTank, locoLine);
|
||
_locoWidth = ((EntityLoco)EntityTrain).FuelTank ? 169 : 83;
|
||
}
|
||
// конструктор для 3 сложной лабы
|
||
public DrawingLoco(EntityLoco train, IWheelDrawing _wheelDrawing, int width, int height ){
|
||
super(train, _wheelDrawing, width, height);
|
||
if (height < _locoHeight || width < _locoWidth)
|
||
return;
|
||
}
|
||
/// <summary>
|
||
/// Установка позиции
|
||
/// </summary>
|
||
/// <param name="x">Координата X</param>
|
||
/// <param name="y">Координата Y</param>
|
||
public void SetPosition(int x, int y)
|
||
{
|
||
_startPosX = Math.min(x, _pictureWidth-_locoWidth);
|
||
_startPosY = Math.min(y, _pictureHeight-_locoHeight);
|
||
}
|
||
/// <summary>
|
||
/// Прорисовка объекта
|
||
/// </summary>
|
||
/// <param name="g"></param>
|
||
public void DrawTransport(Graphics2D g2d)
|
||
{
|
||
|
||
if (EntityTrain == null)
|
||
{
|
||
return;
|
||
}
|
||
|
||
super.DrawTransport(g2d);
|
||
|
||
g2d.setColor(((EntityLoco)EntityTrain).AdditionalColor);
|
||
if (((EntityLoco)EntityTrain).Tube)
|
||
{
|
||
g2d.drawPolyline(new int[] {
|
||
_startPosX + 40,_startPosX + 40,_startPosX + 45,_startPosX + 41,_startPosX + 41,_startPosX + 44,_startPosX + 44,_startPosX + 45,_startPosX + 45,
|
||
},new int[] {
|
||
_startPosY+9,_startPosY+3,_startPosY+3,_startPosY+3,_startPosY,_startPosY,_startPosY+3,_startPosY+3,_startPosY+9,
|
||
},9);
|
||
}
|
||
if (((EntityLoco)EntityTrain).LocoLine)
|
||
{
|
||
g2d.drawPolyline(new int[] {
|
||
_startPosX + 60,_startPosX + 38,
|
||
},new int[] {
|
||
_startPosY+10,_startPosY+32
|
||
},2);
|
||
g2d.drawPolyline(new int[] {
|
||
_startPosX + 65,_startPosX + 43,
|
||
},new int[] {
|
||
_startPosY+10,_startPosY+32
|
||
},2);
|
||
g2d.drawPolyline(new int[] {
|
||
_startPosX + 70,_startPosX + 48,
|
||
},new int[] {
|
||
_startPosY+10,_startPosY+32
|
||
},2);
|
||
}
|
||
if (((EntityLoco)EntityTrain).FuelTank)
|
||
{
|
||
// body
|
||
g2d.setColor(EntityTrain.BodyColor);
|
||
g2d.drawPolyline(new int[]{
|
||
_startPosX + 89, _startPosX + 164, _startPosX + 164, _startPosX + 89, _startPosX + 89,
|
||
}, new int[]{
|
||
_startPosY+10, _startPosY+10, _startPosY+32, _startPosY+32, _startPosY+10
|
||
}, 5);
|
||
g2d.drawPolyline(new int[]{
|
||
_startPosX + 89, _startPosX + 164,
|
||
}, new int[]{
|
||
_startPosY+21, _startPosY+21,
|
||
}, 2);
|
||
|
||
// trucks
|
||
g2d.fillPolygon(new int[]{
|
||
_startPosX + 0+85,_startPosX + 5+85,_startPosX + 32+85,_startPosX + 36+85,
|
||
}, new int[]{
|
||
_startPosY+37,_startPosY+33,_startPosY+33,_startPosY+37
|
||
}, 4);
|
||
g2d.fillPolygon(new int[]{
|
||
_startPosX + 44+85,_startPosX + 49+85,_startPosX + 76+85,_startPosX + 80+85,
|
||
}, new int[]{
|
||
_startPosY+37,_startPosY+33,_startPosY+33,_startPosY+37
|
||
}, 4);
|
||
|
||
//back
|
||
g2d.fillPolygon(new int[]{
|
||
_startPosX + 79+85,_startPosX + 82+85,_startPosX + 82+85,_startPosX + 79+85,
|
||
}, new int[]{
|
||
_startPosY+12,_startPosY+12,_startPosY+30,_startPosY+30
|
||
}, 4);
|
||
|
||
|
||
//front
|
||
g2d.fillPolygon(new int[]{
|
||
_startPosX + 86,_startPosX + 89,_startPosX + 89,_startPosX + 86,
|
||
}, new int[]{
|
||
_startPosY+12,_startPosY+12,_startPosY+30,_startPosY+30
|
||
}, 4);
|
||
|
||
}
|
||
|
||
//wheels
|
||
wheelDrawing.Draw(_startPosX, _startPosY, ((EntityLoco)EntityTrain).FuelTank, EntityTrain.BodyColor, g2d);
|
||
}
|
||
} |