From 6bdd753c333e1e7dde1cb78615df5ac77fb557f6 Mon Sep 17 00:00:00 2001 From: Programmist73 Date: Thu, 3 Nov 2022 22:49:09 +0400 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5=20=D0=B8=D0=BD=D1=82=D0=B5=D1=80=D1=84=D0=B5?= =?UTF-8?q?=D0=B9=D1=81=D0=BE=D0=B2=20=D0=B8=20=D0=B0=D0=B1=D1=81=D1=82?= =?UTF-8?q?=D1=80=D0=B0=D0=BA=D1=82=D0=BD=D0=BE=D0=B3=D0=BE=20=D0=BA=D0=BB?= =?UTF-8?q?=D0=B0=D1=81=D1=81=D0=B0.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .idea/Hard.iml | 4 +- .idea/misc.xml | 2 +- Project/.idea/misc.xml | 2 +- Project/src/.idea/.gitignore | 3 + Project/src/.idea/misc.xml | 6 + Project/src/.idea/modules.xml | 8 ++ Project/src/.idea/vcs.xml | 6 + Project/src/AbstractMap.java | 167 ++++++++++++++++++++++ Project/src/IAdditionalDrawingObject.java | 7 + Project/src/IDrawningObject.java | 18 +++ Project/src/Project.iml | 11 ++ 11 files changed, 231 insertions(+), 3 deletions(-) create mode 100644 Project/src/.idea/.gitignore create mode 100644 Project/src/.idea/misc.xml create mode 100644 Project/src/.idea/modules.xml create mode 100644 Project/src/.idea/vcs.xml create mode 100644 Project/src/AbstractMap.java create mode 100644 Project/src/IAdditionalDrawingObject.java create mode 100644 Project/src/IDrawningObject.java create mode 100644 Project/src/Project.iml diff --git a/.idea/Hard.iml b/.idea/Hard.iml index d6ebd48..b107a2d 100644 --- a/.idea/Hard.iml +++ b/.idea/Hard.iml @@ -2,7 +2,9 @@ - + + + diff --git a/.idea/misc.xml b/.idea/misc.xml index 639900d..1ce6e7f 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,6 +1,6 @@ - + \ No newline at end of file diff --git a/Project/.idea/misc.xml b/Project/.idea/misc.xml index 1ce6e7f..e2ca0b8 100644 --- a/Project/.idea/misc.xml +++ b/Project/.idea/misc.xml @@ -1,6 +1,6 @@ - + \ No newline at end of file diff --git a/Project/src/.idea/.gitignore b/Project/src/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/Project/src/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/Project/src/.idea/misc.xml b/Project/src/.idea/misc.xml new file mode 100644 index 0000000..1ce6e7f --- /dev/null +++ b/Project/src/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Project/src/.idea/modules.xml b/Project/src/.idea/modules.xml new file mode 100644 index 0000000..2ff9c41 --- /dev/null +++ b/Project/src/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/Project/src/.idea/vcs.xml b/Project/src/.idea/vcs.xml new file mode 100644 index 0000000..b2bdec2 --- /dev/null +++ b/Project/src/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Project/src/AbstractMap.java b/Project/src/AbstractMap.java new file mode 100644 index 0000000..65847c5 --- /dev/null +++ b/Project/src/AbstractMap.java @@ -0,0 +1,167 @@ +import java.awt.*; +import java.awt.image.BufferedImage; +import java.util.Random; + +public abstract class AbstractMap +{ + private IDrawningObject _drawingObject = null; + protected int[][] _map = null; + protected int _width; + protected int _height; + protected float _size_x; + protected float _size_y; + protected float[] position; + protected Random _random = new Random(); + protected int _freeRoad = 0; + protected int _barrier = 1; + + public BufferedImage CreateMap(int width, int height, IDrawningObject drawningObject) + { + _width = width; + _height = height; + _drawingObject = drawningObject; + + GenerateMap(); + while (!SetObjectOnMap()) + { + GenerateMap(); + } + + return DrawMapWithObject(); + } + + //проверка на "накладывание" + protected boolean CheckPosition(float Left, float Right, float Top, float Bottom) + { + int x_start = (int)(Left / _size_x); + int y_start = (int)(Right / _size_y); + int x_end = (int)(Top / _size_x); + int y_end = (int)(Bottom / _size_y); + + for(int i = x_start; i <= x_end; i++) + { + for(int j = y_start; j <= y_end; j++) + { + if (_map[i][j] == _barrier) + { + return true; + } + } + } + + return false; + } + + public BufferedImage MoveObject(Direction direction) + { + position = _drawingObject.GetCurrentPosition(); + + for (int i = 0; i < _map.length; ++i) + { + for (int j = 0; j < _map[i].length; ++j) + { + if (_map[i][j] == _barrier) + { + switch (direction) + { + case Up: + if(_size_y * (j+1) >= position[0] - _drawingObject.Step() && _size_y * (j+1) < position[0] && _size_x * (i + 1) > position[3] + && _size_x * (i + 1) <= position[1]) + { + return DrawMapWithObject(); + } + break; + case Down: + if (_size_y * j <= position[2] + _drawingObject.Step() && _size_y * j > position[2] && _size_x * (i+1) > position[3] + && _size_x * (i+1) <= position[1]) + { + return DrawMapWithObject(); + } + break; + case Left: + if (_size_x * (i+1) >= position[3] - _drawingObject.Step() && _size_x * (i + 1) < position[3] && _size_y * (j + 1) < position[2] + && _size_y * (j + 1) >= position[0]) + { + return DrawMapWithObject(); + } + break; + case Right: + if (_size_x * i <= position[1] + _drawingObject.Step() && _size_x * i > position[3] && _size_y * (j + 1) < position[2] + && _size_y * (j + 1) >= position[0]) + { + return DrawMapWithObject(); + } + break; + } + } + } + } + + _drawingObject.MoveObject(direction); + return DrawMapWithObject(); + } + + private boolean SetObjectOnMap() + { + if(_drawingObject == null || _map == null) + { + return false; + } + + int x = _random.nextInt(10); + int y = _random.nextInt(10); + _drawingObject.SetObject(x, y, _width, _height); + + for (int i = 0; i < _map.length; ++i) + { + for(int j = 0; j < _map[0].length; ++j) + { + if(i * _size_x >= x && j * _size_y >= y && + i * _size_x <= x + _drawingObject.GetCurrentPosition()[1] && + j * _size_y <= j + _drawingObject.GetCurrentPosition()[2]) + { + if (_map[i][j] == _barrier) + { + return false; + } + } + } + } + + return true; + } + + private BufferedImage DrawMapWithObject() + { + BufferedImage bmp = new BufferedImage(_width, _height, BufferedImage.TYPE_INT_RGB); + + if(_drawingObject == null || _map == null) + { + return bmp; + } + + Graphics gr = bmp.getGraphics(); + + 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); + } + } + } + + _drawingObject.DrawningObject(gr); + return bmp; + } + + protected abstract void GenerateMap(); + protected abstract void DrawRoadPart(Graphics g, int i, int j); + protected abstract void DrawBarrierPart(Graphics g, int i, int j); +} \ No newline at end of file diff --git a/Project/src/IAdditionalDrawingObject.java b/Project/src/IAdditionalDrawingObject.java new file mode 100644 index 0000000..cf9f27b --- /dev/null +++ b/Project/src/IAdditionalDrawingObject.java @@ -0,0 +1,7 @@ +import java.awt.*; + +public interface IAdditionalDrawingObject +{ + void SetAddEnum(int airplaneWindow); + void DrawAirplaneWindow(Color colorAirplaneWindow, Graphics g, float _startPosX, float _startPosY); +} diff --git a/Project/src/IDrawningObject.java b/Project/src/IDrawningObject.java new file mode 100644 index 0000000..5d5092e --- /dev/null +++ b/Project/src/IDrawningObject.java @@ -0,0 +1,18 @@ +import java.awt.*; + +public interface IDrawningObject { + //шаг перемещения объекта + public float Step(); + + //установка позиции объекта + void SetObject(int x, int y, int width, int height); + + //изменение направления перемещения объекта + void MoveObject(Direction direction); + + //отрисовка объекта + void DrawningObject(Graphics g); + + //получение текущей позиции объекта + float[] GetCurrentPosition(); +} diff --git a/Project/src/Project.iml b/Project/src/Project.iml new file mode 100644 index 0000000..b107a2d --- /dev/null +++ b/Project/src/Project.iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file