145 lines
5.3 KiB
Java
145 lines
5.3 KiB
Java
|
import java.awt.*;
|
||
|
|
||
|
public class DrawingAir {
|
||
|
protected EntityAir entityAir;
|
||
|
protected void setEntityPlane(EntityAir entityPlane){
|
||
|
this.entityAir = entityAir;
|
||
|
}
|
||
|
public EntityAir getEntityPlane() {
|
||
|
return entityAir;
|
||
|
}
|
||
|
private IDrawEngines drawingEngines;
|
||
|
private int _pictureWidth;
|
||
|
private int _pictureHeight;
|
||
|
protected int _startPosX;
|
||
|
public int getPosX(){
|
||
|
return _startPosX;
|
||
|
}
|
||
|
protected int _startPosY;
|
||
|
public int getPosY(){
|
||
|
return _startPosY;
|
||
|
}
|
||
|
private final int _PlaneWidth = 160;
|
||
|
public int getWidth() {
|
||
|
return _PlaneWidth;
|
||
|
}
|
||
|
private final int _PlaneHeight = 160;
|
||
|
public int getHeight(){
|
||
|
return _PlaneHeight;
|
||
|
}
|
||
|
public DrawingAir(int speed, double weight, Color bodyColor, int width, int height, int enginesType, int enginesNumber) {
|
||
|
if (width < _PlaneWidth || height < _PlaneHeight)
|
||
|
return;
|
||
|
_pictureWidth = width;
|
||
|
_pictureHeight = height;
|
||
|
entityAir = new EntityAir(speed, weight, bodyColor);
|
||
|
switch (enginesType){
|
||
|
case 1:
|
||
|
drawingEngines = new DrawingEnginesSquare();
|
||
|
break;
|
||
|
case 2:
|
||
|
drawingEngines = new DrawingEnginesRound();
|
||
|
break;
|
||
|
default:
|
||
|
drawingEngines = new DrawingEnginesOval();
|
||
|
break;
|
||
|
}
|
||
|
drawingEngines.setNumber(enginesNumber);
|
||
|
}
|
||
|
public void setPosition(int x, int y)
|
||
|
{
|
||
|
if (x <= _pictureWidth - _PlaneWidth && x >= 0 && y <= _pictureHeight - _PlaneHeight && y >= 0)
|
||
|
x = y = 2;
|
||
|
_startPosX = x;
|
||
|
_startPosY = y;
|
||
|
}
|
||
|
public void drawTransport(Graphics2D g) {
|
||
|
if (entityAir == null)
|
||
|
return;
|
||
|
BasicStroke pen = new BasicStroke(2);
|
||
|
Color penColor = Color.BLACK;
|
||
|
Color bodyColor = entityAir.getBodyColor();
|
||
|
g.setStroke(pen);
|
||
|
g.setColor(bodyColor);
|
||
|
//фюзеляж
|
||
|
g.fillRect(_startPosX + 20, _startPosY + 70, 140, 20);
|
||
|
//кабина
|
||
|
int[] pointX = new int[]{_startPosX, _startPosX + 20, _startPosX + 20};
|
||
|
int[] pointY = new int[]{_startPosY + 80, _startPosY + 70, _startPosY + 90};
|
||
|
g.setColor(Color.BLACK);
|
||
|
g.fillPolygon(pointX, pointY, 3);
|
||
|
//границы самолета
|
||
|
g.setColor(penColor);
|
||
|
g.drawPolygon(pointX, pointY, 3);
|
||
|
g.drawRect(_startPosX + 20, _startPosY + 70, 140, 20);
|
||
|
//Крылья
|
||
|
pointX = new int[]{_startPosX + 70, _startPosX + 70, _startPosX + 90, _startPosX + 100};
|
||
|
pointY = new int[]{_startPosY + 70, _startPosY, _startPosY, _startPosY + 70};
|
||
|
g.setColor(bodyColor);
|
||
|
g.fillPolygon(pointX, pointY, 4);
|
||
|
g.setColor(penColor);
|
||
|
g.drawPolygon(pointX, pointY, 4);
|
||
|
pointX = new int[]{_startPosX + 70, _startPosX + 70, _startPosX + 90, _startPosX + 100};
|
||
|
pointY = new int[]{_startPosY + 90, _startPosY + 160, _startPosY + 160, _startPosY + 90};
|
||
|
g.setColor(bodyColor);
|
||
|
g.fillPolygon(pointX, pointY, 4);
|
||
|
g.setColor(penColor);
|
||
|
g.drawPolygon(pointX, pointY, 4);
|
||
|
pointX = new int[]{_startPosX + 130, _startPosX + 130, _startPosX + 160, _startPosX + 160};
|
||
|
pointY = new int[]{_startPosY + 70, _startPosY + 50, _startPosY + 30, _startPosY + 70};
|
||
|
g.setColor(bodyColor);
|
||
|
g.fillPolygon(pointX, pointY, 4);
|
||
|
g.setColor(penColor);
|
||
|
g.drawPolygon(pointX, pointY, 4);
|
||
|
pointX = new int[]{_startPosX + 130, _startPosX + 130, _startPosX + 160, _startPosX + 160};
|
||
|
pointY = new int[]{_startPosY + 90, _startPosY + 110, _startPosY + 130, _startPosY + 90};
|
||
|
g.setColor(bodyColor);
|
||
|
g.fillPolygon(pointX, pointY, 4);
|
||
|
g.setColor(penColor);
|
||
|
g.drawPolygon(pointX, pointY, 4);
|
||
|
drawingEngines.drawEngines(g, _startPosX, _startPosY);
|
||
|
}
|
||
|
public boolean canMove(DirectionType direction) {
|
||
|
if (entityAir == null) {
|
||
|
return false;
|
||
|
}
|
||
|
switch(direction) {
|
||
|
case LEFT:
|
||
|
return _startPosX - entityAir.step.get().intValue() > 0;
|
||
|
case UP:
|
||
|
return _startPosY - entityAir.step.get().intValue() > 0;
|
||
|
case RIGHT:
|
||
|
return _startPosX + entityAir.step.get().intValue() + _PlaneWidth < _pictureWidth;
|
||
|
case DOWN:
|
||
|
return _startPosY + entityAir.step.get().intValue() + _PlaneWidth < _pictureWidth;
|
||
|
default:
|
||
|
return false;
|
||
|
}
|
||
|
}
|
||
|
public void moveTransport(DirectionType direction)
|
||
|
{
|
||
|
if (entityAir == null)
|
||
|
return;
|
||
|
int step = entityAir.step.get().intValue();
|
||
|
switch (direction)
|
||
|
{
|
||
|
case LEFT:
|
||
|
if (_startPosX - step > 0)
|
||
|
_startPosX -= step;
|
||
|
break;
|
||
|
case UP:
|
||
|
if (_startPosY - step > 0)
|
||
|
_startPosY -= step;
|
||
|
break;
|
||
|
case RIGHT:
|
||
|
if (_startPosX + _PlaneWidth + step < _pictureWidth)
|
||
|
_startPosX += step;
|
||
|
break;
|
||
|
case DOWN:
|
||
|
if (_startPosY + _PlaneHeight + step < _pictureHeight)
|
||
|
_startPosY += step;
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
}
|