Compare commits

...

8 Commits

22 changed files with 1021 additions and 0 deletions

3
.idea/.gitignore vendored Normal file
View File

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

View File

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

6
.idea/misc.xml Normal file
View File

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

8
.idea/modules.xml Normal file
View File

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

6
.idea/vcs.xml Normal file
View File

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

158
AbstractMap.java Normal file
View File

@ -0,0 +1,158 @@
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.BufferedReader;
import java.util.Random;
public abstract class AbstractMap {
private IDrawningObject _drawningObject = null;
protected int[][] _map = null;
protected int _width;
protected int _height;
protected float _size_x;
protected float _size_y;
protected final Random _random = new Random();
protected final int _freeRoad = 0;
protected final int _barrier = 1;
public BufferedImage CreateMap(int width, int height, IDrawningObject drawningObject){
_width = width;
_height = height;
_drawningObject = drawningObject;
GenerateMap();
while (!SetObjectOnMap())
{
GenerateMap();
}
return DrawMapWithObject();
}
public BufferedImage MoveObject(Direction direction)
{
int _objWidth = (int)(_drawningObject.GetCurrentPosition()[1] / _size_x);
int _startX = (int)(_drawningObject.GetCurrentPosition()[0] / _size_x);
int _startY = (int)(_drawningObject.GetCurrentPosition()[2] / _size_y);
int _objHeight = (int)(_drawningObject.GetCurrentPosition()[3] / _size_y);
boolean isMove = true;
switch (direction)
{
case LEFT:
for (int i = _startX; i >= Math.abs(_startX - (int)(_drawningObject.getStep() / _size_x)); i--)
{
for (int j = _startY; j <= _objHeight && j<_map.length; j++)
{
if (_map[i][j] == _barrier)
{
isMove = false;
break;
}
}
}
break;
case RIGHT:
for (int i = _objWidth; i <=_objWidth + (int)(_drawningObject.getStep() / _size_x); i++)
{
for (int j = _startY; j <= _objHeight && j<_map.length; j++)
{
if (_map[i][j] == _barrier)
{
isMove = false;
break;
}
}
}
break;
case DOWN:
for (int i = _startX; i <= _objWidth && i < _map[0].length; i++)
{
for (int j = _objHeight; j <= _objHeight + (int)(_drawningObject.getStep() / _size_y) && j<_map.length; j++)
{
if (_map[i][j] == _barrier)
{
isMove = false;
break;
}
}
}
break;
case UP:
for (int i = _startX; i <= _objWidth && i < _map[0].length; i++)
{
for (int j = _startY; j >= Math.abs(_startY - (int)(_drawningObject.getStep() / _size_y)) ; j--)
{
if (_map[i][j] == _barrier)
{
isMove = false;
break;
}
}
}
break;
}
if (isMove)
{
_drawningObject.MoveObject(direction);
}
return DrawMapWithObject();
}
private boolean SetObjectOnMap()
{
if (_drawningObject == null || _map == null)
{
return false;
}
int x = _random.nextInt(10, 15);
int y = _random.nextInt(10, 15);
_drawningObject.SetObject(x, y, _width, _height);
// TODO првоерка, что объект не "накладывается" на закрытые участки
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 <= y + _drawningObject.GetCurrentPosition()[3] && _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();
gr.setColor(DrawRoadPart());
gr.fillRect(0,0,_width, _height);
for (int i = 0; i < _map.length; i++)
{
for (int j = 0; j < _map[0].length; j++)
{
if (_map[i][j] == _barrier)
{
DrawBarrierPart(gr, i, j);
}
}
}
_drawningObject.DrawningObject(gr);
return bmp;
}
protected abstract void GenerateMap();
protected abstract Color DrawRoadPart();
protected abstract void DrawBarrierPart(Graphics g, int i, int j);
}

6
Direction.java Normal file
View File

@ -0,0 +1,6 @@
public enum Direction {
UP,
DOWN,
LEFT,
RIGHT
}

View File

@ -0,0 +1,5 @@
public enum DirectionEnginesOnStormtrooper {
TWO,
FOUR,
SIX
}

50
DrawingEngines.java Normal file
View File

@ -0,0 +1,50 @@
import java.awt.*;
public class DrawingEngines implements IDrawningEngines{
private DirectionEnginesOnStormtrooper enginesCount;
public DrawingEngines(int count) {
SetNewEngines(count);
}
@Override
public void Draw(Graphics g, int x, int y, Color bodycolor) {
g.setColor(bodycolor);
switch (enginesCount) {
case TWO:
g.fillRect(x + 50, y, 20, 5);
g.fillRect(x + 50, y+95, 20, 5);
break;
case FOUR:
g.fillRect(x + 50, y, 20, 5);
g.fillRect(x + 50, y+10, 20, 5);
g.fillRect(x + 50, y+85, 20, 5);
g.fillRect(x + 50, y+95, 20, 5);
break;
case SIX:
g.fillRect(x + 50, y, 20, 5);
g.fillRect(x + 50, y+10, 20, 5);
g.fillRect(x + 50, y+20, 20, 5);
g.fillRect(x + 50, y+75, 20, 5);
g.fillRect(x + 50, y+85, 20, 5);
g.fillRect(x + 50, y+95, 20, 5);
break;
}
}
@Override
public void SetNewEngines(int count) {
switch(count)
{
case 2:
enginesCount = DirectionEnginesOnStormtrooper.TWO;
break;
case 4:
enginesCount = DirectionEnginesOnStormtrooper.FOUR;
break;
case 6:
enginesCount = DirectionEnginesOnStormtrooper.SIX;
break;
default:
break;
}
}
}

View File

@ -0,0 +1,36 @@
import java.awt.*;
public class DrawingMilitaryStormtrooper extends DrawingStormtrooper {
public DrawingMilitaryStormtrooper(int speed, float weight, Color bodyColor, Color dopColor, boolean bomb, boolean propeller) {
super(speed, weight, bodyColor, 135, 100);
Stormtrooper = new EntityMilitaryStormtrooper(speed, weight, bodyColor, dopColor, bomb, propeller);
}
@Override
public void DrawTransport(Graphics2D g) {
if(!(Stormtrooper instanceof EntityMilitaryStormtrooper storm))
{
return;
}
_startPosX += 2;
_startPosX -= 2;
super.DrawTransport(g);
EntityMilitaryStormtrooper entityStorm = (EntityMilitaryStormtrooper) Stormtrooper;
if (entityStorm.propeller)
{
g.setColor(entityStorm.dopColor);
g.fillOval((int)_startPosX - 2, (int)_startPosY +30, 5, 20);
g.fillOval((int) _startPosX - 2, (int)_startPosY + 50, 5, 20);
}
if (entityStorm.bomb)
{
g.setColor(Color.RED);
g.fillRect((int)_startPosX+95, (int)_startPosY + 30, 20, 10);
g.fillRect((int)_startPosX+95,(int) _startPosY + 60, 20, 10);
}
}
}

203
DrawingStormtrooper.java Normal file
View File

@ -0,0 +1,203 @@
import java.awt.*;
import java.util.Random;
public class DrawingStormtrooper {
public EntityStormtrooper Stormtrooper;
public EntityStormtrooper getStormtrooper() {
return Stormtrooper;
}
public DrawingEngines drawingEngines;
private IDrawningEngines iDrawingEngines;
public float _startPosX;
public float _startPosY;
private Integer _pictureWidth = null;
private Integer _pictureHeight = null;
private int _StormWidth = 135;
private int _StormHeight = 100;
public DrawingStormtrooper(int speed, float weight, Color bodyColor){
Random random = new Random();
int[] ArrayEngines = new int[]{2, 4, 6};
switch (random.nextInt(3)){
case 0:
iDrawingEngines = new DrawingEngines(ArrayEngines[random.nextInt(0, 3)]);
break;
case 1:
iDrawingEngines = new DrawningOvalEngines(ArrayEngines[random.nextInt(0, 3)]);
break;
case 2:
iDrawingEngines = new DrawningTriangleEngines(ArrayEngines[random.nextInt(0, 3)]);
break;
}
Stormtrooper = new EntityStormtrooper(speed,weight, bodyColor);
}
protected DrawingStormtrooper(int speed, float weight, Color bodyColor, int StormWidth, int StormHeight)
{
this (speed, weight, bodyColor);
_StormWidth = StormWidth;
_StormHeight = StormHeight;
}
public void SetPosition(int x, int y, int width, int height){
if ((x > 0 && y > 0) && (_StormHeight + y < height) && (_StormWidth + x < width))
{
_startPosX = x;
_startPosY = y;
_pictureWidth = width;
_pictureHeight = height;
}
}
public void MoveTransport(Direction direction)
{
if (_pictureWidth == null || _pictureHeight == null)
{
return;
}
switch (direction)
{
// вправо
case RIGHT:
if (_startPosX + _StormWidth + Stormtrooper.Step < _pictureWidth)
{
_startPosX += Stormtrooper.Step;
}
break;
//влево
case LEFT:
if (_startPosX - Stormtrooper.Step > 0)
{
_startPosX -= Stormtrooper.Step;
}
break;
//вверх
case UP:
if (_startPosY - Stormtrooper.Step > 0)
{
_startPosY -= Stormtrooper.Step;
}
break;
//вниз
case DOWN:
if (_startPosY + _StormHeight + Stormtrooper.Step < _pictureHeight)
{
_startPosY += Stormtrooper.Step;
}
break;
}
}
public void DrawTransport(Graphics2D g)
{
if (_startPosX < 0 || _startPosY < 0
|| _pictureHeight == null || _pictureWidth == null)
{
return;
}
int _startPosXInt = (int)_startPosX;
int _startPosYInt = (int)_startPosY;
//фюзеляж самолёта
g.setColor(Color.BLACK);
g.fillRect(_startPosXInt + 20, _startPosYInt + 40, 100, 20);
//отрисовка крыла
int[] wingX =
{
_startPosXInt + 60 ,
_startPosXInt + 80 ,
_startPosXInt+90 ,
_startPosXInt+90 ,
_startPosXInt+80 ,
_startPosXInt + 60
};
int[] wingY =
{
_startPosYInt,
_startPosYInt,
_startPosYInt + 40,
_startPosYInt + 60,
_startPosYInt + 100,
_startPosYInt + 100
};
g.setColor(Stormtrooper.getBodyColor());
g.fillPolygon(wingX, wingY, wingY.length);
//нос самолёта
int[] noseX =
{
_startPosXInt + 20,
_startPosXInt + 20,
_startPosXInt
};
int[] noseY =
{
_startPosYInt + 60,
_startPosYInt + 40,
_startPosYInt +50
};
g.fillPolygon(noseX, noseY, noseX.length);
//стабилизатор
int[] stabX =
{
_startPosXInt + 120,
_startPosXInt + 135,
_startPosXInt + 135,
_startPosXInt + 120
};
int[] stabY =
{
_startPosYInt + 60,
_startPosYInt + 80,
_startPosYInt + 20,
_startPosYInt + 40
};
g.fillPolygon(stabX, stabY, stabX.length);
//отрисовка двигателей
iDrawingEngines.Draw(g, (int) _startPosX, (int) _startPosY, Stormtrooper.getBodyColor());
g.setColor(Color.BLACK);
g.drawRect(_startPosXInt + 20, _startPosYInt + 40, 100, 20);
g.drawPolygon(wingX, wingY, wingX.length);
g.drawPolygon(noseX, noseY, noseX.length);
g.drawPolygon(stabX, stabY, stabX.length);
}
public void ChangeBorders(int width, int height)
{
_pictureWidth = width;
_pictureHeight = height;
if (_pictureWidth <= _StormWidth || _pictureHeight <= _StormHeight)
{
_pictureWidth = null;
_pictureHeight = null;
return;
}
if (_startPosX + _StormWidth > _pictureWidth)
{
_startPosX = _pictureWidth - _StormWidth;
}
if (_startPosY + _StormHeight > _pictureHeight)
{
_startPosY = _pictureHeight - _StormHeight;
}
}
public float[] GetCurrentPosition()
{
return new float[]{_startPosX, _startPosX + _StormWidth, _startPosY, _startPosY + _StormHeight};
}
}

View File

@ -0,0 +1,38 @@
import java.awt.*;
public class DrawningObjectStormtrooper implements IDrawningObject {
private DrawingStormtrooper _stormtrooper = null;
public DrawningObjectStormtrooper(DrawingStormtrooper storm){
_stormtrooper = storm;
}
@Override
public float getStep() {
if (_stormtrooper.Stormtrooper != null) {
return _stormtrooper.Stormtrooper.Step;
}
return 0;
}
@Override
public void SetObject(int x, int y, int width, int height) {
if (_stormtrooper != null) _stormtrooper.SetPosition(x, y, width, height);
}
@Override
public void MoveObject(Direction direction) {
if (_stormtrooper!= null) _stormtrooper.MoveTransport(direction);
}
@Override
public void DrawningObject(Graphics g) {
if (_stormtrooper != null) _stormtrooper.DrawTransport((Graphics2D) g);
}
@Override
public float[] GetCurrentPosition() {
if (_stormtrooper != null) {return _stormtrooper.GetCurrentPosition();}
return null;
}
}

51
DrawningOvalEngines.java Normal file
View File

@ -0,0 +1,51 @@
import java.awt.*;
public class DrawningOvalEngines implements IDrawningEngines{
private DirectionEnginesOnStormtrooper enginesCount;
@Override
public void Draw(Graphics g, int x, int y, Color bodyColor) {
g.setColor(bodyColor);
switch (enginesCount) {
case TWO:
g.fillOval(x + 50, y, 20, 10);
g.fillOval(x + 50, y+90, 20, 10);
break;
case FOUR:
g.fillOval(x + 50, y, 20, 10);
g.fillOval(x + 50, y+15, 20, 10);
g.fillOval(x + 50, y+75, 20, 10);
g.fillOval(x + 50, y+90, 20, 10);
break;
case SIX:
g.fillOval(x + 50, y, 20, 10);
g.fillOval(x + 50, y+15, 20, 10);
g.fillOval(x + 50, y+30, 20, 10);
g.fillOval(x + 50, y+60, 20, 10);
g.fillOval(x + 50, y+75, 20, 10);
g.fillOval(x + 50, y+90, 20, 10);
break;
}
}
@Override
public void SetNewEngines(int count) {
switch(count)
{
case 2:
enginesCount = DirectionEnginesOnStormtrooper.TWO;
break;
case 4:
enginesCount = DirectionEnginesOnStormtrooper.FOUR;
break;
case 6:
enginesCount = DirectionEnginesOnStormtrooper.SIX;
break;
default:
break;
}
}
public DrawningOvalEngines(int count){
SetNewEngines(count);
}
}

View File

@ -0,0 +1,51 @@
import java.awt.*;
public class DrawningTriangleEngines implements IDrawningEngines{
private DirectionEnginesOnStormtrooper enginesCount;
@Override
public void Draw(Graphics g, int x, int y, Color bodyColor) {
g.setColor(bodyColor);
switch (enginesCount) {
case TWO:
g.fillPolygon(new int[]{x + 50,x+60,x+60}, new int[]{y+5,y, y +10 }, 3);
g.fillPolygon(new int[]{x + 50,x+60,x+60}, new int[]{y+95,y+90, y +100 }, 3);
break;
case FOUR:
g.fillPolygon(new int[]{x + 50,x+60,x+60}, new int[]{y+5,y, y +10 }, 3);
g.fillPolygon(new int[]{x + 50,x+60,x+60}, new int[]{y+20,y+15, y +25 }, 3);
g.fillPolygon(new int[]{x + 50,x+60,x+60}, new int[]{y+80,y+75, y +85 }, 3);
g.fillPolygon(new int[]{x + 50,x+60,x+60}, new int[]{y+95,y+90, y +100 }, 3);
break;
case SIX:
g.fillPolygon(new int[]{x + 50,x+60,x+60}, new int[]{y+5,y, y +10 }, 3);
g.fillPolygon(new int[]{x + 50,x+60,x+60}, new int[]{y+20,y+15, y +25 }, 3);
g.fillPolygon(new int[]{x + 50,x+60,x+60}, new int[]{y+35,y+30, y +40 }, 3);
g.fillPolygon(new int[]{x + 50,x+60,x+60}, new int[]{y+65,y+60, y +70 }, 3);
g.fillPolygon(new int[]{x + 50,x+60,x+60}, new int[]{y+80,y+75, y +85 }, 3);
g.fillPolygon(new int[]{x + 50,x+60,x+60}, new int[]{y+95,y+90, y +100 }, 3);
break;
}
}
@Override
public void SetNewEngines(int count) {
switch(count)
{
case 2:
enginesCount = DirectionEnginesOnStormtrooper.TWO;
break;
case 4:
enginesCount = DirectionEnginesOnStormtrooper.FOUR;
break;
case 6:
enginesCount = DirectionEnginesOnStormtrooper.SIX;
break;
default:
break;
}
}
public DrawningTriangleEngines(int count){
SetNewEngines(count);
}
}

View File

@ -0,0 +1,14 @@
import java.awt.*;
public class EntityMilitaryStormtrooper extends EntityStormtrooper {
public final boolean bomb;
public final boolean propeller;
public final Color dopColor;
public EntityMilitaryStormtrooper(int speed, float weight, Color bodyColor, Color DopColor, boolean Bomb, boolean Propeller) {
super(speed, weight, bodyColor);
dopColor = DopColor;
bomb = Bomb;
propeller = Propeller;
}
}

33
EntityStormtrooper.java Normal file
View File

@ -0,0 +1,33 @@
import java.awt.Color;
import java.util.Random;
public class EntityStormtrooper {
private int Speed = 0;
private float Weight = 0;
private Color BodyColor;
public float Step;
public int getSpeed() {
return Speed;
}
public float getWeight() {
return Weight;
}
public Color getBodyColor() {
return BodyColor;
}
public EntityStormtrooper(int speed, float weight, Color bodyColor){
Random rnd = new Random();
Speed = speed <= 0 ? rnd.nextInt(50 + 1) +50 : speed; //генерация в диапазоне от 50 до 100
Weight = weight <= 0 ? rnd.nextInt(50 + 1) +50 : weight;
Step = Speed * 100 / Weight;
BodyColor = bodyColor;
}
}

184
FormMap.java Normal file
View File

@ -0,0 +1,184 @@
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ComponentEvent;
import java.awt.event.ComponentListener;
import java.awt.image.BufferedImage;
import java.util.Random;
public class FormMap extends JComponent {
private AbstractMap _abstractMap;
private DrawingStormtrooper _stormtrooper;
private BufferedImage bufferedImage;
public static void main(String[] args) {
FormMap formMap = new FormMap();
}
public FormMap() {
JFrame form = new JFrame("Карта");
form.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
form.setSize(1000, 500);
form.setVisible(true);
form.setLocationRelativeTo(null);
Panel statusPanel = new Panel();
statusPanel.setBackground(Color.WHITE);
statusPanel.setLayout(new GridBagLayout());
setLayout(new BorderLayout());
form.add(statusPanel, BorderLayout.SOUTH);
Label speedLabel = new Label("Скорость: ");
Label weightLabel = new Label("Вес: ");
Label colorLabel = new Label("Цвет: ");
String[] maps = {
"Простая карта",
"Ясное небо",
"Пасмурное небо"
};
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 ("Простая карта"):
_abstractMap = new SimpleMap();
break;
case ("Ясное небо"):
_abstractMap = new SecondMap();
break;
case ("Пасмурное небо"):
_abstractMap = new ThirdMap();
break;
}
}
});
JButton createButton = new JButton("Создать");
createButton.addActionListener(e -> {
Random rnd = new Random();
var stormtrop = new DrawingStormtrooper(rnd.nextInt(100, 300), rnd.nextInt(1000, 2000),
Color.getHSBColor(rnd.nextInt(0, 256), rnd.nextInt(0, 256),
rnd.nextInt(0, 256)));
speedLabel.setText("Скорость: " + stormtrop.Stormtrooper.getSpeed());
weightLabel.setText("Вес: " + (int)stormtrop.Stormtrooper.getWeight());
colorLabel.setText("Цвет: " + stormtrop.Stormtrooper.getBodyColor().getRed() + " " +
stormtrop.Stormtrooper.getBodyColor().getGreen() + " " + stormtrop.Stormtrooper.getBodyColor().getBlue() );
if (_abstractMap != null) bufferedImage = _abstractMap.CreateMap(form.getWidth(), form.getHeight() - 80, new DrawningObjectStormtrooper(stormtrop));
repaint();
});
JButton modifiedButton = new JButton("Модификация");
modifiedButton.addActionListener(e -> {
Random rnd = new Random();
Color colorFirst = new Color(rnd.nextInt(256), rnd.nextInt(256),rnd.nextInt(256));
Color colorSecond = new Color(rnd.nextInt(256), rnd.nextInt(256),rnd.nextInt(256));
var militarystorm = new DrawingMilitaryStormtrooper(rnd.nextInt(200) + 100, rnd.nextInt(1000) + 1000,
colorFirst,
colorSecond,
rnd.nextBoolean(),
rnd.nextBoolean());
militarystorm.SetPosition(10 + rnd.nextInt(90), 10 + rnd.nextInt(90), form.getWidth(), form.getHeight() - 80);
speedLabel.setText("Скорость: " + militarystorm.Stormtrooper.getSpeed());
weightLabel.setText("Вес: " + militarystorm.Stormtrooper.getWeight());
colorLabel.setText("Цвет: " + militarystorm.Stormtrooper.getBodyColor().getRed() + " " + militarystorm.Stormtrooper.getBodyColor().getGreen() + " " + militarystorm.Stormtrooper.getBodyColor().getBlue() );
if (_abstractMap != null) bufferedImage = _abstractMap.CreateMap(form.getWidth(), form.getHeight() - 80, new DrawningObjectStormtrooper(militarystorm));
repaint();
});
GridBagConstraints c = new GridBagConstraints();//заполнение statuspanel
statusPanel.add(mapSelectComboBox);
statusPanel.add(createButton);
statusPanel.add(modifiedButton);
c.fill = GridBagConstraints.NONE;
c.anchor = GridBagConstraints.CENTER;
c.weightx = 0.5;
c.gridx = 0;
c.gridy = 1;
statusPanel.add(mapSelectComboBox,c);
c.gridx = 1;
c.gridy = 1;
statusPanel.add(createButton,c);
c.gridx = 2;
c.gridy = 1;
statusPanel.add(modifiedButton,c);
c.fill = GridBagConstraints.HORIZONTAL;
c.gridx = 3;
c.gridy = 1;
statusPanel.add(speedLabel,c);
c.gridx = 4;
c.gridy = 1;
statusPanel.add(weightLabel,c);
c.gridx = 5;
c.gridy = 1;
c.gridwidth = 1;
statusPanel.add(colorLabel,c);
JButton upButton = new JButton("");
JButton rightButton = new JButton("");
JButton leftButton = new JButton("");
JButton downButton = new JButton("");
upButton.addActionListener(e -> {
if(bufferedImage != null) bufferedImage = _abstractMap.MoveObject(Direction.UP);
repaint();
});
rightButton.addActionListener(e -> {
if(bufferedImage != null) bufferedImage = _abstractMap.MoveObject(Direction.RIGHT);
repaint();
});
leftButton.addActionListener(e -> {
if(bufferedImage != null) bufferedImage = _abstractMap.MoveObject(Direction.LEFT);
repaint();
});
downButton.addActionListener(e -> {
if(bufferedImage != null) bufferedImage = _abstractMap.MoveObject(Direction.DOWN);
repaint();
});
c.fill = GridBagConstraints.NONE;
c.gridx = 8;
c.gridy = 0;
c.gridwidth = 1;
statusPanel.add(upButton,c);
c.gridx = 7;
c.gridy = 1;
c.gridwidth = 1;
statusPanel.add(leftButton,c);
c.gridx = 9;
c.gridy = 1;
c.gridwidth = 1;
statusPanel.add(rightButton,c);
c.gridx = 8;
c.gridy = 1;
c.gridwidth = 1;
statusPanel.add(downButton,c);
form.getContentPane().add(this);
super.repaint();
}
protected void paintComponent(Graphics g) {
super.paintComponent(g);
Graphics2D g2 = (Graphics2D)g;
if (bufferedImage != null) g2.drawImage(bufferedImage, 0,0,1000,420,null);
super.repaint();
}
}

7
IDrawningEngines.java Normal file
View File

@ -0,0 +1,7 @@
import java.awt.*;
public interface IDrawningEngines {
void Draw(Graphics g, int x, int y, Color bodyColor);
void SetNewEngines(int count);
}

9
IDrawningObject.java Normal file
View File

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

42
SecondMap.java Normal file
View File

@ -0,0 +1,42 @@
import java.awt.*;
public class SecondMap extends AbstractMap {
Color roadColor = Color.BLUE;
Color barrierColor = Color.WHITE;
@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 Color DrawRoadPart() {
return roadColor;
}
@Override
protected void DrawBarrierPart(Graphics g, int i, int j) {
g.setColor(barrierColor);
g.fillRect( (int)(i * _size_x), (int)(j * _size_y),(int) _size_x,(int) _size_y);
}
}

42
SimpleMap.java Normal file
View File

@ -0,0 +1,42 @@
import java.awt.*;
public class SimpleMap extends AbstractMap {
Color roadColor = Color.GRAY;
Color barrierColor = Color.BLACK;
@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 Color DrawRoadPart() {
return roadColor;
}
@Override
protected void DrawBarrierPart(Graphics g, int i, int j) {
g.setColor(barrierColor);
g.fillRect( (int)(i * _size_x), (int)(j * _size_y),(int) _size_x,(int) _size_y);
}
}

58
ThirdMap.java Normal file
View File

@ -0,0 +1,58 @@
import java.awt.*;
public class ThirdMap extends AbstractMap {
Color roadColor = Color.LIGHT_GRAY;
Color barrierColor = 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 < 60)
{
int x = _random.nextInt(0, 20);
int y = _random.nextInt(40, 60);
if (_map[x][y] == _freeRoad)
{
_map[x][y] = _barrier;
counter++;
}
x = _random.nextInt(80, 100);
y = _random.nextInt(0, 20);
if (_map[x][y] == _freeRoad)
{
_map[x][y] = _barrier;
counter++;
}
x = _random.nextInt(40, 60);
y = _random.nextInt(50, 80);
if (_map[x][y] == _freeRoad)
{
_map[x][y] = _barrier;
counter++;
}
}
}
@Override
protected Color DrawRoadPart() {
return roadColor;
}
@Override
protected void DrawBarrierPart(Graphics g, int i, int j) {
g.setColor(barrierColor);
g.fillRect( (int)(i * _size_x), (int)(j * _size_y),(int) _size_x,(int) _size_y);
}
}