Compare commits

...

8 Commits

Author SHA1 Message Date
6c0134cffc final 2022-12-05 21:01:53 +04:00
7660243c11 1 com 2022-12-05 18:09:08 +04:00
2a1c499096 finally 2022-11-21 23:55:09 +04:00
1c92c5b0eb com3 2022-11-08 14:55:22 +04:00
666de2bf79 Изменил(а) на 'FormPlane.java' 2022-11-08 14:54:21 +04:00
91db5cf763 Изменил(а) на 'EntityPlane.java' 2022-11-08 14:54:01 +04:00
5324095e2a Изменил(а) на 'DrawingPlane.java' 2022-11-08 14:53:44 +04:00
968bae0c5b First commit 2022-10-20 23:43:35 +04:00
18 changed files with 734 additions and 57 deletions

162
AbstractMap.java Normal file
View File

@ -0,0 +1,162 @@
import java.awt.*;
import java.awt.image.BufferedImage;
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 final Random _random = new Random();
protected final int _freeRoad = 0;
protected final int _barrier = 1;
protected abstract void GenerateMap();
protected abstract void DrawRoadPart(Graphics g, int i, int j);
protected abstract void DrawBarrierPart(Graphics g, int i, int j);
public BufferedImage CreateMap(int width, int height, IDrawingObject drawningObject)
{
_width = width;
_height = height;
_drawningObject = drawningObject;
GenerateMap(); // abstract void
while (!SetObjectOnMap())
{
GenerateMap();
}
return DrawMapWithObject();
}
public BufferedImage MoveObject(Direction direction)
{
boolean isFree = true;
int startPosX = (int)(_drawningObject.GetCurrentPosition()[3] / _size_x);
int startPosY = (int)(_drawningObject.GetCurrentPosition()[0] / _size_y);
int objectWidth = (int)(_drawningObject.GetCurrentPosition()[1] / _size_x);
int objectHeight = (int)(_drawningObject.GetCurrentPosition()[2] / _size_y);
switch (direction)
{
case Right:
for (int i = objectWidth; i <= objectWidth + (int)(_drawningObject.getStep() / _size_x); i++)
{
for (int j = startPosY; j <= objectHeight; j++)
{
if (_map[i][j] == _barrier)
{
isFree = false;
break;
}
}
}
break;
case Left:
for (int i = startPosX; i >= (int)(_drawningObject.getStep() / _size_x); i--)
{
for (int j = startPosY; j <= objectHeight; j++)
{
if (_map[i][j] == _barrier)
{
isFree = false;
break;
}
}
}
break;
case Up:
for (int i = startPosX; i <= objectWidth; i++)
{
for (int j = startPosY; j >= (int)(_drawningObject.getStep() / _size_y); j--)
{
if (_map[i][j] == _barrier)
{
isFree = false;
break;
}
}
}
break;
case Down:
for (int i = startPosX; i <= objectWidth; i++)
{
for (int j = objectHeight; j <= objectHeight + (int)(_drawningObject.getStep() / _size_y); j++)
{
if (_map[i][j] == _barrier)
{
isFree = false;
break;
}
}
}
break;
}
if (isFree)
{
_drawningObject.MoveObject(direction);
}
return DrawMapWithObject();
}
private boolean SetObjectOnMap()
{
if (_drawningObject == null || _map == null)
{
return false;
}
int x = _random.nextInt( 10);
int y = _random.nextInt( 10);
_drawningObject.SetObject(x, y, _width, _height);
for (int i = 0; i < _map.length; ++i)
{
for (int j = 0; j < _map[0].length; ++j)
{
if (i * _size_x >= x && j * _size_y >= y &&
i * _size_x <= x + _drawningObject.GetCurrentPosition()[1] &&
j * _size_y <= j + _drawningObject.GetCurrentPosition()[2])
{
if (_map[i][j] == _barrier)
{
return false;
}
}
}
}
return true;
}
private BufferedImage DrawMapWithObject()
{
BufferedImage bmp = new BufferedImage(_width, _height, BufferedImage.TYPE_INT_RGB);
if (_drawningObject == null || _map == null)
{
return bmp;
}
Graphics gr = bmp.getGraphics();
for (int i = 0; i < _map.length; ++i)
{
for (int j = 0; j < _map[0].length; ++j)
{
if (_map[i][j] == _freeRoad)
{
DrawRoadPart(gr, i, j);
}
else if (_map[i][j] == _barrier)
{
DrawBarrierPart(gr, i, j);
}
}
}
_drawningObject.DrawingObject(gr);
return bmp;
}
}

View File

@ -1,4 +1,4 @@
enum Direction
{
Right, Left, Up, Down
None, Right, Left, Up, Down
}

3
DopIlum.java Normal file
View File

@ -0,0 +1,3 @@
enum DopIlum {
Ten, Twenty, Thirty
}

View File

@ -0,0 +1,44 @@
import java.awt.*;
public class DrawingAdvancedAirbus extends DrawingAirbus{
public DrawingAdvancedAirbus(int speed, float weight, Color bodyColor, Color extraColor, boolean superTurbine, boolean extraCell)
{
super(speed, weight, bodyColor, 145, 55);
Airbus = new EntityAdvancedAirbus(speed, weight, bodyColor, extraColor, superTurbine, extraCell);
}
@Override
public void DrawTransport(Graphics2D g)
{
if (Airbus instanceof EntityAdvancedAirbus)
{
EntityAdvancedAirbus advancedAirbus = (EntityAdvancedAirbus) Airbus;
if (advancedAirbus.SuperTurbine)
{
g.setColor(advancedAirbus.ExtraColor);
g.fillRect((int)_startPosX, (int)_startPosY + 20, 30, 22);
g.drawLine((int)_startPosX, (int)_startPosY + 42, (int)_startPosX + 30, (int)_startPosY + 42);
}
_startPosX += 10;
_startPosY += 5;
super.DrawTransport((Graphics2D)g);
_startPosX -= 10;
_startPosY -= 5;
if (advancedAirbus.ExtraCell)
{
g.setColor(advancedAirbus.ExtraColor);
g.fillRect((int)_startPosX + 55, (int)_startPosY + 15, 30, 10);
for (int i = (int)_startPosX + 57; i < (int)_startPosX + 83; i += 3)
{
g.setColor(Color.BLUE);
g.fillRect(i, (int)_startPosY + 20, 2, 2);
}
}
}
}
}

View File

@ -1,31 +1,48 @@
import java.awt.*;
public class DrawingPlane {
public EntityPlane Plane;
import java.util.Random;
public EntityPlane getPlane()
{
return Plane;
}
private float _startPosX;
private float _startPosY;
public class DrawingAirbus {
public EntityAirbus Airbus;
protected float _startPosX;
protected float _startPosY;
private Integer _pictureWidth = null;
private Integer _pictureHeight = null;
private final int _planeWidth = 125;
private final int _planeHeight = 45;
private int _airbusWidth = 125;
private int _airbusHeight = 45;
public void Init(int speed, float weight, Color bodyColor, int ilNum, EntityPlane entity)
public IDrawingIlum drawingilum;
private final Random random = new Random();
public DrawingAirbus(int speed, float weight, Color bodyColor)
{
Plane = new EntityPlane();
Plane.Init(speed, weight, bodyColor);
int randExtra = random.nextInt(2);
switch (random.nextInt(3)){
case 0:
drawingilum = new DrawingPlusIlum(randExtra);
break;
case 1:
drawingilum = new DrawingSquareIlum(randExtra);
break;
case 2:
drawingilum = new DrawingIlum(randExtra, bodyColor);
break;
}
Airbus = new EntityAirbus(speed, weight, bodyColor);
}
// Новый конструктор
protected DrawingAirbus (int speed, float weight, Color bodyColor, int airbusWidth, int airbusHeight)
{
this(speed, weight, bodyColor);
_airbusWidth = airbusWidth;
_airbusHeight = airbusHeight;
}
public void SetPosition(int x, int y, int width, int height)
{
if (x < 0 || x + _planeWidth >= width)
if (x < 0 || x + _airbusWidth >= width)
{
return;
}
if (y < 0 || y + _planeHeight >= height)
if (y < 0 || y + _airbusHeight >= height)
{
return;
}
@ -44,44 +61,47 @@ public class DrawingPlane {
{
// вправо
case Right:
if (_startPosX + _planeWidth + Plane.Step() < _pictureWidth)
if (_startPosX + _airbusWidth + Airbus.Step() < _pictureWidth)
{
_startPosX += Plane.Step();
_startPosX += Airbus.Step();
}
else _startPosX = _pictureWidth - _airbusWidth;
break;
//влево
case Left:
if (_startPosX - Plane.Step() > 0)
if (_startPosX - Airbus.Step() >= 0)
{
_startPosX -= Plane.Step();
_startPosX -= Airbus.Step();
}
else _startPosX = 0;
break;
//вверх
case Up:
if (_startPosY - Plane.Step() > 0)
if (_startPosY - Airbus.Step() >= 0)
{
_startPosY -= Plane.Step();
_startPosY -= Airbus.Step();
}
else _startPosY = 0;
break;
//вниз
case Down:
if (_startPosY + _planeHeight + Plane.Step() < _pictureHeight)
if (_startPosY + _airbusHeight + Airbus.Step() < _pictureHeight)
{
_startPosY += Plane.Step();
_startPosY += Airbus.Step();
}
else _startPosY = _pictureHeight - _airbusWidth;
break;
}
}
public void DrawTransport(Graphics g)
public void DrawTransport(Graphics2D g)
{
if (_startPosX < 0 || _startPosY < 0
|| _pictureHeight == null|| _pictureWidth == 0)
{
return;
}
g.setColor(Color.BLACK);
g.setColor(Color.black);
g.drawOval((int)_startPosX, (int)_startPosY + 20, 20, 20);
g.drawRect((int)_startPosX + 8, (int)_startPosY + 20, 100, 20);
@ -104,7 +124,7 @@ public class DrawingPlane {
// корпус
g.setColor(Plane.getBodyColor());
g.setColor(Airbus.getBodyColor());
g.fillOval((int)_startPosX, (int)_startPosY + 20, 20, 20);
g.fillRect((int)_startPosX + 8, (int)_startPosY + 20, 100, 20);
@ -120,6 +140,12 @@ public class DrawingPlane {
new int[] {(int)_startPosY + 20, (int)_startPosY, (int)_startPosY + 20}, 3
);
g.setColor(Color.blue);
for (int tempX = 98; tempX > 38; tempX -= 6) {
g.fillOval((int) _startPosX + tempX, (int)_startPosY + 20, 4, 4);
}
drawingilum.DrawIl((int)_startPosX, (int)_startPosY, g);
g.fillPolygon
(
new int[] {(int)_startPosX + 108, (int)_startPosX + 125, (int)_startPosX + 108},
@ -138,28 +164,32 @@ public class DrawingPlane {
g.fillOval((int)_startPosX, (int)_startPosY + 18, 7, 7);
g.fillOval((int)_startPosX + 20, (int)_startPosY + 18, 7, 7);
g.fillRect((int)_startPosX + 41, (int)_startPosY + 28, 42, 4);
g.fillOval((int)_startPosX + 39, (int)_startPosY + 28, 4, 4);
g.fillOval((int)_startPosX + 81, (int)_startPosY + 28, 4, 4);
g.fillRect((int)_startPosX + 41, (int)_startPosY + 34, 42, 4);
g.fillOval((int)_startPosX + 39, (int)_startPosY + 34, 4, 4);
g.fillOval((int)_startPosX + 81, (int)_startPosY + 34, 4, 4);
}
public void ChangeBorders(int width, int height)
{
_pictureWidth = width;
_pictureHeight = height;
if (_pictureWidth <= _planeWidth || _pictureHeight <= _planeHeight)
if (_pictureWidth <= _airbusWidth || _pictureHeight <= _airbusHeight)
{
_pictureWidth = null;
_pictureHeight = null;
return;
}
if (_startPosX + _planeWidth > _pictureWidth)
if (_startPosX + _airbusWidth > _pictureWidth)
{
_startPosX = _pictureWidth - _planeWidth;
_startPosX = _pictureWidth - _airbusWidth;
}
if (_startPosY + _planeHeight > _pictureHeight)
if (_startPosY + _airbusHeight > _pictureHeight)
{
_startPosY = _pictureHeight - _planeHeight;
_startPosY = _pictureHeight - _airbusHeight;
}
}
public float[] GetCurrentPosition()
{
return new float[] {/*UP*/_startPosY, /*RIGHT*/ _startPosX + _airbusWidth, /*DOWN*/ _startPosY + _airbusHeight, /*LEFT*/ _startPosX};
}
}

49
DrawingIlum.java Normal file
View File

@ -0,0 +1,49 @@
import java.awt.*;
public class DrawingIlum implements IDrawingIlum{
private DopIlum il = DopIlum.Ten;
public void setIl(int num){
switch(num)
{
case 0:
il = DopIlum.Twenty;
break;
case 1:
il = DopIlum.Thirty;
break;
default:
break;
}
}
private Color color;
public DrawingIlum (int num, Color color) {
setIl(num);
this.color = color;
}
public void DrawIl(int startPosX, int startPosY, Graphics2D g) {
g.setColor(Color.blue);
for (int tempX = 98; tempX > 38; tempX -= 6) {
g.fillOval((int) startPosX + tempX, (int) startPosY + 20, 4, 4);
}
switch (il) {
case Twenty: {
for (int tempX = 98; tempX > 38; tempX -= 6) {
g.fillOval((int) startPosX + tempX, (int) startPosY + 26, 4, 4);
}
break;
}
case Thirty: {
for (int tempX = 98; tempX > 38; tempX -= 6) {
g.fillOval((int) startPosX + tempX, (int) startPosY + 25, 4, 4);
g.fillOval((int) startPosX + tempX, (int) startPosY + 30, 4, 4);
}
break;
}
default:
break;
}
}
}

32
DrawingObjectAirbus.java Normal file
View File

@ -0,0 +1,32 @@
import java.awt.*;
public class DrawingObjectAirbus implements IDrawingObject {
private DrawingAirbus _airbus = null;
public DrawingObjectAirbus(DrawingAirbus airbus)
{
_airbus = airbus;
}
public float getStep() {
if (_airbus.Airbus != null) {
return _airbus.Airbus.Step();
}
return 0;
}
public void SetObject(int x, int y, int width, int height) {
if (_airbus != null) _airbus.SetPosition(x, y, width, height);
}
public void MoveObject(Direction direction) {
if (_airbus != null) _airbus.MoveTransport(direction);
}
public void DrawingObject(Graphics g) {
if (_airbus != null) _airbus.DrawTransport((Graphics2D) g);
}
public float[] GetCurrentPosition() {
if (_airbus != null) {
return _airbus.GetCurrentPosition();
}
return null;
}
}

54
DrawingPlusIlum.java Normal file
View File

@ -0,0 +1,54 @@
import java.awt.*;
public class DrawingPlusIlum implements IDrawingIlum{
private DopIlum il = DopIlum.Ten;
@Override
public void setIl(int num) {
switch(num)
{
case 0:
il = DopIlum.Twenty;
break;
case 1:
il = DopIlum.Thirty;
break;
default:
break;
}
}
public DrawingPlusIlum(int num){
setIl(num);
}
@Override
public void DrawIl(int startPosX, int startPosY, Graphics2D g) {
g.setColor(Color.blue);
for (int tempX = 98; tempX > 38; tempX -= 6) {
g.fillRect( startPosX + tempX + 3, (int) startPosY + 20, 1, 5);
g.fillRect( startPosX + tempX, (int) startPosY + 23, 5, 1);
}
switch (il) {
case Twenty: {
for (int tempX = 98; tempX > 38; tempX -= 6) {
g.fillRect( startPosX + tempX + 3, (int) startPosY + 26, 1, 5);
g.fillRect( startPosX + tempX, (int) startPosY + 29, 5, 1);
}
break;
}
case Thirty: {
for (int tempX = 98; tempX > 38; tempX -= 6) {
g.fillRect( startPosX + tempX + 3, (int) startPosY + 26, 1, 5);
g.fillRect( startPosX + tempX, (int) startPosY + 29, 5, 1);
g.fillRect( startPosX + tempX + 3, (int) startPosY + 33, 1, 5);
g.fillRect( startPosX + tempX, (int) startPosY + 34, 5, 1);
}
break;
}
default:
break;
}
}
}

46
DrawingSquareIlum.java Normal file
View File

@ -0,0 +1,46 @@
import java.awt.*;
public class DrawingSquareIlum implements IDrawingIlum {
private DopIlum il = DopIlum.Ten;
@Override
public void setIl(int num) {
switch(num)
{
case 0:
il = DopIlum.Twenty;
break;
case 1:
il = DopIlum.Thirty;
break;
default:
break;
}
}
public DrawingSquareIlum(int num){
setIl(num);
}
@Override
public void DrawIl(int startPosX, int startPosY, Graphics2D g) {
g.setColor(Color.blue);
for (int tempX = 98; tempX > 38; tempX -= 6) {
g.fillRect( startPosX + tempX, (int) startPosY + 20, 4, 4);
}
switch (il) {
case Twenty: {
for (int tempX = 98; tempX > 38; tempX -= 6) {
g.fillRect((int) startPosX + tempX, (int) startPosY + 26, 4, 4);
}
break;
}
case Thirty: {
for (int tempX = 98; tempX > 38; tempX -= 6) {
g.fillRect((int) startPosX + tempX, (int) startPosY + 25, 4, 4);
g.fillRect((int) startPosX + tempX, (int) startPosY + 30, 4, 4);
}
break;
}
default:
break;
}
}
}

15
EntityAdvancedAirbus.java Normal file
View File

@ -0,0 +1,15 @@
import java.awt.*;
public class EntityAdvancedAirbus extends EntityAirbus{
public final Color ExtraColor;
public final boolean SuperTurbine;
public final boolean ExtraCell;
public EntityAdvancedAirbus(int speed, float weight, Color bodyColor, Color extraColor, boolean superTurbine, boolean extraCell)
{
super(speed, weight, bodyColor);
ExtraColor = extraColor;
SuperTurbine = superTurbine;
ExtraCell = extraCell;
}
}

View File

@ -1,7 +1,7 @@
import java.awt.Color;
import java.awt.*;
import java.util.Random;
public class EntityPlane {
public class EntityAirbus {
private int Speed;
private float Weight;
private Color BodyColor;
@ -12,11 +12,17 @@ public class EntityPlane {
public float Step(){return Speed * 100 / Weight;}
public void Init(int speed, float weight, Color bodyColor)
public EntityAirbus(int speed, float weight, Color bodyColor)
{
Random rand = new Random();
if (speed <= 0) speed = rand.nextInt(350, 550);
else {
Speed = speed;
};
if (weight <= 0) weight = rand.nextFloat(350, 550);
else {
Weight = weight;
}
BodyColor = bodyColor;
}
}

View File

@ -3,12 +3,12 @@ import java.awt.*;
import java.awt.event.*;
import java.util.Random;
public class FormPlane extends JComponent
public class FormAirbus extends JComponent
{
private DrawingPlane _plane;
private EntityPlane _entity;
private DrawingAirbus _plane;
private EntityAirbus _entity;
public FormPlane()
public FormAirbus()
{
JFrame formFrame = new JFrame("Plane");
formFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
@ -46,15 +46,14 @@ public class FormPlane extends JComponent
Label colorLabel = new Label("Color:");
JButton createButton = new JButton("Create");
createButton.addActionListener(e -> {
Random rand = new Random();
_plane = new DrawingPlane();
_entity = new EntityPlane();
_plane.Init(300 + rand.nextInt( 100), 1000 + rand.nextInt(1000), Color.getHSBColor(rand.nextInt(256), rand.nextInt(256), rand.nextInt(256)), rand.nextInt(3), _entity);
_plane = new DrawingAirbus(rand.nextInt( 400 + rand.nextInt(200)), 1000 + rand.nextInt(1000), Color.getHSBColor(rand.nextInt(256), rand.nextInt(256), rand.nextInt(256)));
_plane.SetPosition(10 + rand.nextInt(90), 10 + rand.nextInt(90), formFrame.getWidth(), formFrame.getHeight() - 75);
speedLabel.setText("Speed: " + _plane.Plane.getSpeed());
weightLabel.setText("Weight: " + (int)_plane.Plane.getWeight());
colorLabel.setText("Color: " + _plane.Plane.getBodyColor().getRed() + " " + _plane.Plane.getBodyColor().getGreen() + " " + _plane.Plane.getBodyColor().getBlue() );
speedLabel.setText("Speed: " + _plane.Airbus.getSpeed());
weightLabel.setText("Weight: " + (int)_plane.Airbus.getWeight());
colorLabel.setText("Color: " + _plane.Airbus.getBodyColor().getRed() + " " + _plane.Airbus.getBodyColor().getGreen() + " " + _plane.Airbus.getBodyColor().getBlue() );
repaint();
});
@ -84,10 +83,10 @@ public class FormPlane extends JComponent
repaint();
});
statusPanel.add(moveRightButton);
statusPanel.add(moveLeftButton);
statusPanel.add(moveUpButton);
statusPanel.add(moveDownButton);
statusPanel.add(moveLeftButton);
statusPanel.add(moveRightButton);
formFrame.getContentPane().add(this);
}
@ -98,9 +97,4 @@ public class FormPlane extends JComponent
if (_plane != null) _plane.DrawTransport(g2);
super.repaint();
}
public static void main(String[] args) throws Exception {
new FormPlane();
}
}

123
FormMap.java Normal file
View File

@ -0,0 +1,123 @@
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.image.BufferedImage;
import java.util.Random;
public class FormMap extends JComponent{
private AbstractMap _abstractMap;
private BufferedImage bufferImg = null;
public FormMap() {
JFrame formFrame = new JFrame("Form Map");
formFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
formFrame.setSize(1000, 500);
formFrame.setVisible(true);
formFrame.setLocationRelativeTo(null);
Panel statusPanel = new Panel();
statusPanel.setBackground(Color.WHITE);
statusPanel.setLayout(new FlowLayout());
setLayout(new BorderLayout());
add(statusPanel, BorderLayout.SOUTH);
Label speedLabel = new Label("Speed: ");
Label weightLabel = new Label("Weight: ");
Label colorLabel = new Label("Color: ");
String[] maps = {
"Simple Map",
"Sky Map",
};
JComboBox mapSelectComboBox = new JComboBox(maps);
mapSelectComboBox.setEditable(true);
mapSelectComboBox.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
String item = (String)mapSelectComboBox.getSelectedItem();
if (item == null) return;
switch (item) {
case ("Simple Map"):
_abstractMap = new SimpleMap();
break;
case ("Sky Map"):
_abstractMap = new SkyMap();
break;
}
}
});
JButton createButton = new JButton("Create");
createButton.addActionListener(e -> {
Random rnd = new Random();
var airbus = new DrawingAirbus(rnd.nextInt(200) + 100, rnd.nextInt(1000) + 1000, new Color(rnd.nextInt(256), rnd.nextInt(256), rnd.nextInt(256)));
speedLabel.setText("Speed: " + airbus.Airbus.getSpeed());
weightLabel.setText("Weight: " + (int)airbus.Airbus.getWeight());
colorLabel.setText("Color: " + airbus.Airbus.getBodyColor().getRed() + " " + airbus.Airbus.getBodyColor().getGreen() + " " + airbus.Airbus.getBodyColor().getBlue());
if (_abstractMap != null) bufferImg = _abstractMap.CreateMap(1000, 490, new DrawingObjectAirbus(airbus));
repaint();
});
JButton modifiedButton = new JButton("Modified");
modifiedButton.addActionListener(e -> {
Random rnd = new Random();
var airbus = new DrawingAdvancedAirbus(rnd.nextInt(200) + 100, rnd.nextInt(1000) + 1000,
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());
speedLabel.setText("Speed: " + airbus.Airbus.getSpeed());
weightLabel.setText("Weight: " + (int)airbus.Airbus.getWeight());
colorLabel.setText("Color: " + airbus.Airbus.getBodyColor().getRed() + " " + airbus.Airbus.getBodyColor().getGreen() + " " + airbus.Airbus.getBodyColor().getBlue() );
if (_abstractMap != null) bufferImg = _abstractMap.CreateMap(1000, 490, new DrawingObjectAirbus(airbus));
repaint();
});
statusPanel.add(mapSelectComboBox);
statusPanel.add(createButton);
statusPanel.add(modifiedButton);
statusPanel.add(speedLabel);
statusPanel.add(weightLabel);
statusPanel.add(colorLabel);
JButton moveDownButton = new JButton("Down");
moveDownButton.addActionListener(e -> {
if(bufferImg != null) bufferImg = _abstractMap.MoveObject(Direction.Down);
repaint();
});
JButton moveUpButton = new JButton("Up");
moveUpButton.addActionListener(e -> {
if(bufferImg != null) bufferImg = _abstractMap.MoveObject(Direction.Up);
repaint();
});
JButton moveLeftButton = new JButton("Left");
moveLeftButton.addActionListener(e -> {
if(bufferImg != null) bufferImg = _abstractMap.MoveObject(Direction.Left);
repaint();
});
JButton moveRightButton = new JButton("Right");
moveRightButton.addActionListener(e -> {
if(bufferImg != null) bufferImg = _abstractMap.MoveObject(Direction.Right);
repaint();
});
statusPanel.add(moveUpButton);
statusPanel.add(moveDownButton);
statusPanel.add(moveLeftButton);
statusPanel.add(moveRightButton);
formFrame.getContentPane().add(this);
super.repaint();
}
@Override
protected void paintComponent(Graphics g) {
super.paintComponent(g);
Graphics2D g2 = (Graphics2D)g;
if (bufferImg != null) g2.drawImage(bufferImg, 0,0,1000,490,null);
super.repaint();
}
}

6
IDrawingIlum.java Normal file
View File

@ -0,0 +1,6 @@
import java.awt.*;
public interface IDrawingIlum {
void setIl(int num);
void DrawIl(int startPosX, int startPosY, Graphics2D g);
}

17
IDrawingObject.java Normal file
View File

@ -0,0 +1,17 @@
import java.awt.*;
public interface IDrawingObject {
/// Шаг перемещения объекта
float getStep();
/// Установка позиции объекта
void SetObject(int x, int y, int width, int height);
/// Изменение направления перемещения объекта
void MoveObject(Direction direction);
/// Отрисовка объекта
void DrawingObject(Graphics g);
/// Получение текущей позиции объекта
float[] GetCurrentPosition();
//0 - up
//1 - right
//2 - down
//3 - left
}

5
Program.java Normal file
View File

@ -0,0 +1,5 @@
public class Program {
public static void main(String[] args) {
new FormMap();
}
}

46
SimpleMap.java Normal file
View File

@ -0,0 +1,46 @@
import java.awt.*;
public class SimpleMap extends AbstractMap {
/// Цвет участка закрытого
private final Color barrierColor = 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(100);
int y = _random.nextInt(85);
if (_map[x][y] == _freeRoad)
{
_map[x][y] = _barrier;
counter++;
}
}
}
@Override
protected void DrawRoadPart(Graphics g, int i, int j) {
g.setColor(roadColor);
g.fillRect( (int)(i * _size_x), (int)(j * _size_y), (int)(i * (_size_x +
1)),(int)( j * (_size_y + 1)));
}
@Override
protected void DrawBarrierPart(Graphics g, int i, int j) {
g.setColor(barrierColor);
g.fillRect( (int)(i * _size_x), (int)(j * _size_y), (int)(i * (_size_x +
1)), (int)(j * (_size_y + 1)));
}
}

45
SkyMap.java Normal file
View File

@ -0,0 +1,45 @@
import java.awt.*;
public class SkyMap extends AbstractMap {
/// Цвет участка закрытого
private final Color barrierColor = Color.BLACK;
/// Цвет участка открытого
private final Color roadColor = Color.cyan;
@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 < 30)
{
int x = _random.nextInt(100);
int y = _random.nextInt(85);
if (_map[x][y] == _freeRoad)
{
_map[x][y] = _barrier;
counter++;
}
}
}
@Override
protected void DrawRoadPart(Graphics g, int i, int j) {
g.setColor(roadColor);
g.fillRect( (int)(i * _size_x), (int)(j * _size_y), (int)(i * (_size_x +
1)),(int)( j * (_size_y + 1)));
}
@Override
protected void DrawBarrierPart(Graphics g, int i, int j) {
g.setColor(barrierColor);
g.fillPolygon(new int[] {i * (int)_size_x, (int)_size_x + 8, (int)_size_x + 8}, new int[] {j * (int)_size_y, j * (int)_size_y - 5, j * (int)_size_y + 5}, 3);
}
}