113 lines
4.9 KiB
Java
113 lines
4.9 KiB
Java
import java.awt.*;
|
|
public class DrawingWarmlyShip {
|
|
private EntityWarmlyShip entityWarmlyShip;
|
|
public EntityWarmlyShip GetEntityWarmlyShip(){
|
|
return entityWarmlyShip;
|
|
}
|
|
private void SetEntityWarmlyShip(EntityWarmlyShip entityWarmlyShip){
|
|
this.entityWarmlyShip = entityWarmlyShip;
|
|
}
|
|
private DrawingDecks drawingDecks;
|
|
public DrawingDecks GetDrawingDecks(){
|
|
return drawingDecks;
|
|
}
|
|
private void SetDrawingDecks( DrawingDecks drawingDecks){
|
|
this.drawingDecks = drawingDecks;
|
|
}
|
|
private int _pictureWidth;
|
|
private int _pictureHeight;
|
|
private int _startPosX;
|
|
private int _startPosY;
|
|
private final int _shipWidth = 100;
|
|
private final int _shipHeight = 70;
|
|
public boolean Init(int speed, double weight, Color mainColor, Color optionalColor, boolean pipes, boolean fuelCompartment, int width, int height, int numberDecks){
|
|
if (width < _shipWidth || height <_shipHeight){
|
|
return false;
|
|
}
|
|
_pictureWidth = width;
|
|
_pictureHeight = height;
|
|
entityWarmlyShip = new EntityWarmlyShip();
|
|
entityWarmlyShip.Init(speed, weight, mainColor, optionalColor, pipes, fuelCompartment);
|
|
drawingDecks = new DrawingDecks();
|
|
drawingDecks.SetNumberDecks(numberDecks);
|
|
return true;
|
|
}
|
|
public void SetPosition(int x, int y){
|
|
if (x < 0 || x + _shipWidth > _pictureWidth){
|
|
x = 20;
|
|
}
|
|
if (y < 0 || y + _shipHeight > _pictureHeight){
|
|
y = 20;
|
|
}
|
|
_startPosX = x;
|
|
_startPosY = y;
|
|
}
|
|
public void MoveTransport(DirectionType direction){
|
|
if (entityWarmlyShip == null){
|
|
return;
|
|
}
|
|
switch (direction){
|
|
case Left:
|
|
System.out.println(_startPosX + " " + entityWarmlyShip.GetStep() + " " + _shipWidth + " " + (_startPosX + entityWarmlyShip.GetStep() + _shipWidth) + " " + _pictureWidth);
|
|
if (_startPosX - entityWarmlyShip.GetStep() > 0){
|
|
_startPosX -= (int)entityWarmlyShip.GetStep();
|
|
}
|
|
break;
|
|
case Up:
|
|
System.out.println(_startPosY + " " + entityWarmlyShip.GetStep() + " " + (_startPosY + entityWarmlyShip.GetStep()) + " " + _pictureHeight);
|
|
if (_startPosY - entityWarmlyShip.GetStep() > 0){
|
|
_startPosY -= (int)entityWarmlyShip.GetStep();
|
|
}
|
|
break;
|
|
case Right:
|
|
System.out.println(_startPosX + " " + entityWarmlyShip.GetStep() + " " + _shipWidth + " " + (_startPosX + entityWarmlyShip.GetStep() + _shipWidth) + " " + _pictureWidth);
|
|
if (_startPosX + entityWarmlyShip.GetStep() + _shipWidth < _pictureWidth){
|
|
_startPosX += (int)entityWarmlyShip.GetStep();
|
|
}
|
|
break;
|
|
case Down:
|
|
System.out.println(_startPosY + " " + entityWarmlyShip.GetStep() + " " + (_startPosY + entityWarmlyShip.GetStep()) + " " + _pictureHeight);
|
|
if (_startPosY + entityWarmlyShip.GetStep() + _shipHeight < _pictureHeight){
|
|
_startPosY += (int)entityWarmlyShip.GetStep();
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
public void DrawTransport(Graphics g){
|
|
if (entityWarmlyShip == null || drawingDecks == null){
|
|
System.out.println("?????????");
|
|
return;
|
|
}
|
|
if (entityWarmlyShip.GetPipes()){
|
|
g.setColor(entityWarmlyShip.GetOptionalColor());
|
|
g.fillRect(_startPosX + 70, _startPosY, 10, 30);
|
|
g.fillRect(_startPosX + 50, _startPosY + 10, 10, 20);
|
|
g.setColor(Color.black);
|
|
g.drawRect(_startPosX + 50, _startPosY + 10, 10, 20);
|
|
g.drawRect(_startPosX + 70, _startPosY, 10, 30);
|
|
}
|
|
if (entityWarmlyShip.GetFuelCompartment())
|
|
{
|
|
g.setColor(entityWarmlyShip.GetOptionalColor());
|
|
g.fillRect(_startPosX + 10, _startPosY + 30, 10, 10);
|
|
g.setColor(Color.black);
|
|
g.drawRect(_startPosX + 10, _startPosY + 30, 10, 10);
|
|
}
|
|
//палуба
|
|
drawingDecks.DrawingDecks(_startPosX, _startPosY, entityWarmlyShip.GetMainColor(), g);
|
|
//корпус
|
|
int[] xPoints = {_startPosX, _startPosX + 100, _startPosX + 90, _startPosX + 20, _startPosX};
|
|
int[] yPoints = {_startPosY + 40, _startPosY + 40, _startPosY + 60, _startPosY + 60, _startPosY + 40};
|
|
int nPoints = 5;
|
|
g.setColor(entityWarmlyShip.GetMainColor());
|
|
g.fillPolygon(xPoints, yPoints, nPoints);
|
|
g.setColor(Color.black);
|
|
g.drawPolygon(xPoints, yPoints, nPoints);
|
|
//якорь
|
|
g.drawLine(_startPosX + 25, _startPosY + 45, _startPosX + 25, _startPosY + 55);
|
|
g.drawLine(_startPosX + 20, _startPosY + 50, _startPosX + 30, _startPosY + 50);
|
|
g.drawLine(_startPosX + 23, _startPosY + 55, _startPosX + 27, _startPosY + 55);
|
|
}
|
|
|
|
}
|