PIbd-23_Panina_A.D.Cruiser..../DrawingCruiser.java
2023-12-08 23:20:53 +04:00

171 lines
4.5 KiB
Java

import java.awt.*;
public class DrawingCruiser {
public EntityCruiser EntityCruiser;
private int _pictureWidth;
private int _pictureHeight;
protected int _startPosX;
protected int _startPosY;
private int _carWidth = 110;
private int _carHeight = 60;
/// <summary>
/// Координата X объекта
/// </summary>
public int GetPosX(){return _startPosX;};
/// <summary>
/// Координата Y объекта
/// </summary>
public int GetPosY(){return _startPosY;}
/// <summary>
/// Ширина объекта
/// </summary>
public int GetWidth(){return _carWidth;};
/// <summary>
/// Высота объекта
/// </summary>
public int GetHeight(){return _carHeight;}
public IDop wheels;
public DrawingCruiser(int speed, double weight, Color bodyColor, int width, int height)
{
if(width < _carWidth || height < _carHeight)
{
return;
}
_pictureWidth = width;
_pictureHeight = height;
EntityCruiser = new EntityCruiser(speed, weight, bodyColor);
}
public EntityCruiser getEntity(){
return EntityCruiser;
}
protected DrawingCruiser(int speed, double weight, Color bodyColor, int
width, int height, int carWidth, int carHeight)
{
if (width <= _carWidth || height <= _carHeight)
{
return;
}
_pictureWidth = width;
_pictureHeight = height;
_carWidth = carWidth;
_carHeight = carHeight;
EntityCruiser = new EntityCruiser(speed, weight, bodyColor);
}
public DrawingCruiser(EntityCruiser entityCar, IDop wheels)
{
EntityCruiser = entityCar;
this.wheels = wheels;
_pictureWidth = 1000;
_pictureHeight = 1000;
_carWidth = 110;
_carHeight = 60;
}
public void SetPosition(int x, int y)
{
if (x < 0 || x >= _pictureWidth || y < 0 || y >= _pictureHeight)
{
_startPosX = 0;
_startPosY = 0;
}
_startPosX = x;
_startPosY = y;
}
public void MoveTransport(Direction direction)
{
if (!CanMove(direction) || EntityCruiser == null)
{
return;
}
switch (direction)
{
//влево
case Left:
_startPosX -= (int)EntityCruiser.Step();
break;
//вверх
case Up:
_startPosY -= (int)EntityCruiser.Step();
break;
// вправо
case Right:
_startPosX += (int)EntityCruiser.Step();
break;
//РІРЅРёР·
case Down:
_startPosY += (int)EntityCruiser.Step();
break;
}
}
public boolean CanMove(Direction direction)
{
if (EntityCruiser == null)
{
return false;
}
switch (direction)
{
//влево
case Left:
return (_startPosX - EntityCruiser.Step()) > 0;
//вверх
case Up:
return _startPosY - EntityCruiser.Step() > 0;
// вправо
case Right:
return _startPosX + EntityCruiser.Step() + _carWidth < _pictureWidth;
//РІРЅРёР·
case Down:
return _startPosY + EntityCruiser.Step() + _carHeight < _pictureHeight;
default:
return false;
}
}
public void DrawTransport(Graphics g)
{
if (EntityCruiser == null)
{
return;
}
g.setColor(EntityCruiser.BodyColor);
//границы автомобиля
g.fillRect(_startPosX, _startPosY + 35, 110, 10);
g.fillRect( _startPosX + 85, _startPosY, 25, 35);
/*g.fillOval( _startPosX, _startPosY + 35 + 10, 15, 15);
g.fillOval( _startPosX + 15, _startPosY + 35 + 10, 15, 15);
g.fillOval( _startPosX + 95, _startPosY + 35 + 10, 15, 15);*/
if (wheels == null){return;}
wheels.drawWheels(g, _startPosX, _startPosY, EntityCruiser.BodyColor);
}
public IMoveableObject GetMoveableObject(){return new DrawingObjectCruiser(this);}
}