218 lines
6.2 KiB
Java
218 lines
6.2 KiB
Java
package Drawnings;
|
|
|
|
import java.awt.*;
|
|
import java.util.Random;
|
|
import DifferenceOfWheels.*;
|
|
import Entities.EntityTruck;
|
|
|
|
|
|
public class DrawningTruck {
|
|
public EntityTruck EntityTruck;
|
|
protected EntityTruck get_EntityTruck() { return EntityTruck; }
|
|
public IOrnaments _ornament = new DrawningWheels();
|
|
int CountOfWheels = 0;
|
|
int ornament_type;
|
|
|
|
// Ширина окна
|
|
private Integer _pictureWidth;
|
|
|
|
// Высота окна
|
|
private Integer _pictureHeight;
|
|
|
|
// Левая координата прорисовки автомобиля
|
|
protected Integer _startPosX;
|
|
|
|
// Верхняя кооридната прорисовки автомобиля
|
|
protected Integer _startPosY;
|
|
|
|
// Ширина прорисовки самосвала
|
|
private int _drawningTruckWidth = 110; //100
|
|
|
|
// Высота прорисовки самосвала
|
|
private int _drawningTruckHeight = 110; //92
|
|
|
|
public Integer GetPosX() { return _startPosX;}
|
|
public Integer GetPosY() { return _startPosY;}
|
|
public Integer GetWidth() { return _drawningTruckWidth;}
|
|
public Integer GetHeight() { return _drawningTruckHeight;}
|
|
Random random = new Random();
|
|
|
|
private DrawningTruck()
|
|
{
|
|
_pictureWidth = null;
|
|
_pictureHeight = null;
|
|
_startPosX = null;
|
|
_startPosY = null;
|
|
|
|
}
|
|
|
|
public DrawningTruck(int speed, double weight, Color bodyColor)
|
|
{
|
|
EntityTruck = new EntityTruck(speed, weight, bodyColor);
|
|
CountOfWheels = random.nextInt(2, 5);
|
|
ornament_type = random.nextInt(0, 3);
|
|
}
|
|
|
|
protected DrawningTruck(int drawningTruckWidth, int drawningTruckHeight)
|
|
{
|
|
_drawningTruckWidth = drawningTruckWidth;
|
|
_drawningTruckHeight = drawningTruckHeight;
|
|
}
|
|
|
|
public DrawningTruck(EntityTruck _truck, IOrnaments ornament){
|
|
EntityTruck = _truck;
|
|
_ornament = ornament;
|
|
if (_ornament instanceof DrawningOrnamentStar) ornament_type = 0;
|
|
else if (_ornament instanceof DrawningOrnamentTriangle) ornament_type = 1;
|
|
else if (_ornament instanceof DrawningOrnamentRectangle) ornament_type = 2;
|
|
CountOfWheels = _ornament.get_count_weels();
|
|
}
|
|
|
|
protected void SetOrnamentWheel(){
|
|
switch (ornament_type){
|
|
case 0:
|
|
_ornament = new DrawningOrnamentStar();
|
|
_ornament.SetCount(CountOfWheels);
|
|
break;
|
|
case 1:
|
|
_ornament = new DrawningOrnamentTriangle();
|
|
_ornament.SetCount(CountOfWheels);
|
|
break;
|
|
case 2:
|
|
_ornament = new DrawningOrnamentRectangle();
|
|
_ornament.SetCount(CountOfWheels);
|
|
break;
|
|
}
|
|
}
|
|
|
|
public Boolean SetPictureSize(int width, int height)
|
|
{
|
|
if (_drawningTruckWidth > width || _drawningTruckHeight > height)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
if (_pictureWidth != null && width != _pictureWidth || _pictureHeight != null && height != _pictureHeight)
|
|
{
|
|
if (_startPosX + _drawningTruckWidth > width)
|
|
{
|
|
_startPosX -= _drawningTruckWidth;
|
|
}
|
|
|
|
if (_startPosY + _drawningTruckHeight > height)
|
|
{
|
|
_startPosY -= _drawningTruckHeight;
|
|
}
|
|
}
|
|
|
|
_pictureWidth = width;
|
|
_pictureHeight = height;
|
|
return true;
|
|
}
|
|
|
|
public void SetPosition(int x, int y)
|
|
{
|
|
if (_pictureHeight == null|| _pictureWidth == null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (x < 0)
|
|
{
|
|
x = 0;
|
|
}
|
|
if (x + _drawningTruckWidth > _pictureWidth)
|
|
{
|
|
x = (int)_pictureWidth - _drawningTruckWidth;
|
|
}
|
|
if (y < 0)
|
|
{
|
|
y = 0;
|
|
}
|
|
if (y + _drawningTruckHeight > _pictureHeight)
|
|
{
|
|
y = (int)_pictureHeight - _drawningTruckHeight;
|
|
|
|
}
|
|
|
|
_startPosX = x;
|
|
_startPosY = y;
|
|
|
|
}
|
|
|
|
public Boolean MoveTransport(DirectionType direction)
|
|
{
|
|
if (EntityTruck == null || _startPosX == null || _startPosY == null)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
switch (direction)
|
|
{
|
|
//влево
|
|
case DirectionType.Left:
|
|
if (_startPosX - _drawningTruckWidth > 0)
|
|
{
|
|
_startPosX -= (int)EntityTruck.Step;
|
|
}
|
|
return true;
|
|
//вверх
|
|
case DirectionType.Up:
|
|
if (_startPosY - _drawningTruckHeight > 0)
|
|
{
|
|
_startPosY -= (int)EntityTruck.Step;
|
|
}
|
|
return true;
|
|
// вправо
|
|
case DirectionType.Right:
|
|
if (_startPosX + _drawningTruckWidth + (int)EntityTruck.Step < _pictureWidth)
|
|
{
|
|
_startPosX += (int)EntityTruck.Step;
|
|
}
|
|
return true;
|
|
//вниз
|
|
case DirectionType.Down:
|
|
if (_startPosY + _drawningTruckHeight + (int)EntityTruck.Step < _pictureHeight)
|
|
{
|
|
_startPosY += (int)EntityTruck.Step;
|
|
}
|
|
return true;
|
|
default:
|
|
return false;
|
|
}
|
|
}
|
|
|
|
public void DrawTransport(Graphics2D g)
|
|
{
|
|
if (EntityTruck == null || _startPosX == null || _startPosY == null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
g.setPaint(Color.BLACK);
|
|
|
|
// Колёса
|
|
g.setPaint(Color.BLACK);
|
|
SetOrnamentWheel();
|
|
if (_ornament != null){
|
|
_ornament.DrawWeels(g, _startPosX - 5, _startPosY);
|
|
}
|
|
|
|
//Границы самосвала
|
|
g.drawRect( _startPosX + 5, _startPosY + 53, 100, 13);
|
|
g.drawRect( _startPosX + 75, _startPosY + 15, 30, 36);
|
|
g.drawRect(_startPosX + 80, _startPosY + 20, 20, 20);
|
|
|
|
// Кузов
|
|
g.setPaint(EntityTruck.BodyColor);
|
|
g.fillRect(_startPosX + 5, _startPosY + 53, 100, 13);
|
|
g.fillRect(_startPosX + 75, _startPosY + 15, 30, 36);
|
|
|
|
//Окно
|
|
g.setPaint(Color.CYAN);
|
|
g.fillRect(_startPosX + 80, _startPosY + 20, 20, 20);
|
|
|
|
}
|
|
|
|
}
|