From e7c253b1c77cd36887fb06463e7ef07a2c64acc2 Mon Sep 17 00:00:00 2001
From: abazov73 <92822431+abazov73@users.noreply.github.com>
Date: Sun, 30 Oct 2022 11:38:06 +0400
Subject: [PATCH] =?UTF-8?q?=D0=92=D1=82=D0=BE=D1=80=D0=B0=D1=8F=20=D0=BB?=
=?UTF-8?q?=D0=B0=D0=B1=D0=BE=D1=80=D0=B0=D1=82=D0=BE=D1=80=D0=BD=D0=B0?=
=?UTF-8?q?=D1=8F=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D0=B0.?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../src/AirBomberPackage/AbstractMap.java | 120 +++++
AirBomber/src/AirBomberPackage/CityMap.java | 82 +++
AirBomber/src/AirBomberPackage/Direction.java | 33 +-
.../AirBomberPackage/DrawingAirBomber.java | 484 ++++++++++--------
.../src/AirBomberPackage/DrawingEngines.java | 122 ++---
.../AirBomberPackage/DrawingEnginesOval.java | 64 +++
.../DrawingEnginesTriangle.java | 74 +++
.../DrawingHeavyAirBomber.java | 68 +++
.../DrawingObjectAirBomber.java | 56 ++
.../src/AirBomberPackage/EnginesType.java | 15 +
.../src/AirBomberPackage/EntityAirBomber.java | 84 ++-
.../EntityHeavyAirBomber.java | 63 +++
.../src/AirBomberPackage/IDrawingObject.java | 40 ++
.../AirBomberPackage/IDrawingObjectDop.java | 18 +
.../src/AirBomberPackage/JFrameAirBomber.form | 56 +-
.../src/AirBomberPackage/JFrameAirBomber.java | 94 +++-
AirBomber/src/AirBomberPackage/JFrameMap.form | 289 +++++++++++
AirBomber/src/AirBomberPackage/JFrameMap.java | 337 ++++++++++++
AirBomber/src/AirBomberPackage/LineMap.java | 103 ++++
AirBomber/src/AirBomberPackage/SimpleMap.java | 60 +++
20 files changed, 1901 insertions(+), 361 deletions(-)
create mode 100644 AirBomber/src/AirBomberPackage/AbstractMap.java
create mode 100644 AirBomber/src/AirBomberPackage/CityMap.java
create mode 100644 AirBomber/src/AirBomberPackage/DrawingEnginesOval.java
create mode 100644 AirBomber/src/AirBomberPackage/DrawingEnginesTriangle.java
create mode 100644 AirBomber/src/AirBomberPackage/DrawingHeavyAirBomber.java
create mode 100644 AirBomber/src/AirBomberPackage/DrawingObjectAirBomber.java
create mode 100644 AirBomber/src/AirBomberPackage/EnginesType.java
create mode 100644 AirBomber/src/AirBomberPackage/EntityHeavyAirBomber.java
create mode 100644 AirBomber/src/AirBomberPackage/IDrawingObject.java
create mode 100644 AirBomber/src/AirBomberPackage/IDrawingObjectDop.java
create mode 100644 AirBomber/src/AirBomberPackage/JFrameMap.form
create mode 100644 AirBomber/src/AirBomberPackage/JFrameMap.java
create mode 100644 AirBomber/src/AirBomberPackage/LineMap.java
create mode 100644 AirBomber/src/AirBomberPackage/SimpleMap.java
diff --git a/AirBomber/src/AirBomberPackage/AbstractMap.java b/AirBomber/src/AirBomberPackage/AbstractMap.java
new file mode 100644
index 0000000..8115f7c
--- /dev/null
+++ b/AirBomber/src/AirBomberPackage/AbstractMap.java
@@ -0,0 +1,120 @@
+/*
+ * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
+ * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
+ */
+package AirBomberPackage;
+import java.util.Random;
+import java.awt.*;
+import java.awt.image.BufferedImage;
+/**
+ *
+ * @author Андрей
+ */
+public abstract class AbstractMap {
+ private IDrawingObject _drawningObject = null;
+ protected int[][] _map = null;
+ protected int _width;
+ protected int _height;
+ protected int _size_x;
+ protected int _size_y;
+ protected final Random _random = new Random();
+ protected final int _freeRoad = 0;
+ protected final int _barrier = 1;
+
+ public BufferedImage CreateMap(int width, int height, IDrawingObject drawningObject)
+ {
+ _width = width;
+ _height = height;
+ _drawningObject = drawningObject;
+ GenerateMap();
+ while (!SetObjectOnMap())
+ {
+ GenerateMap();
+ }
+ return DrawMapWithObject();
+ }
+ public BufferedImage MoveObject(Direction direction)
+ {
+ if (_drawningObject == null) return DrawMapWithObject();
+ boolean canMove = true;
+ switch (direction)
+ {
+ case LEFT:
+ if (!checkForBarriers(0, -1 * _drawningObject.getStep(), -1 * _drawningObject.getStep(), 0)) canMove = false;
+ break;
+ case RIGHT:
+ if (!checkForBarriers(0, _drawningObject.getStep(), _drawningObject.getStep(), 0)) canMove = false;
+ break;
+ case UP:
+ if (!checkForBarriers(-1 * _drawningObject.getStep(), 0, 0, -1 * _drawningObject.getStep())) canMove = false;
+ break;
+ case DOWN:
+ if (!checkForBarriers(_drawningObject.getStep(), 0, 0, _drawningObject.getStep())) canMove = false;
+ break;
+ }
+ if (canMove)
+ {
+ _drawningObject.MoveObject(direction);
+ }
+ return DrawMapWithObject();
+ }
+ private boolean SetObjectOnMap()
+ {
+ if (_drawningObject == null || _map == null)
+ {
+ return false;
+ }
+ int x = _random.nextInt(0, 10);
+ int y = _random.nextInt(0, 10);
+ _drawningObject.SetObject(x, y, _width, _height);
+ if (!checkForBarriers(0,0,0,0)) return false;
+ return true;
+ }
+ private BufferedImage DrawMapWithObject()
+ {
+ BufferedImage bmp = new BufferedImage(_width, _height, BufferedImage.TYPE_INT_ARGB);
+ if (_drawningObject == null || _map == null)
+ {
+ return bmp;
+ }
+ Graphics2D gr = bmp.createGraphics();
+ for (int i = 0; i < _map.length; ++i)
+ {
+ for (int j = 0; j < _map[i].length; ++j)
+ {
+ if (_map[i][j] == _freeRoad)
+ {
+ DrawRoadPart(gr, i, j);
+ }
+ else if (_map[i][j] == _barrier)
+ {
+ DrawBarrierPart(gr, i, j);
+ }
+ }
+ }
+ _drawningObject.DrawingObject(gr);
+ return bmp;
+ }
+
+ private boolean checkForBarriers(float topOffset, float rightOffset, float leftOffset, float bottomOffset)
+ {
+ float[] position = _drawningObject.GetCurrentPosition();
+ int top = (int)((position[1] + topOffset) / _size_y);
+ int right = (int)((position[2] + rightOffset) / _size_x);
+ int left = (int)((position[0] + leftOffset) / _size_x);
+ int bottom = (int)((position[3] + bottomOffset) / _size_y);
+ if (top < 0 || left < 0 || right >= _map[0].length || bottom >= _map.length) return false;
+ for (int i = top; i <= bottom; i++)
+ {
+ for (int j = left; j <= right; j++)
+ {
+ if (_map[j][i] == 1) return false;
+ }
+ }
+ return true;
+ }
+
+ protected abstract void GenerateMap();
+ protected abstract void DrawRoadPart(Graphics g, int i, int j);
+ protected abstract void DrawBarrierPart(Graphics g, int i, int j);
+}
diff --git a/AirBomber/src/AirBomberPackage/CityMap.java b/AirBomber/src/AirBomberPackage/CityMap.java
new file mode 100644
index 0000000..383f4a6
--- /dev/null
+++ b/AirBomber/src/AirBomberPackage/CityMap.java
@@ -0,0 +1,82 @@
+/*
+ * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
+ * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
+ */
+package AirBomberPackage;
+import java.awt.*;
+/**
+ *
+ * @author Андрей
+ */
+public class CityMap extends AbstractMap {
+ ///
+ /// Цвет участка закрытого
+ ///
+ private final Color barrierColor = Color.GRAY;
+ ///
+ /// Цвет участка открытого
+ ///
+ private final Color roadColor = Color.CYAN;
+ @Override
+ protected void DrawBarrierPart(Graphics g, int i, int j)
+ {
+ g.setColor(barrierColor);
+ g.fillRect(i * _size_x, j * _size_y, _size_x, _size_y);
+ g.setColor(Color.BLACK);
+ }
+ @Override
+ protected void DrawRoadPart(Graphics g, int i, int j)
+ {
+ g.setColor(roadColor);
+ g.fillRect(i * _size_x, j * _size_y, _size_x, _size_y);
+ g.setColor(Color.BLACK);
+ }
+ @Override
+ protected void GenerateMap()
+ {
+ _map = new int[100][100];
+ _size_x = _width / _map.length;
+ _size_y = _height / _map[0].length;
+ int buildingCounter = 0;
+ for (int i = 0; i < _map.length; ++i)
+ {
+ for (int j = 0; j < _map[0].length; ++j)
+ {
+ _map[i][j] = _freeRoad;
+ }
+ }
+ while (buildingCounter < 10)
+ {
+ int x = _random.nextInt(0, 89);
+ int y = _random.nextInt(0, 89);
+ int buildingWidth = _random.nextInt(2, 10);
+ int buildingHeight = _random.nextInt(2, 10);
+ if (x + buildingWidth >= _map.length) x = _random.nextInt(_map.length - buildingWidth - 1, _map.length);
+ if (y + buildingHeight >= _map[0].length) y = _random.nextInt(_map[0].length - buildingHeight - 1, _map[0].length);
+
+ boolean isFreeSpace = true;
+ for (int i = x; i < x + buildingWidth; i++)
+ {
+ for (int j = y; j < y + buildingHeight; j++)
+ {
+ if (_map[i][j] != _freeRoad)
+ {
+ isFreeSpace = false;
+ break;
+ }
+ }
+ }
+ if (isFreeSpace)
+ {
+ for (int i = x; i < x + buildingWidth; i++)
+ {
+ for (int j = y; j < y + buildingHeight; j++)
+ {
+ _map[i][j] = _barrier;
+ }
+ }
+ buildingCounter++;
+ }
+ }
+ }
+}
diff --git a/AirBomber/src/AirBomberPackage/Direction.java b/AirBomber/src/AirBomberPackage/Direction.java
index 7c7d402..a00fa54 100644
--- a/AirBomber/src/AirBomberPackage/Direction.java
+++ b/AirBomber/src/AirBomberPackage/Direction.java
@@ -1,16 +1,17 @@
-/*
- * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
- * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
- */
-package AirBomberPackage;
-
-/**
- *
- * @author Андрей
- */
-public enum Direction {
- UP,
- DOWN,
- LEFT,
- RIGHT
-}
+/*
+ * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
+ * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
+ */
+package AirBomberPackage;
+
+/**
+ *
+ * @author Андрей
+ */
+public enum Direction {
+ NONE,
+ UP,
+ DOWN,
+ LEFT,
+ RIGHT
+}
diff --git a/AirBomber/src/AirBomberPackage/DrawingAirBomber.java b/AirBomber/src/AirBomberPackage/DrawingAirBomber.java
index 7720f00..accd288 100644
--- a/AirBomber/src/AirBomberPackage/DrawingAirBomber.java
+++ b/AirBomber/src/AirBomberPackage/DrawingAirBomber.java
@@ -1,224 +1,260 @@
-/*
- * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
- * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
- */
-package AirBomberPackage;
-import java.awt.*;
-import java.util.Random;
-/**
- *
- * @author Андрей
- */
-public class DrawingAirBomber {
- private EntityAirBomber AirBomber;
- public DrawingEngines drawingEngines;
- public float _startPosX;
- public float _startPosY;
- private Integer _pictureWidth = null;
- private Integer _pictureHeight = null;
- private static final int _airBomberWidth = 110;
- private static final int _airBomberHeight = 100;
-
- public void Init(int speed, float weight, Color bodyColor, int numberOfEngines){
- AirBomber = new EntityAirBomber();
- drawingEngines = new DrawingEngines();
- AirBomber.Init(speed, weight, bodyColor);
- System.out.println(numberOfEngines + "");
- drawingEngines.setNumberOfEngines(numberOfEngines);
- }
-
- public EntityAirBomber getAirBomber() {
- return AirBomber;
- }
-
- public void SetPosition(int x, int y, int width, int height){
- _pictureWidth = width;
- _pictureHeight = height;
- if (_pictureWidth == null || _pictureHeight == null)
- {
- return;
- }
- Random rd = new Random();
- _startPosX = x + _airBomberWidth >= _pictureWidth ? rd.nextInt(0, _pictureWidth - 1 - _airBomberWidth) : x;
- _startPosY = y + _airBomberHeight >= _pictureHeight ? rd.nextInt(0, _pictureHeight - 1 - _airBomberHeight) : y;
- }
-
- public void MoveTransport(Direction direction)
- {
- if (_pictureWidth == null || _pictureHeight == null)
- {
- return;
- }
- switch (direction)
- {
- // вправо
- case RIGHT:
- if (_startPosX + _airBomberWidth + AirBomber.Step < _pictureWidth)
- {
- _startPosX += AirBomber.Step;
- }
- break;
- //влево
- case LEFT:
- if (_startPosX - AirBomber.Step > 0)
- {
- _startPosX -= AirBomber.Step;
- }
- break;
- //вверх
- case UP:
- if (_startPosY - AirBomber.Step > 0)
- {
- _startPosY -= AirBomber.Step;
- }
- break;
- //вниз
- case DOWN:
- if (_startPosY + _airBomberHeight + AirBomber.Step < _pictureHeight)
- {
- _startPosY += AirBomber.Step;
- }
- break;
- }
- }
-
- public void DrawTransport(Graphics2D g)
- {
- if (_startPosX < 0 || _startPosY < 0
- || _pictureHeight == null || _pictureWidth == null)
- {
- return;
- }
-
- int _startPosXInt = (int)_startPosX;
- int _startPosYInt = (int)_startPosY;
-
- //отрисовка двигателей
- drawingEngines.drawEngines(g, _startPosXInt, _startPosYInt, AirBomber.getBodyColor());
-
- //отрисовка кабины
- int[] cabinX =
- {
- _startPosXInt + 5,
- _startPosXInt + 20,
- _startPosXInt + 20
- };
-
- int[] cabinY =
- {
- _startPosYInt + 50,
- _startPosYInt + 40,
- _startPosYInt + 60
- };
-
- g.fillPolygon(cabinX, cabinY, cabinX.length);
- g.setColor(AirBomber.getBodyColor());
- //отрисовка корпуса
- g.fillRect(_startPosXInt + 20, _startPosYInt + 40, 90, 20);
-
- //отрисовка правого крыла
- int[] rightWingX =
- {
- _startPosXInt + 50,
- _startPosXInt + 50,
- _startPosXInt + 60,
- _startPosXInt + 70
- };
-
- int[] rightWingY =
- {
- _startPosYInt + 40,
- _startPosYInt,
- _startPosYInt,
- _startPosYInt + 40
- };
-
- g.fillPolygon(rightWingX, rightWingY, rightWingX.length);
-
- //отрисовка левого крыла
- int[] leftWingX =
- {
- _startPosXInt + 50,
- _startPosXInt + 50,
- _startPosXInt + 60,
- _startPosXInt + 70
- };
-
- int[] leftWingY =
- {
- _startPosYInt + 60,
- _startPosYInt + 100,
- _startPosYInt + 100,
- _startPosYInt + 60
- };
-
- g.fillPolygon(leftWingX, leftWingY, leftWingX.length);
-
- //отрисовка хвоста (справа)
- int[] rightTailX =
- {
- _startPosXInt + 95,
- _startPosXInt + 95,
- _startPosXInt + 110,
- _startPosXInt + 110
- };
-
- int[] rightTailY =
- {
- _startPosYInt + 40,
- _startPosYInt + 30,
- _startPosYInt + 15,
- _startPosYInt + 40
- };
-
- g.fillPolygon(rightTailX, rightTailY, rightTailX.length);
-
- //отрисовка хвоста (слева)
- int[] leftTailX =
- {
- _startPosXInt + 95,
- _startPosXInt + 95,
- _startPosXInt + 110,
- _startPosXInt + 110
- };
-
- int[] leftTailY =
- {
- _startPosYInt + 60,
- _startPosYInt + 70,
- _startPosYInt + 85,
- _startPosYInt + 60
- };
-
- g.fillPolygon(leftTailX, leftTailY, leftTailX.length);
-
- g.setColor(Color.BLACK);
-
- g.drawRect(_startPosXInt + 20, _startPosYInt + 40, 90, 20);
- g.drawPolygon(rightWingX, rightWingY, rightWingX.length);
- g.drawPolygon(leftWingX, leftWingY, leftWingX.length);
- g.drawPolygon(rightTailX, rightTailY, rightTailX.length);
- g.drawPolygon(leftTailX, leftTailY, leftTailX.length);
- g.drawLine(_startPosXInt, _startPosYInt + 50, _startPosXInt + 5, _startPosYInt + 50);
- }
-
- public void ChangeBorders(int width, int height)
- {
- _pictureWidth = width;
- _pictureHeight = height;
- if (_pictureWidth <= _airBomberWidth || _pictureHeight <= _airBomberHeight)
- {
- _pictureWidth = null;
- _pictureHeight = null;
- return;
- }
- if (_startPosX + _airBomberWidth > _pictureWidth)
- {
- _startPosX = _pictureWidth - _airBomberWidth;
- }
- if (_startPosY + _airBomberHeight > _pictureHeight)
- {
- _startPosY = _pictureHeight - _airBomberHeight;
- }
- }
-}
+/*
+ * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
+ * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
+ */
+package AirBomberPackage;
+import java.awt.*;
+import java.util.Random;
+/**
+ *
+ * @author Андрей
+ */
+public class DrawingAirBomber {
+ protected EntityAirBomber AirBomber;
+ public IDrawingObjectDop drawingEngines;
+ public int _startPosX;
+ public int _startPosY;
+ private Integer _pictureWidth = null;
+ private Integer _pictureHeight = null;
+ private int _airBomberWidth = 110;
+ private int _airBomberHeight = 100;
+
+ public DrawingAirBomber(int speed, float weight, Color bodyColor, int numberOfEngines, EnginesType enginesType){
+ AirBomber = new EntityAirBomber(speed, weight, bodyColor);
+ switch (enginesType) {
+ case RECTANGLE:
+ drawingEngines = new DrawingEngines();
+ break;
+ case TRIANGLE:
+ drawingEngines = new DrawingEnginesTriangle();
+ break;
+ case OVAL:
+ drawingEngines = new DrawingEnginesOval();
+ break;
+ default:
+ throw new AssertionError();
+ }
+ drawingEngines.setNumberOfEngines(numberOfEngines);
+ }
+
+ ///
+ /// Инициализация свойств
+ ///
+ /// Скорость
+ /// Вес бомбардировщика
+ /// Цвет корпуса
+ /// Ширина отрисовки бомбардировщика
+ /// Высота отрисовки бомбардировщика
+ protected DrawingAirBomber(int speed, float weight, Color bodyColor, int numberOfEngines, EnginesType enginesType, int airBomberWidth, int airBomberHeight)
+ {
+ this(speed, weight, bodyColor, numberOfEngines, enginesType);
+ this._airBomberWidth = airBomberWidth;
+ this._airBomberHeight = airBomberHeight;
+ }
+
+
+ public EntityAirBomber getAirBomber() {
+ return AirBomber;
+ }
+
+ public void SetPosition(int x, int y, int width, int height){
+ _pictureWidth = width;
+ _pictureHeight = height;
+ if (_pictureWidth == null || _pictureHeight == null)
+ {
+ return;
+ }
+ Random rd = new Random();
+ _startPosX = x + _airBomberWidth >= _pictureWidth ? rd.nextInt(0, _pictureWidth - 1 - _airBomberWidth) : x;
+ _startPosY = y + _airBomberHeight >= _pictureHeight ? rd.nextInt(0, _pictureHeight - 1 - _airBomberHeight) : y;
+ }
+
+ public void MoveTransport(Direction direction)
+ {
+ if (_pictureWidth == null || _pictureHeight == null)
+ {
+ return;
+ }
+ switch (direction)
+ {
+ // вправо
+ case RIGHT:
+ if (_startPosX + _airBomberWidth + AirBomber.Step < _pictureWidth)
+ {
+ _startPosX += AirBomber.Step;
+ }
+ break;
+ //влево
+ case LEFT:
+ if (_startPosX - AirBomber.Step > 0)
+ {
+ _startPosX -= AirBomber.Step;
+ }
+ break;
+ //вверх
+ case UP:
+ if (_startPosY - AirBomber.Step > 0)
+ {
+ _startPosY -= AirBomber.Step;
+ }
+ break;
+ //вниз
+ case DOWN:
+ if (_startPosY + _airBomberHeight + AirBomber.Step < _pictureHeight)
+ {
+ _startPosY += AirBomber.Step;
+ }
+ break;
+ }
+ }
+
+ public void DrawTransport(Graphics2D g)
+ {
+ if (_startPosX < 0 || _startPosY < 0
+ || _pictureHeight == null || _pictureWidth == null)
+ {
+ return;
+ }
+
+ int _startPosXInt = (int)_startPosX;
+ int _startPosYInt = (int)_startPosY;
+
+ //отрисовка двигателей
+ drawingEngines.drawEngines(g, _startPosXInt, _startPosYInt, AirBomber.getBodyColor());
+
+ //отрисовка кабины
+ int[] cabinX =
+ {
+ _startPosXInt + 5,
+ _startPosXInt + 20,
+ _startPosXInt + 20
+ };
+
+ int[] cabinY =
+ {
+ _startPosYInt + 50,
+ _startPosYInt + 40,
+ _startPosYInt + 60
+ };
+
+ g.fillPolygon(cabinX, cabinY, cabinX.length);
+ g.setColor(AirBomber.getBodyColor());
+ //отрисовка корпуса
+ g.fillRect(_startPosXInt + 20, _startPosYInt + 40, 90, 20);
+
+ //отрисовка правого крыла
+ int[] rightWingX =
+ {
+ _startPosXInt + 50,
+ _startPosXInt + 50,
+ _startPosXInt + 60,
+ _startPosXInt + 70
+ };
+
+ int[] rightWingY =
+ {
+ _startPosYInt + 40,
+ _startPosYInt,
+ _startPosYInt,
+ _startPosYInt + 40
+ };
+
+ g.fillPolygon(rightWingX, rightWingY, rightWingX.length);
+
+ //отрисовка левого крыла
+ int[] leftWingX =
+ {
+ _startPosXInt + 50,
+ _startPosXInt + 50,
+ _startPosXInt + 60,
+ _startPosXInt + 70
+ };
+
+ int[] leftWingY =
+ {
+ _startPosYInt + 60,
+ _startPosYInt + 100,
+ _startPosYInt + 100,
+ _startPosYInt + 60
+ };
+
+ g.fillPolygon(leftWingX, leftWingY, leftWingX.length);
+
+ //отрисовка хвоста (справа)
+ int[] rightTailX =
+ {
+ _startPosXInt + 95,
+ _startPosXInt + 95,
+ _startPosXInt + 110,
+ _startPosXInt + 110
+ };
+
+ int[] rightTailY =
+ {
+ _startPosYInt + 40,
+ _startPosYInt + 30,
+ _startPosYInt + 15,
+ _startPosYInt + 40
+ };
+
+ g.fillPolygon(rightTailX, rightTailY, rightTailX.length);
+
+ //отрисовка хвоста (слева)
+ int[] leftTailX =
+ {
+ _startPosXInt + 95,
+ _startPosXInt + 95,
+ _startPosXInt + 110,
+ _startPosXInt + 110
+ };
+
+ int[] leftTailY =
+ {
+ _startPosYInt + 60,
+ _startPosYInt + 70,
+ _startPosYInt + 85,
+ _startPosYInt + 60
+ };
+
+ g.fillPolygon(leftTailX, leftTailY, leftTailX.length);
+
+ g.setColor(Color.BLACK);
+
+ g.drawRect(_startPosXInt + 20, _startPosYInt + 40, 90, 20);
+ g.drawPolygon(rightWingX, rightWingY, rightWingX.length);
+ g.drawPolygon(leftWingX, leftWingY, leftWingX.length);
+ g.drawPolygon(rightTailX, rightTailY, rightTailX.length);
+ g.drawPolygon(leftTailX, leftTailY, leftTailX.length);
+ g.drawLine(_startPosXInt, _startPosYInt + 50, _startPosXInt + 5, _startPosYInt + 50);
+ }
+
+ public float [] GetCurrentPosition()
+ {
+ float[] pos = new float[4];
+ pos[0] = _startPosX;
+ pos[1] = _startPosY;
+ pos[2] = _startPosX + _airBomberWidth;
+ pos[3] = _startPosY + _airBomberHeight;
+ return pos;
+ }
+
+ public void ChangeBorders(int width, int height)
+ {
+ _pictureWidth = width;
+ _pictureHeight = height;
+ if (_pictureWidth <= _airBomberWidth || _pictureHeight <= _airBomberHeight)
+ {
+ _pictureWidth = null;
+ _pictureHeight = null;
+ return;
+ }
+ if (_startPosX + _airBomberWidth > _pictureWidth)
+ {
+ _startPosX = _pictureWidth - _airBomberWidth;
+ }
+ if (_startPosY + _airBomberHeight > _pictureHeight)
+ {
+ _startPosY = _pictureHeight - _airBomberHeight;
+ }
+ }
+}
diff --git a/AirBomber/src/AirBomberPackage/DrawingEngines.java b/AirBomber/src/AirBomberPackage/DrawingEngines.java
index 53e529f..6961bff 100644
--- a/AirBomber/src/AirBomberPackage/DrawingEngines.java
+++ b/AirBomber/src/AirBomberPackage/DrawingEngines.java
@@ -1,61 +1,61 @@
-/*
- * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
- * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
- */
-package AirBomberPackage;
-
-import java.awt.Graphics2D;
-import java.awt.Color;
-
-/**
- *
- * @author Андрей
- */
-public class DrawingEngines {
- private Engines engines = null;
- private int numberOfEngines;
-
- public int getNumberOfEngines() {
- return numberOfEngines;
- }
-
- public void setNumberOfEngines(int numberOfEngines) {
- if (numberOfEngines != 2 && numberOfEngines != 4 && numberOfEngines != 6) return;
- this.numberOfEngines = numberOfEngines;
- switch (this.numberOfEngines) {
- case 2:
- engines = Engines.TWO;
- break;
- case 4:
- engines = Engines.FOUR;
- break;
- case 6:
- engines = Engines.SIX;
- break;
- }
- }
-
- private void drawEngine(Graphics2D g, int startPosX, int startPosY, int yOffset, Color bodyColor){
- g.setColor(bodyColor);
- g.fillRect(startPosX + 45, startPosY + 40 + yOffset, 5, 5);
- g.setColor(Color.BLACK);
- g.drawRect(startPosX + 45, startPosY + 40 + yOffset, 5, 5);
- }
-
- public void drawEngines(Graphics2D g, int startPosX, int startPosY, Color bodyColor){
- if (engines == null) return;
-
- switch (engines) {
- case SIX:
- drawEngine(g, startPosX, startPosY, -5 - 5 - 20, bodyColor);
- drawEngine(g, startPosX, startPosY, 20 + 5 + 20, bodyColor);
- case FOUR:
- drawEngine(g, startPosX, startPosY, -5 - 5 - 10, bodyColor);
- drawEngine(g, startPosX, startPosY, 20 + 5 + 10, bodyColor);
- case TWO:
- drawEngine(g, startPosX, startPosY, -5 - 5, bodyColor);
- drawEngine(g, startPosX, startPosY, 20 + 5, bodyColor);
- break;
- }
- }
-}
+/*
+ * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
+ * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
+ */
+package AirBomberPackage;
+
+import java.awt.Graphics2D;
+import java.awt.Color;
+
+/**
+ *
+ * @author Андрей
+ */
+public class DrawingEngines implements IDrawingObjectDop {
+ private Engines engines = null;
+ private int numberOfEngines;
+ @Override
+ public int getNumberOfEngines() {
+ return numberOfEngines;
+ }
+ @Override
+ public void setNumberOfEngines(int numberOfEngines) {
+ if (numberOfEngines != 2 && numberOfEngines != 4 && numberOfEngines != 6) return;
+ this.numberOfEngines = numberOfEngines;
+ switch (this.numberOfEngines) {
+ case 2:
+ engines = Engines.TWO;
+ break;
+ case 4:
+ engines = Engines.FOUR;
+ break;
+ case 6:
+ engines = Engines.SIX;
+ break;
+ }
+ }
+ @Override
+ public void drawEngine(Graphics2D g, int startPosX, int startPosY, int yOffset, Color bodyColor){
+ g.setColor(bodyColor);
+ g.fillRect(startPosX + 45, startPosY + 40 + yOffset, 5, 5);
+ g.setColor(Color.BLACK);
+ g.drawRect(startPosX + 45, startPosY + 40 + yOffset, 5, 5);
+ }
+ @Override
+ public void drawEngines(Graphics2D g, int startPosX, int startPosY, Color bodyColor){
+ if (engines == null) return;
+
+ switch (engines) {
+ case SIX:
+ drawEngine(g, startPosX, startPosY, -5 - 5 - 20, bodyColor);
+ drawEngine(g, startPosX, startPosY, 20 + 5 + 20, bodyColor);
+ case FOUR:
+ drawEngine(g, startPosX, startPosY, -5 - 5 - 10, bodyColor);
+ drawEngine(g, startPosX, startPosY, 20 + 5 + 10, bodyColor);
+ case TWO:
+ drawEngine(g, startPosX, startPosY, -5 - 5, bodyColor);
+ drawEngine(g, startPosX, startPosY, 20 + 5, bodyColor);
+ break;
+ }
+ }
+}
diff --git a/AirBomber/src/AirBomberPackage/DrawingEnginesOval.java b/AirBomber/src/AirBomberPackage/DrawingEnginesOval.java
new file mode 100644
index 0000000..2f25b7a
--- /dev/null
+++ b/AirBomber/src/AirBomberPackage/DrawingEnginesOval.java
@@ -0,0 +1,64 @@
+/*
+ * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
+ * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
+ */
+package AirBomberPackage;
+
+import java.awt.*;
+
+/**
+ *
+ * @author Андрей
+ */
+public class DrawingEnginesOval implements IDrawingObjectDop {
+ private Engines engines = null;
+ private int numberOfEngines;
+ @Override
+ public int getNumberOfEngines() {
+ return numberOfEngines;
+ }
+
+ @Override
+ public void setNumberOfEngines(int numberOfEngines) {
+ if (numberOfEngines != 2 && numberOfEngines != 4 && numberOfEngines != 6) return;
+ this.numberOfEngines = numberOfEngines;
+ switch (this.numberOfEngines) {
+ case 2:
+ engines = Engines.TWO;
+ break;
+ case 4:
+ engines = Engines.FOUR;
+ break;
+ case 6:
+ engines = Engines.SIX;
+ break;
+ }
+ }
+
+ @Override
+ public void drawEngine(Graphics2D g, int startPosX, int startPosY, int yOffset, Color bodyColor) {
+ g.setColor(bodyColor);
+ g.fillOval(startPosX + 45, startPosY + 40 + yOffset, 5, 5);
+ g.setColor(Color.BLACK);
+ g.drawOval(startPosX + 45, startPosY + 40 + yOffset, 5, 5);
+ }
+
+ @Override
+ public void drawEngines(Graphics2D g, int startPosX, int startPosY, Color bodyColor) {
+ if (engines == null) return;
+
+ switch (engines) {
+ case SIX:
+ drawEngine(g, startPosX, startPosY, -5 - 5 - 20, bodyColor);
+ drawEngine(g, startPosX, startPosY, 20 + 5 + 20, bodyColor);
+ case FOUR:
+ drawEngine(g, startPosX, startPosY, -5 - 5 - 10, bodyColor);
+ drawEngine(g, startPosX, startPosY, 20 + 5 + 10, bodyColor);
+ case TWO:
+ drawEngine(g, startPosX, startPosY, -5 - 5, bodyColor);
+ drawEngine(g, startPosX, startPosY, 20 + 5, bodyColor);
+ break;
+ }
+ }
+
+}
diff --git a/AirBomber/src/AirBomberPackage/DrawingEnginesTriangle.java b/AirBomber/src/AirBomberPackage/DrawingEnginesTriangle.java
new file mode 100644
index 0000000..60b199b
--- /dev/null
+++ b/AirBomber/src/AirBomberPackage/DrawingEnginesTriangle.java
@@ -0,0 +1,74 @@
+/*
+ * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
+ * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
+ */
+package AirBomberPackage;
+
+import java.awt.Color;
+import java.awt.Graphics2D;
+
+/**
+ *
+ * @author Андрей
+ */
+public class DrawingEnginesTriangle implements IDrawingObjectDop {
+ private Engines engines = null;
+ private int numberOfEngines;
+ @Override
+ public int getNumberOfEngines() {
+ return numberOfEngines;
+ }
+
+ @Override
+ public void setNumberOfEngines(int numberOfEngines) {
+ if (numberOfEngines != 2 && numberOfEngines != 4 && numberOfEngines != 6) return;
+ this.numberOfEngines = numberOfEngines;
+ switch (this.numberOfEngines) {
+ case 2:
+ engines = Engines.TWO;
+ break;
+ case 4:
+ engines = Engines.FOUR;
+ break;
+ case 6:
+ engines = Engines.SIX;
+ break;
+ }
+ }
+
+ @Override
+ public void drawEngine(Graphics2D g, int startPosX, int startPosY, int yOffset, Color bodyColor) {
+ g.setColor(bodyColor);
+ int[] engineX = {
+ startPosX + 45,
+ startPosX + 50,
+ startPosX + 50,
+ };
+ int[] engineY = {
+ startPosY + 42 + yOffset,
+ startPosY + 38 + yOffset,
+ startPosY + 46 + yOffset,
+ };
+ g.fillPolygon(engineX, engineY, engineX.length);
+ g.setColor(Color.BLACK);
+ g.drawPolygon(engineX, engineY, engineX.length);
+ }
+
+ @Override
+ public void drawEngines(Graphics2D g, int startPosX, int startPosY, Color bodyColor) {
+ if (engines == null) return;
+
+ switch (engines) {
+ case SIX:
+ drawEngine(g, startPosX, startPosY, -5 - 5 - 20, bodyColor);
+ drawEngine(g, startPosX, startPosY, 20 + 5 + 20, bodyColor);
+ case FOUR:
+ drawEngine(g, startPosX, startPosY, -5 - 5 - 10, bodyColor);
+ drawEngine(g, startPosX, startPosY, 20 + 5 + 10, bodyColor);
+ case TWO:
+ drawEngine(g, startPosX, startPosY, -5 - 5, bodyColor);
+ drawEngine(g, startPosX, startPosY, 20 + 5, bodyColor);
+ break;
+ }
+ }
+}
diff --git a/AirBomber/src/AirBomberPackage/DrawingHeavyAirBomber.java b/AirBomber/src/AirBomberPackage/DrawingHeavyAirBomber.java
new file mode 100644
index 0000000..9044e8c
--- /dev/null
+++ b/AirBomber/src/AirBomberPackage/DrawingHeavyAirBomber.java
@@ -0,0 +1,68 @@
+/*
+ * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
+ * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
+ */
+package AirBomberPackage;
+import java.awt.*;
+/**
+ *
+ * @author Андрей
+ */
+public class DrawingHeavyAirBomber extends DrawingAirBomber {
+ ///
+ /// Инициализация свойств
+ ///
+ /// Скорость
+ /// Вес автомобиля
+ /// Цвет кузова
+ /// Дополнительный цвет
+ /// Признак наличия обвеса
+ /// Признак наличия антикрыла
+ /// Признак наличия гоночной полосы
+ public DrawingHeavyAirBomber(int speed, float weight, Color bodyColor, int numberOfEngines, EnginesType enginesType, Color dopColor, boolean bodyKit, boolean wing, boolean sportLine)
+ {
+ super(speed, weight, bodyColor, numberOfEngines, enginesType, 110, 100);
+ AirBomber = new EntityHeavyAirBomber(speed, weight, bodyColor, dopColor, bodyKit, wing, sportLine);
+ }
+
+ @Override
+ public void DrawTransport(Graphics2D g)
+ {
+ if (!(AirBomber instanceof EntityHeavyAirBomber heavyAirBomber))
+ {
+ return;
+ }
+ if (heavyAirBomber.getBombs())
+ {
+ g.setColor(heavyAirBomber.getDopColor());
+ g.fillOval(_startPosX + 45, _startPosY, 20, 10);
+ g.fillOval(_startPosX + 45, _startPosY + 90, 20, 10);
+ g.setColor(Color.BLACK);
+ g.drawOval(_startPosX + 45, _startPosY, 20, 10);
+ g.drawOval(_startPosX + 45, _startPosY + 90, 20, 10);
+
+ }
+
+ super.DrawTransport(g);
+
+ if (heavyAirBomber.getTailLine())
+ {
+ g.setColor(heavyAirBomber.getDopColor());
+ g.fillRect(_startPosX + 95, _startPosY + 30, 15, 5);
+ g.fillRect(_startPosX + 95, _startPosY + 65, 15, 5);
+ g.setColor(Color.BLACK);
+ }
+
+ if (heavyAirBomber.getFuelTank())
+ {
+ g.setColor(heavyAirBomber.getDopColor());
+ g.fillOval(_startPosX + 23, _startPosY + 42, 25, 15);
+ g.fillOval(_startPosX + 53, _startPosY + 42, 25, 15);
+ g.fillOval(_startPosX + 83, _startPosY + 42, 25, 15);
+ g.setColor(Color.BLACK);
+ g.drawOval(_startPosX + 23, _startPosY + 42, 25, 15);
+ g.drawOval(_startPosX + 53, _startPosY + 42, 25, 15);
+ g.drawOval(_startPosX + 83, _startPosY + 42, 25, 15);
+ }
+ }
+}
diff --git a/AirBomber/src/AirBomberPackage/DrawingObjectAirBomber.java b/AirBomber/src/AirBomberPackage/DrawingObjectAirBomber.java
new file mode 100644
index 0000000..c27eccb
--- /dev/null
+++ b/AirBomber/src/AirBomberPackage/DrawingObjectAirBomber.java
@@ -0,0 +1,56 @@
+/*
+ * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
+ * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
+ */
+package AirBomberPackage;
+import java.awt.*;
+/**
+ *
+ * @author Андрей
+ */
+public class DrawingObjectAirBomber implements IDrawingObject {
+ private DrawingAirBomber _airBomber = null;
+
+ public DrawingObjectAirBomber(DrawingAirBomber airBomber)
+ {
+ _airBomber = airBomber;
+ Step = _airBomber.AirBomber.Step;
+ }
+
+ public float Step;
+ @Override
+ public float getStep(){
+ return Step;
+ }
+
+ @Override
+ public float[] GetCurrentPosition()
+ {
+ if (_airBomber == null) return null;
+ return _airBomber.GetCurrentPosition();
+ }
+ @Override
+ public void MoveObject(Direction direction)
+ {
+ _airBomber.MoveTransport(direction);
+ }
+ @Override
+ public void SetObject(int x, int y, int width, int height)
+ {
+ _airBomber.SetPosition(x, y, width, height);
+ }
+
+ @Override
+ public void DrawingObject(Graphics2D g)
+ {
+ if (_airBomber == null) return;
+ if (_airBomber instanceof DrawingHeavyAirBomber heavyAirBomber)
+ {
+ heavyAirBomber.DrawTransport(g);
+ }
+ else
+ {
+ _airBomber.DrawTransport(g);
+ }
+ }
+}
diff --git a/AirBomber/src/AirBomberPackage/EnginesType.java b/AirBomber/src/AirBomberPackage/EnginesType.java
new file mode 100644
index 0000000..deb65cb
--- /dev/null
+++ b/AirBomber/src/AirBomberPackage/EnginesType.java
@@ -0,0 +1,15 @@
+/*
+ * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
+ * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
+ */
+package AirBomberPackage;
+
+/**
+ *
+ * @author Андрей
+ */
+public enum EnginesType {
+ RECTANGLE,
+ TRIANGLE,
+ OVAL
+}
diff --git a/AirBomber/src/AirBomberPackage/EntityAirBomber.java b/AirBomber/src/AirBomberPackage/EntityAirBomber.java
index d72ade4..e14ff3f 100644
--- a/AirBomber/src/AirBomberPackage/EntityAirBomber.java
+++ b/AirBomber/src/AirBomberPackage/EntityAirBomber.java
@@ -1,43 +1,41 @@
-/*
- * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
- * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
- */
-package AirBomberPackage;
-import java.awt.Color;
-import java.util.Random;
-
-/**
- *
- * @author Андрей
- */
-public class EntityAirBomber {
- private int Speed;
-
- private float Weight;
-
- private Color BodyColor;
-
- public float Step;
-
- public int getSpeed() {
- return Speed;
- }
-
- public float getWeight() {
- return Weight;
- }
-
- public Color getBodyColor() {
- return BodyColor;
- }
-
-
-
- public void Init(int speed, float weight, Color bodyColor){
- Random rnd = new Random();
- Speed = speed <= 0 ? rnd.nextInt(50, 150) : speed;
- Weight = weight <= 0 ? rnd.nextInt(40, 70) : weight;
- Step = Speed * 100 / Weight;
- BodyColor = bodyColor;
- }
-}
+/*
+ * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
+ * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
+ */
+package AirBomberPackage;
+import java.awt.Color;
+import java.util.Random;
+
+/**
+ *
+ * @author Андрей
+ */
+public class EntityAirBomber {
+ private int Speed;
+
+ private float Weight;
+
+ private Color BodyColor;
+
+ public float Step;
+
+ public int getSpeed() {
+ return Speed;
+ }
+
+ public float getWeight() {
+ return Weight;
+ }
+
+ public Color getBodyColor() {
+ return BodyColor;
+ }
+
+ public EntityAirBomber(int speed, float weight, Color bodyColor){
+ Random rnd = new Random();
+ Speed = speed <= 0 ? rnd.nextInt(50, 150) : speed;
+ Weight = weight <= 0 ? rnd.nextInt(40, 70) : weight;
+ Step = Speed * 100 / Weight;
+ BodyColor = bodyColor;
+ }
+}
diff --git a/AirBomber/src/AirBomberPackage/EntityHeavyAirBomber.java b/AirBomber/src/AirBomberPackage/EntityHeavyAirBomber.java
new file mode 100644
index 0000000..a01feb9
--- /dev/null
+++ b/AirBomber/src/AirBomberPackage/EntityHeavyAirBomber.java
@@ -0,0 +1,63 @@
+/*
+ * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
+ * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
+ */
+package AirBomberPackage;
+import java.awt.*;
+/**
+ *
+ * @author Андрей
+ */
+public class EntityHeavyAirBomber extends EntityAirBomber {
+ ///
+ /// Дополнительный цвет
+ ///
+ private Color DopColor;
+ ///
+ /// Признак наличия бомб
+ ///
+ private boolean bombs;
+ ///
+ /// Признак наличия топливных баков
+ ///
+ private boolean fuelTank;
+ ///
+ /// Признак наличия полосы на хвосте
+ ///
+ private boolean tailLine;
+
+ public Color getDopColor() {
+ return DopColor;
+ }
+
+ public boolean getBombs(){
+ return bombs;
+ }
+
+ public boolean getFuelTank(){
+ return fuelTank;
+ }
+
+ public boolean getTailLine(){
+ return tailLine;
+ }
+
+ ///
+ /// Инициализация свойств
+ ///
+ /// Скорость
+ /// Вес бомбардировщика
+ /// Цвет корпуса
+ /// Дополнительный цвет
+ /// Признак наличия обвеса
+ /// Признак наличия антикрыла
+ /// Признак наличия гоночной полосы
+ public EntityHeavyAirBomber(int speed, float weight, Color bodyColor, Color dopColor, boolean bombs, boolean fuelTank, boolean tailLine)
+ {
+ super(speed, weight, bodyColor);
+ DopColor = dopColor;
+ this.bombs = bombs;
+ this.fuelTank = fuelTank;
+ this.tailLine = tailLine;
+ }
+}
diff --git a/AirBomber/src/AirBomberPackage/IDrawingObject.java b/AirBomber/src/AirBomberPackage/IDrawingObject.java
new file mode 100644
index 0000000..ba533bc
--- /dev/null
+++ b/AirBomber/src/AirBomberPackage/IDrawingObject.java
@@ -0,0 +1,40 @@
+/*
+ * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
+ * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Interface.java to edit this template
+ */
+package AirBomberPackage;
+import java.awt.*;
+/**
+ *
+ * @author Андрей
+ */
+public interface IDrawingObject {
+ ///
+ /// Шаг перемещения объекта
+ ///
+ public float getStep();
+ ///
+ /// Установка позиции объекта
+ ///
+ /// Координата X
+ /// Координата Y
+ /// Ширина полотна
+ /// Высота полотна
+ void SetObject(int x, int y, int width, int height);
+ ///
+ /// Изменение направления пермещения объекта
+ ///
+ /// Направление
+ ///
+ void MoveObject(Direction direction);
+ ///
+ /// Отрисовка объекта
+ ///
+ ///
+ void DrawingObject(Graphics2D g);
+ ///
+ /// Получение текущей позиции объекта
+ ///
+ ///
+ float[] GetCurrentPosition();
+}
diff --git a/AirBomber/src/AirBomberPackage/IDrawingObjectDop.java b/AirBomber/src/AirBomberPackage/IDrawingObjectDop.java
new file mode 100644
index 0000000..e9a042c
--- /dev/null
+++ b/AirBomber/src/AirBomberPackage/IDrawingObjectDop.java
@@ -0,0 +1,18 @@
+/*
+ * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
+ * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Interface.java to edit this template
+ */
+package AirBomberPackage;
+
+import java.awt.*;
+
+/**
+ *
+ * @author Андрей
+ */
+public interface IDrawingObjectDop {
+ public int getNumberOfEngines();
+ void setNumberOfEngines(int numberOfEngines);
+ void drawEngine(Graphics2D g, int startPosX, int startPosY, int yOffset, Color bodyColor);
+ void drawEngines(Graphics2D g, int startPosX, int startPosY, Color bodyColor);
+}
diff --git a/AirBomber/src/AirBomberPackage/JFrameAirBomber.form b/AirBomber/src/AirBomberPackage/JFrameAirBomber.form
index 527555d..e29b23f 100644
--- a/AirBomber/src/AirBomberPackage/JFrameAirBomber.form
+++ b/AirBomber/src/AirBomberPackage/JFrameAirBomber.form
@@ -41,10 +41,18 @@
+
+
+
+
+
+
+
+
+
-
-
+
@@ -57,7 +65,10 @@
-
+
+
+
+
@@ -70,9 +81,14 @@
+
+
-
+
+
+
+
@@ -219,5 +235,37 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/AirBomber/src/AirBomberPackage/JFrameAirBomber.java b/AirBomber/src/AirBomberPackage/JFrameAirBomber.java
index e970014..da71d20 100644
--- a/AirBomber/src/AirBomberPackage/JFrameAirBomber.java
+++ b/AirBomber/src/AirBomberPackage/JFrameAirBomber.java
@@ -21,6 +21,7 @@ public class JFrameAirBomber extends javax.swing.JFrame {
}
private DrawingAirBomber _airBomber;
+ private EnginesType enginesType = EnginesType.RECTANGLE;
/**
* This method is called from within the constructor to initialize the form.
@@ -40,6 +41,9 @@ public class JFrameAirBomber extends javax.swing.JFrame {
airBomberCanvas = new AirBomberPackage.CanvasMy();
jLabelEngines = new javax.swing.JLabel();
jComboBoxEngines = new javax.swing.JComboBox<>();
+ ModifyButton = new javax.swing.JButton();
+ jLabelEngines1 = new javax.swing.JLabel();
+ jComboBoxEnginesType = new javax.swing.JComboBox<>();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setTitle("Бомбардировщик");
@@ -113,6 +117,24 @@ public class JFrameAirBomber extends javax.swing.JFrame {
jComboBoxEngines.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "Два", "Четыре", "Шесть" }));
+ ModifyButton.setText("Модификация");
+ ModifyButton.setToolTipText("");
+ ModifyButton.setName("modifyButton"); // NOI18N
+ ModifyButton.addActionListener(new java.awt.event.ActionListener() {
+ public void actionPerformed(java.awt.event.ActionEvent evt) {
+ ModifyButtonActionPerformed(evt);
+ }
+ });
+
+ jLabelEngines1.setText("Тип двигателей: ");
+
+ jComboBoxEnginesType.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "Квадратный", "Треугольный", "Круглый" }));
+ jComboBoxEnginesType.addItemListener(new java.awt.event.ItemListener() {
+ public void itemStateChanged(java.awt.event.ItemEvent evt) {
+ jComboBoxEnginesTypeItemStateChanged(evt);
+ }
+ });
+
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
@@ -124,9 +146,16 @@ public class JFrameAirBomber extends javax.swing.JFrame {
.addContainerGap()
.addComponent(jLabelEngines)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(jComboBoxEngines, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addComponent(createAirBomberButton))
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 369, Short.MAX_VALUE)
+ .addComponent(jComboBoxEngines, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
+ .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
+ .addComponent(jLabelEngines1)
+ .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
+ .addComponent(jComboBoxEnginesType, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
+ .addGroup(layout.createSequentialGroup()
+ .addComponent(createAirBomberButton)
+ .addGap(18, 18, 18)
+ .addComponent(ModifyButton)))
+ .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 157, Short.MAX_VALUE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(upButton, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGroup(layout.createSequentialGroup()
@@ -136,7 +165,9 @@ public class JFrameAirBomber extends javax.swing.JFrame {
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(rightButton, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(17, 17, 17))
- .addComponent(airBomberCanvas, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
+ .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
+ .addComponent(airBomberCanvas, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
+ .addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
@@ -147,9 +178,13 @@ public class JFrameAirBomber extends javax.swing.JFrame {
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabelEngines, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addComponent(jComboBoxEngines, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
+ .addComponent(jComboBoxEngines, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
+ .addComponent(jLabelEngines1)
+ .addComponent(jComboBoxEnginesType, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(createAirBomberButton, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE))
+ .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
+ .addComponent(createAirBomberButton, javax.swing.GroupLayout.DEFAULT_SIZE, 31, Short.MAX_VALUE)
+ .addComponent(ModifyButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addComponent(upButton, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
@@ -166,12 +201,7 @@ public class JFrameAirBomber extends javax.swing.JFrame {
private void createAirBomberButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_createAirBomberButtonActionPerformed
Random rnd = new Random();
- _airBomber = new DrawingAirBomber();
- _airBomber.Init(rnd.nextInt(100, 300), rnd.nextInt(1000, 2000), new Color(rnd.nextInt(0, 256), rnd.nextInt(0, 256), rnd.nextInt(0, 256)), (jComboBoxEngines.getSelectedIndex() + 1) * 2);
- System.out.println(((jComboBoxEngines.getSelectedIndex() + 1) * 2) + "");
- _airBomber.SetPosition(rnd.nextInt(10, 100), rnd.nextInt(10, 100), airBomberCanvas.getWidth(), airBomberCanvas.getHeight());
- statusLabel.setText("Скорость: " + _airBomber.getAirBomber().getSpeed() + " Вес: " + (int) _airBomber.getAirBomber().getWeight() + " Цвет: " + _airBomber.getAirBomber().getBodyColor() + " Двигатели: " + _airBomber.drawingEngines.getNumberOfEngines());
- airBomberCanvas.setAirBomber(_airBomber);
+ _airBomber = new DrawingAirBomber(rnd.nextInt(100, 300), rnd.nextInt(1000, 2000), new Color(rnd.nextInt(0, 256), rnd.nextInt(0, 256), rnd.nextInt(0, 256)), (jComboBoxEngines.getSelectedIndex() + 1) * 2, enginesType);
Draw();
}//GEN-LAST:event_createAirBomberButtonActionPerformed
@@ -201,6 +231,41 @@ public class JFrameAirBomber extends javax.swing.JFrame {
_airBomber.ChangeBorders(airBomberCanvas.getWidth(), airBomberCanvas.getHeight());
}//GEN-LAST:event_airBomberCanvasComponentResized
+ private void ModifyButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ModifyButtonActionPerformed
+ Random rnd = new Random();
+ _airBomber = new DrawingHeavyAirBomber(rnd.nextInt(100, 300), rnd.nextInt(1000, 2000),
+ new Color(rnd.nextInt(0, 256), rnd.nextInt(0, 256), rnd.nextInt(0, 256)),
+ (jComboBoxEngines.getSelectedIndex() + 1) * 2,
+ enginesType,
+ new Color(rnd.nextInt(0, 256), rnd.nextInt(0, 256), rnd.nextInt(0, 256)),
+ rnd.nextBoolean(), rnd.nextBoolean(), rnd.nextBoolean());
+ SetData();
+ Draw();
+ }//GEN-LAST:event_ModifyButtonActionPerformed
+
+ private void jComboBoxEnginesTypeItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_jComboBoxEnginesTypeItemStateChanged
+ switch (jComboBoxEnginesType.getSelectedIndex())
+ {
+ case 0:
+ enginesType = EnginesType.RECTANGLE;
+ break;
+ case 1:
+ enginesType = EnginesType.TRIANGLE;
+ break;
+ case 2:
+ enginesType = EnginesType.OVAL;
+ break;
+ }
+ }//GEN-LAST:event_jComboBoxEnginesTypeItemStateChanged
+
+ private void SetData()
+ {
+ Random rnd = new Random();
+ _airBomber.SetPosition(rnd.nextInt(10, 100), rnd.nextInt(10, 100), airBomberCanvas.getWidth(), airBomberCanvas.getHeight());
+ statusLabel.setText("Скорость: " + _airBomber.getAirBomber().getSpeed() + " Вес: " + (int) _airBomber.getAirBomber().getWeight() + " Цвет: " + _airBomber.getAirBomber().getBodyColor() + " Двигатели: " + _airBomber.drawingEngines.getNumberOfEngines());
+ airBomberCanvas.setAirBomber(_airBomber);
+ }
+
private void Draw(){
airBomberCanvas.repaint();
}
@@ -235,17 +300,20 @@ public class JFrameAirBomber extends javax.swing.JFrame {
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
- new JFrameAirBomber().setVisible(true);
+ new JFrameMap().setVisible(true);
}
});
}
// Variables declaration - do not modify//GEN-BEGIN:variables
+ private javax.swing.JButton ModifyButton;
private AirBomberPackage.CanvasMy airBomberCanvas;
private javax.swing.JButton createAirBomberButton;
private javax.swing.JButton downButton;
private javax.swing.JComboBox jComboBoxEngines;
+ private javax.swing.JComboBox jComboBoxEnginesType;
private javax.swing.JLabel jLabelEngines;
+ private javax.swing.JLabel jLabelEngines1;
private javax.swing.JButton leftButton;
private javax.swing.JButton rightButton;
private javax.swing.JLabel statusLabel;
diff --git a/AirBomber/src/AirBomberPackage/JFrameMap.form b/AirBomber/src/AirBomberPackage/JFrameMap.form
new file mode 100644
index 0000000..fef36a6
--- /dev/null
+++ b/AirBomber/src/AirBomberPackage/JFrameMap.form
@@ -0,0 +1,289 @@
+
+
+
diff --git a/AirBomber/src/AirBomberPackage/JFrameMap.java b/AirBomber/src/AirBomberPackage/JFrameMap.java
new file mode 100644
index 0000000..5f03ccd
--- /dev/null
+++ b/AirBomber/src/AirBomberPackage/JFrameMap.java
@@ -0,0 +1,337 @@
+/*
+ * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
+ * Click nbfs://nbhost/SystemFileSystem/Templates/GUIForms/JFrame.java to edit this template
+ */
+package AirBomberPackage;
+import java.util.*;
+import java.awt.*;
+import javax.swing.*;
+/**
+ *
+ * @author Андрей
+ */
+public class JFrameMap extends javax.swing.JFrame {
+
+ /**
+ * Creates new form JFrameMap
+ */
+ public JFrameMap() {
+ initComponents();
+ }
+
+ private DrawingAirBomber _airBomber;
+ private AbstractMap _abstractMap = new SimpleMap();
+ private EnginesType enginesType = EnginesType.RECTANGLE;
+
+ /**
+ * This method is called from within the constructor to initialize the form.
+ * WARNING: Do NOT modify this code. The content of this method is always
+ * regenerated by the Form Editor.
+ */
+ @SuppressWarnings("unchecked")
+ // //GEN-BEGIN:initComponents
+ private void initComponents() {
+
+ airBomberCanvas = new AirBomberPackage.CanvasMy();
+ jLabelEngines = new javax.swing.JLabel();
+ jComboBoxEngines = new javax.swing.JComboBox<>();
+ createAirBomberButton = new javax.swing.JButton();
+ statusLabel = new javax.swing.JLabel();
+ leftButton = new javax.swing.JButton();
+ downButton = new javax.swing.JButton();
+ rightButton = new javax.swing.JButton();
+ upButton = new javax.swing.JButton();
+ ModifyButton = new javax.swing.JButton();
+ jComboBoxMap = new javax.swing.JComboBox<>();
+ jComboBoxEnginesType = new javax.swing.JComboBox<>();
+ jLabelEngines1 = new javax.swing.JLabel();
+
+ setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
+ setTitle("Бомбардировщик");
+ setAlwaysOnTop(true);
+ setName("FrameMap"); // NOI18N
+ setSize(new java.awt.Dimension(700, 400));
+
+ airBomberCanvas.setPreferredSize(new java.awt.Dimension(700, 300));
+
+ jLabelEngines.setText("Количество двигателей: ");
+
+ jComboBoxEngines.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "Два", "Четыре", "Шесть" }));
+
+ createAirBomberButton.setText("Создать");
+ createAirBomberButton.setName("createAirBomberButton"); // NOI18N
+ createAirBomberButton.addActionListener(new java.awt.event.ActionListener() {
+ public void actionPerformed(java.awt.event.ActionEvent evt) {
+ createAirBomberButtonActionPerformed(evt);
+ }
+ });
+
+ statusLabel.setText("Скорость: Вес: Цвет: Двигатели:");
+ statusLabel.setMinimumSize(new java.awt.Dimension(0, 0));
+
+ leftButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/AirBomberPackage/arrowLeft.png"))); // NOI18N
+ leftButton.setMargin(new java.awt.Insets(0, 0, 0, 0));
+ leftButton.setMaximumSize(new java.awt.Dimension(30, 30));
+ leftButton.setMinimumSize(new java.awt.Dimension(30, 30));
+ leftButton.setName("buttonLeft"); // NOI18N
+ leftButton.setPreferredSize(new java.awt.Dimension(30, 30));
+ leftButton.addActionListener(new java.awt.event.ActionListener() {
+ public void actionPerformed(java.awt.event.ActionEvent evt) {
+ moveButtonActionPerformed(evt);
+ }
+ });
+
+ downButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/AirBomberPackage/arrowDown.png"))); // NOI18N
+ downButton.setMaximumSize(new java.awt.Dimension(30, 30));
+ downButton.setMinimumSize(new java.awt.Dimension(30, 30));
+ downButton.setName("buttonDown"); // NOI18N
+ downButton.setPreferredSize(new java.awt.Dimension(30, 30));
+ downButton.addActionListener(new java.awt.event.ActionListener() {
+ public void actionPerformed(java.awt.event.ActionEvent evt) {
+ moveButtonActionPerformed(evt);
+ }
+ });
+
+ rightButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/AirBomberPackage/arrowRight.png"))); // NOI18N
+ rightButton.setMaximumSize(new java.awt.Dimension(30, 30));
+ rightButton.setMinimumSize(new java.awt.Dimension(30, 30));
+ rightButton.setName("buttonRight"); // NOI18N
+ rightButton.setPreferredSize(new java.awt.Dimension(30, 30));
+ rightButton.addActionListener(new java.awt.event.ActionListener() {
+ public void actionPerformed(java.awt.event.ActionEvent evt) {
+ moveButtonActionPerformed(evt);
+ }
+ });
+
+ upButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/AirBomberPackage/arrowUp.png"))); // NOI18N
+ upButton.setMaximumSize(new java.awt.Dimension(30, 30));
+ upButton.setMinimumSize(new java.awt.Dimension(30, 30));
+ upButton.setName("buttonUp"); // NOI18N
+ upButton.setPreferredSize(new java.awt.Dimension(30, 30));
+ upButton.addActionListener(new java.awt.event.ActionListener() {
+ public void actionPerformed(java.awt.event.ActionEvent evt) {
+ moveButtonActionPerformed(evt);
+ }
+ });
+
+ ModifyButton.setText("Модификация");
+ ModifyButton.setToolTipText("");
+ ModifyButton.setName("modifyButton"); // NOI18N
+ ModifyButton.addActionListener(new java.awt.event.ActionListener() {
+ public void actionPerformed(java.awt.event.ActionEvent evt) {
+ ModifyButtonActionPerformed(evt);
+ }
+ });
+
+ jComboBoxMap.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "Простая карта", "Линейная карта", "Городская карта" }));
+ jComboBoxMap.addItemListener(new java.awt.event.ItemListener() {
+ public void itemStateChanged(java.awt.event.ItemEvent evt) {
+ jComboBoxMapItemStateChanged(evt);
+ }
+ });
+
+ jComboBoxEnginesType.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "Квадратный", "Треугольный", "Круглый" }));
+ jComboBoxEnginesType.addItemListener(new java.awt.event.ItemListener() {
+ public void itemStateChanged(java.awt.event.ItemEvent evt) {
+ jComboBoxEnginesTypeItemStateChanged(evt);
+ }
+ });
+
+ jLabelEngines1.setText("Тип двигателей: ");
+
+ javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
+ getContentPane().setLayout(layout);
+ layout.setHorizontalGroup(
+ layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+ .addComponent(statusLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
+ .addGroup(layout.createSequentialGroup()
+ .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+ .addGroup(layout.createSequentialGroup()
+ .addContainerGap()
+ .addComponent(jLabelEngines)
+ .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
+ .addComponent(jComboBoxEngines, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
+ .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
+ .addComponent(jLabelEngines1)
+ .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
+ .addComponent(jComboBoxEnginesType, javax.swing.GroupLayout.PREFERRED_SIZE, 107, javax.swing.GroupLayout.PREFERRED_SIZE))
+ .addGroup(layout.createSequentialGroup()
+ .addComponent(createAirBomberButton)
+ .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
+ .addComponent(ModifyButton)
+ .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
+ .addComponent(jComboBoxMap, javax.swing.GroupLayout.PREFERRED_SIZE, 127, javax.swing.GroupLayout.PREFERRED_SIZE)))
+ .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 146, Short.MAX_VALUE)
+ .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
+ .addComponent(upButton, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
+ .addGroup(layout.createSequentialGroup()
+ .addComponent(leftButton, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
+ .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
+ .addComponent(downButton, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)))
+ .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
+ .addComponent(rightButton, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
+ .addGap(17, 17, 17))
+ .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
+ .addComponent(airBomberCanvas, javax.swing.GroupLayout.DEFAULT_SIZE, 694, Short.MAX_VALUE)
+ .addContainerGap())
+ );
+ layout.setVerticalGroup(
+ layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+ .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
+ .addComponent(airBomberCanvas, javax.swing.GroupLayout.DEFAULT_SIZE, 298, Short.MAX_VALUE)
+ .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
+ .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+ .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
+ .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
+ .addComponent(jLabelEngines, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE)
+ .addComponent(jComboBoxEngines, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
+ .addComponent(jLabelEngines1)
+ .addComponent(jComboBoxEnginesType, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
+ .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
+ .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
+ .addComponent(createAirBomberButton, javax.swing.GroupLayout.DEFAULT_SIZE, 31, Short.MAX_VALUE)
+ .addComponent(ModifyButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
+ .addComponent(jComboBoxMap)))
+ .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
+ .addComponent(upButton, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE)
+ .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
+ .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
+ .addComponent(leftButton, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE)
+ .addComponent(downButton, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE)
+ .addComponent(rightButton, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE))))
+ .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
+ .addComponent(statusLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 22, javax.swing.GroupLayout.PREFERRED_SIZE))
+ );
+
+ pack();
+ }// //GEN-END:initComponents
+
+ private void createAirBomberButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_createAirBomberButtonActionPerformed
+ Random rnd = new Random();
+ _airBomber = new DrawingAirBomber(rnd.nextInt(100, 300), rnd.nextInt(1000, 2000), new Color(rnd.nextInt(0, 256), rnd.nextInt(0, 256), rnd.nextInt(0, 256)), (jComboBoxEngines.getSelectedIndex() + 1) * 2, enginesType);
+ SetData(_airBomber);
+ }//GEN-LAST:event_createAirBomberButtonActionPerformed
+
+ private void moveButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_moveButtonActionPerformed
+ if (_airBomber == null) return;
+ String name = ((JButton) evt.getSource()).getName();
+ Direction dir = Direction.NONE;
+ switch (name)
+ {
+ case "buttonUp":
+ dir = Direction.UP;
+ break;
+ case "buttonDown":
+ dir = Direction.DOWN;
+ break;
+ case "buttonLeft":
+ dir = Direction.LEFT;
+ break;
+ case "buttonRight":
+ dir = Direction.RIGHT;
+ break;
+ }
+ airBomberCanvas.getGraphics().drawImage(_abstractMap.MoveObject(dir), 0, 0, null);
+ }//GEN-LAST:event_moveButtonActionPerformed
+
+ private void ModifyButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ModifyButtonActionPerformed
+ Random rnd = new Random();
+ _airBomber = new DrawingHeavyAirBomber(rnd.nextInt(100, 300), rnd.nextInt(1000, 2000),
+ new Color(rnd.nextInt(0, 256), rnd.nextInt(0, 256), rnd.nextInt(0, 256)),
+ (jComboBoxEngines.getSelectedIndex() + 1) * 2,
+ enginesType,
+ new Color(rnd.nextInt(0, 256), rnd.nextInt(0, 256), rnd.nextInt(0, 256)),
+ rnd.nextBoolean(), rnd.nextBoolean(), rnd.nextBoolean());
+ SetData(_airBomber);
+ }//GEN-LAST:event_ModifyButtonActionPerformed
+
+ private void jComboBoxMapItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_jComboBoxMapItemStateChanged
+ switch (jComboBoxMap.getSelectedIndex())
+ {
+ case 0:
+ _abstractMap = new SimpleMap();
+ break;
+ case 1:
+ _abstractMap = new LineMap();
+ break;
+ case 2:
+ _abstractMap = new CityMap();
+ break;
+ }
+ }//GEN-LAST:event_jComboBoxMapItemStateChanged
+
+ private void jComboBoxEnginesTypeItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_jComboBoxEnginesTypeItemStateChanged
+ switch (jComboBoxEnginesType.getSelectedIndex())
+ {
+ case 0:
+ enginesType = EnginesType.RECTANGLE;
+ break;
+ case 1:
+ enginesType = EnginesType.TRIANGLE;
+ break;
+ case 2:
+ enginesType = EnginesType.OVAL;
+ break;
+ }
+ }//GEN-LAST:event_jComboBoxEnginesTypeItemStateChanged
+
+ private void SetData(DrawingAirBomber airBomber)
+ {
+ Random rnd = new Random();
+ _airBomber.SetPosition(rnd.nextInt(10, 100), rnd.nextInt(10, 100), airBomberCanvas.getWidth(), airBomberCanvas.getHeight());
+ statusLabel.setText("Скорость: " + _airBomber.getAirBomber().getSpeed() + " Вес: " + (int) _airBomber.getAirBomber().getWeight() + " Цвет: " + _airBomber.getAirBomber().getBodyColor() + " Двигатели: " + _airBomber.drawingEngines.getNumberOfEngines());
+ airBomberCanvas.setAirBomber(_airBomber);
+ airBomberCanvas.getGraphics().drawImage(_abstractMap.CreateMap(airBomberCanvas.getWidth() + 6, airBomberCanvas.getHeight() + 3, new DrawingObjectAirBomber(airBomber)), 0,0,null);
+ }
+
+ /**
+ * @param args the command line arguments
+ */
+ public static void main(String args[]) {
+ /* Set the Nimbus look and feel */
+ //
+ /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
+ * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
+ */
+ try {
+ for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
+ if ("Nimbus".equals(info.getName())) {
+ javax.swing.UIManager.setLookAndFeel(info.getClassName());
+ break;
+ }
+ }
+ } catch (ClassNotFoundException ex) {
+ java.util.logging.Logger.getLogger(JFrameMap.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
+ } catch (InstantiationException ex) {
+ java.util.logging.Logger.getLogger(JFrameMap.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
+ } catch (IllegalAccessException ex) {
+ java.util.logging.Logger.getLogger(JFrameMap.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
+ } catch (javax.swing.UnsupportedLookAndFeelException ex) {
+ java.util.logging.Logger.getLogger(JFrameMap.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
+ }
+ //
+
+ /* Create and display the form */
+ java.awt.EventQueue.invokeLater(new Runnable() {
+ public void run() {
+ new JFrameMap().setVisible(true);
+ }
+ });
+ }
+
+ // Variables declaration - do not modify//GEN-BEGIN:variables
+ private javax.swing.JButton ModifyButton;
+ private AirBomberPackage.CanvasMy airBomberCanvas;
+ private javax.swing.JButton createAirBomberButton;
+ private javax.swing.JButton downButton;
+ private javax.swing.JComboBox jComboBoxEngines;
+ private javax.swing.JComboBox jComboBoxEnginesType;
+ private javax.swing.JComboBox jComboBoxMap;
+ private javax.swing.JLabel jLabelEngines;
+ private javax.swing.JLabel jLabelEngines1;
+ private javax.swing.JButton leftButton;
+ private javax.swing.JButton rightButton;
+ private javax.swing.JLabel statusLabel;
+ private javax.swing.JButton upButton;
+ // End of variables declaration//GEN-END:variables
+}
diff --git a/AirBomber/src/AirBomberPackage/LineMap.java b/AirBomber/src/AirBomberPackage/LineMap.java
new file mode 100644
index 0000000..9e60ada
--- /dev/null
+++ b/AirBomber/src/AirBomberPackage/LineMap.java
@@ -0,0 +1,103 @@
+/*
+ * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
+ * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
+ */
+package AirBomberPackage;
+import java.awt.*;
+/**
+ *
+ * @author Андрей
+ */
+public class LineMap extends AbstractMap {
+ ///
+ /// Цвет участка закрытого
+ ///
+ private final Color barrierColor = Color.BLACK;
+ ///
+ /// Цвет участка открытого
+ ///
+ private final Color roadColor = Color.CYAN;
+
+ @Override
+ protected void DrawBarrierPart(Graphics g, int i, int j)
+ {
+ g.setColor(barrierColor);
+ g.fillRect(i * _size_x, j * _size_y, _size_x, _size_y);
+ g.setColor(Color.BLACK);
+ }
+ @Override
+ protected void DrawRoadPart(Graphics g, int i, int j)
+ {
+ g.setColor(roadColor);
+ g.fillRect(i * _size_x, j * _size_y, _size_x, _size_y);
+ g.setColor(Color.BLACK);
+ }
+ @Override
+ protected void GenerateMap()
+ {
+ _map = new int[100][100];
+ _size_x = _width / _map.length;
+ _size_y = _height / _map[0].length;
+ int lineCounter = 0;
+ int numOfLines = _random.nextInt(1, 4);
+ for (int i = 0; i < _map.length; ++i)
+ {
+ for (int j = 0; j < _map[0].length; ++j)
+ {
+ _map[i][j] = _freeRoad;
+ }
+ }
+ while (lineCounter < numOfLines)
+ {
+ int randomInt = _random.nextInt(0, 1000);
+ boolean vertical = false;
+ if (randomInt % 2 == 0) vertical = true;
+ if (vertical)
+ {
+ int x = _random.nextInt(0, 89);
+ int lineWidth = _random.nextInt(2, 5);
+ if (x + lineWidth >= _map.length) x = _random.nextInt(_map.length - lineWidth - 1, _map.length);
+
+ boolean isFreeSpace = true;
+ for (int i = x; i < x + lineWidth; i++)
+ {
+ if (_map[i][0] != _freeRoad) isFreeSpace = false;
+ }
+ if (isFreeSpace)
+ {
+ for (int i = x; i < x + lineWidth; i++)
+ {
+ for (int j = 0; j < _map.length; j++)
+ {
+ _map[i][j] = _barrier;
+ }
+ }
+ lineCounter++;
+ }
+ }
+ else
+ {
+ int y = _random.nextInt(0, 89);
+ int lineHeigth = _random.nextInt(2, 5);
+ if (y + lineHeigth >= _map[0].length) y = _random.nextInt(_map[0].length - lineHeigth - 1, _map[0].length);
+
+ boolean isFreeSpace = true;
+ for (int j = y; j < y + lineHeigth; j++)
+ {
+ if (_map[0][j] != _freeRoad) isFreeSpace = false;
+ }
+ if (isFreeSpace)
+ {
+ for (int j = y; j < y + lineHeigth; j++)
+ {
+ for (int i = 0; i < _map[0].length; i++)
+ {
+ _map[i][j] = _barrier;
+ }
+ }
+ lineCounter++;
+ }
+ }
+ }
+ }
+}
diff --git a/AirBomber/src/AirBomberPackage/SimpleMap.java b/AirBomber/src/AirBomberPackage/SimpleMap.java
new file mode 100644
index 0000000..32ed0a8
--- /dev/null
+++ b/AirBomber/src/AirBomberPackage/SimpleMap.java
@@ -0,0 +1,60 @@
+/*
+ * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
+ * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
+ */
+package AirBomberPackage;
+import java.awt.*;
+/**
+ *
+ * @author Андрей
+ */
+public class SimpleMap extends AbstractMap {
+ ///
+ /// Цвет участка закрытого
+ ///
+ private final Color barrierColor = Color.BLACK;
+ ///
+ /// Цвет участка открытого
+ ///
+ private final Color roadColor = Color.GRAY;
+
+ @Override
+ protected void DrawBarrierPart(Graphics g, int i, int j)
+ {
+ g.setColor(barrierColor);
+ g.fillRect(i * _size_x, j * _size_y, _size_x, _size_y);
+ g.setColor(Color.BLACK);
+ }
+ @Override
+ protected void DrawRoadPart(Graphics g, int i, int j)
+ {
+ g.setColor(roadColor);
+ g.fillRect(i * _size_x, j * _size_y, _size_x, _size_y);
+ g.setColor(Color.BLACK);
+ }
+ @Override
+ protected void GenerateMap()
+ {
+ _map = new int[100][100];
+ _size_x = _width / _map.length;
+ _size_y = _height / _map[0].length;
+ int counter = 0;
+ for (int i = 0; i < _map.length; ++i)
+ {
+ for (int j = 0; j < _map[0].length; ++j)
+ {
+ _map[i][j] = _freeRoad;
+ }
+ }
+ while (counter < 50)
+ {
+ int x = _random.nextInt(0, 100);
+ int y = _random.nextInt(0, 100);
+ if (_map[x][y] == _freeRoad)
+ {
+ _map[x][y] = _barrier;
+ counter++;
+ }
+ }
+ }
+}