diff --git a/Project/.idea/misc.xml b/Project/.idea/misc.xml
index e2ca0b8..c1a8958 100644
--- a/Project/.idea/misc.xml
+++ b/Project/.idea/misc.xml
@@ -1,6 +1,6 @@
-
+
\ No newline at end of file
diff --git a/Project/src/AbstractMap.java b/Project/src/AbstractMap.java
index 65847c5..8b952f8 100644
--- a/Project/src/AbstractMap.java
+++ b/Project/src/AbstractMap.java
@@ -54,53 +54,94 @@ public abstract class AbstractMap
public BufferedImage MoveObject(Direction direction)
{
- position = _drawingObject.GetCurrentPosition();
-
- for (int i = 0; i < _map.length; ++i)
+ float[] cortege = _drawingObject.GetCurrentPosition();
+ int leftCell = (int)(cortege[0] / _size_x);
+ int upCell = (int)(cortege[1] / _size_y);
+ int downCell = (int)(cortege[3] / _size_y);
+ int rightCell = (int)(cortege[2] / _size_x);
+ int step = (int)_drawingObject.Step();
+ boolean canMove = true;
+ switch (direction)
{
- for (int j = 0; j < _map[i].length; ++j)
- {
- if (_map[i][j] == _barrier)
+ case Left:
+ for (int i = leftCell - (int)(step / _size_x) - 1 >= 0 ? leftCell - (int)(step / _size_x) - 1 : leftCell; i < leftCell; i++)
{
- switch (direction)
+ for (int j = upCell; j < downCell; j++)
{
- case Up:
- if(_size_y * (j+1) >= position[0] - _drawingObject.Step() && _size_y * (j+1) < position[0] && _size_x * (i + 1) > position[3]
- && _size_x * (i + 1) <= position[1])
- {
- return DrawMapWithObject();
- }
- break;
- case Down:
- if (_size_y * j <= position[2] + _drawingObject.Step() && _size_y * j > position[2] && _size_x * (i+1) > position[3]
- && _size_x * (i+1) <= position[1])
- {
- return DrawMapWithObject();
- }
- break;
- case Left:
- if (_size_x * (i+1) >= position[3] - _drawingObject.Step() && _size_x * (i + 1) < position[3] && _size_y * (j + 1) < position[2]
- && _size_y * (j + 1) >= position[0])
- {
- return DrawMapWithObject();
- }
- break;
- case Right:
- if (_size_x * i <= position[1] + _drawingObject.Step() && _size_x * i > position[3] && _size_y * (j + 1) < position[2]
- && _size_y * (j + 1) >= position[0])
- {
- return DrawMapWithObject();
- }
- break;
+ if (_map[i][j] == _barrier)
+ {
+ canMove = false;
+ }
}
}
- }
+ break;
+ case Up:
+ for (int i = leftCell; i <= rightCell; i++)
+ {
+ for (int j = upCell - (int)(step / _size_x) - 1 >= 0 ? upCell - (int)(step / _size_x) - 1 : downCell - (int)(step / _size_x); j < downCell - (int)(step / _size_x); j++)
+ {
+ if (_map[i][j] == _barrier)
+ {
+ canMove = false;
+ }
+ }
+ }
+ break;
+ case Down:
+ for (int i = leftCell; i <= rightCell; i++)
+ {
+ for (int j = downCell + (int)(step / _size_x) + 1 <= _map.length - 1 ? downCell + (int)(step / _size_x) + 1 : upCell; j > upCell; j--)
+ {
+ if (_map[i][j] == _barrier)
+ {
+ canMove = false;
+ }
+ }
+ }
+ break;
+ case Right:
+ for (int i = rightCell + (int)(step / _size_x) + 1 <= _map.length - 1 ? rightCell + (int)(step / _size_x) + 1 : rightCell; i > rightCell; i--)
+ {
+ for (int j = upCell; j < downCell; j++)
+ {
+ if (_map[i][j] == _barrier)
+ {
+ canMove = false;
+ }
+ }
+ }
+ break;
+ }
+ if (canMove)
+ {
+ _drawingObject.MoveObject(direction);
}
-
- _drawingObject.MoveObject(direction);
return DrawMapWithObject();
}
+ /*
+ private Direction MoveObjectBack(Direction direction)
+ {
+ switch (direction)
+ {
+ case Up:
+ return Direction.Up;
+ break;
+ case Down:
+ return Direction.Down;
+ break;
+ case Left:
+ return Direction.Left;
+ break;
+ case Right:
+ return Direction.Right;
+ break;
+ }
+
+ return Direction.None;
+ }
+ */
+
private boolean SetObjectOnMap()
{
if(_drawingObject == null || _map == null)
diff --git a/Project/src/Additional_Enum.java b/Project/src/Additional_Enum.java
index 7795957..f28a2f6 100644
--- a/Project/src/Additional_Enum.java
+++ b/Project/src/Additional_Enum.java
@@ -10,7 +10,8 @@ public enum Additional_Enum {
this.addEnum = i;
}
- public int GetAddEnum(){
+ public int GetAddEnum()
+ {
return addEnum;
}
}
diff --git a/Project/src/DesertStormMap.java b/Project/src/DesertStormMap.java
index a806b60..10ce783 100644
--- a/Project/src/DesertStormMap.java
+++ b/Project/src/DesertStormMap.java
@@ -39,13 +39,13 @@ public class DesertStormMap extends AbstractMap{
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));
+ g2d.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) {
Graphics2D g2d = (Graphics2D)g;
g2d.setPaint(barriedColor);
- g.fillRect((int)(i * _size_x), (int)(j * _size_y), (int)(_size_x), (int)(_size_y));
+ g.fillRect((int)(i * _size_x), (int)(j * _size_y), (int)(i * (_size_x + 1)), (int)(j *(_size_y + 1)));
}
}
diff --git a/Project/src/DrawingAirbus.java b/Project/src/DrawingAirbus.java
index 3c53628..0a46bb8 100644
--- a/Project/src/DrawingAirbus.java
+++ b/Project/src/DrawingAirbus.java
@@ -5,7 +5,7 @@ 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);
+ super(speed, weight, corpusColor, 70, 30);
Plane = new EntityAirbus(speed, weight, corpusColor, addColor, addCompartment, addEngine);
}
diff --git a/Project/src/DrawingPlane.java b/Project/src/DrawingPlane.java
index 8c58f47..9a3a4d9 100644
--- a/Project/src/DrawingPlane.java
+++ b/Project/src/DrawingPlane.java
@@ -135,8 +135,9 @@ public class DrawingPlane extends JPanel
Graphics2D g2d = (Graphics2D)g;
- g2d.setColor(Color.WHITE);
- g2d.fillRect(0, 0, _pictureWidth, _pictureHeight);
+ //корпус
+ g2d.setColor(Plane.GetColor());
+ g2d.fillRect((int)_startPosX, (int)_startPosY + 10, 40, 10);
//заливает фигуру
g2d.setPaint(Color.BLACK);
@@ -157,10 +158,6 @@ public class DrawingPlane extends JPanel
g2d.fillRect((int)_startPosX + 35, (int)_startPosY + 21, 2, 2);
g2d.fillRect((int)_startPosX + 35, (int)_startPosY + 23, 4, 4);
- g2d.setColor(Color.BLACK); //рисует контур
- //корпус
- g2d.drawRect((int)_startPosX, (int)_startPosY + 10, 40, 10);
-
//хвостовое крыло
g2d.drawLine((int)_startPosX, (int)_startPosY + 10, (int)_startPosX, (int)_startPosY);
g2d.drawLine((int)_startPosX, (int)_startPosY, (int)_startPosX + 10, (int)_startPosY + 10);
@@ -200,7 +197,6 @@ public class DrawingPlane extends JPanel
public float[] GetCurrentPosition()
{
- return new float[] {_startPosX, _startPosX + _airbusWidth,
- _startPosY + _airbusHeight, _startPosX};
+ return new float[]{_startPosX, _startPosY, _startPosX + _airbusWidth, _startPosY + _airbusHeight};
}
}
diff --git a/Project/src/DrawingRectAirplaneWindow.java b/Project/src/DrawingRectAirplaneWindow.java
index 9055068..eaacfb2 100644
--- a/Project/src/DrawingRectAirplaneWindow.java
+++ b/Project/src/DrawingRectAirplaneWindow.java
@@ -52,4 +52,3 @@ public class DrawingRectAirplaneWindow extends JComponent implements IAdditional
}
}
}
-
diff --git a/Project/src/EntityPlane.java b/Project/src/EntityPlane.java
index f9e4256..d8e678d 100644
--- a/Project/src/EntityPlane.java
+++ b/Project/src/EntityPlane.java
@@ -2,23 +2,28 @@ import java.awt.*;
public class EntityPlane
{
- public int Speed; //скорость
+ //скорость
+ public int Speed;
public int GetSpeed(){
return Speed;
}
- public float Weight; //вес
+ //вес
+ public float Weight;
public float GetWeight(){
return Weight;
}
- public Color CorpusColor; //цвет корпуса
- public Color GetColor(){
+ //цвет корпуса
+ public Color CorpusColor;
+ public Color GetColor()
+ {
return CorpusColor;
}
//шаг перемещения самолёта
- public float GetStep(){
+ public float GetStep()
+ {
return Speed * 100 / Weight;
}
diff --git a/Project/src/FormMap.form b/Project/src/FormMap.form
index 1aca1e8..0eeac40 100644
--- a/Project/src/FormMap.form
+++ b/Project/src/FormMap.form
@@ -93,7 +93,9 @@
-
+
+
+
@@ -105,7 +107,7 @@
-
+
diff --git a/Project/src/FormMap.java b/Project/src/FormMap.java
index 531d17d..294e93b 100644
--- a/Project/src/FormMap.java
+++ b/Project/src/FormMap.java
@@ -3,11 +3,8 @@ 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
{
@@ -32,31 +29,11 @@ public class FormMap extends JFrame
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);
+ if (bufferImg == null) {
+ return;
}
- validate();
- }
-
- @Override
- public void paint(Graphics g)
- {
- super.paint(g);
- Draw();
+ PictureBoxPlane.getGraphics().drawImage(bufferImg, 0, 0, PictureBoxPlane.getWidth(), PictureBoxPlane.getHeight(), null);
}
public void SetData(DrawingPlane _plane)
@@ -68,17 +45,19 @@ public class FormMap extends JFrame
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);
+ if (_abstractMap != null)
+ {
+ bufferImg = _abstractMap.CreateMap(PictureBoxPlane.getWidth(),
+ PictureBoxPlane.getHeight(), new DrawningObjectPlane(_plane));
+ }
+
PictureBoxPlane.revalidate();
}
public FormMap()
{
_abstractMap = new SimpleMap();
+
//создание строки отображения скорости, веса и цвета объекта
Box LableBox = Box.createHorizontalBox();
LableBox.setMinimumSize(new Dimension(1, 20));
@@ -102,8 +81,6 @@ public class FormMap extends JFrame
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) {
@@ -113,6 +90,7 @@ public class FormMap extends JFrame
plane.SetPosition(rnd.nextInt(10, 100), rnd.nextInt(10, 100),
PictureBoxPlane.getWidth(), PictureBoxPlane.getHeight());
SetData(plane);
+ Draw();
}
});
@@ -129,6 +107,7 @@ public class FormMap extends JFrame
PictureBoxPlane.add(imageWithMapAndObject, BorderLayout.CENTER);
PictureBoxPlane.revalidate();
PictureBoxPlane.repaint();
+ Draw();
}
});
@@ -145,6 +124,7 @@ public class FormMap extends JFrame
PictureBoxPlane.add(imageWithMapAndObject, BorderLayout.CENTER);
PictureBoxPlane.revalidate();
PictureBoxPlane.repaint();
+ Draw();
}
});
@@ -161,6 +141,7 @@ public class FormMap extends JFrame
PictureBoxPlane.add(imageWithMapAndObject, BorderLayout.CENTER);
PictureBoxPlane.revalidate();
PictureBoxPlane.repaint();
+ Draw();
}
});
@@ -177,6 +158,7 @@ public class FormMap extends JFrame
PictureBoxPlane.add(imageWithMapAndObject, BorderLayout.CENTER);
PictureBoxPlane.revalidate();
PictureBoxPlane.repaint();
+ Draw();
}
});
@@ -190,6 +172,7 @@ public class FormMap extends JFrame
_plane.SetPosition(rnd.nextInt(100, 500), rnd.nextInt(10, 100),
PictureBoxPlane.getWidth(), PictureBoxPlane.getHeight());
SetData(_plane);
+ Draw();
}
});
diff --git a/Project/src/IAdditionalDrawingObject.java b/Project/src/IAdditionalDrawingObject.java
index cf9f27b..2a39d53 100644
--- a/Project/src/IAdditionalDrawingObject.java
+++ b/Project/src/IAdditionalDrawingObject.java
@@ -1,7 +1,6 @@
import java.awt.*;
-public interface IAdditionalDrawingObject
-{
+public interface IAdditionalDrawingObject {
void SetAddEnum(int airplaneWindow);
void DrawAirplaneWindow(Color colorAirplaneWindow, Graphics g, float _startPosX, float _startPosY);
}
diff --git a/Project/src/SimpleMap.java b/Project/src/SimpleMap.java
index 3eb01a8..7c016c8 100644
--- a/Project/src/SimpleMap.java
+++ b/Project/src/SimpleMap.java
@@ -39,13 +39,13 @@ public class SimpleMap extends AbstractMap{
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));
+ g2d.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) {
Graphics2D g2d = (Graphics2D)g;
g2d.setPaint(barriedColor);
- g2d.fillRect((int)(i * _size_x), (int)(j * _size_y), (int)(_size_x), (int)(_size_y));
+ g2d.fillRect((int)(i * _size_x), (int)(j * _size_y), (int)(i * (_size_x + 1)), (int)(j *(_size_y + 1)));
}
}
diff --git a/Project/src/StarWarsMap.java b/Project/src/StarWarsMap.java
index 8d184ee..01aa27d 100644
--- a/Project/src/StarWarsMap.java
+++ b/Project/src/StarWarsMap.java
@@ -42,7 +42,7 @@ public class StarWarsMap extends AbstractMap{
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));
+ g2d.fillRect((int)(i * _size_x), (int)(j * _size_y), (int)(i * (_size_x + 1)), (int)(j *(_size_y + 1)));
}
@Override
@@ -50,6 +50,6 @@ public class StarWarsMap extends AbstractMap{
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));
+ g2d.fillRect((int)(i * _size_x), (int)(j * _size_y), (int)(i * (_size_x + 1)), (int)(j *(_size_y + 1)));
}
}