Compare commits

...

6 Commits

31 changed files with 2196 additions and 1 deletions

View File

@ -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);
}

View File

@ -0,0 +1,50 @@
import java.util.Random;
public class AirplaneMixer<T extends EntityAirPlane, U extends IDrawingPorthole> {
private T[] airplanes;
private U[] portholes;
public AirplaneMixer(int countAirplane, int countPortholes) {
airplanes = (T[])(new EntityAirPlane[countAirplane]);
portholes = (U[])(new IDrawingPorthole[countPortholes]);
}
public int add(T a) {
int index = 0;
while(index < airplanes.length && airplanes[index] != null) index++;
if(index == airplanes.length) return -1;
airplanes[index] = a;
return index;
}
public int add(U e) {
int index = 0;
while(index < portholes.length && portholes[index] != null) index++;
if(index == portholes.length) return -1;
portholes[index] = e;
return index;
}
public DrawingEntityPlain constructAirplane(int width, int height) {
Random rnd = new Random();
DrawingEntityPlain air;
T selectedAirplane = airplanes[rnd.nextInt(0, airplanes.length)];
U selectedPortholes = portholes[rnd.nextInt(0, portholes.length)];
DrawingEntityPlain result;
if(selectedAirplane instanceof EntityRadarPlain) {
result = new DrawingRadarPlain(selectedAirplane, selectedPortholes);
}
else result = new DrawingEntityPlain(selectedAirplane, selectedPortholes);
result.SetPosition(10, 10, width, height);
return result;
}
}

View File

@ -0,0 +1,15 @@
import javax.swing.*;
import java.awt.*;
public class Canvas extends JComponent {
Form form;
public Canvas(Form form) {
this.form = form;
}
@Override
public void paintComponent(Graphics g) {
Graphics2D g2 = (Graphics2D) g;
form.Draw(g2);
}
}

View File

@ -0,0 +1,6 @@
public enum Direction {
Up,
Right,
Left,
Down
}

View File

@ -0,0 +1,163 @@
import java.awt.*;
import java.util.Random;
class DrawingEntityPlain
{
public EntityAirPlane Airplane;
public IDrawingPorthole drawingPortholes;
protected float _startPosX;
protected float _startPosY;
private int _pictureWidth = -1;
private int _pictureHeight = -1;
private int _AirplaneWidth = 240;
private int _AirplaneHeight = 150;
private void peekRandomPortholes(Color color) {
Random rnd = new Random();
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 DrawingEntityPlain(EntityAirPlane entityAirPlane, IDrawingPorthole iDrawingPorthole){
Airplane = entityAirPlane;
drawingPortholes = iDrawingPorthole;
}
public void SetPosition(int x, int y, int width, int height)
{
if (width < _AirplaneWidth || height < _AirplaneHeight) return;
if (x + _AirplaneWidth > width || x < 0) return;
if (y + _AirplaneHeight > height || y < 0) return;
_startPosX = x;
_startPosY = y;
_pictureWidth = width;
_pictureHeight = height;
}
public void MoveTransport(Direction direction)
{
if (_pictureWidth == -1 || _pictureHeight == -1)
{
return;
}
switch (direction)
{
case Right:
if (_startPosX + _AirplaneWidth + Airplane.Step < _pictureWidth)
{
_startPosX += Airplane.Step;
}
break;
case Left:
if (_startPosX - Airplane.Step > 0)
{
_startPosX -= Airplane.Step;
}
break;
case Up:
if (_startPosY - Airplane.Step > 0)
{
_startPosY -= Airplane.Step;
}
break;
case Down:
if (_startPosY + _AirplaneHeight + Airplane.Step < _pictureHeight)
{
_startPosY += Airplane.Step;
}
break;
}
}
public void DrawTransport(Graphics2D g)
{
if (_pictureWidth == -1 || _pictureHeight == -1)
{
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);
//koleso1
g.drawRect( (int)_startPosX + 60, (int)_startPosY + 120, 10, 20);
g.drawOval( (int)_startPosX+56,(int) _startPosY+140, 18, 18);
//koleso2
g.drawRect( (int)_startPosX + 160, (int)_startPosY + 120, 10, 20);
g.drawOval( (int)_startPosX + 156, (int)_startPosY + 140, 18, 18);
//Korpys
g.setPaint(Airplane.BodyColor);
g.fillRect((int)_startPosX+6, (int)_startPosY + 66, 188, 48);
g.fillRect( (int)_startPosX+2, (int)_startPosY+2, 38, 58);
//krilya
g.setPaint(Color.black);
g.fillRect((int)_startPosX + 60, (int)_startPosY + 80, 80, 16);
//cabina
g.setPaint(Color.blue);
g.fillRect( (int)_startPosX + 202, (int)_startPosY + 82, 38, 28);
drawingPortholes.draw(g, (int)_startPosX+6, (int)_startPosY+70);
}
public void ChangeBorders(int width, int height)
{
_pictureWidth = width;
_pictureHeight = height;
if (_pictureWidth <= _AirplaneWidth || _pictureHeight <= _AirplaneHeight)
{
_pictureWidth = -1;
_pictureHeight = -1;
return;
}
if (_startPosX + _AirplaneWidth > _pictureWidth)
{
_startPosX = _pictureWidth - _AirplaneWidth;
}
if (_startPosY + _AirplaneHeight > _pictureHeight)
{
_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);
}
}

View File

@ -0,0 +1,44 @@
import java.awt.*;
public class DrawingObjectPlain implements IDrawingObject
{
private DrawingEntityPlain _airplain = null;
public DrawingObjectPlain(DrawingEntityPlain aircraft){
_airplain = aircraft;
}
public DrawingEntityPlain getAirPlane() {
return _airplain;
}
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();
}
}

View File

@ -0,0 +1,43 @@
import java.awt.*;
public class DrawingPorthole implements IDrawingPorthole {
private Porthole PortholeCount;
Color color;
@Override
public void setCount(int count){
if(count <= 10) PortholeCount = Porthole.Ten;
else if(count >= 30) PortholeCount = Porthole.Twenty;
else PortholeCount = Porthole.Thirty;
}
public DrawingPorthole(int count, Color bodyColor) {
setCount(count);
color = bodyColor;
}
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;
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++;
}
}
}

View File

@ -0,0 +1,35 @@
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);
}
public DrawingRadarPlain(EntityAirPlane entityAirPlane, IDrawingPorthole iDrawingPorthole){
super(entityAirPlane,iDrawingPorthole);
}
@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);
}
}
}

View File

@ -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++;
}
}
}

View File

@ -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++;
}
}
}

View File

@ -0,0 +1,22 @@
import java.awt.*;
import java.util.Random;
class EntityAirPlane
{
public int Speed;
public float Weight;
public Color BodyColor;
public float Step;
public EntityAirPlane(int speed, float weight, Color bodyColor)
{
Random rnd = new Random();
Speed = speed <= 0 ? rnd.nextInt(50, 150) : speed;
Weight = weight <= 0 ? rnd.nextInt(50, 70) : weight;
BodyColor = bodyColor;
Step = Speed * 100 / Weight;
}
}

View File

@ -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;
}
}

View File

@ -0,0 +1,5 @@
import java.awt.*;
public interface Form {
void Draw(Graphics2D g);
}

View File

@ -0,0 +1,148 @@
<?xml version="1.0" encoding="UTF-8"?>
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="FormAirPlane">
<grid id="27dc6" binding="mainPanel" layout-manager="GridLayoutManager" row-count="3" column-count="7" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<xy x="20" y="20" width="745" height="400"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<grid id="c3c1c" binding="DrawPlace" layout-manager="CardLayout" hgap="0" vgap="0">
<constraints>
<grid row="0" column="0" row-span="1" col-span="7" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<border type="none"/>
<children/>
</grid>
<grid id="7cdea" layout-manager="GridLayoutManager" row-count="1" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<grid row="2" column="0" row-span="1" col-span="7" vsize-policy="0" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false">
<minimum-size width="-1" height="20"/>
</grid>
</constraints>
<properties/>
<border type="none"/>
<children>
<component id="5d314" class="javax.swing.JLabel" binding="weightLabel">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Вес: "/>
</properties>
</component>
<component id="fa09a" class="javax.swing.JLabel" binding="speedLabel">
<constraints>
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Скорость: "/>
</properties>
</component>
<component id="9494b" class="javax.swing.JLabel" binding="colorLabel">
<constraints>
<grid row="0" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Цвет"/>
</properties>
</component>
</children>
</grid>
<grid id="b5cf" layout-manager="GridLayoutManager" row-count="2" column-count="7" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<grid row="1" column="0" row-span="1" col-span="7" vsize-policy="0" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<hspacer id="eb27d">
<constraints>
<grid row="1" column="2" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
</hspacer>
<component id="df504" class="javax.swing.JButton" binding="createButton">
<constraints>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="создание"/>
</properties>
</component>
<component id="b31a8" class="javax.swing.JButton" binding="downButton" default-binding="true">
<constraints>
<grid row="1" column="5" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false">
<minimum-size width="30" height="30"/>
<preferred-size width="30" height="30"/>
<maximum-size width="30" height="30"/>
</grid>
</constraints>
<properties>
<icon value="Resources/down.png"/>
<text value=""/>
</properties>
</component>
<component id="1d949" class="javax.swing.JButton" binding="leftButton" default-binding="true">
<constraints>
<grid row="1" column="4" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false">
<minimum-size width="30" height="30"/>
<preferred-size width="30" height="30"/>
<maximum-size width="30" height="30"/>
</grid>
</constraints>
<properties>
<icon value="Resources/left.png"/>
<text value=""/>
</properties>
</component>
<component id="527d2" class="javax.swing.JButton" binding="rightButton" default-binding="true">
<constraints>
<grid row="1" column="6" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false">
<minimum-size width="30" height="30"/>
<preferred-size width="30" height="30"/>
<maximum-size width="30" height="30"/>
</grid>
</constraints>
<properties>
<icon value="Resources/right.png"/>
<text value=""/>
</properties>
</component>
<component id="5bf4f" class="javax.swing.JButton" binding="upButton" default-binding="true">
<constraints>
<grid row="0" column="5" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false">
<minimum-size width="30" height="30"/>
<preferred-size width="30" height="30"/>
<maximum-size width="30" height="30"/>
</grid>
</constraints>
<properties>
<icon value="Resources/up.png"/>
<text value=""/>
</properties>
</component>
<component id="b6c27" class="javax.swing.JButton" binding="createModifButton">
<constraints>
<grid row="1" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="модификация"/>
</properties>
</component>
<component id="9de16" class="javax.swing.JButton" binding="selectButton">
<constraints>
<grid row="1" column="3" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="выбрать"/>
</properties>
</component>
</children>
</grid>
</children>
</grid>
</form>

View File

@ -0,0 +1,124 @@
import javax.swing.*;
import java.awt.*;
import java.awt.event.ComponentAdapter;
import java.awt.event.ComponentEvent;
import java.util.Random;
public class FormAirPlane extends JDialog implements Form {
private JButton createButton;
private JButton upButton;
private JButton rightButton;
private JButton downButton;
private JButton leftButton;
private JPanel mainPanel;
private JPanel DrawPlace;
private JLabel speedLabel;
private JLabel weightLabel;
private JLabel colorLabel;
private JButton createModifButton;
private JButton selectButton;
DrawingEntityPlain _airPlane;
private DrawingEntityPlain selectedPlane;
public FormAirPlane() {}
public FormAirPlane(DrawingEntityPlain aircraft) {
_airPlane = aircraft;
}
public DrawingEntityPlain getSelectedPlane() {
return selectedPlane;
}
public void run() {
add(mainPanel);
Canvas canv = new Canvas(this);
DrawPlace.add(canv);
createButton.addActionListener(e -> {
Dimension canvSize = canv.getSize();
Random rnd = new Random();
Color color = JColorChooser.showDialog(this, "Цвет", Color.BLACK);
if(color == null) color = Color.BLACK;
_airPlane = new DrawingEntityPlain(rnd.nextInt(100, 300), rnd.nextInt(1000, 2000), color);
_airPlane.SetPosition((int)rnd.nextInt(10, 100), (int)rnd.nextInt(10, 100), canvSize.width, canvSize.height);
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);
canv.repaint();
});
createModifButton.addActionListener(e -> {
Dimension canvSize = canv.getSize();
Random rnd = new Random();
Color color = JColorChooser.showDialog(this, "Цвет", Color.BLACK);
Color dopColor = JColorChooser.showDialog(this, "Цвет", Color.BLACK);
if(color == null) color = Color.BLACK;
if(dopColor == null) dopColor = Color.BLACK;
_airPlane = new DrawingRadarPlain(rnd.nextInt(100, 300), rnd.nextInt(1000, 2000),
color, dopColor,
rnd.nextInt(0, 2) == 1, rnd.nextInt(0, 2) == 1);
_airPlane.SetPosition((int)rnd.nextInt(10, 100), (int)rnd.nextInt(10, 100), canvSize.width, canvSize.height);
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);
canv.repaint();
});
selectButton.addActionListener(e -> {
selectedPlane = _airPlane;
dispose();
});
addComponentListener(new ComponentAdapter() {
@Override
public void componentResized(ComponentEvent e) {
if(_airPlane == null) return;
_airPlane.ChangeBorders(canv.getSize().width, canv.getSize().height);
}
});
upButton.addActionListener(e -> {
if(_airPlane == null) return;
_airPlane.MoveTransport(Direction.Up);
canv.repaint();
});
rightButton.addActionListener(e -> {
if(_airPlane == null) return;
_airPlane.MoveTransport(Direction.Right);
canv.repaint();
});
downButton.addActionListener(e -> {
if(_airPlane == null) return;
_airPlane.MoveTransport(Direction.Down);
canv.repaint();
});
leftButton.addActionListener(e -> {
if(_airPlane == null) return;
_airPlane.MoveTransport(Direction.Left);
canv.repaint();
});
}
@Override
public void Draw(Graphics2D g) {
if(_airPlane == null) return;
_airPlane.DrawTransport(g);
}
}

View File

@ -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();
}

View File

@ -0,0 +1,6 @@
import java.awt.*;
public interface IDrawingPorthole {
void setCount(int count);
void draw(Graphics2D g, int x, int y);
}

View File

@ -0,0 +1,169 @@
import java.awt.*;
import java.awt.image.BufferedImage;
public class MapWithSetPlane<T extends IDrawingObject, U extends AbstractMap>
{
private int _pictureWidth;
private int _pictureHeight;
private int _placeSizeWidth = 210;
private int _placeSizeHeight = 170;
private SetPlaneGeneric<T> _setPlane;
private U _map;
public MapWithSetPlane(int picWidth, int picHeight, U map)
{
int width = picWidth / _placeSizeWidth;
int height = picHeight / _placeSizeHeight;
_setPlane = new SetPlaneGeneric<T>(width * height);
_pictureWidth = picWidth;
_pictureHeight = picHeight;
_map = map;
}
public int addAirPlane(T airplane)
{
return _setPlane.Insert(airplane);
}
public T removeAirPlane(int position)
{
return _setPlane.Remove(position);
}
public Image ShowSet()
{
BufferedImage img = new BufferedImage(_pictureWidth, _pictureHeight, BufferedImage.TYPE_INT_ARGB);
Graphics2D gr = (Graphics2D) img.getGraphics();
DrawBackground(gr);
DrawPlanes(gr);
return img;
}
public Image ShowOnMap()
{
BufferedImage img = new BufferedImage(_pictureWidth, _pictureHeight, BufferedImage.TYPE_INT_ARGB);
Graphics2D g = (Graphics2D) img.getGraphics();
Shaking();
for (int i = 0; i < _setPlane.getCount(); i++)
{
var car = _setPlane.Get(i);
if (car != null)
{
_map.CreateMap(_pictureWidth, _pictureHeight, car);
_map.DrawMapWithObject(g);
return img;
}
}
return img;
}
public Image MoveObject(Direction direction)
{
BufferedImage img = new BufferedImage(_pictureWidth, _pictureHeight, BufferedImage.TYPE_INT_ARGB);
Graphics2D g = (Graphics2D) img.getGraphics();
if (_map != null)
{
_map.MoveObject(direction);
_map.DrawMapWithObject(g);
}
return img;
}
private void Shaking()
{
int j = _setPlane.getCount() - 1;
for (int i = 0; i < _setPlane.getCount(); i++)
{
if (_setPlane.Get(i) == null)
{
for (; j > i; j--)
{
var car = _setPlane.Get(j);
if (car != null)
{
_setPlane.Insert(car, i);
_setPlane.Remove(j);
break;
}
}
if (j <= i)
{
return;
}
}
}
}
private void DrawBackground(Graphics2D g)
{
g.setPaint(new Color(160, 160, 160));
g.fillRect(0, 0, _pictureWidth , _pictureHeight );
g.setPaint(Color.black);
g.setStroke(new BasicStroke(3));
for (int i = 0; i < _pictureWidth / _placeSizeWidth; i++)
{
for (int j = 0; j < _pictureHeight / _placeSizeHeight + 1; ++j)
{
g.drawLine(i * _placeSizeWidth, j * _placeSizeHeight, i *
_placeSizeWidth + _placeSizeWidth / 2, j * _placeSizeHeight);
}
g.drawLine( i * _placeSizeWidth, 0, i * _placeSizeWidth,
(_pictureHeight / _placeSizeHeight) * _placeSizeHeight);
}
g.setStroke(new BasicStroke(1));
}
private void DrawPlanes(Graphics2D g)
{
int CountWidth = _pictureWidth / _placeSizeWidth;
int x = _pictureWidth - _placeSizeWidth - _placeSizeWidth/2 - _placeSizeWidth / 4;
int y = _placeSizeHeight/4;
for (int k = 0; k < _setPlane.getCount(); k++)
{
if (_setPlane.Get(k) != null)
{
if ((k+1) % CountWidth != 0 || k ==0)
{
_setPlane.Get(k).SetObject(x, y, _pictureWidth, _pictureHeight);
_setPlane.Get(k).DrawningObject(g);
x -= _placeSizeWidth;
}
else
{
_setPlane.Get(k).SetObject(x, y, _pictureWidth, _pictureHeight);
_setPlane.Get(k).DrawningObject(g);
x = _pictureWidth - _placeSizeWidth - _placeSizeWidth / 2 - _placeSizeWidth / 4;
y += _placeSizeHeight ;
}
}
if (_setPlane.Get(k) == null)
{
if ((k + 1) % CountWidth != 0 || k ==0)
x -= _placeSizeWidth;
else
{
x = _pictureWidth - _placeSizeWidth - _placeSizeWidth / 2 - _placeSizeWidth / 4;
y += _placeSizeHeight;
}
}
}
}
public T getPlane(int pos){
return _setPlane.Get(pos);
}
}

View File

@ -0,0 +1,39 @@
import java.util.LinkedHashMap;
import java.util.List;
public class MapsCollection
{
public LinkedHashMap<String, MapWithSetPlane<DrawingObjectPlain, AbstractMap>> _mapStorages;
private int _pictureWidth;
private int _pictureHeight;
public List<String> getKeys() { return _mapStorages.keySet().stream().toList(); }
public MapsCollection(int pictureWidth, int pictureHeight)
{
_mapStorages = new LinkedHashMap<>();
_pictureWidth = pictureWidth;
_pictureHeight = pictureHeight;
}
public DrawingObjectPlain Indexator (String key, int pos){
return _mapStorages.get(key).getPlane(pos);
}
public void AddMap(String name, AbstractMap map)
{
boolean check = _mapStorages.containsKey(name);
if (check) return;
_mapStorages.put(name, new MapWithSetPlane(_pictureWidth, _pictureHeight, map));
}
public void DelMap(String name)
{
_mapStorages.remove(name);
}
public MapWithSetPlane<DrawingObjectPlain, AbstractMap> getMap(String name)
{
return _mapStorages.getOrDefault(name, null);
}
}

View File

@ -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++;
}
}
}

View File

@ -0,0 +1,5 @@
public enum Porthole {
Ten,
Twenty,
Thirty
}

View File

@ -0,0 +1,17 @@
import java.awt.*;
import java.util.Random;
public class PortholeFabric {
public static IDrawingPorthole createRandom(Color color) {
Random rnd = new Random();
int type = rnd.nextInt(0, 3);
return switch(type) {
case 0 -> new DrawingPorthole(rnd.nextInt(1, 40), color);
case 1 -> new DrawingSquarePorthole(rnd.nextInt(1, 40), color);
case 2 -> new DrawingTrianglePorthole(rnd.nextInt(1, 40), color);
default -> null;
};
}
}

View File

@ -3,6 +3,6 @@ import java.awt.*;
public class Program {
public static void main(String[] args) {
System.out.println("Hello world");
new formMapWithSetPlane().run();
}
}

View File

@ -0,0 +1,40 @@
import java.util.ArrayList;
public class SetPlaneGeneric<T>
{
private ArrayList<T> _places;
private int _maxCount;
public int getCount() {
return _places.size();
}
public SetPlaneGeneric(int count)
{
_places = new ArrayList<>();
_maxCount = count;
}
public int Insert(T plane)
{
if (_places.size() == _maxCount) return -1;
_places.add(0, plane);
return 0;
}
public int Insert(T plane, int position)
{
if (_places.size() == _maxCount) return -1;
_places.add(position, plane);
return position;
}
public T Remove(int position)
{
if(position > _maxCount || position < 0) return null;
T res = _places.get(position);
_places.remove(res);
return res;
}
public T Get(int position)
{
return _places.get(position);
}
}

View File

@ -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++;
}
}
}
}

View File

@ -0,0 +1,176 @@
<?xml version="1.0" encoding="UTF-8"?>
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="formMap">
<grid id="27dc6" binding="mainPanel" layout-manager="GridLayoutManager" row-count="4" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<xy x="20" y="20" width="700" height="700"/>
</constraints>
<properties>
<minimumSize width="555" height="555"/>
<preferredSize width="1200" height="1100"/>
</properties>
<border type="none"/>
<children>
<grid id="e3a5c" binding="DrawPlace" layout-manager="CardLayout" hgap="0" vgap="0">
<constraints>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<toolTipText value=""/>
</properties>
<border type="none"/>
<children/>
</grid>
<grid id="6cd69" layout-manager="GridLayoutManager" row-count="2" column-count="6" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<hspacer id="73e7d">
<constraints>
<grid row="1" column="2" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
</hspacer>
<component id="2f248" class="javax.swing.JButton" binding="createButton">
<constraints>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="создание"/>
</properties>
</component>
<component id="59723" class="javax.swing.JButton" binding="downButton" default-binding="true">
<constraints>
<grid row="1" column="4" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false">
<minimum-size width="30" height="30"/>
<preferred-size width="30" height="30"/>
<maximum-size width="30" height="30"/>
</grid>
</constraints>
<properties>
<icon value="Resources/down.png"/>
<text value=""/>
</properties>
</component>
<component id="c4a07" class="javax.swing.JButton" binding="leftButton" default-binding="true">
<constraints>
<grid row="1" column="3" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false">
<minimum-size width="30" height="30"/>
<preferred-size width="30" height="30"/>
<maximum-size width="30" height="30"/>
</grid>
</constraints>
<properties>
<icon value="Resources/left.png"/>
<text value=""/>
</properties>
</component>
<component id="c0037" class="javax.swing.JButton" binding="rightButton" default-binding="true">
<constraints>
<grid row="1" column="5" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false">
<minimum-size width="30" height="30"/>
<preferred-size width="30" height="30"/>
<maximum-size width="30" height="30"/>
</grid>
</constraints>
<properties>
<icon value="Resources/right.png"/>
<text value=""/>
</properties>
</component>
<component id="5b159" class="javax.swing.JButton" binding="upButton" default-binding="true">
<constraints>
<grid row="0" column="4" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false">
<minimum-size width="30" height="30"/>
<preferred-size width="30" height="30"/>
<maximum-size width="30" height="30"/>
</grid>
</constraints>
<properties>
<icon value="Resources/up.png"/>
<text value=""/>
</properties>
</component>
<component id="fb982" class="javax.swing.JButton" binding="modifiedButton">
<constraints>
<grid row="1" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Модификация"/>
</properties>
</component>
</children>
</grid>
<grid id="86a02" layout-manager="GridLayoutManager" row-count="1" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<grid row="3" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false">
<minimum-size width="-1" height="20"/>
</grid>
</constraints>
<properties/>
<border type="none"/>
<children>
<component id="81cff" class="javax.swing.JLabel" binding="weightLabel">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Вес: "/>
</properties>
</component>
<component id="e587f" class="javax.swing.JLabel" binding="speedLabel">
<constraints>
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Скорость: "/>
</properties>
</component>
<component id="ea489" class="javax.swing.JLabel" binding="colorLabel">
<constraints>
<grid row="0" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Цвет"/>
</properties>
</component>
</children>
</grid>
<grid id="c8210" layout-manager="GridLayoutManager" row-count="1" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<component id="50374" class="javax.swing.JComboBox" binding="comboBoxSelectorMap">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="1" indent="0" use-parent-layout="false">
<minimum-size width="160" height="30"/>
<preferred-size width="160" height="30"/>
<maximum-size width="160" height="30"/>
</grid>
</constraints>
<properties>
<model>
<item value="Простая карта"/>
<item value="Моя карта"/>
</model>
<toolTipText value=""/>
</properties>
</component>
<hspacer id="d5463">
<constraints>
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
</hspacer>
</children>
</grid>
</children>
</grid>
</form>

View File

@ -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);
}
}

View File

@ -0,0 +1,210 @@
<?xml version="1.0" encoding="UTF-8"?>
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="formMapWithSetPlane">
<grid id="27dc6" binding="MainPane" layout-manager="GridLayoutManager" row-count="1" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<xy x="20" y="20" width="662" height="590"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<grid id="afa3d" binding="drawPanel" layout-manager="CardLayout" hgap="0" vgap="0">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<border type="none"/>
<children/>
</grid>
<grid id="e9a63" layout-manager="GridLayoutManager" row-count="14" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="3" hsize-policy="0" anchor="0" fill="3" indent="0" use-parent-layout="false">
<minimum-size width="150" height="-1"/>
</grid>
</constraints>
<properties/>
<border type="none"/>
<children>
<component id="f23ee" class="javax.swing.JButton" binding="buttonAddPlane">
<constraints>
<grid row="6" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Добавить"/>
</properties>
</component>
<component id="2e61e" class="javax.swing.JComboBox" binding="comboBoxSelectorMap">
<constraints>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="2" anchor="8" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<model>
<item value="Простая карта"/>
<item value="Моя карта"/>
</model>
</properties>
</component>
<component id="5c428" class="javax.swing.JButton" binding="buttonRemovePlane">
<constraints>
<grid row="8" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Удалить"/>
</properties>
</component>
<component id="e24b9" class="javax.swing.JButton" binding="buttonShowStorage">
<constraints>
<grid row="9" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Посмотреть Хранилище"/>
</properties>
</component>
<component id="ac087" class="javax.swing.JButton" binding="buttonShowOnMap">
<constraints>
<grid row="10" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Посмотреть карту"/>
</properties>
</component>
<grid id="2821b" layout-manager="GridLayoutManager" row-count="2" column-count="5" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<grid row="13" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="0" anchor="0" fill="3" indent="0" use-parent-layout="false">
<minimum-size width="150" height="-1"/>
</grid>
</constraints>
<properties/>
<border type="none"/>
<children>
<component id="6d803" class="javax.swing.JButton" binding="leftButton">
<constraints>
<grid row="1" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false">
<minimum-size width="30" height="30"/>
<preferred-size width="30" height="30"/>
<maximum-size width="30" height="30"/>
</grid>
</constraints>
<properties>
<icon value="Resources/left.png"/>
<text value=""/>
</properties>
</component>
<component id="c0db2" class="javax.swing.JButton" binding="upButton">
<constraints>
<grid row="0" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false">
<minimum-size width="30" height="30"/>
<preferred-size width="30" height="30"/>
<maximum-size width="30" height="30"/>
</grid>
</constraints>
<properties>
<icon value="Resources/up.png"/>
<text value=""/>
</properties>
</component>
<component id="ca0da" class="javax.swing.JButton" binding="downButton">
<constraints>
<grid row="1" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false">
<minimum-size width="30" height="30"/>
<preferred-size width="30" height="30"/>
<maximum-size width="30" height="30"/>
</grid>
</constraints>
<properties>
<icon value="Resources/down.png"/>
<text value=""/>
</properties>
</component>
<component id="c3e45" class="javax.swing.JButton" binding="rightButton">
<constraints>
<grid row="1" column="3" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false">
<minimum-size width="30" height="30"/>
<preferred-size width="30" height="30"/>
<maximum-size width="30" height="30"/>
</grid>
</constraints>
<properties>
<icon value="Resources/right.png"/>
<text value=""/>
</properties>
</component>
<hspacer id="1f200">
<constraints>
<grid row="1" column="4" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
</hspacer>
<hspacer id="f8b3b">
<constraints>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
</hspacer>
</children>
</grid>
<vspacer id="b833e">
<constraints>
<grid row="12" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
</constraints>
</vspacer>
<component id="181ac" class="javax.swing.JTextField" binding="textBoxPosition">
<constraints>
<grid row="7" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
<preferred-size width="150" height="-1"/>
</grid>
</constraints>
<properties/>
</component>
<component id="55673" class="javax.swing.JTextField" binding="textBoxNewMapName">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
<preferred-size width="150" height="-1"/>
</grid>
</constraints>
<properties/>
</component>
<component id="204a1" class="javax.swing.JButton" binding="buttonAddMap">
<constraints>
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Добавить карту"/>
</properties>
</component>
<component id="113db" class="javax.swing.JList" binding="listBoxMaps">
<constraints>
<grid row="3" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="2" anchor="0" fill="3" indent="0" use-parent-layout="false">
<minimum-size width="-1" height="100"/>
<preferred-size width="150" height="50"/>
<maximum-size width="-1" height="100"/>
</grid>
</constraints>
<properties/>
</component>
<component id="694cc" class="javax.swing.JButton" binding="buttonDeleteMap">
<constraints>
<grid row="4" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Удалить карту"/>
</properties>
</component>
<vspacer id="e3260">
<constraints>
<grid row="5" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
</constraints>
</vspacer>
<component id="8891" class="javax.swing.JButton" binding="buttonShowDeleted">
<constraints>
<grid row="11" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Показать удаленные"/>
</properties>
</component>
</children>
</grid>
</children>
</grid>
</form>

View File

@ -0,0 +1,240 @@
import javax.swing.*;
import java.awt.*;
import java.util.*;
import java.util.List;
public class formMapWithSetPlane implements Form {
private JPanel MainPane;
private JButton buttonAddPlane;
private JComboBox comboBoxSelectorMap;
private JTextField textBoxPosition;
private JButton buttonRemovePlane;
private JButton buttonShowStorage;
private JButton buttonShowOnMap;
private JButton upButton;
private JButton leftButton;
private JButton rightButton;
private JButton downButton;
private JPanel drawPanel;
private JTextField textBoxNewMapName;
private JList listBoxMaps;
private JButton buttonAddMap;
private JButton buttonDeleteMap;
private JButton buttonShowDeleted;
private MapsCollection _mapsCollection;
private HashMap<String, AbstractMap> _mapsDict = new HashMap<>(){{
put( "Простая карта", new SimpleMap() );
put( "Моя карта", new MyMap() );
}};
private Canvas canv = new Canvas(this);
private Queue<IDrawingObject> deletedPlanes = new ArrayDeque<>();
JFrame jFrame = getFrame();
Image img;
private JFrame getFrame() {
JFrame frame = new JFrame();
frame.setVisible(true);
frame.setBounds(300, 50, 1000, 750);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
return frame;
}
private void ReloadMaps()
{
int index = listBoxMaps.getSelectedIndex();
List<String> items = _mapsCollection.getKeys();
listBoxMaps.setListData(items.toArray());
if (items.size() > 0 && (index == -1 || index >= items.size()))
{
listBoxMaps.setSelectedIndex(0);
}
else if (items.size() > 0 && index > -1 && index < items.size())
{
listBoxMaps.setSelectedIndex(index);
}
}
public void run() {
jFrame.add(MainPane);
drawPanel.add(canv);
jFrame.revalidate();
_mapsCollection = new MapsCollection(canv.getSize().width, canv.getSize().height);
comboBoxSelectorMap.removeAllItems();
_mapsDict.keySet().forEach(elem -> {
comboBoxSelectorMap.addItem(elem);
});
comboBoxSelectorMap.setSelectedIndex(-1);
listBoxMaps.addListSelectionListener(e -> {
if(listBoxMaps.getSelectedValue() == null) return;
img = _mapsCollection.getMap(listBoxMaps.getSelectedValue().toString()).ShowSet();
canv.repaint();
});
buttonAddMap.addActionListener(e -> {
if (comboBoxSelectorMap.getSelectedIndex() == -1 || textBoxNewMapName.getText() == "")
{
JOptionPane.showMessageDialog(jFrame, "Не все данные заполнены");
return;
}
if (!_mapsDict.containsKey(comboBoxSelectorMap.getSelectedItem().toString()))
{
JOptionPane.showMessageDialog(jFrame, "Нет такой карты");
return;
}
_mapsCollection.AddMap(textBoxNewMapName.getText(),
_mapsDict.get(comboBoxSelectorMap.getSelectedItem().toString()));
ReloadMaps();
});
buttonDeleteMap.addActionListener(e -> {
if (listBoxMaps.getSelectedIndex() == -1)
{
return;
}
String mapName = listBoxMaps.getSelectedValue().toString();
if (JOptionPane.showConfirmDialog(jFrame, "Удалить карту " + mapName,
"Удаление", JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION)
{
_mapsCollection.DelMap(mapName);
ReloadMaps();
}
});
buttonAddPlane.addActionListener(e -> {
if (listBoxMaps.getSelectedIndex() == -1)
{
return;
}
FormAirPlane dialog = new FormAirPlane();
dialog.run();
dialog.setSize(800, 500);
dialog.setModalityType(Dialog.ModalityType.APPLICATION_MODAL);
dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
dialog.setVisible(true);
if (dialog.getSelectedPlane() == null) return;
DrawingObjectPlain aircraft = new DrawingObjectPlain(dialog.getSelectedPlane());
if (_mapsCollection.getMap(listBoxMaps.getSelectedValue().toString()).addAirPlane(aircraft) != -1)
{
JOptionPane.showMessageDialog(jFrame, "Объект добавлен");
img = _mapsCollection.getMap(listBoxMaps.getSelectedValue().toString()).ShowSet();
canv.repaint();
}
else
{
JOptionPane.showMessageDialog(jFrame, "Не удалось добавить объект");
}
});
buttonRemovePlane.addActionListener(e -> {
String text = textBoxPosition.getText();
if(text.isEmpty()) return;
if(JOptionPane.showConfirmDialog(
jFrame,
"Вы действительно хотите удалить объект?",
"Удаление",
JOptionPane.YES_NO_OPTION) == JOptionPane.NO_OPTION) return;
int pos;
try {
pos = Integer.parseInt(text);
} catch (Exception err) {
return;
}
pos = Integer.parseInt(text);
String mapName = listBoxMaps.getSelectedValue().toString();
IDrawingObject deleted = _mapsCollection.getMap(mapName).removeAirPlane(pos);
if(deleted != null) {
JOptionPane.showMessageDialog(jFrame, "Объект удален");
img = _mapsCollection.getMap(mapName).ShowSet();
deletedPlanes.add(deleted);
canv.repaint();
} else {
JOptionPane.showMessageDialog(jFrame, "Не удалось удалить объект");
}
});
buttonShowStorage.addActionListener(e -> {
if(listBoxMaps.getSelectedValue() == null) return;
img = _mapsCollection.getMap(listBoxMaps.getSelectedValue().toString()).ShowSet();
canv.repaint();
});
buttonShowOnMap.addActionListener(e -> {
if(listBoxMaps.getSelectedValue() == null) return;
img = _mapsCollection.getMap(listBoxMaps.getSelectedValue().toString()).ShowOnMap();
canv.repaint();
});
buttonShowDeleted.addActionListener(e -> {
if (listBoxMaps.getSelectedIndex() == -1)
{
return;
}
if(deletedPlanes.size() == 0) {
JOptionPane.showMessageDialog(jFrame, "Очередь пуста");
return;
}
DrawingObjectPlain deleted = (DrawingObjectPlain) deletedPlanes.peek();
FormAirPlane dialog = new FormAirPlane(deleted.getAirPlane());
deletedPlanes.remove();
dialog.run();
dialog.setSize(800, 500);
dialog.setModalityType(Dialog.ModalityType.APPLICATION_MODAL);
dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
dialog.setVisible(true);
});
leftButton.addActionListener(e -> {
if(listBoxMaps.getSelectedValue() == null) return;
img = _mapsCollection.getMap(listBoxMaps.getSelectedValue().toString()).MoveObject(Direction.Left);
canv.repaint();
});
rightButton.addActionListener(e -> {
if(listBoxMaps.getSelectedValue() == null) return;
img = _mapsCollection.getMap(listBoxMaps.getSelectedValue().toString()).MoveObject(Direction.Right);
canv.repaint();
});
upButton.addActionListener(e -> {
if(listBoxMaps.getSelectedValue() == null) return;
img = _mapsCollection.getMap(listBoxMaps.getSelectedValue().toString()).MoveObject(Direction.Up);
canv.repaint();
});
downButton.addActionListener(e -> {
if(listBoxMaps.getSelectedValue() == null) return;
img = _mapsCollection.getMap(listBoxMaps.getSelectedValue().toString()).MoveObject(Direction.Down);
canv.repaint();
});
}
@Override
public void Draw(Graphics2D g) {
if(img == null) return;
g.drawImage(img, 0, 0, null);
}
}

View File

@ -0,0 +1,29 @@
<?xml version="1.0" encoding="UTF-8"?>
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="formPlaneGenerator">
<grid id="27dc6" binding="mainPanel" layout-manager="GridLayoutManager" row-count="2" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<xy x="20" y="20" width="500" height="400"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<component id="b9cac" class="javax.swing.JButton" binding="generateButton">
<constraints>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Сгенерировать"/>
</properties>
</component>
<grid id="d138" binding="drawPanel" layout-manager="CardLayout" hgap="0" vgap="0">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<border type="none"/>
<children/>
</grid>
</children>
</grid>
</form>

View File

@ -0,0 +1,76 @@
import javax.swing.*;
import java.awt.*;
import java.util.Random;
public class formPlaneGenerator implements Form {
private JButton generateButton;
private JPanel drawPanel;
private JPanel mainPanel;
private Canvas canv = new Canvas(this);
private DrawingEntityPlain airplane;
private AirplaneMixer<EntityAirPlane, IDrawingPorthole> mixer = new AirplaneMixer<>(10, 20);
private JFrame jframe = getFrame();
private JFrame getFrame() {
JFrame frame = new JFrame();
frame.setVisible(true);
frame.setBounds(300, 100, 400, 300);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
return frame;
}
public void run() {
jframe.add(mainPanel);
drawPanel.add(canv);
Random rnd = new Random();
for(int i = 0; i < 10; ++i) {
if(rnd.nextBoolean()) {
mixer.add(new EntityAirPlane(rnd.nextInt(100, 250), rnd.nextInt(1000, 2000),
new Color(
rnd.nextInt(0, 255),
rnd.nextInt(0, 255),
rnd.nextInt(0, 255)
)));
continue;
}
mixer.add(new EntityRadarPlain(rnd.nextInt(100, 250), rnd.nextInt(1000, 2000),
new Color(
rnd.nextInt(0, 255),
rnd.nextInt(0, 255),
rnd.nextInt(0, 255)
),
new Color(
rnd.nextInt(0, 255),
rnd.nextInt(0, 255),
rnd.nextInt(0, 255)
),
rnd.nextBoolean(), rnd.nextBoolean()
));
}
for(int i = 0; i < 20; ++i) {
Color randomColor = new Color(
rnd.nextInt(0, 255),
rnd.nextInt(0, 255),
rnd.nextInt(0, 255));
mixer.add(PortholeFabric.createRandom(randomColor));
}
generateButton.addActionListener(e -> {
Dimension canvSize = canv.getSize();
airplane = mixer.constructAirplane(canvSize.width, canvSize.height);
canv.repaint();
});
}
@Override
public void Draw(Graphics2D g) {
if(airplane == null) return;
airplane.DrawTransport(g);
}
}