import java.awt.*; public class DrawingAir { protected EntityAir entityAir; protected void setEntityAir(EntityAir entityAir){this.entityAir = entityAir;} public EntityAir getEntityAir() { 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 DrawingEnginesOval(); break; case 2: drawingEngines = new DrawingEnginesRound(); break; default: drawingEngines = new DrawingEnginesSquare(); break; } drawingEngines.setNumber(enginesNumber); } public IMoveableObject GetMoveableObject() {return new DrawingObjectPlane(this);} public void setPosition(int x, int y) { if (x < 0 || y < 0 || x + _PlaneWidth > _pictureWidth || y + _PlaneHeight > _pictureHeight) x = y = 0; _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 < _pictureHeight; default: return false; } } public void moveTransport(DirectionType direction) { if (!canMove(direction) || entityAir == null) return; switch (direction) { //влево case LEFT: _startPosX -= entityAir.step.get().intValue(); break; //вверх case UP: _startPosY -= entityAir.step.get().intValue(); break; // вправо case RIGHT: _startPosX += entityAir.step.get().intValue(); break; //вниз case DOWN: _startPosY += entityAir.step.get().intValue(); break; } } }