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