Compare commits

..

No commits in common. "LabWork04" and "master" have entirely different histories.

35 changed files with 0 additions and 1890 deletions

3
.idea/.gitignore generated vendored
View File

@ -1,3 +0,0 @@
# Default ignored files
/shelf/
/workspace.xml

View File

@ -1,11 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

6
.idea/misc.xml generated
View File

@ -1,6 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" project-jdk-name="openjdk-19" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>

8
.idea/modules.xml generated
View File

@ -1,8 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/ProjectAirbus.iml" filepath="$PROJECT_DIR$/.idea/ProjectAirbus.iml" />
</modules>
</component>
</project>

6
.idea/vcs.xml generated
View File

@ -1,6 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="" vcs="Git" />
</component>
</project>

View File

@ -1,115 +0,0 @@
import java.awt.*;
import java.awt.image.BufferedImage;
import java.util.Random;
public abstract class AbstractMap {
private IDrawningObject _drawningObject = null;
protected int[][] _map = null;
protected int _width;
protected int _height;
protected float _size_x;
protected float _size_y;
protected final Random _random = new Random();
protected final int _freeRoad = 0;
protected final int _barrier = 1;
public BufferedImage CreateMap(int width, int height, IDrawningObject drawningObject)
{
_width = width;
_height = height;
_drawningObject = drawningObject;
GenerateMap();
while (!SetObjectOnMap())
{
GenerateMap();
}
return DrawMapWithObject();
}
private boolean CheckBarriers(float topOffset, float rightOffset, float leftOffset, float bottomOffset)
{
float[] arrayPossition = _drawningObject.GetCurrentPosition();
int top = (int)((arrayPossition[1] + topOffset) / _size_y);
int right = (int)((arrayPossition[2] + rightOffset) / _size_x);
int left = (int)((arrayPossition[0] + leftOffset) / _size_x);
int bottom = (int)((arrayPossition[3] + bottomOffset) / _size_y);
if (top < 0 || left < 0 || right >= _map[0].length || bottom >= _map.length) return false;
for (int i = top; i <= bottom; i++)
{
for (int j = left; j <= right; j++)
{
if (_map[j][i] == _barrier) return false;
}
}
return true;
}
public BufferedImage MoveObject(Direction direction)
{
if (_drawningObject == null) return DrawMapWithObject();
boolean isTrue = true;
switch (direction)
{
case Left:
if (!CheckBarriers(0, -1 * _drawningObject.Step(), -1 * _drawningObject.Step(), 0)) isTrue = false;
break;
case Right:
if (!CheckBarriers(0, _drawningObject.Step(), _drawningObject.Step(), 0)) isTrue = false;
break;
case Up:
if (!CheckBarriers(-1 * _drawningObject.Step(), 0, 0, -1 * _drawningObject.Step())) isTrue = false;
break;
case Down:
if (!CheckBarriers(_drawningObject.Step(), 0, 0, _drawningObject.Step())) isTrue = false;
break;
}
if (isTrue)
{
_drawningObject.MoveObject(direction);
}
return DrawMapWithObject();
}
private boolean SetObjectOnMap()
{
if (_drawningObject == null || _map == null)
{
return false;
}
int x = _random.nextInt(0, 10);
int y = _random.nextInt(0, 10);
_drawningObject.SetObject(x, y, _width, _height);
if (!CheckBarriers(0, 0, 0, 0)) return false;
return true;
}
BufferedImage DrawMapWithObject()
{
BufferedImage bmp = new BufferedImage(_width, _height, BufferedImage.TYPE_INT_RGB);
if (_drawningObject == null || _map == null)
{
return bmp;
}
Graphics gr = bmp.getGraphics();
for (int i = 0; i < _map.length; ++i)
{
for (int j = 0; j < _map[0].length; ++j)
{
if (_map[i][j] == _freeRoad)
{
DrawRoadPart((Graphics2D) gr, i, j);
}
else if (_map[i][j] == _barrier)
{
DrawBarrierPart((Graphics2D) gr, i, j);
}
}
}
_drawningObject.DrawningObject(gr);
return bmp;
}
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

@ -1,8 +0,0 @@
public enum Direction {
Up(1),
Down(2),
Left(3),
Right(4),
None(0);
Direction(int value){}
}

View File

@ -1,59 +0,0 @@
import java.awt.*;
public class DrawningAirbus extends DrawningPlane{
public DrawningAirbus(int speed, float weight, Color bodyColor, Color dopColor, boolean bodyKit, boolean wing, boolean sportLine)
{
super(speed, weight, bodyColor, 140, 70);
Plane = new EntityAirbus(speed, weight, bodyColor, dopColor, bodyKit, wing, sportLine);
}
protected DrawningAirbus(EntityPlane plane, IDrawningIlluminator illum){
super(plane,illum);
Plane = plane;
}
@Override
public void DrawTransport(Graphics g)
{
if (! (Plane instanceof EntityAirbus Airbus))
{
return;
}
super.paintComponent(g);
Graphics2D g2d = (Graphics2D) g;
g2d.setColor(Color.BLACK);
_startPosX += 10;
_startPosY += 5;
super.DrawTransport(g);
_startPosX -= 10;
_startPosY -= 5;
if (Airbus.BodyKit)
{
g.drawRect(_startPosX + 70, _startPosY + 50, 22, 16);
g.drawRect(_startPosX + 8, _startPosY + 18, 22, 16);
g.drawOval(_startPosX, _startPosY + 18, 16, 16);
g.drawOval(_startPosX + 62, _startPosY + 50, 16, 16);
g2d.setPaint(Airbus.DopColor);
g.fillRect(_startPosX + 70, _startPosY + 50, 22, 16);
g.fillOval(_startPosX + 84, _startPosY + 50, 16, 16);
g.fillOval(_startPosX + 24, _startPosY + 18, 16, 16);
g.fillRect(_startPosX + 8, _startPosY + 18, 22, 16);
g2d.setPaint(Color.BLACK);
g.fillOval(_startPosX, _startPosY + 18, 16, 16);
g.fillOval(_startPosX + 62, _startPosY + 50, 16, 16);
}
if (Airbus.Wing)
{
g.drawLine(_startPosX + 70, _startPosY + 20, _startPosX + 70, _startPosY + 35);
g.drawLine(_startPosX + 70, _startPosY + 20, _startPosX + 90, _startPosY + 35);
}
if (Airbus.SportLine)
{
g.drawOval(_startPosX + 110, _startPosY + 40, 9, 9);
g.fillOval(_startPosX + 110, _startPosY + 40, 9, 9);
}
}
}

View File

@ -1,57 +0,0 @@
import java.util.Random;
public class DrawningEntities <T extends EntityPlane, U extends IDrawningIlluminator>
{
public T[] _entities;
public U[] _illuminator;
int entitiesCount = 0;
int illumCount = 0;
String indx;
String indy;
public DrawningEntities(int countE,int countI){
_entities = (T[]) new EntityPlane[countE];
_illuminator = (U[]) new IDrawningIlluminator[countI];
}
public int Insert(T plane){
if(entitiesCount < _entities.length){
_entities[entitiesCount] = plane;
entitiesCount++;
return entitiesCount - 1;
}
return -1;
}
public int Insert(U illuminator){
if(illumCount < _illuminator.length){
_illuminator[illumCount] = illuminator;
illumCount++;
return illumCount - 1;
}
return -1;
}
public void SetIndexs(int ind1, int ind2)
{
indx=Integer.toString(ind1);
indy=Integer.toString(ind2);
}
public DrawningPlane CreatePlane(){
Random random = new Random();
int indEnt = 0;
int indIllum = 0;
if(entitiesCount - 1 != 0 & illumCount - 1 != 0){
indEnt = random.nextInt(0,entitiesCount - 1);
indIllum = random.nextInt(0, illumCount - 1);
}
T plane = (T)_entities[indEnt];
U illum = (U)_illuminator[indIllum];
SetIndexs(indEnt,indIllum);
if(plane instanceof EntityAirbus){
return new DrawningAirbus(plane,illum);
}
return new DrawningPlane(plane,illum);
}
}

View File

@ -1,36 +0,0 @@
import java.awt.*;
public class DrawningIlluminator implements IDrawningIlluminator{
private IlluminatorCount _Illuminator;
@Override
public void SetIlluminatorCount(int numOfIllum) {
_Illuminator = IlluminatorCount.GetIlluminatorCount(numOfIllum);
}
@Override
public void DrawIlluminator(Graphics g, int _startPosX, int _startPosY) {
Graphics2D g2d = (Graphics2D) g;
g2d.setColor(Color.BLACK);
int numOfIlluminator = 0;
switch (_Illuminator)
{
case Ten:
numOfIlluminator = 10;
break;
case Twenty:
numOfIlluminator = 20;
break;
case Thirty:
numOfIlluminator = 30;
break;
}
for(int i = numOfIlluminator; i >= 1; --i){
g2d.setColor(Color.CYAN);
g2d.fillOval(_startPosX + 105 - 3 * i, _startPosY + 35, 3, 3);
g2d.setColor(Color.BLACK);
g2d.drawOval(_startPosX + 105 - 3 * i, _startPosY + 35, 3, 3);
}
}
}

View File

@ -1,41 +0,0 @@
import java.awt.*;
public class DrawningObjectPlane implements IDrawningObject {
private DrawningPlane _plane = null;
public DrawningObjectPlane(DrawningPlane plane)
{
_plane = plane;
}
@Override
public float Step() {
if(_plane != null && _plane.Plane != null)
return _plane.Plane.GetStep();
return 0;
}
@Override
public void SetObject(int x, int y, int width, int height) {
_plane.SetPosition(x,y,width,height);
}
@Override
public void MoveObject(Direction direction) {
_plane.MoveTransport(direction);
}
@Override
public void DrawningObject(Graphics g) {
_plane.DrawTransport(g);
}
@Override
public float[] GetCurrentPosition() {
if(_plane!=null)
return _plane.GetCurrentPosition();
return null;
}
public DrawningPlane GetDrawningObjectPlane() {
return _plane;
}
}

View File

@ -1,170 +0,0 @@
import javax.swing.*;
import java.awt.*;
import java.util.Random;
public class DrawningPlane extends JPanel {
EntityPlane Plane;
public EntityPlane GetPlane(){
return Plane;
}
protected int _startPosX;
protected int _startPosY;
public IDrawningIlluminator IlluminatorDraw;
public Integer _pictureWidth = null;
public Integer _pictureHeight = null;
private int _PlaneWidth = 130;
private int _PlaneHeight = 70;
public void SetIlluminator() {
Random r = new Random();
int numIllum = r.nextInt(1,4);
numIllum = numIllum * 10;
IlluminatorDraw.SetIlluminatorCount(numIllum);
}
public DrawningPlane(int speed, float weight, Color bodyColor)
{
Plane = new EntityPlane(speed, weight, bodyColor);
Random random = new Random();
switch (random.nextInt(3)){
case 0:
IlluminatorDraw = new DrawningIlluminator();
break;
case 1:
IlluminatorDraw = new DrawningSqareIlluminator();
break;
case 2:
IlluminatorDraw = new DrawningTriangleIlluminator();
break;
}
SetIlluminator();
}
protected DrawningPlane(EntityPlane plane, IDrawningIlluminator illum){
Plane = plane;
IlluminatorDraw = illum;
}
public void SetPosition(int x, int y, int width, int height)
{
if (x >= 0 && x + _PlaneWidth <= width && y >= 0 && y + _PlaneHeight <= height) {
_startPosX = x;
_startPosY = y;
_pictureWidth = width;
_pictureHeight = height;
}
}
public void MoveTransport(Direction direction)
{
if (_pictureWidth == null || _pictureHeight == null)
{
return;
}
switch (direction)
{
case Right:
if (_startPosX + _PlaneWidth + Plane.Step < _pictureWidth)
{
_startPosX += Plane.Step;
}
break;
case Left:
if (_startPosX - Plane.Step > 0)
{
_startPosX -= Plane.Step;
}
break;
case Up:
if (_startPosY - Plane.Step > 0)
{
_startPosY -= Plane.Step;
}
break;
case Down:
if (_startPosY + _PlaneHeight + Plane.Step < _pictureHeight)
{
_startPosY += Plane.Step;
}
break;
}
}
protected DrawningPlane(int speed, float weight, Color bodyColor, int planeWidth, int planeHeight)
{
this(speed, weight, bodyColor);
_PlaneWidth = planeWidth;
_PlaneHeight = planeHeight;
}
public void DrawTransport(Graphics g) {
if (_startPosX < 0 || _startPosY < 0 || _pictureWidth == null || _pictureHeight == null) {
return;
}
if (GetPlane() == null) {
return;
}
super.paintComponent(g);
Graphics2D g2d = (Graphics2D) g;
g2d.setColor(Color.BLACK);
g2d.drawOval(_startPosX, _startPosY + 30, 20, 20);
g2d.drawRect(_startPosX + 10, _startPosY + 30, 100, 20);
g2d.drawLine(_startPosX + 110, _startPosY + 30, _startPosX + 130, _startPosY+40);
g2d.drawLine(_startPosX + 110, _startPosY+50, _startPosX + 130, _startPosY+40);
g2d.drawLine(_startPosX, _startPosY, _startPosX, _startPosY+40);
g2d.drawLine(_startPosX, _startPosY, _startPosX + 30, _startPosY+30);
g2d.drawLine(_startPosX + 40, _startPosY + 50, _startPosX + 40, _startPosY+55);
g2d.drawLine(_startPosX + 100, _startPosY + 50, _startPosX + 100, _startPosY+55);
g2d.drawOval(_startPosX + 95, _startPosY + 55, 10, 10);
g2d.drawOval(_startPosX + 29, _startPosY + 55, 10, 10);
g2d.drawOval(_startPosX + 41, _startPosY + 55, 10, 10);
g2d.setPaint(Plane.GetBodyColor());
g2d.fillOval(_startPosX, _startPosY + 31, 20, 19);
g2d.fillRect(_startPosX + 10, _startPosY + 31, 100, 19);
g2d.setPaint(Color.BLACK);
g2d.fillOval(_startPosX + 40, _startPosY + 40, 60, 5);
g2d.fillOval(_startPosX - 5, _startPosY + 25, 30, 10);
IlluminatorDraw.DrawIlluminator(g, _startPosX, _startPosY);
repaint();
}
public void ChangeBorders(int width, int height)
{
_pictureWidth = width;
_pictureHeight = height;
if (_pictureWidth <= _PlaneWidth || _pictureHeight <= _PlaneHeight)
{
_pictureWidth = null;
_pictureHeight = null;
return;
}
if (_startPosX + _PlaneWidth > _pictureWidth)
{
_startPosX = _pictureWidth - _PlaneWidth;
}
if (_startPosY + _PlaneHeight > _pictureHeight)
{
_startPosY = _pictureHeight - _PlaneHeight;
}
}
public float[] GetCurrentPosition() {
float[] dim = new float[4];
dim[0] = _startPosX;
dim[1] =_startPosY;
dim[2] = _startPosX + _PlaneWidth;
dim[3] = _startPosY + _PlaneHeight;
return dim;
}
}

View File

@ -1,33 +0,0 @@
import java.awt.*;
public class DrawningSqareIlluminator implements IDrawningIlluminator{
private IlluminatorCount _Illuminator;
@Override
public void SetIlluminatorCount(int numOfIllum) {_Illuminator = IlluminatorCount.GetIlluminatorCount(numOfIllum); }
@Override
public void DrawIlluminator(Graphics g, int _startPosX, int _startPosY) {
Graphics2D g2d = (Graphics2D) g;
g2d.setColor(Color.BLACK);
int numOfIlluminator = 0;
switch (_Illuminator)
{
case Ten:
numOfIlluminator = 10;
break;
case Twenty:
numOfIlluminator = 20;
break;
case Thirty:
numOfIlluminator = 30;
break;
}
for(int i = numOfIlluminator; i >= 1; --i){
g2d.setColor(Color.CYAN);
g2d.fillRect(_startPosX + 105 - 3 * i, _startPosY + 35, 3, 3);
g2d.setColor(Color.BLACK);
g2d.drawRect(_startPosX + 105 - 3 * i, _startPosY + 35, 3, 3);
}
}
}

View File

@ -1,36 +0,0 @@
import java.awt.*;
public class DrawningTriangleIlluminator implements IDrawningIlluminator{
private IlluminatorCount _Illuminator;
@Override
public void SetIlluminatorCount(int numOfIllum) {
_Illuminator = IlluminatorCount.GetIlluminatorCount(numOfIllum);
}
@Override
public void DrawIlluminator(Graphics g, int _startPosX, int _startPosY) {
Graphics2D g2d = (Graphics2D) g;
g2d.setColor(Color.BLACK);
int numOfIlluminator = 0;
switch (_Illuminator)
{
case Ten:
numOfIlluminator = 10;
break;
case Twenty:
numOfIlluminator = 20;
break;
case Thirty:
numOfIlluminator = 30;
break;
}
for(int i = numOfIlluminator; i >= 1; --i){
g2d.setColor(Color.CYAN);
g2d.drawPolygon(new int[] {_startPosX + 105 - 3 * i, _startPosX + 102 - 3 * i, _startPosX + 108 - 3 * i}, new int[] {_startPosY + 35, _startPosY + 38, _startPosY + 38}, 3);
g2d.setColor(Color.BLACK);
g2d.fillPolygon(new int[] {_startPosX + 105 - 3 * i, _startPosX + 102 - 3 * i, _startPosX + 108 - 3 * i}, new int[] {_startPosY + 35, _startPosY + 38, _startPosY + 38}, 3);
}
}
}

View File

@ -1,20 +0,0 @@
import java.awt.*;
public class EntityAirbus extends EntityPlane{
public Color DopColor;
public boolean BodyKit;
public boolean Wing;
public boolean SportLine;
public EntityAirbus(int speed, float weight, Color bodyColor, Color dopColor, boolean bodyKit, boolean wing, boolean sportLine) {
super(speed, weight, bodyColor);
DopColor = dopColor;
BodyKit = bodyKit;
Wing = wing;
SportLine = sportLine;
}
}

View File

@ -1,31 +0,0 @@
import java.awt.*;
import java.util.Random;
public class EntityPlane {
private int Speed;
public int GetSpeed() {
return Speed;
}
private float Weight;
public float GetWeight() {
return Weight;
}
private Color BodyColor;
public Color GetBodyColor() {
return BodyColor;
}
public float Step;
public float GetStep(){return Step;}
public EntityPlane(int speed, float weight, Color bodyColor)
{
Random rnd = new Random();
Speed = speed <= 0 ? rnd.nextInt(50,150) : speed;
Weight = weight <= 0 ? rnd.nextInt(40,70) : weight;
BodyColor = bodyColor;
Step = Speed * 100 / (int)Weight;
}
}

View File

@ -1,202 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="FormMapWithSetPlanes">
<grid id="27dc6" binding="Mainpanel" layout-manager="GridLayoutManager" row-count="4" 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="798" height="526"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<grid id="9bb5a" binding="pictureBoxPlane" layout-manager="BorderLayout" hgap="0" vgap="0">
<constraints>
<grid row="0" column="0" row-span="3" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false">
<minimum-size width="600" height="500"/>
<preferred-size width="600" height="500"/>
<maximum-size width="600" height="500"/>
</grid>
</constraints>
<properties>
<enabled value="true"/>
</properties>
<border type="none"/>
<children/>
</grid>
<hspacer id="b305e">
<constraints>
<grid row="3" 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>
<grid id="4fa91" binding="GroupBoxTools" layout-manager="GridLayoutManager" row-count="8" 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="1" column="1" row-span="3" 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>
<component id="cdb80" class="javax.swing.JButton" binding="ButtonAddPlane">
<constraints>
<grid row="0" column="0" row-span="1" col-span="3" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Добавить самолёт"/>
</properties>
</component>
<component id="e5494" class="javax.swing.JTextField" binding="maskedTextBoxPosition">
<constraints>
<grid row="1" column="0" row-span="1" col-span="3" 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="8bb89" class="javax.swing.JButton" binding="ButtonDeletePlane">
<constraints>
<grid row="2" column="0" row-span="1" col-span="3" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Удалить самолёт"/>
</properties>
</component>
<component id="aa482" class="javax.swing.JButton" binding="ButtonShowStorage">
<constraints>
<grid row="3" column="0" row-span="1" col-span="3" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Показать хранилище"/>
</properties>
</component>
<component id="9ebdc" class="javax.swing.JButton" binding="ButtonShowMap">
<constraints>
<grid row="4" column="0" row-span="1" col-span="3" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Показать карту"/>
</properties>
</component>
<component id="acbc" class="javax.swing.JButton" binding="ButtonUp">
<constraints>
<grid row="6" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="3" 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>
<text value=""/>
</properties>
</component>
<component id="a584e" class="javax.swing.JButton" binding="ButtonDown">
<constraints>
<grid row="7" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="3" 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>
<text value=""/>
</properties>
</component>
<component id="e9fe6" class="javax.swing.JButton" binding="ButtonLeft">
<constraints>
<grid row="7" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="3" 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>
<text value=""/>
</properties>
</component>
<component id="25a22" class="javax.swing.JButton" binding="ButtonRight">
<constraints>
<grid row="7" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="3" 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>
<text value=""/>
</properties>
</component>
<component id="6734a" class="javax.swing.JButton" binding="ButtonCheckDel">
<constraints>
<grid row="5" column="0" row-span="1" col-span="3" 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="d087c" binding="GroupBoxMaps" layout-manager="GridLayoutManager" row-count="7" 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="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<component id="124b6" class="javax.swing.JTextField" binding="textBoxNewMapName">
<constraints>
<grid row="1" 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>
<vspacer id="3ed0f">
<constraints>
<grid row="6" 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="95ba3" class="javax.swing.JComboBox" binding="ComboBoxSelectorMap">
<constraints>
<grid row="2" 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="Карта острова"/>
<item value="Карта скалы"/>
</model>
</properties>
</component>
<component id="fb777" class="javax.swing.JButton" binding="ButtonAddMap">
<constraints>
<grid row="3" 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="a358a" class="javax.swing.JButton" binding="ButtonDeleteMap">
<constraints>
<grid row="5" 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="64e67">
<constraints>
<grid row="0" 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="e221" class="javax.swing.JList" binding="ListBoxMaps" custom-create="true">
<constraints>
<grid row="4" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="2" anchor="0" fill="3" indent="0" use-parent-layout="false">
<preferred-size width="150" height="50"/>
</grid>
</constraints>
<properties/>
</component>
</children>
</grid>
</children>
</grid>
</form>

View File

@ -1,229 +0,0 @@
import javax.imageio.ImageIO;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.image.BufferedImage;
import java.util.HashMap;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
public class FormMapWithSetPlanes extends JFrame{
public JPanel Mainpanel;
private JPanel pictureBoxPlane;
private JPanel GroupBoxTools;
private JComboBox ComboBoxSelectorMap;
private JButton ButtonAddPlane;
private JButton ButtonDeletePlane;
private JButton ButtonShowStorage;
private JButton ButtonShowMap;
private JButton ButtonLeft;
private JButton ButtonDown;
private JButton ButtonUp;
private JButton ButtonRight;
private JTextField maskedTextBoxPosition;
private JTextField textBoxNewMapName;
private int picWidth=600;
private int picHeight=500;
private JButton ButtonAddMap;
private JList ListBoxMaps;
private JButton ButtonDeleteMap;
private JPanel GroupBoxMaps;
private JButton ButtonCheckDel;
private MapWithSetPlanesGeneric<DrawningObjectPlane,AbstractMap> _mapPlanesCollectionGeneric;
private final HashMap<String,AbstractMap> _mapsDict = new HashMap<>(){{
put("Простая карта",new SimpleMap());
put("Вторая карта",new MyMap());
}};
private final MapsCollection _mapsCollection;
public void UpdateWindow(BufferedImage bmp)
{
pictureBoxPlane.removeAll();
JLabel imageWithMapAndObject = new JLabel();
imageWithMapAndObject.setPreferredSize(pictureBoxPlane.getSize());
imageWithMapAndObject.setMinimumSize(new Dimension(1, 1));
imageWithMapAndObject.setIcon(new ImageIcon(bmp));
pictureBoxPlane.add(imageWithMapAndObject, BorderLayout.CENTER);
pictureBoxPlane.revalidate();
}
private void ReloadMaps(){
int index = ListBoxMaps.getSelectedIndex();
DefaultListModel<String> model1 = (DefaultListModel<String>) ListBoxMaps.getModel();
model1.removeAllElements();
for(int i=0;i<_mapsCollection.Keys().size();i++)
{
model1.addElement(_mapsCollection.Keys().get(i));
}
if (ListBoxMaps.getModel().getSize() > 0 && (index == -1 || index >= ListBoxMaps.getModel().getSize()))
{
ListBoxMaps.setSelectedIndex(0);
}
else if (ListBoxMaps.getModel().getSize() > 0 && index > -1 && index < ListBoxMaps.getModel().getSize())
{
ListBoxMaps.setSelectedIndex(index);
}
}
private void ButtonMove_Click(String name)
{
Direction direction = Direction.None;
switch (name)
{
case "buttonLeft":
direction = Direction.Left;
break;
case "buttonUp":
direction = Direction.Up;
break;
case "buttonRight":
direction = Direction.Right;
break;
case "buttonDown":
direction = Direction.Down;
break;
}
UpdateWindow(_mapsCollection.Get(ListBoxMaps.getSelectedValue().toString()).MoveObject(direction));
}
public FormMapWithSetPlanes()
{
_mapsCollection = new MapsCollection(picWidth, picHeight);
ComboBoxSelectorMap.removeAllItems();
for (String elem : _mapsDict.keySet()) {
ComboBoxSelectorMap.addItem(elem);
}
try {
Image img = ImageIO.read(FormPlane.class.getResource("/Resource/arrowUp.jpg"));
ButtonUp.setIcon(new ImageIcon(img));
img = ImageIO.read(FormPlane.class.getResource("/Resource/arrowDown.jpg"));
ButtonDown.setIcon(new ImageIcon(img));
img = ImageIO.read(FormPlane.class.getResource("/Resource/arrowLeft.jpg"));
ButtonLeft.setIcon(new ImageIcon(img));
img = ImageIO.read(FormPlane.class.getResource("/Resource/arrowRight.jpg"));
ButtonRight.setIcon(new ImageIcon(img));
} catch (Exception ex) {
System.out.println(ex);
}
ButtonAddPlane.addActionListener(e -> {
if (ListBoxMaps.getSelectedIndex() == -1)
{
return;
}
FormPlane dialog = new FormPlane();
dialog.setSize(800, 600);
dialog.setLocation(500, 200);
dialog.setModalityType(Dialog.ModalityType.APPLICATION_MODAL);
dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
dialog.setVisible(true);
if (dialog.GetSelectedPlane() == null) return;
DrawningObjectPlane Plane = new DrawningObjectPlane(dialog.GetSelectedPlane());
if(_mapsCollection.Get(ListBoxMaps.getSelectedValue().toString()).addPlane(Plane)!=-1)
{
JOptionPane.showMessageDialog(null,"Объект добавлен");
UpdateWindow(_mapsCollection.Get(ListBoxMaps.getSelectedValue().toString()).ShowSet());
}
else
{
JOptionPane.showMessageDialog(null, "Не удалось добавить объект");
}
});
ListBoxMaps.addListSelectionListener(e -> {
if (ListBoxMaps.getSelectedIndex() == -1)
return;
UpdateWindow(_mapsCollection.Get(ListBoxMaps.getSelectedValue().toString()).ShowSet());
});
ButtonDeletePlane.addActionListener(e -> {
if (maskedTextBoxPosition.getText().isEmpty())
{
return;
}
int result = JOptionPane.showConfirmDialog(null,"Удалить объект?","Удаление",JOptionPane.YES_NO_OPTION,JOptionPane.WARNING_MESSAGE);
if(result==JOptionPane.NO_OPTION)
{
return;
}
int pos=Integer.parseInt(maskedTextBoxPosition.getText());
if(_mapsCollection.Get(ListBoxMaps.getSelectedValue().toString()).removePlane(pos)!=null)
{
JOptionPane.showMessageDialog(null, "Объект удален");
UpdateWindow(_mapsCollection.Get(ListBoxMaps.getSelectedValue().toString()).ShowSet());
}
else
{
JOptionPane.showMessageDialog(null, "Не удалось удалить объект");
}
});
ButtonShowStorage.addActionListener(e -> {
if (ListBoxMaps.getSelectedIndex() == -1)
{
return;
}
UpdateWindow(_mapsCollection.Get(ListBoxMaps.getSelectedValue().toString()).ShowSet());
});
ButtonShowMap.addActionListener(e -> {
if (ListBoxMaps.getSelectedIndex() == -1)
{
return;
}
UpdateWindow(_mapsCollection.Get(ListBoxMaps.getSelectedValue().toString()).ShowOnMap());
});
ButtonUp.addActionListener(e -> ButtonMove_Click("buttonUp"));
ButtonLeft.addActionListener(e -> ButtonMove_Click("buttonLeft"));
ButtonDown.addActionListener(e -> ButtonMove_Click("buttonDown"));
ButtonRight.addActionListener(e -> ButtonMove_Click("buttonRight"));
maskedTextBoxPosition.addKeyListener(new KeyAdapter() {
@Override
public void keyTyped(KeyEvent e) {
char c = e.getKeyChar();
if ( ((c < '0') || (c > '9')) || maskedTextBoxPosition.getText().length() >= 2) {
e.consume();
}
}
});
ButtonAddMap.addActionListener(e -> {
if (ComboBoxSelectorMap.getSelectedIndex() == -1 || textBoxNewMapName.getText().isEmpty())
{
JOptionPane.showMessageDialog(null,"Не все данные заполнены","Ошибка",JOptionPane.ERROR_MESSAGE);
return;
}
if(!_mapsDict.containsKey(ComboBoxSelectorMap.getSelectedItem()))
{
JOptionPane.showMessageDialog(null,"Нет такой карты","Ошибка",JOptionPane.ERROR_MESSAGE);
}
_mapsCollection.AddMap(textBoxNewMapName.getText(),_mapsDict.get(ComboBoxSelectorMap.getSelectedItem().toString()));
ReloadMaps();
});
ButtonDeleteMap.addActionListener(e -> {
if (ListBoxMaps.getSelectedIndex() == -1)
{
return;
}
if(JOptionPane.showConfirmDialog(null,"Удалить карту"+ListBoxMaps.getSelectedValue().toString()+"?","Удаление",JOptionPane.YES_NO_OPTION)==0)
{
_mapsCollection.DelMap(ListBoxMaps.getSelectedValue().toString());
ReloadMaps();
}
});
ButtonCheckDel.addActionListener(e -> {
if (ListBoxMaps.getSelectedIndex() == -1)
{
return;
}
DrawningObjectPlane Plane=_mapsCollection.Get(ListBoxMaps.getSelectedValue().toString()).GetPlanesDeleted();
if(Plane==null)
{
JOptionPane.showMessageDialog(null,"Коллекция пуста","Ошибка",JOptionPane.ERROR_MESSAGE);
return;
}
FormPlane formPlane=new FormPlane(Plane);
formPlane.setSize(1000,800);
formPlane.setVisible(true);
});
}
private void createUIComponents() {
DefaultListModel<String> dlm = new DefaultListModel<String>();
ListBoxMaps = new JList(dlm);
}
}

View File

@ -1,62 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="FormParam">
<grid id="27dc6" binding="MainPanel" layout-manager="GridLayoutManager" row-count="4" 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="500" height="400"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<grid id="7700e" binding="pictureBoxPlane" layout-manager="BorderLayout" hgap="0" vgap="0">
<constraints>
<grid row="0" column="0" row-span="1" col-span="2" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<border type="none"/>
<children/>
</grid>
<component id="b960b" class="javax.swing.JButton" binding="ButtonCreate">
<constraints>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Создать"/>
</properties>
</component>
<component id="a44b0" class="javax.swing.JButton" binding="ButtonCreateModif">
<constraints>
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Модификация"/>
</properties>
</component>
<hspacer id="56304">
<constraints>
<grid row="1" 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>
<component id="31e01" class="javax.swing.JLabel" binding="LabelInfo">
<constraints>
<grid row="2" 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>
<toolbar id="7a0ba" binding="StatusStrip">
<constraints>
<grid row="3" column="0" row-span="1" col-span="2" vsize-policy="0" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false">
<preferred-size width="-1" height="20"/>
</grid>
</constraints>
<properties>
<enabled value="false"/>
</properties>
<border type="none"/>
<children/>
</toolbar>
</children>
</grid>
</form>

View File

@ -1,104 +0,0 @@
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.image.BufferedImage;
import java.util.Random;
public class FormParam extends JFrame{
public JPanel MainPanel;
private JPanel pictureBoxPlane;
private JButton ButtonCreate;
private JButton ButtonCreateModif;
private JToolBar StatusStrip;
private JLabel LabelInfo;
private JLabel JLabelSpeed = new JLabel();
private JLabel JLabelWeight = new JLabel();
private JLabel JLabelColor = new JLabel();
private DrawningEntities<EntityPlane,IDrawningIlluminator> _drawningEntities;
private IDrawningIlluminator SetData()
{
Random random=new Random();
int r = random.nextInt(3);
if(r==0)
{
return new DrawningIlluminator();
}
if(r==1)
{
return new DrawningSqareIlluminator();
}
else
{
return new DrawningTriangleIlluminator();
}
}
private void Draw(DrawningPlane _plane) {
pictureBoxPlane.removeAll();
Random random = new Random();
BufferedImage bmp = new BufferedImage(pictureBoxPlane.getWidth(), pictureBoxPlane.getHeight(),BufferedImage.TYPE_INT_RGB);
Graphics gr = bmp.getGraphics();
gr.setColor(new Color(238, 238, 238));
gr.fillRect(0, 0, pictureBoxPlane.getWidth(), pictureBoxPlane.getHeight());
if (_plane != null) {
_plane.SetPosition(random.nextInt(10, 100), random.nextInt(10, 100), pictureBoxPlane.getWidth(), pictureBoxPlane.getHeight());
_plane.DrawTransport(gr);
JLabelSpeed.setText("орость: " + _plane.GetPlane().GetSpeed() + " ");
JLabelWeight.setText("Вес: " + _plane.GetPlane().GetWeight() + " ");
JLabelColor.setText(("Цвет: " + _plane.GetPlane().GetBodyColor() + " "));
JLabel imageOfPlane = new JLabel();
imageOfPlane.setPreferredSize(pictureBoxPlane.getSize());
imageOfPlane.setMinimumSize(new Dimension(1, 1));
imageOfPlane.setIcon(new ImageIcon(bmp));
pictureBoxPlane.add(imageOfPlane,BorderLayout.CENTER);
}
validate();
}
public FormParam()
{
Box LabelBox = Box.createHorizontalBox();
LabelBox.setMinimumSize(new Dimension(1, 20));
LabelBox.add(JLabelSpeed);
LabelBox.add(JLabelWeight);
LabelBox.add(JLabelColor);
StatusStrip.add(LabelBox);
_drawningEntities = new DrawningEntities<>(10,10);
ButtonCreate.addActionListener(e -> {
Random random = new Random();
Color colorFirst = JColorChooser.showDialog(null, "Цвет", null);
EntityPlane _plane = new EntityPlane(random.nextInt(100,300), random.nextInt(1000,2000),colorFirst);
IDrawningIlluminator illum = SetData();
int IllumCount = random.nextInt(1,4) * 10;
illum.SetIlluminatorCount(IllumCount);
if((_drawningEntities.Insert(_plane)!=-1) & (_drawningEntities.Insert(illum)!=-1))
{
JOptionPane.showMessageDialog(null,"Объект добавлен");
Draw(_drawningEntities.CreatePlane());
LabelInfo.setText(_drawningEntities.indx+ " " + _drawningEntities.indy);
}
else
{
JOptionPane.showMessageDialog(null, "Не удалось добавить объект");
}
});
ButtonCreateModif.addActionListener(e -> {
Random random = new Random();
Color colorFirst = JColorChooser.showDialog(null, "Цвет", null);
Color colorSecond = JColorChooser.showDialog(null, "Цвет", null);
EntityAirbus _plane = new EntityAirbus(random.nextInt(100, 300), random.nextInt(1000, 2000), colorFirst, colorSecond, random.nextBoolean(), random.nextBoolean(), random.nextBoolean());
IDrawningIlluminator illum = SetData();
int IllumCount = random.nextInt(1,4) * 10;
illum.SetIlluminatorCount(IllumCount);
if((_drawningEntities.Insert(_plane)!=-1) & (_drawningEntities.Insert(illum)!=-1))
{
JOptionPane.showMessageDialog(null,"Объект добавлен");
Draw(_drawningEntities.CreatePlane());
LabelInfo.setText(_drawningEntities.indx+ " " + _drawningEntities.indy);
}
else
{
JOptionPane.showMessageDialog(null, "Не удалось добавить объект");
}
});
}
}

View File

@ -1,116 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="FormPlane">
<grid id="27dc6" binding="Mainpanel" layout-manager="GridLayoutManager" row-count="4" 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="513" height="406"/>
</constraints>
<properties>
<opaque value="true"/>
<preferredSize width="800" height="600"/>
</properties>
<border type="none"/>
<children>
<component id="2ea16" class="javax.swing.JButton" binding="ButtonDown">
<constraints>
<grid row="2" column="5" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="3" 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>
<text value=""/>
</properties>
</component>
<component id="4f60a" class="javax.swing.JButton" binding="ButtonLeft">
<constraints>
<grid row="2" column="4" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="3" 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>
<text value=""/>
</properties>
</component>
<component id="4eb88" class="javax.swing.JButton" binding="ButtonRight">
<constraints>
<grid row="2" column="6" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="3" 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>
<horizontalAlignment value="0"/>
<text value=""/>
</properties>
</component>
<toolbar id="e747d" binding="StatusStrip">
<constraints>
<grid row="3" column="0" row-span="1" col-span="7" vsize-policy="0" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false">
<minimum-size width="-1" height="20"/>
<preferred-size width="-1" height="20"/>
<maximum-size width="-1" height="20"/>
</grid>
</constraints>
<properties>
<enabled value="false"/>
</properties>
<border type="none"/>
<children/>
</toolbar>
<component id="9e2ce" class="javax.swing.JButton" binding="ButtonCreate">
<constraints>
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Создать"/>
</properties>
</component>
<grid id="febd4" binding="PictureBox" layout-manager="FlowLayout" hgap="5" vgap="5" flow-align="1">
<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>
<component id="fb937" class="javax.swing.JButton" binding="ButtonUp">
<constraints>
<grid row="1" column="5" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="3" 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>
<text value=""/>
</properties>
</component>
<component id="44b75" class="javax.swing.JButton" binding="ButtonModif">
<constraints>
<grid row="2" 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="f022f" class="javax.swing.JButton" binding="ButtonSelectPlane">
<constraints>
<grid row="2" 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>
<hspacer id="3f9b1">
<constraints>
<grid row="2" 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>
</children>
</grid>
</form>

View File

@ -1,139 +0,0 @@
import javax.imageio.ImageIO;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ComponentAdapter;
import java.awt.event.ComponentEvent;
import java.awt.image.BufferedImage;
import java.util.Random;
import static java.lang.Boolean.parseBoolean;
public class FormPlane extends JDialog{
public JPanel Mainpanel;
private JButton ButtonCreate;
private JButton ButtonLeft;
private JButton ButtonUp;
private JButton ButtonDown;
private JButton ButtonRight;
protected DrawningPlane _plane;
private JPanel PictureBox;
private JToolBar StatusStrip;
private JButton ButtonModif;
private JButton ButtonSelectPlane;
private final JLabel JLabelSpeed = new JLabel();
private final JLabel JLabelWeight = new JLabel();
private final JLabel JLabelColor = new JLabel();
private DrawningPlane SelectedPlane;
public DrawningPlane GetSelectedPlane() {
return SelectedPlane;
}
public void Draw() {
PictureBox.removeAll();
BufferedImage bmp = new BufferedImage(PictureBox.getWidth(), PictureBox.getHeight(),BufferedImage.TYPE_INT_RGB);
Graphics gr = bmp.getGraphics();
gr.setColor(new Color(238, 238, 238));
gr.fillRect(0, 0, PictureBox.getWidth(), PictureBox.getHeight());
if (_plane != null) {
_plane.DrawTransport(gr);
JLabel imageOfPlane = new JLabel();
imageOfPlane.setPreferredSize(PictureBox.getSize());
imageOfPlane.setMinimumSize(new Dimension(1, 1));
imageOfPlane.setIcon(new ImageIcon(bmp));
PictureBox.add(imageOfPlane,BorderLayout.CENTER);
}
validate();
}
private void SetData(){
Random random = new Random();
_plane.SetPosition(random.nextInt(10, 100), random.nextInt(10, 100), PictureBox.getWidth(), PictureBox.getHeight());
JLabelSpeed.setText("орость: " + _plane.GetPlane().GetSpeed() + " ");
JLabelWeight.setText("Вес: " + _plane.GetPlane().GetWeight() + " ");
JLabelColor.setText(("Цвет: " + _plane.GetPlane().GetBodyColor() + " "));
}
private void CreateWindow(){
add(Mainpanel);
Box LabelBox = Box.createHorizontalBox();
LabelBox.setMinimumSize(new Dimension(1, 20));
LabelBox.add(JLabelSpeed);
LabelBox.add(JLabelWeight);
LabelBox.add(JLabelColor);
StatusStrip.add(LabelBox);
try {
Image img = ImageIO.read(FormPlane.class.getResource("/Resource/arrowUp.jpg"));
ButtonUp.setIcon(new ImageIcon(img));
img = ImageIO.read(FormPlane.class.getResource("/Resource/arrowDown.jpg"));
ButtonDown.setIcon(new ImageIcon(img));
img = ImageIO.read(FormPlane.class.getResource("/Resource/arrowLeft.jpg"));
ButtonLeft.setIcon(new ImageIcon(img));
img = ImageIO.read(FormPlane.class.getResource("/Resource/arrowRight.jpg"));
ButtonRight.setIcon(new ImageIcon(img));
} catch (Exception ex) {
System.out.println(ex);
}
ButtonCreate.addActionListener(e -> {
Random random = new Random();
Color color = JColorChooser.showDialog(null, "Цвет", null);
_plane = new DrawningPlane(random.nextInt(100, 300),random.nextInt(1000, 2000),color);
SetData();
Draw();
});
ButtonModif.addActionListener(e -> {
Random random = new Random();
Color first = JColorChooser.showDialog(null, "Цвет", null);
Color second = JColorChooser.showDialog(null, "Цвет", null);
_plane = new DrawningAirbus(random.nextInt(100, 300), random.nextInt(1000, 2000), first, second, random.nextBoolean(), random.nextBoolean(), random.nextBoolean());
SetData();
Draw();
});
PictureBox.addComponentListener(new ComponentAdapter() {
@Override
public void componentResized(ComponentEvent e) {
if(_plane == null || _plane.GetPlane() == null) return;
super.componentResized(e);
_plane.ChangeBorders(PictureBox.getWidth(), PictureBox.getHeight());
PictureBox.revalidate();
Draw();
}
});
ButtonUp.addActionListener(e -> {
_plane.MoveTransport(Direction.Up);
PictureBox.revalidate();
Draw();
});
ButtonDown.addActionListener(e -> {
_plane.MoveTransport(Direction.Down);
PictureBox.revalidate();
Draw();
});
ButtonRight.addActionListener(e -> {
_plane.MoveTransport(Direction.Right);
PictureBox.revalidate();
Draw();
});
ButtonLeft.addActionListener(e -> {
_plane.MoveTransport(Direction.Left);
PictureBox.revalidate();
Draw();
});
ButtonSelectPlane.addActionListener(e -> {
SelectedPlane = _plane;
setVisible(false);
dispose();
});
}
public FormPlane() {
super(new Frame("Самолёт"));
CreateWindow();
setModal(true);
getContentPane().add(Mainpanel);
}
public FormPlane(DrawningObjectPlane plane){
super(new Frame("Корабль"));
CreateWindow();
setModal(true);
_plane = plane.GetDrawningObjectPlane();
getContentPane().add(Mainpanel);
}
}

View File

@ -1,7 +0,0 @@
import java.awt.*;
public interface IDrawningIlluminator {
void SetIlluminatorCount(int numOfIllum);
void DrawIlluminator(Graphics g, int _startPosX, int _startPosY);
}

View File

@ -1,13 +0,0 @@
import java.awt.*;
public interface IDrawningObject {
float Step();
void SetObject(int x, int y, int width, int height);
void MoveObject(Direction direction);
void DrawningObject(Graphics g);
float[] GetCurrentPosition();
}

View File

@ -1,22 +0,0 @@
public enum IlluminatorCount {
Ten,
Twenty,
Thirty;
public static IlluminatorCount GetIlluminatorCount(int Value)
{
switch(Value)
{
case 10:
return Ten;
case 20:
return Twenty;
case 30:
return Thirty;
}
return null;
}
}

View File

@ -1,14 +0,0 @@
import javax.swing.*;
public class Main {
public static void main(String[] args) {
JFrame frame = new JFrame("Самолёт");
frame.setContentPane(new FormMapWithSetPlanes().Mainpanel);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setLocation(500, 200);
frame.pack();
frame.setSize(800, 600);
frame.setVisible(true);
}
}

View File

@ -1,155 +0,0 @@
import java.awt.*;
import java.awt.image.BufferedImage;
import java.util.LinkedList;
public class MapWithSetPlanesGeneric <T extends IDrawningObject, U extends AbstractMap>
{
private int _pictureWidth;
private int _pictureHeight;
private int _placeSizeWidth = 210;
private int _placeSizeHeight = 90;
private SetPlanesGeneric<T> _setPlanes;
private U _map;
private LinkedList<T> _deletedPlanes;
public MapWithSetPlanesGeneric(int picWidth, int picHeight, U map)
{
_deletedPlanes = new LinkedList<>();
int width = picWidth / _placeSizeWidth;
int height = picHeight / _placeSizeHeight;
_setPlanes = new SetPlanesGeneric<T>(width * height);
_pictureWidth = picWidth;
_pictureHeight = picHeight;
_map = map;
}
public int addPlane(T planes)
{
return _setPlanes.Insert(planes);
}
public T removePlane(int position)
{
T plane = _setPlanes.Remove(position);
_deletedPlanes.offerFirst(plane);
return plane;
}
public BufferedImage ShowSet()
{
BufferedImage img = new BufferedImage(_pictureWidth, _pictureHeight, BufferedImage.TYPE_INT_ARGB);
Graphics2D gr = (Graphics2D) img.getGraphics();
DrawBackground(gr);
DrawPlanes(gr);
return img;
}
public BufferedImage ShowOnMap()
{
BufferedImage bmp = new BufferedImage(_pictureWidth, _pictureHeight, BufferedImage.TYPE_INT_RGB);
Shaking();
for (int i = 0; i < _setPlanes.Count(); i++)
{
var ship = _setPlanes.Get(i);
if (ship != null)
{
return _map.CreateMap(_pictureWidth, _pictureHeight, ship);
}
}
return bmp;
}
public BufferedImage MoveObject(Direction direction)
{
BufferedImage img = new BufferedImage(_pictureWidth, _pictureHeight, BufferedImage.TYPE_INT_ARGB);
if (_map != null)
{
_map.MoveObject(direction);
}
return img;
}
private void Shaking()
{
int j = _setPlanes.Count() - 1;
for (int i = 0; i < _setPlanes.Count(); i++)
{
if (_setPlanes.Get(i) == null)
{
for (; j > i; j--)
{
var plane = _setPlanes.Get(j);
if (plane != null)
{
_setPlanes.Insert(plane, i);
_setPlanes.Remove(j);
break;
}
}
if (j <= i)
{
return;
}
}
}
}
private void DrawBackground(Graphics g)
{
Graphics2D g2d = (Graphics2D) g;
g2d.setColor(Color.GRAY);
g.fillRect(0, 0, _pictureWidth, _pictureHeight);
g2d.setColor(Color.WHITE);
for (int y = 0; y < _pictureHeight; y+=80)
{
g.fillRect(_pictureWidth / 2 - 10, y, 20, 70);
}
int lastLine = 0;
for (int y = 50; y < _pictureHeight; y += _pictureHeight/3 - 50)
{
g.fillRect(_pictureWidth / 3 - 10, y, 20, 70);
g.fillRect(_pictureWidth - _pictureWidth / 3 - 10, y, 20, 70);
lastLine = y;
}
g.fillRect(_pictureWidth / 3 - 40, lastLine, 20, 70);
g.fillRect(_pictureWidth - _pictureWidth / 3 + 20, lastLine, 20, 70);
g2d.setColor(Color.BLACK);
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);
}
}
private void DrawPlanes(Graphics g)
{
int width = _pictureWidth / _placeSizeWidth;
int height = _pictureHeight / _placeSizeHeight;
for (int i = 0; i < _setPlanes.Count(); i++)
{
if(_setPlanes.Get(i) != null)
{
_setPlanes.Get(i).SetObject((width - i % width - 1) * _placeSizeWidth,(height - i / width - 1) * _placeSizeHeight, _pictureWidth, _pictureHeight);
_setPlanes.Get(i).DrawningObject(g);
}
}
}
public T GetSelectedPlane(int ind){
return _setPlanes.Get(ind);
}
public T GetPlanesDeleted()
{
if(_deletedPlanes.isEmpty())
{
return null;
}
return _deletedPlanes.removeFirst();
}
}

View File

@ -1,44 +0,0 @@
import java.util.ArrayList;
import java.util.HashMap;
public class MapsCollection {
private final HashMap<String,MapWithSetPlanesGeneric<DrawningObjectPlane, AbstractMap>> _mapStorages;
public ArrayList<String> Keys()
{
return new ArrayList<>(_mapStorages.keySet());
}
private final int _pictureWidth;
private final int _pictureHeight;
public MapsCollection(int pictureWidth,int pictureHeight)
{
_mapStorages=new HashMap<>();
_pictureWidth=pictureWidth;
_pictureHeight=pictureHeight;
}
public void AddMap(String Name, AbstractMap Map)
{
if(!_mapStorages.containsKey(Name))
{
_mapStorages.put(Name,new MapWithSetPlanesGeneric<>(_pictureWidth,_pictureHeight,Map));
}
}
public void DelMap(String name)
{
_mapStorages.remove(name);
}
public MapWithSetPlanesGeneric<DrawningObjectPlane,AbstractMap> Get(String ind)
{
if(_mapStorages.containsKey(ind))
{
return _mapStorages.get(ind);
}
return null;
}
public DrawningObjectPlane Get(String name, int ind) {
if (_mapStorages.containsKey(name))
{
return _mapStorages.get(name).GetSelectedPlane(ind);
}
return null;
}
}

View File

@ -1,44 +0,0 @@
import java.awt.*;
public class MyMap extends AbstractMap{
private Color barrierColor = Color.WHITE;
private Color roadColor = Color.CYAN;
@Override
protected void DrawBarrierPart(Graphics2D g, int i, int j)
{
g.setPaint(barrierColor);
g.fillRect((int)Math.floor(i * _size_x), (int)Math.floor(j * _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)Math.floor(i * _size_x), (int)Math.floor(j * _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 < 25)
{
int x = _random.nextInt(0, 100);
int y = _random.nextInt(0, 100);
if (_map[x][y] == _freeRoad)
{
_map[x][y] = _barrier;
counter++;
}
}
}
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.2 KiB

View File

@ -1,54 +0,0 @@
import java.util.ArrayList;
import java.util.Iterator;
public class SetPlanesGeneric<T extends Object> implements Iterable<T> {
private ArrayList<T> _places;
private final int _maxCount;
public int Count() {
return _places.size();
}
public SetPlanesGeneric(int count) {
_maxCount=count;
_places = new ArrayList<>();
}
public int Insert(T plane) {
return Insert(plane, 0);
}
public int Insert(T plane, int position) {
if (position < 0 || position > Count() || _maxCount == Count()) return -1;
_places.add(position,plane);
return position;
}
public T Remove(int position) {
if (position >= Count() || position < 0)
{
return null;
}
T ship = (T) _places.get(position);
_places.remove(ship);
return ship;
}
public T Get(int position) {
if (position >= Count() || position<0)
{
return null;
}
return _places.get(position);
}
public void Set(int position,T value)
{
if (position < _maxCount || position >= 0)
{
Insert(value,position);
}
}
@Override
public Iterator<T> iterator() {
return _places.iterator();
}
}

View File

@ -1,45 +0,0 @@
import java.awt.*;
public class SimpleMap extends AbstractMap{
private Color barrierColor = Color.BLACK;
private Color roadColor = Color.GRAY;
@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 < 50)
{
int x = _random.nextInt(0, 100);
int y = _random.nextInt(0, 100);
if (_map[x][y] == _freeRoad)
{
_map[x][y] = _barrier;
counter++;
}
}
}
@Override
protected void DrawRoadPart(Graphics2D g, int i, int j)
{
g.setPaint(roadColor);
g.fillRect((int)Math.floor(i * _size_x), (int)Math.floor(j * _size_y), (int)Math.ceil(_size_x), (int)Math.ceil(_size_y));
}
@Override
protected void DrawBarrierPart(Graphics2D g, int i, int j)
{
g.setPaint(barrierColor);
g.fillRect((int)Math.floor(i * _size_x), (int)Math.floor(j * _size_y), (int)Math.ceil(_size_x), (int)Math.ceil(_size_y));
}
}