Compare commits
9 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
6663b98a92 | ||
|
015b2df664 | ||
|
dcdcdaaa20 | ||
|
ace10a75f7 | ||
|
8d9e0c9eb8 | ||
|
9f2db8fe31 | ||
|
f25feff68b | ||
|
685b97e188 | ||
|
86f553ca83 |
188
AbstractMap.java
Normal file
188
AbstractMap.java
Normal 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)
|
||||
{
|
||||
// TODO проверка, что объект может переместится в требуемом
|
||||
|
||||
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);
|
||||
// TODO првоерка, что объект не "накладывается" на закрытые участки
|
||||
|
||||
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);
|
||||
}
|
71
AircraftFactory.java
Normal file
71
AircraftFactory.java
Normal file
@ -0,0 +1,71 @@
|
||||
import java.awt.*;
|
||||
import java.util.Objects;
|
||||
|
||||
public class AircraftFactory {
|
||||
private static char _separatorForObject = ':';
|
||||
private static Color convertStrToColor(String str) {
|
||||
String color[] = str.split(",");
|
||||
int r = Integer.parseInt(color[0]);
|
||||
int g = Integer.parseInt(color[1]);
|
||||
int b = Integer.parseInt(color[2]);
|
||||
|
||||
return new Color(r, g, b);
|
||||
}
|
||||
|
||||
public static DrawingAircraft createAircraftFromData(String data) {
|
||||
String strsArr[] = data.split(_separatorForObject + "");
|
||||
|
||||
DrawingAircraft result;
|
||||
IDrawingEngines engines;
|
||||
|
||||
switch(strsArr[3]) {
|
||||
case "DrawingTruncatedEngines":
|
||||
engines = new DrawingTruncatedEngines(Integer.parseInt(strsArr[4]), convertStrToColor(strsArr[5]));
|
||||
break;
|
||||
case "DrawingWavyEngines":
|
||||
engines = new DrawingWavyEngines(Integer.parseInt(strsArr[4]), convertStrToColor(strsArr[5]));
|
||||
break;
|
||||
default:
|
||||
engines = new DrawingEngines(Integer.parseInt(strsArr[4]), convertStrToColor(strsArr[5]));
|
||||
}
|
||||
|
||||
if(strsArr.length == 9) {
|
||||
result = new DrawingModernAircraft(
|
||||
Integer.parseInt(strsArr[0]), Float.parseFloat(strsArr[1]), convertStrToColor(strsArr[2]),
|
||||
convertStrToColor(strsArr[6]), Objects.equals(strsArr[8], "true"), Objects.equals(strsArr[7], "true")
|
||||
);
|
||||
} else {
|
||||
result = new DrawingAircraft(
|
||||
Integer.parseInt(strsArr[0]), Float.parseFloat(strsArr[1]), convertStrToColor(strsArr[2])
|
||||
);
|
||||
}
|
||||
result.setEngines(engines);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public static String getDataForSave(DrawingAircraft drawingAircraft) {
|
||||
EntityAircraft aircraft = drawingAircraft.AirFighter;
|
||||
|
||||
String res = aircraft.Speed + "" + _separatorForObject;
|
||||
res += aircraft.Weight + "" + _separatorForObject;
|
||||
res += aircraft.BodyColor.getRed() + "," + aircraft.BodyColor.getGreen() + "," + aircraft.BodyColor.getBlue();
|
||||
res += _separatorForObject;
|
||||
|
||||
IDrawingEngines engines = drawingAircraft.getEngines();
|
||||
|
||||
res += engines.getClass().getName() + _separatorForObject;
|
||||
res += engines.getCount() + "" + _separatorForObject;
|
||||
res += engines.getColor().getRed() + "," + engines.getColor().getGreen() + "," + engines.getColor().getBlue();
|
||||
|
||||
if(aircraft instanceof EntityModernAircraft a) {
|
||||
res += _separatorForObject;
|
||||
res += a.DopColor.getRed() + "," + a.DopColor.getGreen() + "," + a.DopColor.getBlue();
|
||||
res += _separatorForObject;
|
||||
res += a.Rockets + "" + _separatorForObject;
|
||||
res += a.DopWings + "";
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
}
|
50
AircraftMixer.java
Normal file
50
AircraftMixer.java
Normal file
@ -0,0 +1,50 @@
|
||||
import java.util.Random;
|
||||
|
||||
public class AircraftMixer<T extends EntityAircraft, U extends IDrawingEngines> {
|
||||
private T[] aircrafts;
|
||||
private U[] engines;
|
||||
|
||||
public AircraftMixer(int countAircrafts, int countEngines) {
|
||||
aircrafts = (T[])(new EntityAircraft[countAircrafts]);
|
||||
engines = (U[])(new IDrawingEngines[countEngines]);
|
||||
}
|
||||
|
||||
public int add(T a) {
|
||||
int index = 0;
|
||||
while(index < aircrafts.length && aircrafts[index] != null) index++;
|
||||
|
||||
if(index == aircrafts.length) return -1;
|
||||
|
||||
aircrafts[index] = a;
|
||||
return index;
|
||||
}
|
||||
|
||||
public int add(U e) {
|
||||
int index = 0;
|
||||
while(index < engines.length && engines[index] != null) index++;
|
||||
|
||||
if(index == engines.length) return -1;
|
||||
|
||||
engines[index] = e;
|
||||
return index;
|
||||
}
|
||||
|
||||
public DrawingAircraft constructAircraft(int width, int height) {
|
||||
Random rnd = new Random();
|
||||
|
||||
DrawingAircraft air;
|
||||
|
||||
T selectedAircraft = aircrafts[rnd.nextInt(0, aircrafts.length)];
|
||||
U selectedEngines = engines[rnd.nextInt(0, engines.length)];
|
||||
|
||||
DrawingAircraft result;
|
||||
|
||||
if(selectedAircraft instanceof EntityModernAircraft) {
|
||||
result = new DrawingModernAircraft(selectedAircraft, selectedEngines);
|
||||
}
|
||||
else result = new DrawingAircraft(selectedAircraft, selectedEngines);
|
||||
|
||||
result.SetPosition(10, 10, width, height);
|
||||
return result;
|
||||
}
|
||||
}
|
16
Canvas.java
Normal file
16
Canvas.java
Normal file
@ -0,0 +1,16 @@
|
||||
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);
|
||||
}
|
||||
}
|
6
Direction.java
Normal file
6
Direction.java
Normal file
@ -0,0 +1,6 @@
|
||||
public enum Direction {
|
||||
Up,
|
||||
Right,
|
||||
Left,
|
||||
Down
|
||||
}
|
203
DrawingAircraft.java
Normal file
203
DrawingAircraft.java
Normal file
@ -0,0 +1,203 @@
|
||||
import java.awt.*;
|
||||
import java.util.Random;
|
||||
|
||||
class DrawingAircraft
|
||||
{
|
||||
public EntityAircraft AirFighter;
|
||||
public IDrawingEngines drawingEngines;
|
||||
|
||||
protected float _startPosX;
|
||||
protected float _startPosY;
|
||||
|
||||
private int _pictureWidth = -1;
|
||||
private int _pictureHeight = -1;
|
||||
|
||||
private int _airFighterWidth = 195;
|
||||
private int _airFighterHeight = 166;
|
||||
|
||||
private void peekRandomEngines(Color color) {
|
||||
Random rnd = new Random();
|
||||
int randEngine = rnd.nextInt(1, 4);
|
||||
|
||||
switch(randEngine) {
|
||||
case 1:
|
||||
drawingEngines = new DrawingEngines(rnd.nextInt(1, 8), color);
|
||||
break;
|
||||
case 2:
|
||||
drawingEngines = new DrawingTruncatedEngines(rnd.nextInt(1, 8), color);
|
||||
break;
|
||||
case 3:
|
||||
drawingEngines = new DrawingWavyEngines(rnd.nextInt(1, 8), color);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public DrawingAircraft(int speed, float weight, Color bodyColor)
|
||||
{
|
||||
AirFighter = new EntityAircraft(speed, weight, bodyColor);
|
||||
peekRandomEngines(bodyColor);
|
||||
}
|
||||
|
||||
public DrawingAircraft(EntityAircraft airFighter, IDrawingEngines engines)
|
||||
{
|
||||
AirFighter = airFighter;
|
||||
this.drawingEngines = engines;
|
||||
}
|
||||
|
||||
public DrawingAircraft(int speed, float weight, Color bodyColor, int airFighterWidth, int airFighterHeight)
|
||||
{
|
||||
this(speed, weight, bodyColor);
|
||||
_airFighterWidth = airFighterWidth;
|
||||
_airFighterHeight = airFighterHeight;
|
||||
}
|
||||
|
||||
public void setEngines(IDrawingEngines engines) {
|
||||
drawingEngines = engines;
|
||||
}
|
||||
|
||||
public IDrawingEngines getEngines() {
|
||||
return drawingEngines;
|
||||
}
|
||||
|
||||
public void setColor(Color color) {
|
||||
AirFighter.BodyColor = color;
|
||||
}
|
||||
|
||||
public Color getColor() {
|
||||
return AirFighter.BodyColor;
|
||||
}
|
||||
|
||||
public void SetPosition(int x, int y, int width, int height)
|
||||
{
|
||||
if (width < _airFighterWidth || height < _airFighterHeight) return;
|
||||
|
||||
if (x + _airFighterWidth > width || x < 0) return;
|
||||
if (y + _airFighterHeight > 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 + _airFighterWidth + AirFighter.Step < _pictureWidth)
|
||||
{
|
||||
_startPosX += AirFighter.Step;
|
||||
}
|
||||
break;
|
||||
case Left:
|
||||
if (_startPosX - AirFighter.Step > 0)
|
||||
{
|
||||
_startPosX -= AirFighter.Step;
|
||||
}
|
||||
break;
|
||||
case Up:
|
||||
if (_startPosY - AirFighter.Step > 0)
|
||||
{
|
||||
_startPosY -= AirFighter.Step;
|
||||
}
|
||||
break;
|
||||
case Down:
|
||||
if (_startPosY + _airFighterHeight + AirFighter.Step < _pictureHeight)
|
||||
{
|
||||
_startPosY += AirFighter.Step;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void DrawTransport(Graphics2D g)
|
||||
{
|
||||
if (_pictureWidth == -1 || _pictureHeight == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
g.setPaint(AirFighter.BodyColor);
|
||||
|
||||
Polygon front = new Polygon();
|
||||
front.addPoint((int)(_startPosX + 160), (int)(_startPosY + 70));
|
||||
front.addPoint((int)(_startPosX + 195), (int)(_startPosY + 83));
|
||||
front.addPoint((int)(_startPosX + 160), (int)(_startPosY + 96));
|
||||
|
||||
|
||||
Polygon tailTop = new Polygon();
|
||||
tailTop.addPoint((int)(_startPosX), (int)(_startPosY + 30));
|
||||
tailTop.addPoint((int)(_startPosX), (int)(_startPosY + 70));
|
||||
tailTop.addPoint((int)(_startPosX + 25), (int)(_startPosY + 70));
|
||||
tailTop.addPoint((int)(_startPosX + 25), (int)(_startPosY + 55));
|
||||
|
||||
|
||||
Polygon tailBottom = new Polygon();
|
||||
tailBottom.addPoint((int)(_startPosX), (int)(_startPosY + 96));
|
||||
tailBottom.addPoint((int)(_startPosX), (int)(_startPosY + 136));
|
||||
tailBottom.addPoint((int)(_startPosX + 25), (int)(_startPosY + 111));
|
||||
tailBottom.addPoint((int)(_startPosX + 25), (int)(_startPosY + 96));
|
||||
|
||||
|
||||
Polygon wingTop = new Polygon();
|
||||
wingTop.addPoint((int)(_startPosX + 100), (int)(_startPosY));
|
||||
wingTop.addPoint((int)(_startPosX + 100), (int)(_startPosY + 70));
|
||||
wingTop.addPoint((int)(_startPosX + 75), (int)(_startPosY + 70));
|
||||
wingTop.addPoint((int)(_startPosX + 90), (int)(_startPosY));
|
||||
|
||||
|
||||
|
||||
Polygon wingBottom = new Polygon();
|
||||
wingBottom.addPoint((int)(_startPosX + 100), (int)(_startPosY + 96));
|
||||
wingBottom.addPoint((int)(_startPosX + 100), (int)(_startPosY + 166));
|
||||
wingBottom.addPoint((int)(_startPosX + 90), (int)(_startPosY + 166));
|
||||
wingBottom.addPoint((int)(_startPosX + 75), (int)(_startPosY + 96));
|
||||
|
||||
g.fillPolygon(front);
|
||||
g.drawPolygon(tailTop);
|
||||
g.drawPolygon(tailBottom);
|
||||
g.drawPolygon(wingTop);
|
||||
g.drawPolygon(wingBottom);
|
||||
g.drawRect((int)_startPosX, (int)_startPosY + 70, 160, 26);
|
||||
|
||||
drawingEngines.draw(g, (int)_startPosX, (int)_startPosY);
|
||||
}
|
||||
|
||||
public void ChangeBorders(int width, int height)
|
||||
{
|
||||
_pictureWidth = width;
|
||||
_pictureHeight = height;
|
||||
if (_pictureWidth <= _airFighterWidth || _pictureHeight <= _airFighterHeight)
|
||||
{
|
||||
_pictureWidth = -1;
|
||||
_pictureHeight = -1;
|
||||
return;
|
||||
}
|
||||
if (_startPosX + _airFighterWidth > _pictureWidth)
|
||||
{
|
||||
_startPosX = _pictureWidth - _airFighterWidth;
|
||||
}
|
||||
if (_startPosY + _airFighterHeight > _pictureHeight)
|
||||
{
|
||||
_startPosY = _pictureHeight - _airFighterHeight;
|
||||
}
|
||||
}
|
||||
|
||||
public Point getLeftTop() {
|
||||
return new Point((int)_startPosX, (int)_startPosY);
|
||||
}
|
||||
|
||||
public Point getRightBottom() {
|
||||
return new Point((int)_startPosX + _airFighterWidth, (int)_startPosY + _airFighterHeight);
|
||||
}
|
||||
}
|
||||
|
51
DrawingEngines.java
Normal file
51
DrawingEngines.java
Normal file
@ -0,0 +1,51 @@
|
||||
import java.awt.*;
|
||||
|
||||
public class DrawingEngines implements IDrawingEngines {
|
||||
private EnginesCount enginesCount;
|
||||
private Color color;
|
||||
|
||||
public DrawingEngines(int count, Color bodyColor) {
|
||||
setCount(count);
|
||||
color = bodyColor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCount(int count) {
|
||||
if(count <= 2) enginesCount = EnginesCount.Two;
|
||||
else if(count >= 6) enginesCount = EnginesCount.Six;
|
||||
else enginesCount = EnginesCount.Four;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setColor(Color color) {
|
||||
this.color = color;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
if(enginesCount == EnginesCount.Two) return 2;
|
||||
if(enginesCount == EnginesCount.Four) return 4;
|
||||
return 6;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Color getColor() {
|
||||
return color;
|
||||
}
|
||||
|
||||
public void draw(Graphics2D g, int startPosX, int startPosY) {
|
||||
g.setPaint(color);
|
||||
g.fillOval(startPosX + 80, startPosY + 10, 30, 15);
|
||||
g.fillOval(startPosX + 80, startPosY + 141, 30, 15);
|
||||
|
||||
if(enginesCount == EnginesCount.Two) return;
|
||||
|
||||
g.fillOval(startPosX + 80, startPosY + 30, 30, 15);
|
||||
g.fillOval(startPosX + 80, startPosY + 121, 30, 15);
|
||||
|
||||
if(enginesCount == EnginesCount.Four) return;
|
||||
|
||||
g.fillOval(startPosX + 80, startPosY + 50, 30, 15);
|
||||
g.fillOval(startPosX + 80, startPosY + 101, 30, 15);
|
||||
}
|
||||
}
|
88
DrawingModernAircraft.java
Normal file
88
DrawingModernAircraft.java
Normal file
@ -0,0 +1,88 @@
|
||||
import java.awt.*;
|
||||
|
||||
public class DrawingModernAircraft extends DrawingAircraft
|
||||
{
|
||||
public DrawingModernAircraft(EntityAircraft airFighter, IDrawingEngines engines)
|
||||
{
|
||||
super(airFighter, engines);
|
||||
}
|
||||
|
||||
public DrawingModernAircraft(int speed, float weight, Color bodyColor, Color dopColor, boolean dopWings, boolean rockets)
|
||||
{
|
||||
super(speed, weight, bodyColor, 195, 166);
|
||||
AirFighter = new EntityModernAircraft(speed, weight, bodyColor, dopColor, dopWings, rockets);
|
||||
}
|
||||
|
||||
public void setDopColor(Color color) {
|
||||
((EntityModernAircraft)AirFighter).DopColor = color;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void DrawTransport(Graphics2D g)
|
||||
{
|
||||
if (!(AirFighter instanceof EntityModernAircraft))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
EntityModernAircraft modernAircraft = (EntityModernAircraft)AirFighter;
|
||||
|
||||
g.setPaint(modernAircraft.DopColor);
|
||||
|
||||
if (modernAircraft.DopWings)
|
||||
{
|
||||
Polygon topDopWing = new Polygon();
|
||||
topDopWing.addPoint((int)_startPosX + 78, (int)_startPosY + 56);
|
||||
topDopWing.addPoint((int)_startPosX + 75, (int)_startPosY + 70);
|
||||
topDopWing.addPoint((int)_startPosX + 55, (int)_startPosY + 50);
|
||||
topDopWing.addPoint((int)_startPosX + 60, (int)_startPosY + 45);
|
||||
|
||||
Polygon bottomDopWing = new Polygon();
|
||||
bottomDopWing.addPoint((int)_startPosX + 78, (int)_startPosY + 110);
|
||||
bottomDopWing.addPoint((int)_startPosX + 75, (int)_startPosY + 96);
|
||||
bottomDopWing.addPoint((int)_startPosX + 55, (int)_startPosY + 116);
|
||||
bottomDopWing.addPoint((int)_startPosX + 60, (int)_startPosY + 121);
|
||||
|
||||
g.fillPolygon(topDopWing);
|
||||
g.fillPolygon(bottomDopWing);
|
||||
}
|
||||
|
||||
if (modernAircraft.Rockets)
|
||||
{
|
||||
Polygon topRocket1 = new Polygon();
|
||||
topRocket1.addPoint((int)_startPosX + 100, (int)_startPosY + 20);
|
||||
topRocket1.addPoint((int)_startPosX + 100, (int)_startPosY + 30);
|
||||
topRocket1.addPoint((int)_startPosX + 112, (int)_startPosY + 30);
|
||||
topRocket1.addPoint((int)_startPosX + 120, (int)_startPosY + 25);
|
||||
topRocket1.addPoint((int)_startPosX + 112, (int)_startPosY + 20);
|
||||
|
||||
Polygon topRocket2 = new Polygon();
|
||||
topRocket2.addPoint((int)_startPosX + 100, (int)_startPosY + 35);
|
||||
topRocket2.addPoint((int)_startPosX + 100, (int)_startPosY + 45);
|
||||
topRocket2.addPoint((int)_startPosX + 112, (int)_startPosY + 45);
|
||||
topRocket2.addPoint((int)_startPosX + 120, (int)_startPosY + 40);
|
||||
topRocket2.addPoint((int)_startPosX + 112, (int)_startPosY + 35);
|
||||
|
||||
Polygon bottomRocket1 = new Polygon();
|
||||
bottomRocket1.addPoint((int)_startPosX + 100, (int)_startPosY + 146);
|
||||
bottomRocket1.addPoint((int)_startPosX + 100, (int)_startPosY + 136);
|
||||
bottomRocket1.addPoint((int)_startPosX + 112, (int)_startPosY + 136);
|
||||
bottomRocket1.addPoint((int)_startPosX + 120, (int)_startPosY + 141);
|
||||
bottomRocket1.addPoint((int)_startPosX + 112, (int)_startPosY + 146);
|
||||
|
||||
Polygon bottomRocket2 = new Polygon();
|
||||
bottomRocket2.addPoint((int)_startPosX + 100, (int)_startPosY + 131);
|
||||
bottomRocket2.addPoint((int)_startPosX + 100, (int)_startPosY + 121);
|
||||
bottomRocket2.addPoint((int)_startPosX + 112, (int)_startPosY + 121);
|
||||
bottomRocket2.addPoint((int)_startPosX + 120, (int)_startPosY + 126);
|
||||
bottomRocket2.addPoint((int)_startPosX + 112, (int)_startPosY + 131);
|
||||
|
||||
g.fillPolygon(topRocket1);
|
||||
g.fillPolygon(topRocket2);
|
||||
g.fillPolygon(bottomRocket1);
|
||||
g.fillPolygon(bottomRocket2);
|
||||
}
|
||||
|
||||
super.DrawTransport(g);
|
||||
}
|
||||
}
|
55
DrawingObjectAircraft.java
Normal file
55
DrawingObjectAircraft.java
Normal file
@ -0,0 +1,55 @@
|
||||
import java.awt.*;
|
||||
|
||||
public class DrawingObjectAircraft implements IDrawingObject
|
||||
{
|
||||
private DrawingAircraft _aircraft = null;
|
||||
public DrawingObjectAircraft(DrawingAircraft aircraft){
|
||||
_aircraft = aircraft;
|
||||
}
|
||||
|
||||
public DrawingAircraft getAircraft() {
|
||||
return _aircraft;
|
||||
}
|
||||
|
||||
public void MoveObject(Direction direction) {
|
||||
if(_aircraft == null) return;
|
||||
_aircraft.MoveTransport(direction);
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getStep() {
|
||||
if(_aircraft == null) return 0;
|
||||
return _aircraft.AirFighter.Step;
|
||||
}
|
||||
|
||||
public void SetObject(int x, int y, int width, int height)
|
||||
{
|
||||
_aircraft.SetPosition(x, y, width, height);
|
||||
}
|
||||
public void DrawningObject(Graphics2D g)
|
||||
{
|
||||
// TODO
|
||||
_aircraft.DrawTransport(g);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Point GetLeftTop() {
|
||||
if(_aircraft == null) return new Point(0,0);
|
||||
return _aircraft.getLeftTop();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Point GetRightBottom() {
|
||||
if(_aircraft == null) return new Point(0,0);
|
||||
return _aircraft.getRightBottom();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String GetInfo() {
|
||||
return AircraftFactory.getDataForSave(_aircraft);
|
||||
}
|
||||
|
||||
public static DrawingObjectAircraft Create(String data) {
|
||||
return new DrawingObjectAircraft(AircraftFactory.createAircraftFromData(data));
|
||||
}
|
||||
}
|
51
DrawingTruncatedEngines.java
Normal file
51
DrawingTruncatedEngines.java
Normal file
@ -0,0 +1,51 @@
|
||||
import java.awt.*;
|
||||
|
||||
public class DrawingTruncatedEngines implements IDrawingEngines {
|
||||
private EnginesCount enginesCount;
|
||||
private Color color;
|
||||
|
||||
public DrawingTruncatedEngines(int count, Color bodyColor) {
|
||||
setCount(count);
|
||||
color = bodyColor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCount(int count) {
|
||||
if(count <= 2) enginesCount = EnginesCount.Two;
|
||||
else if(count >= 6) enginesCount = EnginesCount.Six;
|
||||
else enginesCount = EnginesCount.Four;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setColor(Color color) {
|
||||
this.color = color;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
if(enginesCount == EnginesCount.Two) return 2;
|
||||
if(enginesCount == EnginesCount.Four) return 4;
|
||||
return 6;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Color getColor() {
|
||||
return color;
|
||||
}
|
||||
|
||||
public void draw(Graphics2D g, int startPosX, int startPosY) {
|
||||
g.setPaint(color);
|
||||
g.fillArc(startPosX + 90, startPosY + 10, 30, 15, 90, 180);
|
||||
g.fillArc(startPosX + 90, startPosY + 141, 30, 15, 90, 180);
|
||||
|
||||
if(enginesCount == EnginesCount.Two) return;
|
||||
|
||||
g.fillArc(startPosX + 90, startPosY + 30, 30, 15, 90, 180);
|
||||
g.fillArc(startPosX + 90, startPosY + 121, 30, 15, 90, 180);
|
||||
|
||||
if(enginesCount == EnginesCount.Four) return;
|
||||
|
||||
g.fillArc(startPosX + 90, startPosY + 50, 30, 15, 90, 180);
|
||||
g.fillArc(startPosX + 90, startPosY + 101, 30, 15, 90, 180);
|
||||
}
|
||||
}
|
63
DrawingWavyEngines.java
Normal file
63
DrawingWavyEngines.java
Normal file
@ -0,0 +1,63 @@
|
||||
import java.awt.*;
|
||||
|
||||
public class DrawingWavyEngines implements IDrawingEngines {
|
||||
private EnginesCount enginesCount;
|
||||
private Color color;
|
||||
|
||||
public DrawingWavyEngines(int count, Color bodyColor) {
|
||||
setCount(count);
|
||||
color = bodyColor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCount(int count) {
|
||||
if(count <= 2) enginesCount = EnginesCount.Two;
|
||||
else if(count >= 6) enginesCount = EnginesCount.Six;
|
||||
else enginesCount = EnginesCount.Four;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setColor(Color color) {
|
||||
this.color = color;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
if(enginesCount == EnginesCount.Two) return 2;
|
||||
if(enginesCount == EnginesCount.Four) return 4;
|
||||
return 6;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Color getColor() {
|
||||
return color;
|
||||
}
|
||||
|
||||
private void drawEngine(Graphics2D g, int x, int y) {
|
||||
g.setColor(color);
|
||||
g.fillRect(x, y, 21, 10);
|
||||
|
||||
g.fillArc(x, y - 4, 7, 8, 0, 180);
|
||||
g.fillArc(x + 7, y - 4, 7, 8, 0, 180);
|
||||
g.fillArc(x + 14, y - 4, 7, 8, 0, 180);
|
||||
|
||||
g.fillArc(x, y + 6, 7, 8, 180, 180);
|
||||
g.fillArc(x + 7, y + 6, 7, 8, 180, 180);
|
||||
g.fillArc(x + 14, y + 6, 7, 8, 180, 180);
|
||||
}
|
||||
|
||||
public void draw(Graphics2D g, int startPosX, int startPosY) {
|
||||
drawEngine(g, startPosX + 84, startPosY + 10);
|
||||
drawEngine(g, startPosX + 84, startPosY + 146);
|
||||
|
||||
if(enginesCount == EnginesCount.Two) return;
|
||||
|
||||
drawEngine(g, startPosX + 84, startPosY + 30);
|
||||
drawEngine(g, startPosX + 84, startPosY + 125);
|
||||
|
||||
if(enginesCount == EnginesCount.Four) return;
|
||||
|
||||
drawEngine(g, startPosX + 84, startPosY + 50);
|
||||
drawEngine(g, startPosX + 84, startPosY + 106);
|
||||
}
|
||||
}
|
5
EnginesCount.java
Normal file
5
EnginesCount.java
Normal file
@ -0,0 +1,5 @@
|
||||
public enum EnginesCount {
|
||||
Two,
|
||||
Four,
|
||||
Six
|
||||
}
|
17
EnginesFabric.java
Normal file
17
EnginesFabric.java
Normal file
@ -0,0 +1,17 @@
|
||||
import java.awt.*;
|
||||
import java.util.Random;
|
||||
|
||||
public class EnginesFabric {
|
||||
public static IDrawingEngines createRandom(Color color) {
|
||||
Random rnd = new Random();
|
||||
|
||||
int type = rnd.nextInt(0, 3);
|
||||
|
||||
return switch(type) {
|
||||
case 0 -> new DrawingEngines(rnd.nextInt(1, 7), color);
|
||||
case 1 -> new DrawingWavyEngines(rnd.nextInt(1, 7), color);
|
||||
case 2 -> new DrawingTruncatedEngines(rnd.nextInt(1, 7), color);
|
||||
default -> null;
|
||||
};
|
||||
}
|
||||
}
|
22
EntityAircraft.java
Normal file
22
EntityAircraft.java
Normal file
@ -0,0 +1,22 @@
|
||||
import java.awt.*;
|
||||
import java.util.Random;
|
||||
|
||||
class EntityAircraft
|
||||
{
|
||||
public int Speed;
|
||||
public float Weight;
|
||||
public Color BodyColor;
|
||||
|
||||
public float Step;
|
||||
|
||||
public EntityAircraft(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;
|
||||
}
|
||||
}
|
18
EntityModernAircraft.java
Normal file
18
EntityModernAircraft.java
Normal file
@ -0,0 +1,18 @@
|
||||
import java.awt.*;
|
||||
|
||||
public class EntityModernAircraft extends EntityAircraft
|
||||
{
|
||||
public Color DopColor;
|
||||
public boolean DopWings;
|
||||
public boolean Rockets;
|
||||
|
||||
|
||||
public EntityModernAircraft(int speed, float weight, Color bodyColor, Color
|
||||
dopColor, boolean dopWings, boolean rockets)
|
||||
{
|
||||
super(speed, weight, bodyColor);
|
||||
DopColor = dopColor;
|
||||
DopWings = dopWings;
|
||||
Rockets = rockets;
|
||||
}
|
||||
}
|
5
Form.java
Normal file
5
Form.java
Normal file
@ -0,0 +1,5 @@
|
||||
import java.awt.*;
|
||||
|
||||
public interface Form {
|
||||
void Draw(Graphics2D g);
|
||||
}
|
148
FormAircraft.form
Normal file
148
FormAircraft.form
Normal 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="FormAircraft">
|
||||
<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>
|
130
FormAircraft.java
Normal file
130
FormAircraft.java
Normal file
@ -0,0 +1,130 @@
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.ComponentAdapter;
|
||||
import java.awt.event.ComponentEvent;
|
||||
import java.util.Random;
|
||||
|
||||
public class FormAircraft 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;
|
||||
|
||||
DrawingAircraft _airFighter;
|
||||
private DrawingAircraft selectedAircraft;
|
||||
|
||||
public DrawingAircraft getSelectedAircraft() {
|
||||
return selectedAircraft;
|
||||
}
|
||||
|
||||
public FormAircraft() {}
|
||||
|
||||
public FormAircraft(DrawingAircraft aircraft) {
|
||||
_airFighter = aircraft;
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
_airFighter = new DrawingAircraft(rnd.nextInt(100, 300), rnd.nextInt(1000, 2000), color);
|
||||
|
||||
_airFighter.SetPosition((int)rnd.nextInt(10, 100), (int)rnd.nextInt(10, 100), canvSize.width, canvSize.height);
|
||||
|
||||
Color bodyColor = _airFighter.AirFighter.BodyColor;
|
||||
String colorString = "(" + bodyColor.getRed() + ", " + bodyColor.getGreen() + ", " + bodyColor.getBlue() + ")";
|
||||
|
||||
speedLabel.setText("Скорость: " + _airFighter.AirFighter.Speed + " ");
|
||||
weightLabel.setText("Вес: " + _airFighter.AirFighter.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;
|
||||
|
||||
_airFighter = new DrawingModernAircraft(rnd.nextInt(100, 300), rnd.nextInt(1000, 2000),
|
||||
color, dopColor,
|
||||
rnd.nextInt(0, 2) == 1, rnd.nextInt(0, 2) == 1);
|
||||
|
||||
_airFighter.SetPosition((int)rnd.nextInt(10, 100), (int)rnd.nextInt(10, 100), canvSize.width, canvSize.height);
|
||||
|
||||
Color bodyColor = _airFighter.AirFighter.BodyColor;
|
||||
String colorString = "(" + bodyColor.getRed() + ", " + bodyColor.getGreen() + ", " + bodyColor.getBlue() + ")";
|
||||
|
||||
speedLabel.setText("Скорость: " + _airFighter.AirFighter.Speed + " ");
|
||||
weightLabel.setText("Вес: " + _airFighter.AirFighter.Weight + " ");
|
||||
colorLabel.setText("Цвет: " + colorString);
|
||||
|
||||
canv.repaint();
|
||||
});
|
||||
|
||||
selectButton.addActionListener(e -> {
|
||||
selectedAircraft = _airFighter;
|
||||
dispose();
|
||||
});
|
||||
|
||||
addComponentListener(new ComponentAdapter() {
|
||||
@Override
|
||||
public void componentResized(ComponentEvent e) {
|
||||
if(_airFighter == null) return;
|
||||
_airFighter.ChangeBorders(canv.getSize().width, canv.getSize().height);
|
||||
revalidate();
|
||||
}
|
||||
});
|
||||
|
||||
upButton.addActionListener(e -> {
|
||||
if(_airFighter == null) return;
|
||||
_airFighter.MoveTransport(Direction.Up);
|
||||
canv.repaint();
|
||||
});
|
||||
rightButton.addActionListener(e -> {
|
||||
if(_airFighter == null) return;
|
||||
_airFighter.MoveTransport(Direction.Right);
|
||||
canv.repaint();
|
||||
});
|
||||
downButton.addActionListener(e -> {
|
||||
if(_airFighter == null) return;
|
||||
_airFighter.MoveTransport(Direction.Down);
|
||||
canv.repaint();
|
||||
});
|
||||
leftButton.addActionListener(e -> {
|
||||
if(_airFighter == null) return;
|
||||
_airFighter.MoveTransport(Direction.Left);
|
||||
canv.repaint();
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void Draw(Graphics2D g) {
|
||||
if(_airFighter == null) return;
|
||||
_airFighter.DrawTransport(g);
|
||||
}
|
||||
}
|
478
FormAircraftConfig.form
Normal file
478
FormAircraftConfig.form
Normal file
@ -0,0 +1,478 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="FormAircraftConfig">
|
||||
<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="813" height="425"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<grid id="11ed" layout-manager="GridLayoutManager" row-count="1" 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="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 id="6bdf" 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>
|
||||
<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 id="b99b4" layout-manager="GridLayoutManager" row-count="4" 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="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" title="Параметры самолета"/>
|
||||
<children>
|
||||
<grid id="bf610" binding="colorsPane" layout-manager="GridLayoutManager" row-count="2" column-count="4" 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="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="3" indent="0" use-parent-layout="false">
|
||||
<minimum-size width="250" height="130"/>
|
||||
<preferred-size width="250" height="130"/>
|
||||
<maximum-size width="250" height="130"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none" title="Цвета"/>
|
||||
<children>
|
||||
<grid id="b0657" binding="panelRed" layout-manager="GridLayoutManager" row-count="1" 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="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>
|
||||
<background color="-4389370"/>
|
||||
</properties>
|
||||
<border type="none"/>
|
||||
<children/>
|
||||
</grid>
|
||||
<grid id="454fe" binding="panelYellow" layout-manager="GridLayoutManager" row-count="1" 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>
|
||||
<background color="-7414"/>
|
||||
</properties>
|
||||
<border type="none"/>
|
||||
<children/>
|
||||
</grid>
|
||||
<grid id="acb3b" binding="panelGreen" layout-manager="GridLayoutManager" row-count="1" 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="2" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<background color="-16408064"/>
|
||||
</properties>
|
||||
<border type="none"/>
|
||||
<children/>
|
||||
</grid>
|
||||
<grid id="e10ed" binding="panelBlue" layout-manager="GridLayoutManager" row-count="1" 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="3" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<background color="-14474274"/>
|
||||
</properties>
|
||||
<border type="none"/>
|
||||
<children/>
|
||||
</grid>
|
||||
<grid id="6a752" binding="panelWhite" layout-manager="GridLayoutManager" row-count="1" 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="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>
|
||||
<background color="-1"/>
|
||||
</properties>
|
||||
<border type="none"/>
|
||||
<children/>
|
||||
</grid>
|
||||
<grid id="4650b" binding="panelGray" layout-manager="GridLayoutManager" row-count="1" 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="1" 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>
|
||||
<background color="-5723992"/>
|
||||
</properties>
|
||||
<border type="none"/>
|
||||
<children/>
|
||||
</grid>
|
||||
<grid id="37a23" binding="panelBlack" layout-manager="GridLayoutManager" row-count="1" 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="1" column="2" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<background color="-16777216"/>
|
||||
</properties>
|
||||
<border type="none"/>
|
||||
<children/>
|
||||
</grid>
|
||||
<grid id="6424" binding="panelPurple" layout-manager="GridLayoutManager" row-count="1" 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="1" column="3" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<background color="-5166919"/>
|
||||
</properties>
|
||||
<border type="none"/>
|
||||
<children/>
|
||||
</grid>
|
||||
</children>
|
||||
</grid>
|
||||
<hspacer id="acd9a">
|
||||
<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>
|
||||
<grid id="f9e1b" layout-manager="GridLayoutManager" row-count="3" 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="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">
|
||||
<minimum-size width="130" height="-1"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<component id="290f9" class="javax.swing.JSpinner" binding="spinnerSpeed">
|
||||
<constraints>
|
||||
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
</component>
|
||||
<component id="76346" class="javax.swing.JSpinner" binding="spinnerWeight">
|
||||
<constraints>
|
||||
<grid row="1" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
</component>
|
||||
<component id="f3384" class="javax.swing.JLabel">
|
||||
<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="28dee" class="javax.swing.JLabel">
|
||||
<constraints>
|
||||
<grid row="1" 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>
|
||||
</children>
|
||||
</grid>
|
||||
<vspacer id="15d55">
|
||||
<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>
|
||||
<grid id="7ab15" 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="2" 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>
|
||||
<grid id="add02" layout-manager="GridLayoutManager" row-count="1" 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="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="line"/>
|
||||
<children>
|
||||
<component id="30e35" class="javax.swing.JLabel" binding="labelBase">
|
||||
<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>
|
||||
<font size="16"/>
|
||||
<horizontalAlignment value="0"/>
|
||||
<horizontalTextPosition value="0"/>
|
||||
<text value="Простой"/>
|
||||
</properties>
|
||||
</component>
|
||||
</children>
|
||||
</grid>
|
||||
<grid id="28265" layout-manager="GridLayoutManager" row-count="1" 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="line"/>
|
||||
<children>
|
||||
<component id="72db3" class="javax.swing.JLabel" binding="labelAdvanced">
|
||||
<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>
|
||||
<font size="16"/>
|
||||
<horizontalAlignment value="0"/>
|
||||
<horizontalTextPosition value="0"/>
|
||||
<text value="Продвинутый"/>
|
||||
</properties>
|
||||
</component>
|
||||
</children>
|
||||
</grid>
|
||||
</children>
|
||||
</grid>
|
||||
<grid id="12688" 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>
|
||||
<grid row="2" 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>
|
||||
<component id="e5986" class="javax.swing.JCheckBox" binding="checkboxDopWings">
|
||||
<constraints>
|
||||
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="Дополнительные крылья"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="cfe9b" class="javax.swing.JCheckBox" binding="checkboxRockets">
|
||||
<constraints>
|
||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="ракеты"/>
|
||||
</properties>
|
||||
</component>
|
||||
</children>
|
||||
</grid>
|
||||
<vspacer id="18b96">
|
||||
<constraints>
|
||||
<grid row="3" 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>
|
||||
</children>
|
||||
</grid>
|
||||
<grid id="6e579" 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>
|
||||
<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/>
|
||||
<border type="none" title="Параметры двигателей"/>
|
||||
<children>
|
||||
<grid id="b79df" 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="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<component id="8c10b" class="javax.swing.JLabel">
|
||||
<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="609e1" class="javax.swing.JSpinner" binding="spinnerEnginesCount">
|
||||
<constraints>
|
||||
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
|
||||
<maximum-size width="100" height="-1"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties/>
|
||||
</component>
|
||||
</children>
|
||||
</grid>
|
||||
<grid id="83f65" 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="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/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<grid id="28e30" layout-manager="GridLayoutManager" row-count="1" 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="line"/>
|
||||
<children>
|
||||
<component id="f884f" class="javax.swing.JLabel" binding="labelTruncatedEngine">
|
||||
<constraints>
|
||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<font size="16"/>
|
||||
<horizontalAlignment value="0"/>
|
||||
<text value="Усеченный"/>
|
||||
</properties>
|
||||
</component>
|
||||
</children>
|
||||
</grid>
|
||||
<grid id="96986" layout-manager="GridLayoutManager" row-count="1" 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="2" 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="line"/>
|
||||
<children>
|
||||
<component id="492da" class="javax.swing.JLabel" binding="labelWavyEngine">
|
||||
<constraints>
|
||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<font size="16"/>
|
||||
<horizontalAlignment value="0"/>
|
||||
<text value="Волнистый"/>
|
||||
</properties>
|
||||
</component>
|
||||
</children>
|
||||
</grid>
|
||||
<grid id="5bd24" layout-manager="GridLayoutManager" row-count="1" 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="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="line"/>
|
||||
<children>
|
||||
<component id="43319" class="javax.swing.JLabel" binding="labelBaseEngine">
|
||||
<constraints>
|
||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<font size="16"/>
|
||||
<horizontalAlignment value="0"/>
|
||||
<text value="Простой"/>
|
||||
</properties>
|
||||
</component>
|
||||
</children>
|
||||
</grid>
|
||||
</children>
|
||||
</grid>
|
||||
</children>
|
||||
</grid>
|
||||
</children>
|
||||
</grid>
|
||||
</children>
|
||||
</grid>
|
||||
<grid id="1e193" layout-manager="GridLayoutManager" row-count="3" 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="1" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false">
|
||||
<minimum-size width="300" height="-1"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none" title="Превью"/>
|
||||
<children>
|
||||
<grid id="c4ea7" 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="2" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<grid id="b8c0b" binding="panelBaseColor" layout-manager="GridLayoutManager" row-count="1" 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="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false">
|
||||
<minimum-size width="-1" height="50"/>
|
||||
<maximum-size width="-1" height="50"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="line"/>
|
||||
<children>
|
||||
<component id="b477" class="javax.swing.JLabel">
|
||||
<constraints>
|
||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<font size="16"/>
|
||||
<horizontalAlignment value="0"/>
|
||||
<text value="Цвет"/>
|
||||
</properties>
|
||||
</component>
|
||||
</children>
|
||||
</grid>
|
||||
<grid id="e2d48" binding="panelDopColor" layout-manager="GridLayoutManager" row-count="1" 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">
|
||||
<minimum-size width="-1" height="50"/>
|
||||
<maximum-size width="-1" height="50"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="line"/>
|
||||
<children>
|
||||
<component id="13ad3" class="javax.swing.JLabel">
|
||||
<constraints>
|
||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<font size="16"/>
|
||||
<horizontalAlignment value="0"/>
|
||||
<text value="Доп. цвет"/>
|
||||
</properties>
|
||||
</component>
|
||||
</children>
|
||||
</grid>
|
||||
</children>
|
||||
</grid>
|
||||
<grid id="74d53" binding="panelDraw" layout-manager="CardLayout" hgap="0" vgap="0">
|
||||
<constraints>
|
||||
<grid row="1" column="0" row-span="1" col-span="2" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false">
|
||||
<minimum-size width="-1" height="300"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="line"/>
|
||||
<children/>
|
||||
</grid>
|
||||
<component id="14b28" class="javax.swing.JButton" binding="buttonAdd">
|
||||
<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="7f448" class="javax.swing.JButton" binding="buttonCancel">
|
||||
<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>
|
||||
</children>
|
||||
</grid>
|
||||
</children>
|
||||
</grid>
|
||||
</form>
|
171
FormAircraftConfig.java
Normal file
171
FormAircraftConfig.java
Normal file
@ -0,0 +1,171 @@
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.util.ArrayList;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public class FormAircraftConfig implements Form {
|
||||
private JPanel mainPane;
|
||||
private JSpinner spinnerSpeed;
|
||||
private JSpinner spinnerWeight;
|
||||
private JPanel colorsPane;
|
||||
private JCheckBox checkboxDopWings;
|
||||
private JCheckBox checkboxRockets;
|
||||
private JSpinner spinnerEnginesCount;
|
||||
private JButton buttonAdd;
|
||||
private JButton buttonCancel;
|
||||
private JPanel panelRed;
|
||||
private JPanel panelYellow;
|
||||
private JPanel panelGreen;
|
||||
private JPanel panelBlue;
|
||||
private JPanel panelWhite;
|
||||
private JPanel panelGray;
|
||||
private JPanel panelBlack;
|
||||
private JPanel panelPurple;
|
||||
private JPanel panelBaseColor;
|
||||
private JPanel panelDopColor;
|
||||
private JPanel panelDraw;
|
||||
private JLabel labelBase;
|
||||
private JLabel labelAdvanced;
|
||||
private JLabel labelTruncatedEngine;
|
||||
private JLabel labelWavyEngine;
|
||||
private JLabel labelBaseEngine;
|
||||
|
||||
private JFrame jframe = getFrame();
|
||||
private DrawingAircraft aircraft;
|
||||
private boolean isMousePressed = false;
|
||||
private Canvas canv = new Canvas(this);
|
||||
private ArrayList<Consumer<DrawingAircraft>> listeners = new ArrayList<>();
|
||||
|
||||
private JFrame getFrame() {
|
||||
JFrame frame = new JFrame();
|
||||
frame.setVisible(true);
|
||||
frame.setBounds(300, 100, 800, 500);
|
||||
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
return frame;
|
||||
}
|
||||
|
||||
public void addListener(Consumer<DrawingAircraft> l) {
|
||||
listeners.add(l);
|
||||
}
|
||||
|
||||
public void run() {
|
||||
jframe.add(mainPane);
|
||||
panelDraw.add(canv);
|
||||
|
||||
buttonAdd.addActionListener(e -> {
|
||||
jframe.dispose();
|
||||
for(var l : listeners) l.accept(aircraft);
|
||||
});
|
||||
|
||||
buttonCancel.addActionListener(e -> jframe.dispose());
|
||||
|
||||
MouseAdapter mouseHandler = new MouseAdapter() {
|
||||
@Override
|
||||
public void mouseEntered(MouseEvent e) {
|
||||
super.mouseEntered(e);
|
||||
jframe.setCursor(new Cursor(Cursor.HAND_CURSOR));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseExited(MouseEvent e) {
|
||||
super.mouseExited(e);
|
||||
if(!isMousePressed) jframe.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mousePressed(MouseEvent e) {
|
||||
super.mousePressed(e);
|
||||
isMousePressed = true;
|
||||
jframe.setCursor(new Cursor(Cursor.HAND_CURSOR));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseReleased(MouseEvent e) {
|
||||
super.mouseReleased(e);
|
||||
isMousePressed = false;
|
||||
jframe.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
|
||||
drop((JComponent) e.getSource());
|
||||
canv.repaint();
|
||||
}
|
||||
};
|
||||
|
||||
spinnerSpeed.setModel(new SpinnerNumberModel(100, 70, 200, 1));
|
||||
spinnerWeight.setModel(new SpinnerNumberModel(700, 600, 1500, 1));
|
||||
spinnerEnginesCount.setModel(new SpinnerNumberModel(4, 2, 6, 2));
|
||||
|
||||
panelRed.addMouseListener(mouseHandler);
|
||||
panelYellow.addMouseListener(mouseHandler);
|
||||
panelGreen.addMouseListener(mouseHandler);
|
||||
panelBlue.addMouseListener(mouseHandler);
|
||||
panelWhite.addMouseListener(mouseHandler);
|
||||
panelGray.addMouseListener(mouseHandler);
|
||||
panelBlack.addMouseListener(mouseHandler);
|
||||
panelPurple.addMouseListener(mouseHandler);
|
||||
|
||||
labelBase.addMouseListener(mouseHandler);
|
||||
labelAdvanced.addMouseListener(mouseHandler);
|
||||
|
||||
labelTruncatedEngine.addMouseListener(mouseHandler);
|
||||
labelWavyEngine.addMouseListener(mouseHandler);
|
||||
labelBaseEngine.addMouseListener(mouseHandler);
|
||||
}
|
||||
|
||||
private void drop(JComponent elem) {
|
||||
if(elem instanceof JPanel panel) {
|
||||
if(aircraft == null) return;
|
||||
if(panelBaseColor.getMousePosition() != null) {
|
||||
aircraft.setColor(panel.getBackground());
|
||||
aircraft.getEngines().setColor(panel.getBackground());
|
||||
}
|
||||
|
||||
if(panelDopColor.getMousePosition() != null && aircraft instanceof DrawingModernAircraft advanced) {
|
||||
advanced.setDopColor(panel.getBackground());
|
||||
}
|
||||
}
|
||||
|
||||
Point test = panelDraw.getMousePosition();
|
||||
|
||||
if(elem instanceof JLabel label && test != null) {
|
||||
int speed = (int)spinnerSpeed.getValue();
|
||||
int weight = (int)spinnerWeight.getValue();
|
||||
int enginesCount = (int)spinnerEnginesCount.getValue();
|
||||
|
||||
if(label == labelBase) {
|
||||
aircraft = new DrawingAircraft(speed, weight, Color.WHITE);
|
||||
aircraft.SetPosition(20, 40, canv.getWidth(), canv.getHeight());
|
||||
|
||||
aircraft.getEngines().setCount(enginesCount);
|
||||
aircraft.getEngines().setColor(Color.WHITE);
|
||||
}
|
||||
|
||||
if(label == labelAdvanced) {
|
||||
aircraft = new DrawingModernAircraft(speed, weight, Color.WHITE, Color.BLACK,
|
||||
checkboxDopWings.isSelected(), checkboxRockets.isSelected());
|
||||
|
||||
aircraft.SetPosition(10, 10, canv.getWidth(), canv.getHeight());
|
||||
aircraft.getEngines().setCount(enginesCount);
|
||||
aircraft.getEngines().setColor(Color.WHITE);
|
||||
}
|
||||
|
||||
if(aircraft == null) return;
|
||||
|
||||
if(label == labelBaseEngine) {
|
||||
aircraft.setEngines(new DrawingEngines(enginesCount, aircraft.getColor()));
|
||||
}
|
||||
if(label == labelTruncatedEngine) {
|
||||
aircraft.setEngines(new DrawingTruncatedEngines(enginesCount, aircraft.getColor()));
|
||||
}
|
||||
if(label == labelWavyEngine) {
|
||||
aircraft.setEngines(new DrawingWavyEngines(enginesCount, aircraft.getColor()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void Draw(Graphics2D g) {
|
||||
if(aircraft == null) return;
|
||||
aircraft.DrawTransport(g);
|
||||
}
|
||||
}
|
210
FormMapWithSetAircrafts.form
Normal file
210
FormMapWithSetAircrafts.form
Normal 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="FormMapWithSetAircrafts">
|
||||
<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="buttonAddAircraft">
|
||||
<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="buttonRemoveAircraft">
|
||||
<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>
|
317
FormMapWithSetAircrafts.java
Normal file
317
FormMapWithSetAircrafts.java
Normal file
@ -0,0 +1,317 @@
|
||||
import javax.swing.*;
|
||||
import javax.swing.filechooser.FileNameExtensionFilter;
|
||||
import java.awt.*;
|
||||
import java.util.*;
|
||||
import java.util.List;
|
||||
|
||||
public class FormMapWithSetAircrafts implements Form {
|
||||
private JPanel MainPane;
|
||||
private JButton buttonAddAircraft;
|
||||
private JComboBox comboBoxSelectorMap;
|
||||
private JTextField textBoxPosition;
|
||||
private JButton buttonRemoveAircraft;
|
||||
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 JMenuBar menu;
|
||||
|
||||
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> deletedAircrafts = 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();
|
||||
|
||||
menu = new JMenuBar();
|
||||
JMenu fileActions = new JMenu("Файл");
|
||||
|
||||
menu.add(fileActions);
|
||||
jFrame.setJMenuBar(menu);
|
||||
|
||||
JMenuItem saveItem = new JMenuItem("Сохранить");
|
||||
JMenuItem loadItem = new JMenuItem("Загрузить");
|
||||
JMenuItem saveMapItem = new JMenuItem("Сохранить карту");
|
||||
JMenuItem loadMapItem = new JMenuItem("Загрузить карту");
|
||||
|
||||
fileActions.add(saveItem);
|
||||
fileActions.add(loadItem);
|
||||
fileActions.add(saveMapItem);
|
||||
fileActions.add(loadMapItem);
|
||||
|
||||
saveItem.addActionListener(e -> {
|
||||
JFileChooser chooser = new JFileChooser();
|
||||
chooser.setFileFilter(new FileNameExtensionFilter("TXT format", "txt"));
|
||||
chooser.showSaveDialog(jFrame);
|
||||
|
||||
if(chooser.getSelectedFile() == null) return;
|
||||
|
||||
String path = chooser.getSelectedFile().getAbsolutePath();
|
||||
|
||||
if(_mapsCollection.SaveData(path)) {
|
||||
JOptionPane.showMessageDialog(jFrame, "Сохранение прошло успешно");
|
||||
} else JOptionPane.showMessageDialog(jFrame, "Не сохранилось");
|
||||
|
||||
});
|
||||
|
||||
loadItem.addActionListener(e -> {
|
||||
JFileChooser chooser = new JFileChooser();
|
||||
chooser.setFileFilter(new FileNameExtensionFilter("TXT format", "txt"));
|
||||
chooser.showOpenDialog(jFrame);
|
||||
|
||||
if(chooser.getSelectedFile() == null) return;
|
||||
|
||||
String path = chooser.getSelectedFile().getAbsolutePath();
|
||||
if(_mapsCollection.LoadData(path)) {
|
||||
JOptionPane.showMessageDialog(jFrame, "Загрузка прошла успешно");
|
||||
ReloadMaps();
|
||||
} else JOptionPane.showMessageDialog(jFrame, "Не загрузилось");
|
||||
});
|
||||
|
||||
saveMapItem.addActionListener(e -> {
|
||||
if(_mapsCollection == null) return;
|
||||
if(listBoxMaps.getSelectedValue() == null) return;
|
||||
|
||||
JFileChooser chooser = new JFileChooser();
|
||||
chooser.setFileFilter(new FileNameExtensionFilter("TXT format", "txt"));
|
||||
chooser.showSaveDialog(jFrame);
|
||||
|
||||
if(chooser.getSelectedFile() == null) return;
|
||||
|
||||
String path = chooser.getSelectedFile().getAbsolutePath();
|
||||
|
||||
if(_mapsCollection.SaveMap(path, listBoxMaps.getSelectedValue().toString())) {
|
||||
JOptionPane.showMessageDialog(jFrame, "Сохранение прошло успешно");
|
||||
} else JOptionPane.showMessageDialog(jFrame, "Не сохранилось");
|
||||
|
||||
});
|
||||
|
||||
loadMapItem.addActionListener(e -> {
|
||||
JFileChooser chooser = new JFileChooser();
|
||||
chooser.setFileFilter(new FileNameExtensionFilter("TXT format", "txt"));
|
||||
chooser.showOpenDialog(jFrame);
|
||||
|
||||
if(chooser.getSelectedFile() == null) return;
|
||||
|
||||
String path = chooser.getSelectedFile().getAbsolutePath();
|
||||
if(_mapsCollection.LoadMap(path)) {
|
||||
JOptionPane.showMessageDialog(jFrame, "Загрузка прошла успешно");
|
||||
ReloadMaps();
|
||||
} else JOptionPane.showMessageDialog(jFrame, "Не загрузилось");
|
||||
});
|
||||
|
||||
_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();
|
||||
}
|
||||
});
|
||||
|
||||
buttonAddAircraft.addActionListener(e -> {
|
||||
if (listBoxMaps.getSelectedIndex() == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
FormAircraftConfig formConfig = new FormAircraftConfig();
|
||||
formConfig.run();
|
||||
|
||||
formConfig.addListener(drawingAircraft -> {
|
||||
if(drawingAircraft == null) return;
|
||||
|
||||
DrawingObjectAircraft aircraft = new DrawingObjectAircraft(drawingAircraft);
|
||||
if (_mapsCollection.getMap(listBoxMaps.getSelectedValue().toString()).addAircraft(aircraft) != -1)
|
||||
{
|
||||
JOptionPane.showMessageDialog(jFrame, "Объект добавлен");
|
||||
img = _mapsCollection.getMap(listBoxMaps.getSelectedValue().toString()).ShowSet();
|
||||
canv.repaint();
|
||||
}
|
||||
else
|
||||
{
|
||||
JOptionPane.showMessageDialog(jFrame, "Не удалось добавить объект");
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
buttonRemoveAircraft.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).removeAircraft(pos);
|
||||
|
||||
if(deleted != null) {
|
||||
JOptionPane.showMessageDialog(jFrame, "Объект удален");
|
||||
img = _mapsCollection.getMap(mapName).ShowSet();
|
||||
deletedAircrafts.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(deletedAircrafts.size() == 0) {
|
||||
JOptionPane.showMessageDialog(jFrame, "Очередь пуста");
|
||||
return;
|
||||
}
|
||||
|
||||
DrawingObjectAircraft deleted = (DrawingObjectAircraft) deletedAircrafts.peek();
|
||||
|
||||
FormAircraft dialog = new FormAircraft(deleted.getAircraft());
|
||||
deletedAircrafts.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);
|
||||
}
|
||||
}
|
9
IDrawingEngines.java
Normal file
9
IDrawingEngines.java
Normal file
@ -0,0 +1,9 @@
|
||||
import java.awt.*;
|
||||
|
||||
public interface IDrawingEngines {
|
||||
void setCount(int count);
|
||||
void setColor(Color color);
|
||||
int getCount();
|
||||
Color getColor();
|
||||
void draw(Graphics2D g, int x, int y);
|
||||
}
|
12
IDrawingObject.java
Normal file
12
IDrawingObject.java
Normal file
@ -0,0 +1,12 @@
|
||||
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();
|
||||
String GetInfo();
|
||||
}
|
5
Main.java
Normal file
5
Main.java
Normal file
@ -0,0 +1,5 @@
|
||||
public class Main {
|
||||
public static void main(String[] args) {
|
||||
new FormMapWithSetAircrafts().run();
|
||||
}
|
||||
}
|
184
MapWithSetAircraftsGeneric.java
Normal file
184
MapWithSetAircraftsGeneric.java
Normal file
@ -0,0 +1,184 @@
|
||||
import java.awt.*;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.util.ListIterator;
|
||||
|
||||
public class MapWithSetAircraftsGeneric<T extends IDrawingObject, U extends AbstractMap>
|
||||
{
|
||||
private int _pictureWidth;
|
||||
private int _pictureHeight;
|
||||
private int _placeSizeWidth = 210;
|
||||
private int _placeSizeHeight = 170;
|
||||
private SetAircraftsGeneric<T> _setAircrafts;
|
||||
private U _map;
|
||||
|
||||
public MapWithSetAircraftsGeneric(int picWidth, int picHeight, U map)
|
||||
{
|
||||
int width = picWidth / _placeSizeWidth;
|
||||
int height = picHeight / _placeSizeHeight;
|
||||
_setAircrafts = new SetAircraftsGeneric<T>(width * height);
|
||||
_pictureWidth = picWidth;
|
||||
_pictureHeight = picHeight;
|
||||
_map = map;
|
||||
}
|
||||
|
||||
public U getMap() {
|
||||
return _map;
|
||||
}
|
||||
|
||||
public String GetData(char separatorType, char separatorData)
|
||||
{
|
||||
String data = _map.getClass().getName() + "" + separatorType;
|
||||
ListIterator<T> iter = _setAircrafts.GetElems();
|
||||
while (iter.hasNext())
|
||||
{
|
||||
data += iter.next().GetInfo() + separatorData;
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
public void ClearMap() {
|
||||
_setAircrafts.Clear();
|
||||
}
|
||||
|
||||
public void LoadData(String[] records) {
|
||||
for (String rec : records)
|
||||
{
|
||||
_setAircrafts.Insert((T)DrawingObjectAircraft.Create(rec));
|
||||
}
|
||||
}
|
||||
|
||||
public int addAircraft(T aircraft)
|
||||
{
|
||||
return _setAircrafts.Insert(aircraft);
|
||||
}
|
||||
|
||||
public T removeAircraft(int position)
|
||||
{
|
||||
return _setAircrafts.Remove(position);
|
||||
}
|
||||
|
||||
public Image ShowSet()
|
||||
{
|
||||
BufferedImage img = new BufferedImage(_pictureWidth, _pictureHeight, BufferedImage.TYPE_INT_ARGB);
|
||||
Graphics2D gr = (Graphics2D) img.getGraphics();
|
||||
|
||||
DrawBackground(gr);
|
||||
DrawCars(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 < _setAircrafts.getCount(); i++)
|
||||
{
|
||||
var car = _setAircrafts.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;
|
||||
}
|
||||
|
||||
public ListIterator<T> getAircraftsIter() {
|
||||
return _setAircrafts.GetElems();
|
||||
}
|
||||
|
||||
private void Shaking()
|
||||
{
|
||||
int j = _setAircrafts.getCount() - 1;
|
||||
for (int i = 0; i < _setAircrafts.getCount(); i++)
|
||||
{
|
||||
if (_setAircrafts.Get(i) == null)
|
||||
{
|
||||
for (; j > i; j--)
|
||||
{
|
||||
var car = _setAircrafts.Get(j);
|
||||
if (car != null)
|
||||
{
|
||||
_setAircrafts.Insert(car, i);
|
||||
_setAircrafts.Remove(j);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (j <= i)
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void DrawBackground(Graphics2D g)
|
||||
{
|
||||
Polygon angar = new Polygon();
|
||||
|
||||
|
||||
angar.addPoint(0, _pictureHeight );
|
||||
angar.addPoint(0, _pictureHeight / 4 );
|
||||
angar.addPoint(_pictureWidth / 2 , 9);
|
||||
angar.addPoint(_pictureWidth, _pictureHeight / 4 );
|
||||
angar.addPoint(_pictureWidth, _pictureHeight );
|
||||
|
||||
g.setPaint(new Color(211, 136, 84));
|
||||
g.fillPolygon(angar);
|
||||
|
||||
g.setPaint(new Color(160, 160, 160));
|
||||
g.fillRect(_pictureWidth / 6, (_pictureHeight * 5) / 12, (_pictureWidth * 2) / 3, (_pictureHeight * 7) / 12);
|
||||
|
||||
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 DrawCars(Graphics2D g)
|
||||
{
|
||||
int width = _pictureWidth / _placeSizeWidth;
|
||||
|
||||
for (int i = 0; i < _setAircrafts.getCount(); i++)
|
||||
{
|
||||
int x = i % width;
|
||||
int y = i / width;
|
||||
|
||||
T current =_setAircrafts.Get(i);
|
||||
|
||||
if(current == null) continue;
|
||||
|
||||
current.SetObject(x * _placeSizeWidth, y * _placeSizeHeight, _pictureWidth, _pictureHeight);
|
||||
current.DrawningObject(g);
|
||||
}
|
||||
}
|
||||
}
|
177
MapsCollection.java
Normal file
177
MapsCollection.java
Normal file
@ -0,0 +1,177 @@
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
import java.io.FileWriter;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.ListIterator;
|
||||
|
||||
public class MapsCollection
|
||||
{
|
||||
public LinkedHashMap<String, MapWithSetAircraftsGeneric<DrawingObjectAircraft, AbstractMap>> _mapStorages;
|
||||
private int _pictureWidth;
|
||||
private int _pictureHeight;
|
||||
|
||||
private char separatorDict = '|';
|
||||
private char separatorData = ';';
|
||||
|
||||
public List<String> getKeys() { return _mapStorages.keySet().stream().toList(); }
|
||||
|
||||
public MapsCollection(int pictureWidth, int pictureHeight)
|
||||
{
|
||||
_mapStorages = new LinkedHashMap<>();
|
||||
_pictureWidth = pictureWidth;
|
||||
_pictureHeight = pictureHeight;
|
||||
}
|
||||
|
||||
public boolean SaveData(String filename)
|
||||
{
|
||||
File file = new File(filename);
|
||||
if (file.exists()) file.delete();
|
||||
|
||||
try {
|
||||
file.createNewFile();
|
||||
|
||||
FileWriter writer = new FileWriter(file);
|
||||
writer.append("MapsCollection\n");
|
||||
|
||||
for(String key : _mapStorages.keySet()) {
|
||||
String record = key + separatorDict + _mapStorages.get(key).GetData(separatorDict, separatorData) + "\n";
|
||||
writer.append(record);
|
||||
}
|
||||
|
||||
writer.flush();
|
||||
writer.close();
|
||||
} catch(Exception err) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean LoadData(String filename)
|
||||
{
|
||||
File file = new File(filename);
|
||||
if (!file.exists()) return false;
|
||||
|
||||
try {
|
||||
BufferedReader reader = new BufferedReader(new FileReader(file));
|
||||
String current = reader.readLine();
|
||||
|
||||
if (!current.equals("MapsCollection")) return false;
|
||||
_mapStorages.clear();
|
||||
|
||||
while ((current = reader.readLine()) != null)
|
||||
{
|
||||
String elem[] = current.split("\\" + separatorDict);
|
||||
AbstractMap map = null;
|
||||
switch (elem[1])
|
||||
{
|
||||
case "SimpleMap":
|
||||
map = new SimpleMap();
|
||||
break;
|
||||
case "MyMap":
|
||||
map = new MyMap();
|
||||
break;
|
||||
}
|
||||
_mapStorages.put(elem[0], new MapWithSetAircraftsGeneric<DrawingObjectAircraft, AbstractMap>(_pictureWidth, _pictureHeight, map));
|
||||
_mapStorages.get(elem[0]).LoadData(elem[2].split(separatorData + ""));
|
||||
}
|
||||
|
||||
reader.close();
|
||||
} catch(Exception err) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
public boolean SaveMap(String filename, String key) {
|
||||
File file = new File(filename);
|
||||
if(file.exists()) file.delete();
|
||||
|
||||
MapWithSetAircraftsGeneric<DrawingObjectAircraft, AbstractMap> item = _mapStorages.getOrDefault(key, null);
|
||||
if(item == null) return false;
|
||||
|
||||
try {
|
||||
file.createNewFile();
|
||||
FileWriter writer = new FileWriter(file);
|
||||
|
||||
writer.append("Map\n");
|
||||
writer.append(key + "\n");
|
||||
writer.append(item.getMap().getClass().getName() + "\n");
|
||||
ListIterator<DrawingObjectAircraft> iter = item.getAircraftsIter();
|
||||
while(iter.hasNext()) {
|
||||
writer.append(AircraftFactory.getDataForSave(iter.next().getAircraft()) + "\n");
|
||||
}
|
||||
|
||||
writer.flush();
|
||||
writer.close();
|
||||
} catch(Exception err) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean LoadMap(String filename) {
|
||||
File file = new File(filename);
|
||||
if (!file.exists()) return false;
|
||||
|
||||
try {
|
||||
BufferedReader reader = new BufferedReader(new FileReader(file));
|
||||
String format = reader.readLine();
|
||||
if (!format.equals("Map")) return false;
|
||||
|
||||
String key = reader.readLine();
|
||||
String mapStr = reader.readLine();
|
||||
|
||||
AbstractMap map = null;
|
||||
|
||||
switch (mapStr)
|
||||
{
|
||||
case "SimpleMap":
|
||||
map = new SimpleMap();
|
||||
break;
|
||||
case "MyMap":
|
||||
map = new MyMap();
|
||||
break;
|
||||
}
|
||||
|
||||
if(_mapStorages.containsKey(key)) _mapStorages.get(key).ClearMap();
|
||||
else _mapStorages.put(key, new MapWithSetAircraftsGeneric<>(_pictureWidth, _pictureHeight, map));
|
||||
|
||||
String current = null;
|
||||
while ((current = reader.readLine()) != null)
|
||||
{
|
||||
_mapStorages.get(key).addAircraft(DrawingObjectAircraft.Create(current));
|
||||
}
|
||||
reader.close();
|
||||
} catch(Exception err) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public void AddMap(String name, AbstractMap map)
|
||||
{
|
||||
// TODO Прописать логику для добавления
|
||||
boolean check = _mapStorages.containsKey(name);
|
||||
if (check) return;
|
||||
|
||||
_mapStorages.put(name, new MapWithSetAircraftsGeneric(_pictureWidth, _pictureHeight, map));
|
||||
}
|
||||
|
||||
public void DelMap(String name)
|
||||
{
|
||||
// TODO Прописать логику для удаления
|
||||
_mapStorages.remove(name);
|
||||
}
|
||||
|
||||
public MapWithSetAircraftsGeneric<DrawingObjectAircraft, AbstractMap> getMap(String name)
|
||||
{
|
||||
return _mapStorages.getOrDefault(name, null);
|
||||
}
|
||||
}
|
72
MyMap.java
Normal file
72
MyMap.java
Normal file
@ -0,0 +1,72 @@
|
||||
import java.awt.*;
|
||||
|
||||
public class MyMap extends AbstractMap
|
||||
{
|
||||
|
||||
private Color barrierColor = Color.BLACK;
|
||||
private Color roadColor = Color.GRAY;
|
||||
|
||||
@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;
|
||||
|
||||
for (int i = 0; i < _map.length; ++i)
|
||||
{
|
||||
for (int j = 0; j < _map[0].length; ++j)
|
||||
{
|
||||
_map[i][j] = _freeRoad;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
for(int i = 0; i < 20; ++i)
|
||||
{
|
||||
int x = _random.nextInt(0, 100);
|
||||
int y = _random.nextInt(0, 100);
|
||||
|
||||
GenerateMap(x, y, _random.nextInt(13, 23));
|
||||
}
|
||||
}
|
||||
|
||||
private void GenerateMap(int x, int y, int depth)
|
||||
{
|
||||
if (depth <= 0) return;
|
||||
boolean check = false;
|
||||
|
||||
while (!check)
|
||||
{
|
||||
int deltaX = _random.nextInt(-1, 2);
|
||||
int deltaY = _random.nextInt(-1, 2);
|
||||
|
||||
if (x + deltaX < 0 || x + deltaX >= 100) continue;
|
||||
if (y + deltaY < 0 || y + deltaY >= 100) continue;
|
||||
|
||||
if (_map[y + deltaY][x + deltaX] == _barrier) depth--;
|
||||
x += deltaX;
|
||||
y += deltaY;
|
||||
|
||||
_map[y][x] = _barrier;
|
||||
|
||||
check = true;
|
||||
}
|
||||
|
||||
GenerateMap(x, y, depth - 1);
|
||||
}
|
||||
}
|
BIN
Resources/down.png
Normal file
BIN
Resources/down.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 451 B |
BIN
Resources/left.png
Normal file
BIN
Resources/left.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 367 B |
BIN
Resources/right.png
Normal file
BIN
Resources/right.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 366 B |
BIN
Resources/up.png
Normal file
BIN
Resources/up.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 360 B |
50
SetAircraftsGeneric.java
Normal file
50
SetAircraftsGeneric.java
Normal file
@ -0,0 +1,50 @@
|
||||
import java.util.ArrayList;
|
||||
import java.util.ListIterator;
|
||||
|
||||
public class SetAircraftsGeneric<T>
|
||||
{
|
||||
private ArrayList<T> _places;
|
||||
private int _maxCount;
|
||||
public int getCount() {
|
||||
return _places.size();
|
||||
}
|
||||
|
||||
public SetAircraftsGeneric(int count)
|
||||
{
|
||||
_places = new ArrayList<>();
|
||||
_maxCount = count;
|
||||
}
|
||||
public int Insert(T aircraft)
|
||||
{
|
||||
if (_places.size() == _maxCount) return -1;
|
||||
_places.add(0, aircraft);
|
||||
return 0;
|
||||
}
|
||||
public int Insert(T aircraft, int position)
|
||||
{
|
||||
if (_places.size() == _maxCount) return -1;
|
||||
_places.add(position, aircraft);
|
||||
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 ListIterator<T> GetElems() {
|
||||
return _places.listIterator();
|
||||
}
|
||||
|
||||
public void Clear() {
|
||||
_places.clear();
|
||||
}
|
||||
|
||||
public T Get(int position)
|
||||
{
|
||||
return _places.get(position);
|
||||
}
|
||||
}
|
47
SimpleMap.java
Normal file
47
SimpleMap.java
Normal file
@ -0,0 +1,47 @@
|
||||
import java.awt.*;
|
||||
|
||||
public class SimpleMap extends AbstractMap
|
||||
{
|
||||
private Color barrierColor = Color.BLACK;
|
||||
private Color roadColor = Color.GRAY;
|
||||
|
||||
@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 < 50)
|
||||
{
|
||||
int x = _random.nextInt(0, 100);
|
||||
int y = _random.nextInt(0, 100);
|
||||
if (_map[x][y] == _freeRoad)
|
||||
{
|
||||
_map[x][y] = _barrier;
|
||||
counter++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
29
formAircraftGenerator.form
Normal file
29
formAircraftGenerator.form
Normal 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="formAircraftGenerator">
|
||||
<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>
|
76
formAircraftGenerator.java
Normal file
76
formAircraftGenerator.java
Normal file
@ -0,0 +1,76 @@
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.util.Random;
|
||||
|
||||
public class formAircraftGenerator implements Form {
|
||||
private JButton generateButton;
|
||||
private JPanel drawPanel;
|
||||
private JPanel mainPanel;
|
||||
private Canvas canv = new Canvas(this);
|
||||
|
||||
private DrawingAircraft aircraft;
|
||||
private AircraftMixer<EntityAircraft, IDrawingEngines> mixer = new AircraftMixer<>(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 EntityAircraft(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 EntityModernAircraft(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(EnginesFabric.createRandom(randomColor));
|
||||
}
|
||||
|
||||
generateButton.addActionListener(e -> {
|
||||
Dimension canvSize = canv.getSize();
|
||||
aircraft = mixer.constructAircraft(canvSize.width, canvSize.height);
|
||||
canv.repaint();
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void Draw(Graphics2D g) {
|
||||
if(aircraft == null) return;
|
||||
aircraft.DrawTransport(g);
|
||||
}
|
||||
}
|
173
formMap.form
Normal file
173
formMap.form
Normal file
@ -0,0 +1,173 @@
|
||||
<?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="500" height="400"/>
|
||||
</constraints>
|
||||
<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>
|
119
formMap.java
Normal file
119
formMap.java
Normal 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 DrawingAircraft _aircraft;
|
||||
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(DrawingAircraft aircraft)
|
||||
{
|
||||
Color bodyColor = _aircraft.AirFighter.BodyColor;
|
||||
String colorString = "(" + bodyColor.getRed() + ", " + bodyColor.getGreen() + ", " + bodyColor.getBlue() + ")";
|
||||
|
||||
speedLabel.setText("Скорость: " + _aircraft.AirFighter.Speed + " ");
|
||||
weightLabel.setText("Вес: " + _aircraft.AirFighter.Weight + " ");
|
||||
colorLabel.setText("Цвет: " + colorString);
|
||||
|
||||
Dimension canvSize = canv.getSize();
|
||||
|
||||
_abstractMap.CreateMap(canvSize.width, canvSize.height, new DrawingObjectAircraft(aircraft));
|
||||
}
|
||||
|
||||
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();
|
||||
|
||||
_aircraft = new DrawingAircraft(rnd.nextInt(100, 300), rnd.nextInt(1000, 2000),
|
||||
new Color(rnd.nextInt(0, 256), rnd.nextInt(0, 256), rnd.nextInt(0, 256)));
|
||||
|
||||
SetData(_aircraft);
|
||||
canv.repaint();
|
||||
});
|
||||
|
||||
modifiedButton.addActionListener(e -> {
|
||||
Random rnd = new Random();
|
||||
|
||||
_aircraft = new DrawingModernAircraft(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(_aircraft);
|
||||
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);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user