Добавление классов отрисовки карт, формы, и т.д.
This commit is contained in:
parent
6bdd753c33
commit
90ceb3ed94
51
Project/src/DesertStormMap.java
Normal file
51
Project/src/DesertStormMap.java
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
import java.awt.*;
|
||||||
|
|
||||||
|
public class DesertStormMap extends AbstractMap{
|
||||||
|
//цвет закрытого участка
|
||||||
|
private final Color barriedColor = new Color(139, 0, 0);
|
||||||
|
|
||||||
|
//цвет открытого участка
|
||||||
|
private final Color roadColor = new Color(255, 140, 0);
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void GenerateMap() {
|
||||||
|
_map = new int[100][100];
|
||||||
|
_size_x = (float)_width / _map.length;
|
||||||
|
_size_y = (float)_height / _map[0].length;
|
||||||
|
int counter = 0;
|
||||||
|
|
||||||
|
for(int i = 0; i < _map.length; ++i)
|
||||||
|
{
|
||||||
|
for(int j = 0; j < _map[0].length; ++j)
|
||||||
|
{
|
||||||
|
_map[i][j] = _freeRoad;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
while(counter < 50)
|
||||||
|
{
|
||||||
|
int x = _random.nextInt(0, 100);
|
||||||
|
int y = _random.nextInt(0, 100);
|
||||||
|
|
||||||
|
if (_map[x][y] == _freeRoad)
|
||||||
|
{
|
||||||
|
_map[x][y] = _barrier;
|
||||||
|
counter++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void DrawRoadPart(Graphics g, int i, int j) {
|
||||||
|
Graphics2D g2d = (Graphics2D)g;
|
||||||
|
g2d.setPaint(roadColor);
|
||||||
|
g2d.fillRect((int)(i * _size_x), (int)(j * _size_y), (int)(_size_x), (int)(_size_y));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void DrawBarrierPart(Graphics g, int i, int j) {
|
||||||
|
Graphics2D g2d = (Graphics2D)g;
|
||||||
|
g2d.setPaint(barriedColor);
|
||||||
|
g.fillRect((int)(i * _size_x), (int)(j * _size_y), (int)(_size_x), (int)(_size_y));
|
||||||
|
}
|
||||||
|
}
|
@ -1,4 +1,6 @@
|
|||||||
public enum Direction {
|
//направление перемещения
|
||||||
|
public enum Direction
|
||||||
|
{
|
||||||
Up(1),
|
Up(1),
|
||||||
Down(2),
|
Down(2),
|
||||||
Left(3),
|
Left(3),
|
||||||
|
48
Project/src/DrawingAirbus.java
Normal file
48
Project/src/DrawingAirbus.java
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
import java.awt.*;
|
||||||
|
|
||||||
|
public class DrawingAirbus extends DrawingPlane
|
||||||
|
{
|
||||||
|
//Инициализаци свойств
|
||||||
|
public DrawingAirbus(int speed, int weight, Color corpusColor, Color addColor, boolean addCompartment, boolean addEngine)
|
||||||
|
{
|
||||||
|
super(speed, weight, corpusColor, 110, 60);
|
||||||
|
Plane = new EntityAirbus(speed, weight, corpusColor, addColor, addCompartment, addEngine);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void DrawTransport(Graphics g)
|
||||||
|
{
|
||||||
|
Graphics2D g2d = (Graphics2D) g;
|
||||||
|
EntityAirbus airbus;
|
||||||
|
|
||||||
|
if (!(GetPlane() instanceof EntityAirbus))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
airbus = (EntityAirbus) Plane;
|
||||||
|
_startPosX += 10;
|
||||||
|
_startPosY += 5;
|
||||||
|
super.DrawTransport(g);
|
||||||
|
_startPosX -= 10;
|
||||||
|
_startPosY -= 5;
|
||||||
|
|
||||||
|
//дополнительный пассажирский отсек
|
||||||
|
if (airbus.AddСompartment)
|
||||||
|
{
|
||||||
|
g2d.setPaint(airbus.AddColor);
|
||||||
|
g.fillRect((int)_startPosX + 30, (int)_startPosY + 12, 14, 3);
|
||||||
|
g2d.setPaint(Color.BLACK);
|
||||||
|
g.drawRect((int)_startPosX + 30, (int)_startPosY + 12, 14, 3);
|
||||||
|
}
|
||||||
|
|
||||||
|
//дополнительный двигатель
|
||||||
|
if (airbus.AddEngine)
|
||||||
|
{
|
||||||
|
g2d.setPaint(airbus.AddColor);
|
||||||
|
g.fillOval((int)_startPosX + 24, (int)_startPosY + 22, 10, 5);
|
||||||
|
g2d.setPaint(Color.BLACK);
|
||||||
|
g.drawOval((int)_startPosX + 24, (int)_startPosY + 22, 10, 5);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,16 +1,19 @@
|
|||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
|
|
||||||
public class DrawingAirplaneWindow extends JComponent
|
public class DrawingAirplaneWindow extends JComponent implements IAdditionalDrawingObject
|
||||||
{
|
{
|
||||||
private Additional_Enum _airplaneWindowEnum;
|
private Additional_Enum _airplaneWindowEnum;
|
||||||
|
|
||||||
public void SetAddEnum(int decksAmount) {
|
@Override
|
||||||
|
public void SetAddEnum(int airplaneWindow)
|
||||||
|
{
|
||||||
for(Additional_Enum item : _airplaneWindowEnum.values())
|
for(Additional_Enum item : _airplaneWindowEnum.values())
|
||||||
{
|
{
|
||||||
if(item.GetAddEnum() == decksAmount)
|
if(item.GetAddEnum() == airplaneWindow)
|
||||||
{
|
{
|
||||||
_airplaneWindowEnum = item;
|
_airplaneWindowEnum = item;
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -21,35 +24,31 @@ public class DrawingAirplaneWindow extends JComponent
|
|||||||
super.paintComponent(g);
|
super.paintComponent(g);
|
||||||
Graphics2D g2d = (Graphics2D) g;
|
Graphics2D g2d = (Graphics2D) g;
|
||||||
|
|
||||||
switch(_airplaneWindowEnum.GetAddEnum())
|
if(_airplaneWindowEnum.GetAddEnum() >= 1)
|
||||||
{
|
{
|
||||||
case 1:
|
g2d.setPaint(colorWindow);
|
||||||
g2d.setPaint(colorWindow);
|
g2d.fillOval((int)_startPosX + 9, (int)_startPosY + 11, 6, 4);
|
||||||
g2d.fillOval((int)_startPosX + 9, (int)_startPosY + 11, 6, 4);
|
|
||||||
|
|
||||||
g2d.setPaint(Color.BLACK);
|
g2d.setPaint(Color.BLACK);
|
||||||
g2d.drawOval((int)_startPosX + 9, (int)_startPosY + 11, 6, 4);
|
g2d.drawOval((int)_startPosX + 9, (int)_startPosY + 11, 6, 4);
|
||||||
break;
|
}
|
||||||
case 2:
|
|
||||||
g2d.setPaint(colorWindow);
|
|
||||||
g2d.fillOval((int)_startPosX + 9, (int)_startPosY + 11, 6, 4);
|
|
||||||
g2d.fillOval((int)_startPosX + 18, (int)_startPosY + 11, 6, 4);
|
|
||||||
|
|
||||||
g2d.setPaint(Color.BLACK);
|
if(_airplaneWindowEnum.GetAddEnum() >= 2)
|
||||||
g2d.drawOval((int)_startPosX + 9, (int)_startPosY + 11, 6, 4);
|
{
|
||||||
g2d.drawOval((int)_startPosX + 18, (int)_startPosY + 11, 6, 4);
|
g2d.setPaint(colorWindow);
|
||||||
break;
|
g2d.fillOval((int)_startPosX + 18, (int)_startPosY + 11, 6, 4);
|
||||||
case 3:
|
|
||||||
g2d.setPaint(colorWindow);
|
|
||||||
g2d.fillOval((int)_startPosX + 9, (int)_startPosY + 11, 6, 4);
|
|
||||||
g2d.fillOval((int)_startPosX + 18, (int)_startPosY + 11, 6, 4);
|
|
||||||
g2d.fillOval((int)_startPosX + 27, (int)_startPosY + 11, 6, 4);
|
|
||||||
|
|
||||||
g2d.setPaint(Color.BLACK);
|
g2d.setPaint(Color.BLACK);
|
||||||
g2d.drawOval((int)_startPosX + 9, (int)_startPosY + 11, 6, 4);
|
g2d.drawOval((int)_startPosX + 18, (int)_startPosY + 11, 6, 4);
|
||||||
g2d.drawOval((int)_startPosX + 18, (int)_startPosY + 11, 6, 4);
|
}
|
||||||
g2d.drawOval((int)_startPosX + 27, (int)_startPosY + 11, 6, 4);
|
|
||||||
break;
|
if(_airplaneWindowEnum.GetAddEnum() >= 3)
|
||||||
|
{
|
||||||
|
g2d.setPaint(colorWindow);
|
||||||
|
g2d.fillOval((int)_startPosX + 27, (int)_startPosY + 11, 6, 4);
|
||||||
|
|
||||||
|
g2d.setPaint(Color.BLACK);
|
||||||
|
g2d.drawOval((int)_startPosX + 27, (int)_startPosY + 11, 6, 4);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,40 +1,68 @@
|
|||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
|
import javax.swing.*;
|
||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
public class DrawingPlane
|
public class DrawingPlane extends JPanel
|
||||||
{
|
{
|
||||||
public EntityPlane Airbus; //класс-сущность
|
protected EntityPlane Plane; //класс-сущность
|
||||||
public DrawingAirplaneWindow _airplaneWindow; //для дополнительной отрисовки
|
public IAdditionalDrawingObject _airplaneWindow; //для дополнительной отрисовки
|
||||||
|
|
||||||
private float _startPosX; //левая координата отрисовки
|
|
||||||
private float _startPosY; //верхняя координата отрисовки
|
|
||||||
private Integer _pictureWidth = null; //ширина окна отрисовки
|
|
||||||
private Integer _pictureHeight = null; //высота окна отрисовки
|
|
||||||
protected final int _airbusWidth = 50; //ширина отрисовки самолёта
|
|
||||||
protected final int _airbusHeight = 16; //высота отрисовки самолёта
|
|
||||||
|
|
||||||
//инициализаци свойств
|
|
||||||
public void Initial(int speed, float weight, Color corpusColor)
|
|
||||||
{
|
|
||||||
Airbus = new EntityPlane();
|
|
||||||
Airbus.Initial(speed, weight, corpusColor);
|
|
||||||
_airplaneWindow = new DrawingAirplaneWindow();
|
|
||||||
|
|
||||||
SetAddEnum();
|
|
||||||
}
|
|
||||||
|
|
||||||
//установка кол-ва иллюминаторов
|
|
||||||
public void SetAddEnum()
|
public void SetAddEnum()
|
||||||
{
|
{
|
||||||
Random rnd = new Random();
|
Random rnd = new Random();
|
||||||
int countWindow = rnd.nextInt(1, 4);
|
int numbEnum = rnd.nextInt(1, 4);
|
||||||
_airplaneWindow.SetAddEnum(countWindow);
|
_airplaneWindow.SetAddEnum(numbEnum);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SetFormEnum()
|
||||||
|
{
|
||||||
|
Random rnd = new Random();
|
||||||
|
|
||||||
|
int numbEnum = rnd.nextInt(1, 4);
|
||||||
|
|
||||||
|
if(numbEnum == 1)
|
||||||
|
{
|
||||||
|
_airplaneWindow = new DrawingAirplaneWindow();
|
||||||
|
}
|
||||||
|
|
||||||
|
if(numbEnum == 2)
|
||||||
|
{
|
||||||
|
_airplaneWindow = new DrawingTriangleAirplaneWindow();
|
||||||
|
}
|
||||||
|
|
||||||
|
if(numbEnum == 3)
|
||||||
|
{
|
||||||
|
_airplaneWindow = new DrawingRectAirplaneWindow();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public EntityPlane GetPlane()
|
public EntityPlane GetPlane()
|
||||||
{
|
{
|
||||||
return Airbus;
|
return Plane;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected float _startPosX; //левая координата отрисовки
|
||||||
|
protected float _startPosY; //верхняя координата отрисовки
|
||||||
|
private Integer _pictureWidth = null; //ширина окна отрисовки
|
||||||
|
private Integer _pictureHeight = null; //высота окна отрисовки
|
||||||
|
protected int _airbusWidth = 50; //ширина отрисовки самолёта
|
||||||
|
protected int _airbusHeight = 16; //высота отрисовки самолёта
|
||||||
|
|
||||||
|
//конструктор
|
||||||
|
public DrawingPlane(int speed, float weight, Color corpusColor)
|
||||||
|
{
|
||||||
|
Plane = new EntityPlane(speed, weight, corpusColor);
|
||||||
|
SetFormEnum();
|
||||||
|
SetAddEnum();
|
||||||
|
}
|
||||||
|
|
||||||
|
//конструктор
|
||||||
|
public DrawingPlane(int speed, float weight, Color corpusColor, int planeWidth, int planeHeight)
|
||||||
|
{
|
||||||
|
this(speed, weight, corpusColor);
|
||||||
|
_airbusWidth = planeWidth;
|
||||||
|
_airbusHeight = planeHeight;
|
||||||
}
|
}
|
||||||
|
|
||||||
//установка координат позиции самолёта
|
//установка координат позиции самолёта
|
||||||
@ -65,30 +93,30 @@ public class DrawingPlane
|
|||||||
switch (direction)
|
switch (direction)
|
||||||
{
|
{
|
||||||
case Right: //вправо
|
case Right: //вправо
|
||||||
if (_startPosX + _airbusWidth + Airbus.GetStep() < _pictureWidth)
|
if (_startPosX + _airbusWidth + Plane.GetStep() < _pictureWidth)
|
||||||
{
|
{
|
||||||
_startPosX += Airbus.GetStep();
|
_startPosX += Plane.GetStep();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Left: //влево
|
case Left: //влево
|
||||||
if (_startPosX - _airbusWidth - Airbus.GetStep() > 0)
|
if (_startPosX - _airbusWidth - Plane.GetStep() > 0)
|
||||||
{
|
{
|
||||||
_startPosX -= Airbus.GetStep();
|
_startPosX -= Plane.GetStep();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Up: //вверх
|
case Up: //вверх
|
||||||
if (_startPosY - _airbusHeight - Airbus.GetStep() > 0)
|
if (_startPosY - _airbusHeight - Plane.GetStep() > 0)
|
||||||
{
|
{
|
||||||
_startPosY -= Airbus.GetStep();
|
_startPosY -= Plane.GetStep();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Down: //вниз
|
case Down: //вниз
|
||||||
if (_startPosY + _airbusHeight + Airbus.GetStep() < _pictureHeight)
|
if (_startPosY + _airbusHeight + Plane.GetStep() < _pictureHeight)
|
||||||
{
|
{
|
||||||
_startPosY += Airbus.GetStep();
|
_startPosY += Plane.GetStep();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -143,7 +171,7 @@ public class DrawingPlane
|
|||||||
g2d.drawLine((int)_startPosX + 40, (int)_startPosY + 20, (int)_startPosX + 50, (int)_startPosY + 15);
|
g2d.drawLine((int)_startPosX + 40, (int)_startPosY + 20, (int)_startPosX + 50, (int)_startPosY + 15);
|
||||||
|
|
||||||
//отрисовка иллюминаторов
|
//отрисовка иллюминаторов
|
||||||
_airplaneWindow.DrawAirplaneWindow(Airbus.GetColor(), g, _startPosX, _startPosY);
|
_airplaneWindow.DrawAirplaneWindow(Plane.GetColor(), g, _startPosX, _startPosY);
|
||||||
}
|
}
|
||||||
|
|
||||||
//смена границ формы отрисовки
|
//смена границ формы отрисовки
|
||||||
@ -169,4 +197,10 @@ public class DrawingPlane
|
|||||||
_startPosY = _pictureHeight - _airbusHeight;
|
_startPosY = _pictureHeight - _airbusHeight;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public float[] GetCurrentPosition()
|
||||||
|
{
|
||||||
|
return new float[] {_startPosX, _startPosX + _airbusWidth,
|
||||||
|
_startPosY + _airbusHeight, _startPosX};
|
||||||
|
}
|
||||||
}
|
}
|
55
Project/src/DrawingRectAirplaneWindow.java
Normal file
55
Project/src/DrawingRectAirplaneWindow.java
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
import javax.swing.*;
|
||||||
|
import java.awt.*;
|
||||||
|
|
||||||
|
public class DrawingRectAirplaneWindow extends JComponent implements IAdditionalDrawingObject
|
||||||
|
{
|
||||||
|
private Additional_Enum _airplaneWindowEnum;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void SetAddEnum(int airplaneWindow)
|
||||||
|
{
|
||||||
|
for(Additional_Enum item : _airplaneWindowEnum.values())
|
||||||
|
{
|
||||||
|
if(item.GetAddEnum() == airplaneWindow)
|
||||||
|
{
|
||||||
|
_airplaneWindowEnum = item;
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void DrawAirplaneWindow(Color colorWindow, Graphics g, float _startPosX, float _startPosY)
|
||||||
|
{
|
||||||
|
super.paintComponent(g);
|
||||||
|
Graphics2D g2d = (Graphics2D) g;
|
||||||
|
|
||||||
|
if(_airplaneWindowEnum.GetAddEnum() >= 1)
|
||||||
|
{
|
||||||
|
g2d.setPaint(colorWindow);
|
||||||
|
g2d.fillRect((int)_startPosX + 9, (int)_startPosY + 11, 6, 4);
|
||||||
|
|
||||||
|
g2d.setPaint(Color.BLACK);
|
||||||
|
g2d.drawRect((int)_startPosX + 9, (int)_startPosY + 11, 6, 4);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(_airplaneWindowEnum.GetAddEnum() >= 2)
|
||||||
|
{
|
||||||
|
g2d.setPaint(colorWindow);
|
||||||
|
g2d.fillRect((int)_startPosX + 18, (int)_startPosY + 11, 6, 4);
|
||||||
|
|
||||||
|
g2d.setPaint(Color.BLACK);
|
||||||
|
g2d.drawRect((int)_startPosX + 18, (int)_startPosY + 11, 6, 4);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(_airplaneWindowEnum.GetAddEnum() >= 3)
|
||||||
|
{
|
||||||
|
g2d.setPaint(colorWindow);
|
||||||
|
g2d.fillRect((int)_startPosX + 27, (int)_startPosY + 11, 6, 4);
|
||||||
|
|
||||||
|
g2d.setPaint(Color.BLACK);
|
||||||
|
g2d.drawRect((int)_startPosX + 27, (int)_startPosY + 11, 6, 4);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
63
Project/src/DrawingTriangleAirplaneWindow.java
Normal file
63
Project/src/DrawingTriangleAirplaneWindow.java
Normal file
@ -0,0 +1,63 @@
|
|||||||
|
import javax.swing.*;
|
||||||
|
import java.awt.*;
|
||||||
|
|
||||||
|
public class DrawingTriangleAirplaneWindow extends JComponent implements IAdditionalDrawingObject
|
||||||
|
{
|
||||||
|
private Additional_Enum _airplaneWindowEnum;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void SetAddEnum(int airplaneWindow)
|
||||||
|
{
|
||||||
|
for(Additional_Enum item : _airplaneWindowEnum.values())
|
||||||
|
{
|
||||||
|
if(item.GetAddEnum() == airplaneWindow)
|
||||||
|
{
|
||||||
|
_airplaneWindowEnum = item;
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void DrawAirplaneWindow(Color colorWindow, Graphics g, float _startPosX, float _startPosY)
|
||||||
|
{
|
||||||
|
super.paintComponent(g);
|
||||||
|
Graphics2D g2d = (Graphics2D) g;
|
||||||
|
|
||||||
|
if(_airplaneWindowEnum.GetAddEnum() >= 1)
|
||||||
|
{
|
||||||
|
int[] x_point = {(int)_startPosX + 12, (int)_startPosX + 16, (int)_startPosX + 9};
|
||||||
|
int[] y_point = {(int)_startPosY + 11, (int)_startPosY + 15, (int)_startPosY + 15};
|
||||||
|
|
||||||
|
g2d.setPaint(colorWindow);
|
||||||
|
g2d.fillPolygon(x_point, y_point, 3);
|
||||||
|
|
||||||
|
g2d.setPaint(Color.BLACK);
|
||||||
|
g2d.drawPolygon(x_point, y_point, 3);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(_airplaneWindowEnum.GetAddEnum() >= 2)
|
||||||
|
{
|
||||||
|
int[] x_point = {(int)_startPosX + 21, (int)_startPosX + 25, (int)_startPosX + 18};
|
||||||
|
int[] y_point = {(int)_startPosY + 11, (int)_startPosY + 15, (int)_startPosY + 15};
|
||||||
|
|
||||||
|
g2d.setPaint(colorWindow);
|
||||||
|
g2d.fillPolygon(x_point, y_point, 3);
|
||||||
|
|
||||||
|
g2d.setPaint(Color.BLACK);
|
||||||
|
g2d.drawPolygon(x_point, y_point, 3);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(_airplaneWindowEnum.GetAddEnum() >= 3)
|
||||||
|
{
|
||||||
|
int[] x_point = {(int)_startPosX + 30, (int)_startPosX + 34, (int)_startPosX + 27};
|
||||||
|
int[] y_point = {(int)_startPosY + 11, (int)_startPosY + 15, (int)_startPosY + 15};
|
||||||
|
|
||||||
|
g2d.setPaint(colorWindow);
|
||||||
|
g2d.fillPolygon(x_point, y_point, 3);
|
||||||
|
|
||||||
|
g2d.setPaint(Color.BLACK);
|
||||||
|
g2d.drawPolygon(x_point, y_point, 3);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
50
Project/src/DrawningObjectPlane.java
Normal file
50
Project/src/DrawningObjectPlane.java
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
import java.awt.*;
|
||||||
|
|
||||||
|
public class DrawningObjectPlane implements IDrawningObject
|
||||||
|
{
|
||||||
|
private DrawingPlane _plane = null;
|
||||||
|
|
||||||
|
public DrawningObjectPlane(DrawingPlane plane){
|
||||||
|
_plane = plane;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public float Step()
|
||||||
|
{
|
||||||
|
if(_plane != null && _plane.Plane != null)
|
||||||
|
{
|
||||||
|
return _plane.Plane.GetStep();
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void SetObject(int x, int y, int width, int height)
|
||||||
|
{
|
||||||
|
_plane.SetPosition(x, y, width, height);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void MoveObject(Direction direction)
|
||||||
|
{
|
||||||
|
_plane.MoveTransport(direction);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void DrawningObject(Graphics g)
|
||||||
|
{
|
||||||
|
_plane.DrawTransport(g);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public float[] GetCurrentPosition()
|
||||||
|
{
|
||||||
|
if(_plane != null)
|
||||||
|
{
|
||||||
|
return _plane.GetCurrentPosition();
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
21
Project/src/EntityAirbus.java
Normal file
21
Project/src/EntityAirbus.java
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
import java.awt.*;
|
||||||
|
|
||||||
|
public class EntityAirbus extends EntityPlane{
|
||||||
|
//Дополнительный цвет
|
||||||
|
public Color AddColor;
|
||||||
|
|
||||||
|
//Признак наличия дополнительно пассажирского отсека
|
||||||
|
public boolean AddСompartment;
|
||||||
|
|
||||||
|
//Признак наличия дополнительных двигателей
|
||||||
|
public boolean AddEngine;
|
||||||
|
|
||||||
|
//Инициализация свойств
|
||||||
|
public EntityAirbus(int speed, float weight, Color corpusColor, Color addColor, boolean addCompartment, boolean addEngine)
|
||||||
|
{
|
||||||
|
super(speed, weight, corpusColor);
|
||||||
|
AddColor = addColor;
|
||||||
|
AddСompartment = addCompartment;
|
||||||
|
AddEngine = addEngine;
|
||||||
|
}
|
||||||
|
}
|
@ -22,7 +22,7 @@ public class EntityPlane
|
|||||||
return Speed * 100 / Weight;
|
return Speed * 100 / Weight;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Initial(int speed, float weight, Color corpusColor)
|
public EntityPlane(int speed, float weight, Color corpusColor)
|
||||||
{
|
{
|
||||||
Speed = speed;
|
Speed = speed;
|
||||||
Weight = weight;
|
Weight = weight;
|
||||||
|
@ -63,7 +63,7 @@
|
|||||||
<border type="none"/>
|
<border type="none"/>
|
||||||
<children/>
|
<children/>
|
||||||
</toolbar>
|
</toolbar>
|
||||||
<grid id="b0c9a" binding="PictureBox" layout-manager="BorderLayout" hgap="0" vgap="0">
|
<grid id="b0c9a" binding="PictureBoxPlane" layout-manager="BorderLayout" hgap="0" vgap="0">
|
||||||
<constraints>
|
<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"/>
|
<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>
|
</constraints>
|
||||||
|
@ -9,7 +9,7 @@ import java.util.Random;
|
|||||||
|
|
||||||
public class FormAirbus
|
public class FormAirbus
|
||||||
{
|
{
|
||||||
protected DrawingPlane plane = new DrawingPlane();
|
protected DrawingPlane plane;
|
||||||
|
|
||||||
public JPanel MainPanel;
|
public JPanel MainPanel;
|
||||||
private JButton ButtonCreate;
|
private JButton ButtonCreate;
|
||||||
@ -18,7 +18,7 @@ public class FormAirbus
|
|||||||
private JButton ButtonRight;
|
private JButton ButtonRight;
|
||||||
private JButton ButtonUp;
|
private JButton ButtonUp;
|
||||||
private JToolBar StatusStrip;
|
private JToolBar StatusStrip;
|
||||||
private JPanel PictureBox;
|
private JPanel PictureBoxPlane;
|
||||||
private JLabel LabelSpeed = new JLabel();
|
private JLabel LabelSpeed = new JLabel();
|
||||||
private JLabel LabelWeight = new JLabel();
|
private JLabel LabelWeight = new JLabel();
|
||||||
private JLabel LabelColor = new JLabel();
|
private JLabel LabelColor = new JLabel();
|
||||||
@ -51,12 +51,11 @@ public class FormAirbus
|
|||||||
ButtonCreate.addActionListener(new ActionListener() {
|
ButtonCreate.addActionListener(new ActionListener() {
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
plane = new DrawingPlane();
|
|
||||||
Random rnd = new Random();
|
Random rnd = new Random();
|
||||||
plane.Initial(rnd.nextInt(100, 300), rnd.nextInt(1000, 2000),
|
plane = new DrawingPlane(rnd.nextInt(100, 300), rnd.nextInt(1000, 2000),
|
||||||
new Color(rnd.nextInt(256), rnd.nextInt(256), rnd.nextInt(256)));
|
new Color(rnd.nextInt(256), rnd.nextInt(256), rnd.nextInt(256)));
|
||||||
plane.SetPosition(rnd.nextInt(10, 100), rnd.nextInt(10, 100),
|
plane.SetPosition(rnd.nextInt(10, 100), rnd.nextInt(10, 100),
|
||||||
PictureBox.getWidth(), PictureBox.getHeight());
|
PictureBoxPlane.getWidth(), PictureBoxPlane.getHeight());
|
||||||
LabelSpeed.setText("Скорость: " + plane.GetPlane().GetSpeed() + " ");
|
LabelSpeed.setText("Скорость: " + plane.GetPlane().GetSpeed() + " ");
|
||||||
LabelWeight.setText("Вес: " + plane.GetPlane().GetWeight() + " ");
|
LabelWeight.setText("Вес: " + plane.GetPlane().GetWeight() + " ");
|
||||||
LabelColor.setText("Цвет: r = " + plane.GetPlane().GetColor().getRed() + " g = " + plane.GetPlane().GetColor().getGreen() +
|
LabelColor.setText("Цвет: r = " + plane.GetPlane().GetColor().getRed() + " g = " + plane.GetPlane().GetColor().getGreen() +
|
||||||
@ -70,7 +69,7 @@ public class FormAirbus
|
|||||||
@Override
|
@Override
|
||||||
public void componentResized(ComponentEvent e) {
|
public void componentResized(ComponentEvent e) {
|
||||||
super.componentResized(e);
|
super.componentResized(e);
|
||||||
plane.ChangeBorders(PictureBox.getWidth(), PictureBox.getHeight());
|
plane.ChangeBorders(PictureBoxPlane.getWidth(), PictureBoxPlane.getHeight());
|
||||||
Draw();
|
Draw();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -115,6 +114,6 @@ public class FormAirbus
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
plane.DrawTransport(PictureBox.getGraphics());
|
plane.DrawTransport(PictureBoxPlane.getGraphics());
|
||||||
}
|
}
|
||||||
}
|
}
|
125
Project/src/FormMap.form
Normal file
125
Project/src/FormMap.form
Normal file
@ -0,0 +1,125 @@
|
|||||||
|
<?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="8" 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="796" height="519"/>
|
||||||
|
</constraints>
|
||||||
|
<properties/>
|
||||||
|
<border type="none"/>
|
||||||
|
<children>
|
||||||
|
<toolbar id="cf96b" binding="StatusStrip">
|
||||||
|
<constraints>
|
||||||
|
<grid row="3" column="0" row-span="1" col-span="2" vsize-policy="0" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false">
|
||||||
|
<preferred-size width="-1" height="20"/>
|
||||||
|
</grid>
|
||||||
|
</constraints>
|
||||||
|
<properties/>
|
||||||
|
<border type="none"/>
|
||||||
|
<children/>
|
||||||
|
</toolbar>
|
||||||
|
<component id="34e5f" class="javax.swing.JButton" binding="ButtonCreate">
|
||||||
|
<constraints>
|
||||||
|
<grid row="3" column="2" 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="5d8c4" class="javax.swing.JButton" binding="ButtonCreateModif">
|
||||||
|
<constraints>
|
||||||
|
<grid row="3" 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>
|
||||||
|
<horizontalAlignment value="0"/>
|
||||||
|
<text value="Модифицировать"/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
<hspacer id="150e1">
|
||||||
|
<constraints>
|
||||||
|
<grid row="3" 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>
|
||||||
|
<component id="dfc6f" class="javax.swing.JButton" binding="ButtonLeft">
|
||||||
|
<constraints>
|
||||||
|
<grid row="3" column="5" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="0" indent="0" use-parent-layout="false">
|
||||||
|
<minimum-size width="45" height="45"/>
|
||||||
|
<preferred-size width="45" height="45"/>
|
||||||
|
<maximum-size width="45" height="45"/>
|
||||||
|
</grid>
|
||||||
|
</constraints>
|
||||||
|
<properties>
|
||||||
|
<horizontalTextPosition value="0"/>
|
||||||
|
<text value=""/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
<component id="aa961" class="javax.swing.JButton" binding="ButtonDown">
|
||||||
|
<constraints>
|
||||||
|
<grid row="3" 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="45" height="45"/>
|
||||||
|
<preferred-size width="45" height="45"/>
|
||||||
|
<maximum-size width="45" height="45"/>
|
||||||
|
</grid>
|
||||||
|
</constraints>
|
||||||
|
<properties>
|
||||||
|
<text value=""/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
<component id="ab8aa" class="javax.swing.JButton" binding="ButtonRight">
|
||||||
|
<constraints>
|
||||||
|
<grid row="3" column="7" 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="45" height="45"/>
|
||||||
|
<preferred-size width="45" height="45"/>
|
||||||
|
<maximum-size width="45" height="45"/>
|
||||||
|
</grid>
|
||||||
|
</constraints>
|
||||||
|
<properties>
|
||||||
|
<text value=""/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
<component id="2b365" class="javax.swing.JButton" binding="ButtonUp">
|
||||||
|
<constraints>
|
||||||
|
<grid row="2" 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="45" height="45"/>
|
||||||
|
<preferred-size width="45" height="45"/>
|
||||||
|
<maximum-size width="45" height="45"/>
|
||||||
|
</grid>
|
||||||
|
</constraints>
|
||||||
|
<properties>
|
||||||
|
<text value=""/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
<grid id="c63c0" binding="PictureBoxPlane" layout-manager="BorderLayout" hgap="0" vgap="0">
|
||||||
|
<constraints>
|
||||||
|
<grid row="1" column="0" row-span="1" col-span="8" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
<properties/>
|
||||||
|
<border type="none"/>
|
||||||
|
<children/>
|
||||||
|
</grid>
|
||||||
|
<component id="ae3f0" class="javax.swing.JComboBox" binding="ComboBoxSelectorMap">
|
||||||
|
<constraints>
|
||||||
|
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="2" anchor="8" fill="1" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
<properties>
|
||||||
|
<model>
|
||||||
|
<item value="Простая карта"/>
|
||||||
|
<item value="Буря в пустыне"/>
|
||||||
|
<item value="Звёздные Войны"/>
|
||||||
|
</model>
|
||||||
|
<toolTipText value="" noi18n="true"/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
<hspacer id="ac18c">
|
||||||
|
<constraints>
|
||||||
|
<grid row="0" column="2" row-span="1" col-span="6" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
</hspacer>
|
||||||
|
<hspacer id="43771">
|
||||||
|
<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>
|
||||||
|
</form>
|
217
Project/src/FormMap.java
Normal file
217
Project/src/FormMap.java
Normal file
@ -0,0 +1,217 @@
|
|||||||
|
import javax.imageio.ImageIO;
|
||||||
|
import javax.swing.*;
|
||||||
|
import java.awt.*;
|
||||||
|
import java.awt.event.ActionEvent;
|
||||||
|
import java.awt.event.ActionListener;
|
||||||
|
import java.awt.event.ComponentAdapter;
|
||||||
|
import java.awt.event.ComponentEvent;
|
||||||
|
import java.awt.image.BufferedImage;
|
||||||
|
import java.util.Random;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
public class FormMap extends JFrame
|
||||||
|
{
|
||||||
|
public JPanel MainPanel;
|
||||||
|
private JButton ButtonCreate;
|
||||||
|
private JButton ButtonCreateModif;
|
||||||
|
private JButton ButtonLeft;
|
||||||
|
private JButton ButtonDown;
|
||||||
|
private JButton ButtonRight;
|
||||||
|
private JButton ButtonUp;
|
||||||
|
private JToolBar StatusStrip;
|
||||||
|
private JPanel PictureBoxPlane;
|
||||||
|
private JComboBox ComboBoxSelectorMap;
|
||||||
|
private JLabel LabelSpeed = new JLabel();
|
||||||
|
private JLabel LabelWeight = new JLabel();
|
||||||
|
private JLabel LabelColor = new JLabel();
|
||||||
|
|
||||||
|
protected DrawingPlane _plane;
|
||||||
|
private AbstractMap _abstractMap;
|
||||||
|
private Random rnd = new Random();
|
||||||
|
private BufferedImage bufferImg = null;
|
||||||
|
|
||||||
|
public void Draw()
|
||||||
|
{
|
||||||
|
PictureBoxPlane.removeAll();
|
||||||
|
|
||||||
|
bufferImg = new BufferedImage(PictureBoxPlane.getWidth(), PictureBoxPlane.getHeight(), BufferedImage.TYPE_INT_RGB);
|
||||||
|
Graphics g = bufferImg.getGraphics();
|
||||||
|
g.setColor(new Color(238, 238, 238));
|
||||||
|
g.fillRect(0, 0, PictureBoxPlane.getWidth(), PictureBoxPlane.getHeight());
|
||||||
|
|
||||||
|
if(_plane != null)
|
||||||
|
{
|
||||||
|
_plane.DrawTransport(g);
|
||||||
|
JLabel imageOfLogo = new JLabel();
|
||||||
|
imageOfLogo.setPreferredSize(PictureBoxPlane.getSize());
|
||||||
|
imageOfLogo.setMinimumSize(new Dimension(1, 1));
|
||||||
|
imageOfLogo.setIcon(new ImageIcon(bufferImg));
|
||||||
|
PictureBoxPlane.add(imageOfLogo, BorderLayout.CENTER);
|
||||||
|
}
|
||||||
|
|
||||||
|
validate();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void paint(Graphics g)
|
||||||
|
{
|
||||||
|
super.paint(g);
|
||||||
|
Draw();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SetData(DrawingPlane _plane)
|
||||||
|
{
|
||||||
|
PictureBoxPlane.removeAll();
|
||||||
|
|
||||||
|
LabelSpeed.setText("Скорость: " + _plane.GetPlane().GetSpeed() + " ");
|
||||||
|
LabelWeight.setText("Вес: " + _plane.GetPlane().GetWeight() + " ");
|
||||||
|
LabelColor.setText("Цвет: r = " + _plane.GetPlane().GetColor().getRed() + " g = " + _plane.GetPlane().GetColor().getGreen() +
|
||||||
|
" b = " + _plane.GetPlane().GetColor().getBlue());
|
||||||
|
|
||||||
|
JLabel imageWithMapAndObject = new JLabel();
|
||||||
|
imageWithMapAndObject.setPreferredSize(PictureBoxPlane.getSize());
|
||||||
|
imageWithMapAndObject.setMinimumSize(new Dimension(1, 1));
|
||||||
|
imageWithMapAndObject.setIcon(new ImageIcon(_abstractMap.CreateMap(PictureBoxPlane.getWidth(), PictureBoxPlane.getHeight(), new DrawningObjectPlane((_plane)))));
|
||||||
|
PictureBoxPlane.add(imageWithMapAndObject, BorderLayout.CENTER);
|
||||||
|
PictureBoxPlane.revalidate();
|
||||||
|
}
|
||||||
|
|
||||||
|
public FormMap()
|
||||||
|
{
|
||||||
|
_abstractMap = new SimpleMap();
|
||||||
|
//создание строки отображения скорости, веса и цвета объекта
|
||||||
|
Box LableBox = Box.createHorizontalBox();
|
||||||
|
LableBox.setMinimumSize(new Dimension(1, 20));
|
||||||
|
LableBox.add(LabelSpeed);
|
||||||
|
LableBox.add(LabelWeight);
|
||||||
|
LableBox.add(LabelColor);
|
||||||
|
StatusStrip.add(LableBox);
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Image img = ImageIO.read(getClass().getResource("resourses/Up.png"));
|
||||||
|
ButtonUp.setIcon(new ImageIcon(img));
|
||||||
|
img = ImageIO.read(getClass().getResource("resourses/Left.png"));
|
||||||
|
ButtonLeft.setIcon(new ImageIcon(img));
|
||||||
|
img = ImageIO.read(getClass().getResource("resourses/Down.png"));
|
||||||
|
ButtonDown.setIcon(new ImageIcon(img));
|
||||||
|
img = ImageIO.read(getClass().getResource("resourses/Right.png"));
|
||||||
|
ButtonRight.setIcon(new ImageIcon(img));
|
||||||
|
} catch (Exception ex)
|
||||||
|
{
|
||||||
|
System.out.println(ex.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
_plane = new DrawingPlane(rnd.nextInt(100, 300), rnd.nextInt(1000, 2000), new Color(rnd.nextInt(256), rnd.nextInt(256), rnd.nextInt(256)));
|
||||||
|
|
||||||
|
ButtonCreate.addActionListener(new ActionListener() {
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
Random rnd = new Random();
|
||||||
|
var plane = new DrawingPlane(rnd.nextInt(100, 300), rnd.nextInt(1000, 2000),
|
||||||
|
new Color(rnd.nextInt(256), rnd.nextInt(256), rnd.nextInt(256)));
|
||||||
|
plane.SetPosition(rnd.nextInt(10, 100), rnd.nextInt(10, 100),
|
||||||
|
PictureBoxPlane.getWidth(), PictureBoxPlane.getHeight());
|
||||||
|
SetData(plane);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
ButtonUp.addActionListener(new ActionListener() {
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
PictureBoxPlane.removeAll();
|
||||||
|
|
||||||
|
JLabel imageWithMapAndObject = new JLabel();
|
||||||
|
imageWithMapAndObject.setPreferredSize(PictureBoxPlane.getSize());
|
||||||
|
imageWithMapAndObject.setMinimumSize(new Dimension(1, 1));
|
||||||
|
imageWithMapAndObject.setIcon(new ImageIcon(_abstractMap.MoveObject((Direction.Up))));
|
||||||
|
|
||||||
|
PictureBoxPlane.add(imageWithMapAndObject, BorderLayout.CENTER);
|
||||||
|
PictureBoxPlane.revalidate();
|
||||||
|
PictureBoxPlane.repaint();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
ButtonLeft.addActionListener(new ActionListener() {
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
PictureBoxPlane.removeAll();
|
||||||
|
|
||||||
|
JLabel imageWithMapAndObject = new JLabel();
|
||||||
|
imageWithMapAndObject.setPreferredSize(PictureBoxPlane.getSize());
|
||||||
|
imageWithMapAndObject.setMinimumSize(new Dimension(1, 1));
|
||||||
|
imageWithMapAndObject.setIcon(new ImageIcon(_abstractMap.MoveObject((Direction.Left))));
|
||||||
|
|
||||||
|
PictureBoxPlane.add(imageWithMapAndObject, BorderLayout.CENTER);
|
||||||
|
PictureBoxPlane.revalidate();
|
||||||
|
PictureBoxPlane.repaint();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
ButtonDown.addActionListener(new ActionListener() {
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
PictureBoxPlane.removeAll();
|
||||||
|
|
||||||
|
JLabel imageWithMapAndObject = new JLabel();
|
||||||
|
imageWithMapAndObject.setPreferredSize(PictureBoxPlane.getSize());
|
||||||
|
imageWithMapAndObject.setMinimumSize(new Dimension(1, 1));
|
||||||
|
imageWithMapAndObject.setIcon(new ImageIcon(_abstractMap.MoveObject((Direction.Down))));
|
||||||
|
|
||||||
|
PictureBoxPlane.add(imageWithMapAndObject, BorderLayout.CENTER);
|
||||||
|
PictureBoxPlane.revalidate();
|
||||||
|
PictureBoxPlane.repaint();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
ButtonRight.addActionListener(new ActionListener() {
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
PictureBoxPlane.removeAll();
|
||||||
|
|
||||||
|
JLabel imageWithMapAndObject = new JLabel();
|
||||||
|
imageWithMapAndObject.setPreferredSize(PictureBoxPlane.getSize());
|
||||||
|
imageWithMapAndObject.setMinimumSize(new Dimension(1, 1));
|
||||||
|
imageWithMapAndObject.setIcon(new ImageIcon(_abstractMap.MoveObject((Direction.Right))));
|
||||||
|
|
||||||
|
PictureBoxPlane.add(imageWithMapAndObject, BorderLayout.CENTER);
|
||||||
|
PictureBoxPlane.revalidate();
|
||||||
|
PictureBoxPlane.repaint();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
ButtonCreateModif.addActionListener(new ActionListener() {
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
_plane = new DrawingAirbus(rnd.nextInt(100, 300), rnd.nextInt(1000, 2000),
|
||||||
|
new Color(rnd.nextInt(256), rnd.nextInt(256), rnd.nextInt(256)),
|
||||||
|
new Color(rnd.nextInt(256), rnd.nextInt(256), rnd.nextInt(256)),
|
||||||
|
rnd.nextBoolean(), rnd.nextBoolean());
|
||||||
|
_plane.SetPosition(rnd.nextInt(100, 500), rnd.nextInt(10, 100),
|
||||||
|
PictureBoxPlane.getWidth(), PictureBoxPlane.getHeight());
|
||||||
|
SetData(_plane);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
ComboBoxSelectorMap.addActionListener(new ActionListener() {
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
ComboBoxSelectorMap = (JComboBox)e.getSource();
|
||||||
|
String item = (String)ComboBoxSelectorMap.getSelectedItem();
|
||||||
|
switch(item)
|
||||||
|
{
|
||||||
|
case "Простая карта":
|
||||||
|
_abstractMap = new SimpleMap();
|
||||||
|
break;
|
||||||
|
case "Буря в пустыне":
|
||||||
|
_abstractMap = new DesertStormMap();
|
||||||
|
break;
|
||||||
|
case "Звёздные войны":
|
||||||
|
_abstractMap = new StarWarsMap();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
@ -3,7 +3,7 @@ import javax.swing.*;
|
|||||||
public class Main {
|
public class Main {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
JFrame frame = new JFrame("Airbus");
|
JFrame frame = new JFrame("Airbus");
|
||||||
frame.setContentPane(new FormAirbus().MainPanel);
|
frame.setContentPane(new FormMap().MainPanel);
|
||||||
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||||
frame.setLocation(500, 200);
|
frame.setLocation(500, 200);
|
||||||
frame.pack();
|
frame.pack();
|
||||||
|
51
Project/src/SimpleMap.java
Normal file
51
Project/src/SimpleMap.java
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
import java.awt.*;
|
||||||
|
|
||||||
|
public class SimpleMap extends AbstractMap{
|
||||||
|
//цвет закрытого участка
|
||||||
|
private final Color barriedColor = Color.black;
|
||||||
|
|
||||||
|
//цвет открытого участка
|
||||||
|
private final Color roadColor = Color.gray;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void GenerateMap() {
|
||||||
|
_map = new int[100][100];
|
||||||
|
_size_x = (float)_width / _map.length;
|
||||||
|
_size_y = (float)_height / _map[0].length;
|
||||||
|
int counter = 0;
|
||||||
|
|
||||||
|
for(int i = 0; i < _map.length; ++i)
|
||||||
|
{
|
||||||
|
for(int j = 0; j < _map[0].length; ++j)
|
||||||
|
{
|
||||||
|
_map[i][j] = _freeRoad;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
while(counter < 50)
|
||||||
|
{
|
||||||
|
int x = _random.nextInt(0, 100);
|
||||||
|
int y = _random.nextInt(0, 100);
|
||||||
|
|
||||||
|
if (_map[x][y] == _freeRoad)
|
||||||
|
{
|
||||||
|
_map[x][y] = _barrier;
|
||||||
|
counter++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void DrawRoadPart(Graphics g, int i, int j) {
|
||||||
|
Graphics2D g2d = (Graphics2D)g;
|
||||||
|
g2d.setPaint(roadColor);
|
||||||
|
g2d.fillRect((int)(i * _size_x), (int)(j * _size_y), (int)(_size_x), (int)(_size_y));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void DrawBarrierPart(Graphics g, int i, int j) {
|
||||||
|
Graphics2D g2d = (Graphics2D)g;
|
||||||
|
g2d.setPaint(barriedColor);
|
||||||
|
g2d.fillRect((int)(i * _size_x), (int)(j * _size_y), (int)(_size_x), (int)(_size_y));
|
||||||
|
}
|
||||||
|
}
|
55
Project/src/StarWarsMap.java
Normal file
55
Project/src/StarWarsMap.java
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
import java.awt.*;
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
|
public class StarWarsMap extends AbstractMap{
|
||||||
|
Random rnd = new Random();
|
||||||
|
|
||||||
|
//цвет закрытого участка
|
||||||
|
Color barriedColor;
|
||||||
|
|
||||||
|
//цвет открытого участка
|
||||||
|
private final Color roadColor = new Color(0, 0, 139);
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void GenerateMap() {
|
||||||
|
_map = new int[100][100];
|
||||||
|
_size_x = (float)_width / _map.length;
|
||||||
|
_size_y = (float)_height / _map[0].length;
|
||||||
|
int counter = 0;
|
||||||
|
|
||||||
|
for(int i = 0; i < _map.length; ++i)
|
||||||
|
{
|
||||||
|
for(int j = 0; j < _map[0].length; ++j)
|
||||||
|
{
|
||||||
|
_map[i][j] = _freeRoad;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
while(counter < 50)
|
||||||
|
{
|
||||||
|
int x = _random.nextInt(0, 100);
|
||||||
|
int y = _random.nextInt(0, 100);
|
||||||
|
|
||||||
|
if (_map[x][y] == _freeRoad)
|
||||||
|
{
|
||||||
|
_map[x][y] = _barrier;
|
||||||
|
counter++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void DrawRoadPart(Graphics g, int i, int j) {
|
||||||
|
Graphics2D g2d = (Graphics2D)g;
|
||||||
|
g2d.setPaint(roadColor);
|
||||||
|
g2d.fillRect((int)(i * _size_x), (int)(j * _size_y), (int)(_size_x), (int)(_size_y));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void DrawBarrierPart(Graphics g, int i, int j) {
|
||||||
|
Graphics2D g2d = (Graphics2D)g;
|
||||||
|
barriedColor = new Color(rnd.nextInt(256), rnd.nextInt(256), rnd.nextInt(256));
|
||||||
|
g2d.setPaint(barriedColor);
|
||||||
|
g2d.fillRect((int)(i * _size_x), (int)(j * _size_y), (int)(_size_x), (int)(_size_y));
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user