PIbd21.LyovushkinaA.A.Conta.../DrawingContainerShip.java

131 lines
5.8 KiB
Java
Raw Normal View History

2023-09-25 18:40:25 +04:00
import java.awt.*;
public class DrawingContainerShip {
public EntityContainerShip EntityContainerShip;
private int _pictureWidth;
private int _pictureHeight;
private int _startPosX;
private int _startPosY;
private int _shipWidth = 110;
private int _shipHeight = 65;
private DrawingDecks drawingDecks;
public boolean Init(int speed, double weight, Color bodyColor, Color
additionalColor, boolean crane, boolean container, int deck, int width, int height)
{
_pictureWidth = width;
_pictureHeight = height;
if (_pictureWidth < _shipWidth || _pictureHeight < _shipHeight)
{
return false;
}
EntityContainerShip = new EntityContainerShip();
EntityContainerShip.Init(speed, weight, bodyColor, additionalColor,
crane, container, deck);
drawingDecks = new DrawingDecks();
drawingDecks.setNumDecks(deck);
return true;
}
public void SetPosition(int x, int y)
{
_startPosX = Math.min(x, _pictureWidth - _shipWidth);
_startPosY = Math.min(y, _pictureHeight - _shipHeight);
}
public void MoveTransport(Direction direction)
{
if (EntityContainerShip == null)
{
return;
}
switch (direction)
{
case Left:
if (_startPosX - EntityContainerShip.Step > 0)
{
_startPosX -= (int)EntityContainerShip.Step;
}
break;
case Up:
if (_startPosY - EntityContainerShip.Step > 0)
{
_startPosY -= (int)EntityContainerShip.Step;
}
break;
case Right:
if (_startPosX + EntityContainerShip.Step + _shipWidth < _pictureWidth)
{
_startPosX += (int)EntityContainerShip.Step;
}
break;
case Down:
if (_startPosY + EntityContainerShip.Step + _shipHeight< _pictureHeight)
{
_startPosY += (int)EntityContainerShip.Step;
}
break;
}
}
public void DrawShip(Graphics2D g)
{
if (EntityContainerShip == null)
{
return;
}
//Pen pen = new Pen(Color.Black);
//Brush adbrush = new SolidBrush(EntityContainerShip.AdditionalColor);
//Brush brBlue = new SolidBrush(Color.Blue);
g.setPaint(Color.BLUE);
// заполнение борта
int x[] = {_startPosX+ 20, _startPosX+40, _startPosX+110, _startPosX+130, _startPosX+ 20};
int y[] = {_startPosY+65,_startPosY+85, _startPosY+85, _startPosY+65, _startPosY+65};
g.fillPolygon(x, y, 5);
//борт корабля контур
g.setPaint(Color.BLACK);
int _x[] = {_startPosX+ 20, _startPosX+40, _startPosX+110, _startPosX+130, _startPosX+ 20};
int _y[] = {_startPosY+65,_startPosY+85, _startPosY+85, _startPosY+65, _startPosY+65};
g.drawPolyline(_x, _y, 5);
//рисунок на борту
g.drawLine(_startPosX + 43, _startPosY + 80, _startPosX + 47, _startPosY + 80);
g.drawLine(_startPosX + 45, _startPosY + 70, _startPosX + 45, _startPosY + 80);
g.drawLine(_startPosX + 40, _startPosY + 75, _startPosX + 50, _startPosY + 75);
//контейнеры
if (EntityContainerShip.Conteiners)
{
g.setPaint(EntityContainerShip.AdditionalColor);
g.fillRect(_startPosX + 50, _startPosY + 55, 35, 10);
g.fillRect(_startPosX + 85, _startPosY + 55, 20, 10);
g.fillRect(_startPosX + 105, _startPosY + 50, 15, 15);
g.fillRect(_startPosX + 50, _startPosY + 45, 15, 10);
g.fillRect(_startPosX + 65, _startPosY + 45, 55, 5);
g.fillRect(_startPosX + 65, _startPosY + 50, 40, 5);
g.setPaint(Color.BLACK);
g.drawRect(_startPosX + 50, _startPosY + 55, 35, 10);
g.drawRect(_startPosX + 85, _startPosY + 55, 20, 10);
g.drawRect(_startPosX + 105, _startPosY + 50, 15, 15);
g.drawRect(_startPosX + 50, _startPosY + 45, 15, 10);
g.drawRect(_startPosX + 65, _startPosY + 45, 55, 5);
g.drawRect(_startPosX + 65, _startPosY + 50, 40, 5);
}
//кран
if (EntityContainerShip.Crane)
{
g.setPaint(EntityContainerShip.AdditionalColor);
g.fillRect(_startPosX + 43, _startPosY+20, 5, 45);
g.fillRect(_startPosX + 47, _startPosY + 30, 20, 3);
g.setPaint(Color.BLACK);
g.drawRect(_startPosX + 43, _startPosY+20, 5, 45);
g.drawRect(_startPosX + 47, _startPosY + 30, 20, 3);
g.drawLine(_startPosX + 47, _startPosY+20, _startPosX + 67, _startPosY + 30);
g.drawLine(_startPosX + 67, _startPosY + 33, _startPosX + 67, _startPosY + 45);
}
drawingDecks.DrawDeck(_startPosX, _startPosY, g);
}
}