From 315ef45c937a33052b6fba736177536d73bcbf3e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=92=D0=BE=D0=BB=D0=BE=D0=B4=D1=8F?= Date: Sun, 4 Dec 2022 12:42:37 +0300 Subject: [PATCH] =?UTF-8?q?=D0=9B=D0=B0=D0=B1=2002?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- RadarAirplane/src/AbstractMap.java | 188 ++++++++++++++++++ RadarAirplane/src/DrawingEntityPlain.java | 46 ++++- RadarAirplane/src/DrawingObjectPlain.java | 41 ++++ RadarAirplane/src/DrawingPorthole.java | 14 +- RadarAirplane/src/DrawingRadarPlain.java | 32 +++ RadarAirplane/src/DrawingSquarePorthole.java | 41 ++++ .../src/DrawingTrianglePorthole.java | 50 +++++ RadarAirplane/src/EntityAirPlane.java | 2 +- RadarAirplane/src/EntityRadarPlain.java | 18 ++ RadarAirplane/src/FormAirPlane.java | 4 +- RadarAirplane/src/IDrawingObject.java | 11 + RadarAirplane/src/IDrawingPorthole.java | 6 + RadarAirplane/src/MyMap.java | 59 ++++++ RadarAirplane/src/Program.java | 2 +- RadarAirplane/src/SimpleMap.java | 47 +++++ RadarAirplane/src/formMap.form | 176 ++++++++++++++++ RadarAirplane/src/formMap.java | 119 +++++++++++ 17 files changed, 835 insertions(+), 21 deletions(-) create mode 100644 RadarAirplane/src/AbstractMap.java create mode 100644 RadarAirplane/src/DrawingObjectPlain.java create mode 100644 RadarAirplane/src/DrawingRadarPlain.java create mode 100644 RadarAirplane/src/DrawingSquarePorthole.java create mode 100644 RadarAirplane/src/DrawingTrianglePorthole.java create mode 100644 RadarAirplane/src/EntityRadarPlain.java create mode 100644 RadarAirplane/src/IDrawingObject.java create mode 100644 RadarAirplane/src/IDrawingPorthole.java create mode 100644 RadarAirplane/src/MyMap.java create mode 100644 RadarAirplane/src/SimpleMap.java create mode 100644 RadarAirplane/src/formMap.form create mode 100644 RadarAirplane/src/formMap.java diff --git a/RadarAirplane/src/AbstractMap.java b/RadarAirplane/src/AbstractMap.java new file mode 100644 index 0000000..cb98a54 --- /dev/null +++ b/RadarAirplane/src/AbstractMap.java @@ -0,0 +1,188 @@ +import java.awt.*; +import java.util.Random; + +public abstract class AbstractMap +{ + private IDrawingObject _drawningObject = null; + protected int[][] _map = null; + protected int _width; + protected int _height; + protected float _size_x; + protected float _size_y; + protected Random _random = new Random(); + protected int _freeRoad = 0; + protected int _barrier = 1; + public void CreateMap(int width, int height, IDrawingObject drawningObject) + { + _width = width; + _height = height; + _drawningObject = drawningObject; + GenerateMap(); + while (!SetObjectOnMap()) + { + GenerateMap(); + } + } + + private Point checkBarrier(Point leftTop, Point rightBottom) + { + return checkBarrier(leftTop, rightBottom, false, false, true, false); + } + private Point checkBarrier(Point leftTop, Point rightBottom, boolean minLeft, boolean maxLeft, boolean isTop, boolean isBottom) + { + Point res = new Point(-1, -1); + + for (int i = (int)(leftTop.y / _size_y); i <= (int)(rightBottom.y / _size_y) && i < _map.length; ++i) + { + for (int j = (int)(leftTop.x / _size_x); j <= (int)(rightBottom.x / _size_x) && j < _map[0].length; ++j) + { + if (j < 0) j = 0; + if (i < 0) i = 0; + if (_map[i][j] != _barrier) continue; + + if (res.y == -1) res = new Point(j, i); + if (minLeft && res.x > j) res = new Point(j, i); + if (maxLeft && res.x < j) res = new Point(j, i); + if(isBottom) res = new Point(j, i); + if (isTop) return new Point(j, i); + } + } + + return res; + } + public void MoveObject(Direction direction) + { + + + Point leftTop = _drawningObject.GetLeftTop(); + Point rightBottom = _drawningObject.GetRightBottom(); + + float drawningWidth = rightBottom.x - leftTop.x; + float drawningHeight = rightBottom.y - leftTop.y; + + boolean minLeft = false; + boolean maxLeft = false; + boolean isTop = false; + boolean isBottom = false; + + if (direction == Direction.Left) + { + leftTop.x -= _drawningObject.getStep(); + maxLeft = true; + } + if (direction == Direction.Right) + { + leftTop.x += _drawningObject.getStep(); + minLeft = true; + } + if (direction == Direction.Up) { + leftTop.y -= _drawningObject.getStep(); + isTop = true; + } + if (direction == Direction.Down) + { + leftTop.y += _drawningObject.getStep(); + isBottom = true; + } + + rightBottom.x = leftTop.x + (int)drawningWidth; + rightBottom.y = leftTop.y + (int)drawningHeight; + + Point currentBarrier = checkBarrier(leftTop, rightBottom, minLeft, maxLeft, isTop, isBottom); + + if (currentBarrier.x == -1) + { + _drawningObject.MoveObject(direction); + } + + else if (direction == Direction.Left) + leftTop.x = (int)((currentBarrier.x + 1) * _size_x) + 1; + + else if (direction == Direction.Right) + leftTop.x = (int)(currentBarrier.x * _size_x) - (int)drawningWidth - 1; + + else if (direction == Direction.Up) + leftTop.y = (int)((currentBarrier.y + 1) * _size_y) + 1; + + else if (direction == Direction.Down) + leftTop.y = (int)(currentBarrier.y * _size_y) - (int)drawningHeight - 1; + + if (currentBarrier.y != -1) + _drawningObject.SetObject(leftTop.x, leftTop.y, _width, _height); + + } + 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); + + + Point leftTop = _drawningObject.GetLeftTop(); + Point rightBottom = _drawningObject.GetRightBottom(); + + float drawningWidth = rightBottom.x - leftTop.x; + float drawningHeight = rightBottom.y - leftTop.y; + + Point currentBarrier = checkBarrier(leftTop, rightBottom); + int minRowIndex = _map.length; + + while(currentBarrier.y != -1) + { + minRowIndex = currentBarrier.y < minRowIndex ? currentBarrier.y : minRowIndex; + + leftTop.x = (int)((currentBarrier.x + 1) * _size_x) + 1; + rightBottom.x = leftTop.x + (int)drawningWidth; + + if(rightBottom.x > _width) + { + leftTop.y = (int)((minRowIndex + 1) * _size_y) + 1; + rightBottom.y = leftTop.y + (int)drawningHeight; + + leftTop.x = 0; + rightBottom.x = (int)drawningWidth; + + minRowIndex = _map.length; + } + + if (rightBottom.y > _height) { + return false; + } + + currentBarrier = checkBarrier(leftTop, rightBottom); + } + + _drawningObject.SetObject((int)leftTop.x, (int)leftTop.y, _width, _height); + + return true; + } + public void DrawMapWithObject(Graphics2D gr) + { + if (_drawningObject == null || _map == null) + { + return; + } + for (int i = 0; i < _map.length; ++i) + { + for (int j = 0; j < _map[0].length; ++j) + { + if (_map[i][j] == _freeRoad) + { + DrawRoadPart(gr, i, j); + } + else if (_map[i][j] == _barrier) + { + DrawBarrierPart(gr, i, j); + } + } + } + _drawningObject.DrawningObject(gr); + } + protected abstract void GenerateMap(); + protected abstract void DrawRoadPart(Graphics2D g, int i, int j); + protected abstract void DrawBarrierPart(Graphics2D g, int i, int j); +} \ No newline at end of file diff --git a/RadarAirplane/src/DrawingEntityPlain.java b/RadarAirplane/src/DrawingEntityPlain.java index 34ad00b..e74d87e 100644 --- a/RadarAirplane/src/DrawingEntityPlain.java +++ b/RadarAirplane/src/DrawingEntityPlain.java @@ -3,9 +3,9 @@ import java.util.Random; class DrawingEntityPlain { public EntityAirPlane Airplane; - public DrawingPorthole drawingPortholes = new DrawingPorthole(); - private float _startPosX; - private float _startPosY; + public IDrawingPorthole drawingPortholes; + protected float _startPosX; + protected float _startPosY; private int _pictureWidth = -1; private int _pictureHeight = -1; @@ -13,14 +13,35 @@ class DrawingEntityPlain private int _AirplaneWidth = 240; private int _AirplaneHeight = 150; - public void Init(int speed, float weight, Color bodyColor) - { + private void peekRandomPortholes(Color color) { Random rnd = new Random(); - Airplane = new EntityAirPlane(); - Airplane.Init(speed, weight, bodyColor); - drawingPortholes.Init(rnd.nextInt(1, 35),Airplane.BodyColor); + int randPorthole = rnd.nextInt(1, 4); + + switch(randPorthole) { + case 1: + drawingPortholes = new DrawingPorthole(rnd.nextInt(1, 35), color); + break; + case 2: + drawingPortholes = new DrawingSquarePorthole(rnd.nextInt(1, 35), color); + break; + case 3: + drawingPortholes = new DrawingTrianglePorthole(rnd.nextInt(1, 35), color); + break; + } } + public DrawingEntityPlain(int speed, float weight, Color bodyColor) + { + Airplane = new EntityAirPlane(speed, weight, bodyColor); + peekRandomPortholes(bodyColor); + } + + public DrawingEntityPlain(int speed, float weight, Color bodyColor, int airPlaneWidth, int airPlaneHeight) + { + this(speed, weight, bodyColor); + _AirplaneWidth = airPlaneWidth; + _AirplaneHeight = airPlaneHeight; + } public void SetPosition(int x, int y, int width, int height) { if (width < _AirplaneWidth || height < _AirplaneHeight) return; @@ -80,7 +101,7 @@ class DrawingEntityPlain return; } - + g.setPaint(Color.black); g.drawRect( (int)_startPosX, (int)_startPosY, 40, 60); g.drawRect( (int)_startPosX, (int)_startPosY + 60, 200, 60); g.drawRect( (int)_startPosX+100, (int)_startPosY + 80, 40, 30); @@ -126,5 +147,12 @@ class DrawingEntityPlain _startPosY = _pictureHeight - _AirplaneHeight; } } + public Point getLeftTop() { + return new Point((int)_startPosX, (int)_startPosY); + } + + public Point getRightBottom() { + return new Point((int)_startPosX + _AirplaneWidth, (int)_startPosY + _AirplaneHeight); + } } \ No newline at end of file diff --git a/RadarAirplane/src/DrawingObjectPlain.java b/RadarAirplane/src/DrawingObjectPlain.java new file mode 100644 index 0000000..f481706 --- /dev/null +++ b/RadarAirplane/src/DrawingObjectPlain.java @@ -0,0 +1,41 @@ +import java.awt.*; + +public class DrawingObjectPlain implements IDrawingObject +{ + private DrawingEntityPlain _airplain = null; + public DrawingObjectPlain(DrawingEntityPlain aircraft){ + _airplain = aircraft; + } + + public void MoveObject(Direction direction) { + if(_airplain == null) return; + _airplain.MoveTransport(direction); + } + + @Override + public float getStep() { + if(_airplain == null) return 0; + return _airplain.Airplane.Step; + } + + public void SetObject(int x, int y, int width, int height) + { + _airplain.SetPosition(x, y, width, height); + } + public void DrawningObject(Graphics2D g) + { + _airplain.DrawTransport(g); + } + + @Override + public Point GetLeftTop() { + if(_airplain == null) return new Point(0,0); + return _airplain.getLeftTop(); + } + + @Override + public Point GetRightBottom() { + if(_airplain == null) return new Point(0,0); + return _airplain.getRightBottom(); + } +} \ No newline at end of file diff --git a/RadarAirplane/src/DrawingPorthole.java b/RadarAirplane/src/DrawingPorthole.java index 9dd300a..cb95422 100644 --- a/RadarAirplane/src/DrawingPorthole.java +++ b/RadarAirplane/src/DrawingPorthole.java @@ -1,24 +1,24 @@ import java.awt.*; -public class DrawingPorthole { +public class DrawingPorthole implements IDrawingPorthole { private Porthole PortholeCount; Color color; - public void SetCount(int count){ + @Override + public void setCount(int count){ if(count <= 10) PortholeCount = Porthole.Ten; else if(count >= 30) PortholeCount = Porthole.Twenty; else PortholeCount = Porthole.Thirty; } - public void Init(int count, Color bodyColor) { - SetCount(count); + public DrawingPorthole(int count, Color bodyColor) { + setCount(count); color = bodyColor; } public void draw(Graphics2D g, int startPosX, int startPosY) { - g.setPaint(Color.white); int count = 0; int i = -1; int j = 0; @@ -32,12 +32,12 @@ public class DrawingPorthole { if(PortholeCount == Porthole.Ten && count==10) break; else if(PortholeCount == Porthole.Twenty && count==20) break; else if(PortholeCount == Porthole.Thirty && count==30) break; + g.setPaint(Color.black); g.drawOval(startPosX+i*12 , startPosY + j, 10, 10); + g.setPaint(color); g.fillOval(startPosX+i*12, startPosY + j, 10, 10); count++; } - - } } diff --git a/RadarAirplane/src/DrawingRadarPlain.java b/RadarAirplane/src/DrawingRadarPlain.java new file mode 100644 index 0000000..9781da8 --- /dev/null +++ b/RadarAirplane/src/DrawingRadarPlain.java @@ -0,0 +1,32 @@ +import java.awt.*; + +public class DrawingRadarPlain extends DrawingEntityPlain +{ + public DrawingRadarPlain(int speed, float weight, Color bodyColor, Color dopColor, boolean Radar, boolean OilBox) + { + super(speed, weight, bodyColor, 240, 150); + Airplane = new EntityRadarPlain(speed, weight, bodyColor, dopColor, Radar, OilBox); + } + @Override + public void DrawTransport(Graphics2D g) + { + if (!(Airplane instanceof EntityRadarPlain)) + { + return; + } + + EntityRadarPlain radarPlain = (EntityRadarPlain)Airplane; + super.DrawTransport(g); + g.setPaint(radarPlain.DopColor); + if (radarPlain.Radar) + { + g.fillRect( (int)_startPosX +110, (int)_startPosY + 40, 20, 20); + g.fillOval( (int)_startPosX + 80, (int)_startPosY + 26, 80, 20); + } + + if (radarPlain.OilBox) { + g.fillRect((int) _startPosX + 80, (int) _startPosY + 96, 40, 20); + g.fillRect((int) _startPosX, (int) _startPosY + 30, 60, 20); + } + } +} diff --git a/RadarAirplane/src/DrawingSquarePorthole.java b/RadarAirplane/src/DrawingSquarePorthole.java new file mode 100644 index 0000000..d31f271 --- /dev/null +++ b/RadarAirplane/src/DrawingSquarePorthole.java @@ -0,0 +1,41 @@ +import java.awt.*; + +public class DrawingSquarePorthole implements IDrawingPorthole { + private Porthole PortholeCount; + private Color color; + + public DrawingSquarePorthole(int count, Color bodyColor) { + setCount(count); + color = bodyColor; + } + + @Override + public void setCount(int count) { + if(count <= 10) PortholeCount = Porthole.Ten; + else if(count >= 30) PortholeCount = Porthole.Twenty; + else PortholeCount = Porthole.Thirty; + } + + public void draw(Graphics2D g, int startPosX, int startPosY) { + g.setPaint(color); + int count = 0; + int i = -1; + int j = 0; + while(true) + { + if(i==14) { + i = 0; + j=30; + } + else i++; + if(PortholeCount == Porthole.Ten && count==10) break; + else if(PortholeCount == Porthole.Twenty && count==20) break; + else if(PortholeCount == Porthole.Thirty && count==30) break; + g.setPaint(Color.black); + g.drawRect(startPosX+i*12 , startPosY + j, 10, 10); + g.setPaint(color); + g.fillRect(startPosX+i*12, startPosY + j, 10, 10); + count++; + } + } +} \ No newline at end of file diff --git a/RadarAirplane/src/DrawingTrianglePorthole.java b/RadarAirplane/src/DrawingTrianglePorthole.java new file mode 100644 index 0000000..1a9e958 --- /dev/null +++ b/RadarAirplane/src/DrawingTrianglePorthole.java @@ -0,0 +1,50 @@ +import java.awt.*; + +public class DrawingTrianglePorthole implements IDrawingPorthole { + private Porthole PortholeCount; + private Color color; + + public DrawingTrianglePorthole(int count, Color bodyColor) { + setCount(count); + color = bodyColor; + } + + @Override + public void setCount(int count) { + if(count <= 10) PortholeCount = Porthole.Ten; + else if(count >= 30) PortholeCount = Porthole.Twenty; + else PortholeCount = Porthole.Thirty; + } + + private void drawEngine(Graphics2D g, int x, int y) { + + g.setColor(Color.black); + g.drawRect(x+2, y, 4, 5); + g.drawRect(x, y+5, 5, 5); + g.drawRect(x+5, y+5, 5, 5); + g.setPaint(color); + g.fillRect(x+2, y, 4, 5); + g.fillRect(x, y+5, 5, 5); + g.fillRect(x+5, y+5, 5, 5); + + } + + public void draw(Graphics2D g, int startPosX, int startPosY) { + int count = 0; + int i = -1; + int j = 0; + while(true) + { + if(i==14) { + i = 0; + j=30; + } + else i++; + if(PortholeCount == Porthole.Ten && count==10) break; + else if(PortholeCount == Porthole.Twenty && count==20) break; + else if(PortholeCount == Porthole.Thirty && count==30) break; + drawEngine(g,startPosX+i*12 , startPosY + j); + count++; + } + } +} \ No newline at end of file diff --git a/RadarAirplane/src/EntityAirPlane.java b/RadarAirplane/src/EntityAirPlane.java index 7559eec..48e22e1 100644 --- a/RadarAirplane/src/EntityAirPlane.java +++ b/RadarAirplane/src/EntityAirPlane.java @@ -9,7 +9,7 @@ class EntityAirPlane public float Step; - public void Init(int speed, float weight, Color bodyColor) + public EntityAirPlane(int speed, float weight, Color bodyColor) { Random rnd = new Random(); diff --git a/RadarAirplane/src/EntityRadarPlain.java b/RadarAirplane/src/EntityRadarPlain.java new file mode 100644 index 0000000..619effc --- /dev/null +++ b/RadarAirplane/src/EntityRadarPlain.java @@ -0,0 +1,18 @@ +import java.awt.*; + +public class EntityRadarPlain extends EntityAirPlane +{ + public Color DopColor; + public boolean Radar; + public boolean OilBox; + + + public EntityRadarPlain(int speed, float weight, Color bodyColor, Color + dopColor, boolean radar, boolean oil) + { + super(speed, weight, bodyColor); + DopColor = dopColor; + Radar = radar; + OilBox = oil; + } +} \ No newline at end of file diff --git a/RadarAirplane/src/FormAirPlane.java b/RadarAirplane/src/FormAirPlane.java index f02cf12..7e93acc 100644 --- a/RadarAirplane/src/FormAirPlane.java +++ b/RadarAirplane/src/FormAirPlane.java @@ -40,9 +40,7 @@ public class FormAirPlane implements Form { Dimension canvSize = canv.getSize(); Random rnd = new Random(); - _airPlane = new DrawingEntityPlain(); - - _airPlane.Init(rnd.nextInt(100, 300), rnd.nextInt(1000, 2000), + _airPlane = new DrawingEntityPlain(rnd.nextInt(100, 300), rnd.nextInt(1000, 2000), new Color(rnd.nextInt(0, 256), rnd.nextInt(0, 256), rnd.nextInt(0, 256))); _airPlane.SetPosition((int)rnd.nextInt(10, 100), (int)rnd.nextInt(10, 100), canvSize.width, canvSize.height); diff --git a/RadarAirplane/src/IDrawingObject.java b/RadarAirplane/src/IDrawingObject.java new file mode 100644 index 0000000..8594f34 --- /dev/null +++ b/RadarAirplane/src/IDrawingObject.java @@ -0,0 +1,11 @@ +import java.awt.*; + +public interface IDrawingObject +{ + float getStep(); + void SetObject(int x, int y, int width, int height); + void MoveObject(Direction direction); + void DrawningObject(Graphics2D g); + Point GetLeftTop(); + Point GetRightBottom(); +} \ No newline at end of file diff --git a/RadarAirplane/src/IDrawingPorthole.java b/RadarAirplane/src/IDrawingPorthole.java new file mode 100644 index 0000000..8e5bfea --- /dev/null +++ b/RadarAirplane/src/IDrawingPorthole.java @@ -0,0 +1,6 @@ +import java.awt.*; + +public interface IDrawingPorthole { + void setCount(int count); + void draw(Graphics2D g, int x, int y); +} \ No newline at end of file diff --git a/RadarAirplane/src/MyMap.java b/RadarAirplane/src/MyMap.java new file mode 100644 index 0000000..2d21612 --- /dev/null +++ b/RadarAirplane/src/MyMap.java @@ -0,0 +1,59 @@ +import java.awt.*; +import java.util.Random; +public class MyMap extends AbstractMap +{ + + private Color barrierColor = Color.BLACK; + private Color roadColor = new Color(235,252,255); + Random rnd = new Random(); + + @Override + protected void DrawBarrierPart(Graphics2D g, int i, int j) + { + g.setPaint(barrierColor); + g.fillRect((int)(j * _size_x), (int)(i * _size_y), (int)Math.ceil(_size_x), (int)Math.ceil(_size_y)); + } + + @Override + protected void DrawRoadPart(Graphics2D g, int i, int j) + { + g.setPaint(roadColor); + g.fillRect((int)(j * _size_x), (int)(i * _size_y), (int)Math.ceil(_size_x), (int)Math.ceil(_size_y)); + } + + @Override + protected void GenerateMap() + { + _map = new int[100][ 100]; + _size_x = (float)_width / _map.length; + _size_y = (float)_height / _map[0].length; + int sizeHole = 70; + 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 < 3) + { + Random rand = new Random(); + int iWall = rnd.nextInt(0, 100); + int jWall = rnd.nextInt(0, 100); + if (iWall > _map.length - sizeHole) + continue; + for (int i = 0; i < _map.length; i++) + { + + if (i < iWall || i > iWall + sizeHole) + _map[jWall][i] = _barrier; + + } + counter++; + } + + + } + + +} \ No newline at end of file diff --git a/RadarAirplane/src/Program.java b/RadarAirplane/src/Program.java index 113c3d8..1efe066 100644 --- a/RadarAirplane/src/Program.java +++ b/RadarAirplane/src/Program.java @@ -3,6 +3,6 @@ import java.awt.*; public class Program { public static void main(String[] args) { - new FormAirPlane().run(); + new formMap().run(); } } \ No newline at end of file diff --git a/RadarAirplane/src/SimpleMap.java b/RadarAirplane/src/SimpleMap.java new file mode 100644 index 0000000..08d95c1 --- /dev/null +++ b/RadarAirplane/src/SimpleMap.java @@ -0,0 +1,47 @@ +import java.awt.*; + +public class SimpleMap extends AbstractMap +{ + private Color barrierColor = Color.BLACK; + private Color roadColor = new Color(235,252,255); + + @Override + protected void DrawBarrierPart(Graphics2D g, int i, int j) + { + g.setPaint(barrierColor); + g.fillRect((int)(j * _size_x), (int)(i * _size_y), (int)Math.ceil(_size_x), (int)Math.ceil(_size_y)); + } + + @Override + protected void DrawRoadPart(Graphics2D g, int i, int j) + { + g.setPaint(roadColor); + g.fillRect((int)(j * _size_x), (int)(i * _size_y), (int)Math.ceil(_size_x), (int)Math.ceil(_size_y)); + } + + @Override + protected void GenerateMap() + { + _map = new int[100][100]; + _size_x = (float)_width / _map.length; + _size_y = (float)_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 < 20) + { + int x = _random.nextInt(0, 100); + int y = _random.nextInt(0, 100); + if (_map[x][y] == _freeRoad) + { + _map[x][y] = _barrier; + counter++; + } + } + } +} \ No newline at end of file diff --git a/RadarAirplane/src/formMap.form b/RadarAirplane/src/formMap.form new file mode 100644 index 0000000..5a4f232 --- /dev/null +++ b/RadarAirplane/src/formMap.form @@ -0,0 +1,176 @@ + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
diff --git a/RadarAirplane/src/formMap.java b/RadarAirplane/src/formMap.java new file mode 100644 index 0000000..1c13514 --- /dev/null +++ b/RadarAirplane/src/formMap.java @@ -0,0 +1,119 @@ +import javax.swing.*; +import java.awt.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.util.Random; + +public class formMap implements Form { + private JPanel DrawPlace; + private JLabel weightLabel; + private JLabel speedLabel; + private JLabel colorLabel; + private JButton createButton; + private JButton downButton; + private JButton leftButton; + private JButton rightButton; + private JButton upButton; + private JComboBox comboBoxSelectorMap; + private JPanel mainPanel; + private JButton modifiedButton; + + private Canvas canv = new Canvas(this); + private DrawingEntityPlain _airplane; + private AbstractMap _abstractMap = new SimpleMap(); + private JFrame jframe = getFrame(); + + public formMap() { + } + + private JFrame getFrame() { + JFrame frame = new JFrame(); + frame.setVisible(true); + frame.setBounds(300, 100, 800, 600); + frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + return frame; + } + + private void SetData(DrawingEntityPlain airplane) + { + Color bodyColor = _airplane.Airplane.BodyColor; + String colorString = "(" + bodyColor.getRed() + ", " + bodyColor.getGreen() + ", " + bodyColor.getBlue() + ")"; + + speedLabel.setText("Скорость: " + _airplane.Airplane.Speed + " "); + weightLabel.setText("Вес: " + _airplane.Airplane.Weight + " "); + colorLabel.setText("Цвет: " + colorString); + + Dimension canvSize = canv.getSize(); + + _abstractMap.CreateMap(canvSize.width, canvSize.height, new DrawingObjectPlain(airplane)); + } + + public void run() { + jframe.add(mainPanel); + DrawPlace.add(canv); + + comboBoxSelectorMap.addActionListener(e -> { + String selectedItem = comboBoxSelectorMap.getSelectedItem().toString(); + switch(selectedItem) { + case "Простая карта": + _abstractMap = new SimpleMap(); + break; + case "Моя карта": + _abstractMap = new MyMap(); + break; + } + }); + + createButton.addActionListener(e -> { + Random rnd = new Random(); + + _airplane = new DrawingEntityPlain(rnd.nextInt(100, 300), rnd.nextInt(1000, 2000), + new Color(rnd.nextInt(0, 256), rnd.nextInt(0, 256), rnd.nextInt(0, 256))); + + SetData(_airplane); + canv.repaint(); + }); + + modifiedButton.addActionListener(e -> { + Random rnd = new Random(); + + _airplane = new DrawingRadarPlain(rnd.nextInt(100, 300), rnd.nextInt(1000, 2000), + new Color(rnd.nextInt(0, 256), rnd.nextInt(0, 256), rnd.nextInt(0, 256)), + new Color(rnd.nextInt(0, 256), rnd.nextInt(0, 256), rnd.nextInt(0, 256)), + rnd.nextInt(0, 2) == 1, rnd.nextInt(0, 2) == 1); + + + SetData(_airplane); + canv.repaint(); + }); + + downButton.addActionListener(e -> { + if(_abstractMap == null) return; + _abstractMap.MoveObject(Direction.Down); + canv.repaint(); + }); + + upButton.addActionListener(e -> { + if(_abstractMap == null) return; + _abstractMap.MoveObject(Direction.Up); + canv.repaint(); + }); + + leftButton.addActionListener(e -> { + if(_abstractMap == null) return; + _abstractMap.MoveObject(Direction.Left); + canv.repaint(); + }); + + rightButton.addActionListener(e -> { + if(_abstractMap == null) return; + _abstractMap.MoveObject(Direction.Right); + canv.repaint(); + }); + } + + @Override + public void Draw(Graphics2D g) { + _abstractMap.DrawMapWithObject(g); + } +} \ No newline at end of file