Compare commits

...

5 Commits

25 changed files with 999 additions and 2 deletions

View File

@ -2,7 +2,9 @@
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$" />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>

View File

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

115
AbstractMap.java Normal file
View File

@ -0,0 +1,115 @@
import java.awt.*;
import java.awt.image.BufferedImage;
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 Random _random = new Random();
protected int _freeRoad = 0;
protected int _barrier = 1;
public BufferedImage CreateMap(int width, int height, IDrawningObject drawningObject)
{
_width = width;
_height = height;
_drawningObject = drawningObject;
GenerateMap();
while (!SetObjectOnMap())
{
GenerateMap();
}
return DrawMapWithObject();
}
private boolean CanMove(float[] position) //Проверка на возможность шага
{
for (int i = (int)(position[2] / _size_y); i <= (int)(position[3] / _size_y); ++i)
{
for (int j = (int)(position[0] / _size_x); j <= (int)(position[1] / _size_x); ++j)
{
if (i >= 0 && j >= 0 && i < _map.length && j < _map[0].length && _map[i][j] == _barrier) return false;
}
}
return true;
}
public BufferedImage MoveObject(Direction direction)
{
float[] position = _drawningObject.GetCurrentPosition();
if (direction == Direction.Left)
{
position[0] -= _drawningObject.getStep();
}
else if (direction == Direction.Right)
{
position[1] += _drawningObject.getStep();
}
else if (direction == Direction.Up)
{
position[2] -= _drawningObject.getStep();
}
else if (direction == Direction.Down)
{
position[3] += _drawningObject.getStep();
}
if (CanMove(position))
{
_drawningObject.MoveObject(direction);
}
return DrawMapWithObject();
}
private boolean SetObjectOnMap()
{
if (_drawningObject == null || _map == null)
{
return false;
}
int x = _random.nextInt(0, 10);
int y = _random.nextInt(0, 10);
_drawningObject.SetObject(x, y, _width, _height);
for (int i = (int)(_drawningObject.GetCurrentPosition()[2] / _size_y); i <= (int)(_drawningObject.GetCurrentPosition()[3] / _size_y); ++i)
{
for (int j = (int)(_drawningObject.GetCurrentPosition()[0] / _size_x); j <= (int)(_drawningObject.GetCurrentPosition()[1] / _size_x); ++j)
{
if (_map[i][j] == _barrier) _map[i][j] = _freeRoad;
}
}
return true;
}
private BufferedImage DrawMapWithObject()
{
BufferedImage bmp = new BufferedImage(_width, _height, BufferedImage.TYPE_INT_RGB);
if (_drawningObject == null || _map == null)
{
return bmp;
}
Graphics g = 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(g, i, j);
}
else if (_map[i][j] == _barrier)
{
DrawBarrierPart(g, i, j);
}
}
}
_drawningObject.DrawningObject(g);
return bmp;
}
protected abstract void GenerateMap();
protected abstract void DrawRoadPart(Graphics g, int i, int j);
protected abstract void DrawBarrierPart(Graphics g, int i, int j);
}

13
Direction.java Normal file
View File

@ -0,0 +1,13 @@
public enum Direction
{
None(0),
Up(1),
Down(2),
Left(3),
Right(4);
Direction(int i )
{
}
}

38
DrawEngines.java Normal file
View File

@ -0,0 +1,38 @@
import java.awt.*;
public class DrawEngines implements IDrawningEngines
{
private Engines numEngines;
@Override
public void SetNumEngines(int i) { numEngines = Engines.GetNumEngines(i); }
@Override
public void DrawningEngines(float _startPosX, float _startPosY, Graphics2D g2d, int _airBomberWidth, int _airBomberHeight)
{
switch(numEngines)
{
case TwoEngines:
g2d.fillRect((int)_startPosX + _airBomberWidth / 2 - 20, (int)_startPosY + _airBomberHeight / 2 - 20, 20, 10);
g2d.fillRect((int)_startPosX + _airBomberWidth / 2 - 20, (int)_startPosY + _airBomberHeight / 2 + 10, 20, 10);
break;
case FourEngines:
g2d.fillRect((int)_startPosX + _airBomberWidth / 2 - 20, (int)_startPosY + _airBomberHeight / 2 - 20, 20, 10);
g2d.fillRect((int)_startPosX + _airBomberWidth / 2 - 20, (int)_startPosY + _airBomberHeight / 2 + 10, 20, 10);
g2d.fillRect((int)_startPosX + _airBomberWidth / 2 - 15, (int)_startPosY + _airBomberHeight / 2 - 35, 15, 10);
g2d.fillRect((int)_startPosX + _airBomberWidth / 2 - 15, (int)_startPosY + _airBomberHeight / 2 + 25, 15, 10);
break;
case SixEngines:
g2d.fillRect((int)_startPosX + _airBomberWidth / 2 - 20, (int)_startPosY + _airBomberHeight / 2 - 20, 20, 10);
g2d.fillRect((int)_startPosX + _airBomberWidth / 2 - 20, (int)_startPosY + _airBomberHeight / 2 + 10, 20, 10);
g2d.fillRect((int)_startPosX + _airBomberWidth / 2 - 15, (int)_startPosY + _airBomberHeight / 2 - 35, 15, 10);
g2d.fillRect((int)_startPosX + _airBomberWidth / 2 - 15, (int)_startPosY + _airBomberHeight / 2 + 25, 15, 10);
g2d.fillRect((int)_startPosX + _airBomberWidth / 2 - 10, (int)_startPosY + _airBomberHeight / 2 - 50, 10, 10);
g2d.fillRect((int)_startPosX + _airBomberWidth / 2 - 10, (int)_startPosY + _airBomberHeight / 2 + 40, 10, 10);
break;
}
}
}

25
DrawRocketEngine.java Normal file
View File

@ -0,0 +1,25 @@
import java.awt.*;
public class DrawRocketEngine implements IDrawningEngines
{
private Engines numRocketEngines;
@Override
public void SetNumEngines(int i) { numRocketEngines = Engines.GetNumEngines(i); }
@Override
public void DrawningEngines(float _startPosX, float _startPosY, Graphics2D g2d, int _airBomberWidth, int _airBomberHeight)
{
switch(numRocketEngines)
{
case TwoEngines:
break;
case FourEngines:
g2d.fillRect((int)_startPosX + _airBomberWidth, (int)_startPosY + _airBomberHeight / 2 - 10, 20, 20);
break;
case SixEngines:
g2d.fillRect((int)_startPosX + _airBomberWidth, (int)_startPosY + _airBomberHeight / 2 - 10, 20, 20);
break;
}
}
}

27
DrawWings.java Normal file
View File

@ -0,0 +1,27 @@
import java.awt.*;
public class DrawWings implements IDrawningEngines
{
private Engines numWings;
@Override
public void SetNumEngines(int i) { numWings = Engines.GetNumEngines(i); }
@Override
public void DrawningEngines(float _startPosX, float _startPosY, Graphics2D g2d, int _airBomberWidth, int _airBomberHeight)
{
switch(numWings)
{
case TwoEngines:
break;
case FourEngines:
g2d.fillRect((int)_startPosX + _airBomberWidth / 2 + 25, (int)_startPosY + _airBomberHeight / 2 - 10, 20, 10);
g2d.fillRect((int)_startPosX + _airBomberWidth / 2 + 25, (int)_startPosY + _airBomberHeight / 2, 20, 10);
break;
case SixEngines:
g2d.fillRect((int)_startPosX + _airBomberWidth / 2 + 25, (int)_startPosY + _airBomberHeight / 2 - 10, 20, 10);
g2d.fillRect((int)_startPosX + _airBomberWidth / 2 + 25, (int)_startPosY + _airBomberHeight / 2, 20, 10);
break;
}
}
}

184
DrawningBomber.java Normal file
View File

@ -0,0 +1,184 @@
import javax.swing.*;
import java.awt.*;
import java.util.*;
public class DrawningBomber extends JPanel
{
public EntityAirBomber AirBomber;
public EntityAirBomber getAirBomber() { return AirBomber; }
public float _startPosX;
public float _startPosY;
private int _pictureWidth = 0;
private int _pictureHeight = 0;
private int _airBomberWidth = 100;
private int _airBomberHeight = 100;
private DrawEngines drawEngines = new DrawEngines();
private IDrawningEngines ide;
public DrawningBomber(int speed, float weight, Color bodyColor)
{
AirBomber = new EntityAirBomber(speed, weight, bodyColor);
Random random = new Random();
switch (random.nextInt(3))
{
case 0:
ide = new DrawEngines();
break;
case 1:
ide = new DrawRocketEngine();
break;
case 2:
ide = new DrawWings();
break;
}
ide.SetNumEngines(random.nextInt(1, 4));
}
protected DrawningBomber(int speed, float weight, Color bodyColor, int airBomberWidth, int airBomberHeight)
{
this(speed, weight, bodyColor);
_airBomberWidth = airBomberWidth;
_airBomberHeight = airBomberHeight;
}
public void SetPosition(int x, int y, int width, int height)
{
if (x + _airBomberWidth > width || x < 0) return;
else _startPosX = x;
if (y + _airBomberHeight> height || y < 0) return;
else _startPosY = y;
_pictureWidth = width;
_pictureHeight = height;
}
public void MoveTransport(Direction direction)
{
if (!(_pictureWidth > 0 || _pictureHeight > 0))
{
return;
}
switch (direction)
{
case Right:
if (_startPosX + _airBomberWidth + AirBomber.GetStep() < _pictureWidth)
{
_startPosX += AirBomber.GetStep();
}
break;
case Left:
if (_startPosX - AirBomber.GetStep() > 0)
{
_startPosX -= AirBomber.GetStep();
}
break;
case Up:
if (_startPosY - AirBomber.GetStep() > 0)
{
_startPosY -= AirBomber.GetStep();
}
break;
case Down:
if (_startPosY + _airBomberHeight + AirBomber.GetStep() < _pictureHeight)
{
_startPosY += AirBomber.GetStep();
}
break;
}
}
public void DrawTransport(Graphics g)
{
if (getAirBomber() == null || _startPosX < 0 || _startPosY < 0 || _pictureHeight == 0 || _pictureWidth == 0)
{
return;
}
super.paintComponent(g);
Graphics2D g2d = (Graphics2D) g;
g2d.setColor(AirBomber.GetColor());
int[] xPos = {
(int)(_startPosX + _airBomberWidth),
(int)(_startPosX + _airBomberWidth),
(int)(_startPosX + _airBomberWidth - 10),
(int)(_startPosX + _airBomberWidth - 10)};
int[] yPos = {
(int)(_startPosY + _airBomberHeight / 2 - 20),
(int)(_startPosY + _airBomberHeight / 2 + 20),
(int)(_startPosY + _airBomberHeight / 2 + 10),
(int)(_startPosY + _airBomberHeight / 2 - 10)};
g2d.fillPolygon(xPos, yPos, xPos.length);
xPos = new int[] {
(int)(_startPosX + _airBomberWidth / 2),
(int)(_startPosX + _airBomberWidth / 2 + 10),
(int)(_startPosX + _airBomberWidth / 2 + 20),
(int)(_startPosX + _airBomberWidth / 2 + 10),
(int)(_startPosX + _airBomberWidth / 2)};
yPos = new int[] {
(int)(_startPosY),
(int)(_startPosY),
(int)(_startPosY + _airBomberHeight / 2),
(int)(_startPosY + _airBomberHeight),
(int)(_startPosY + _airBomberHeight)};
g2d.fillPolygon(xPos, yPos, xPos.length);
xPos = new int[] {
(int)(_startPosX + 20),
(int)(_startPosX + _airBomberWidth),
(int)(_startPosX + _airBomberWidth),
(int)(_startPosX + 20)};
yPos = new int[] {
(int)(_startPosY + _airBomberHeight / 2 - 5),
(int)(_startPosY + _airBomberHeight / 2 - 5),
(int)(_startPosY + _airBomberHeight / 2 + 5),
(int)(_startPosY + _airBomberHeight / 2 + 5)};
g2d.fillPolygon(xPos, yPos, xPos.length);
xPos = new int[] {
(int)(_startPosX),
(int)(_startPosX + 20),
(int)(_startPosX + 20)};
yPos = new int[] {
(int)(_startPosY + _airBomberHeight / 2),
(int)(_startPosY + _airBomberHeight / 2 - 5),
(int)(_startPosY + _airBomberHeight / 2 + 5)};
g2d.fillPolygon(xPos, yPos, xPos.length);
ide.DrawningEngines(_startPosX, _startPosY, g2d, _airBomberWidth, _airBomberHeight);
}
public void ChangeBorders(int width, int height)
{
_pictureWidth = width;
_pictureHeight = height;
if (_pictureWidth <= _airBomberWidth || _pictureHeight <= _airBomberHeight)
{
_pictureWidth = 0;
_pictureHeight = 0;
return;
}
if (_startPosX + _airBomberWidth > _pictureWidth)
{
_startPosX = _pictureWidth - _airBomberWidth;
}
if (_startPosY + _airBomberHeight > _pictureHeight)
{
_startPosY = _pictureHeight - _airBomberHeight;
}
}
public float[] GetCurrentPosition()
{
return new float[]{_startPosX, _startPosX + _airBomberWidth, _startPosY, _startPosY + _airBomberHeight};
}
}

38
DrawningObjectBomber.java Normal file
View File

@ -0,0 +1,38 @@
import java.awt.*;
public class DrawningObjectBomber implements IDrawningObject
{
private DrawningBomber _airBomber = null;
public DrawningObjectBomber(DrawningBomber airBomber)
{
_airBomber = airBomber;
}
@Override
public float getStep() {
if (_airBomber == null || _airBomber.AirBomber == null) return 0;
return _airBomber.AirBomber.GetStep();
}
@Override
public void SetObject(int x, int y, int width, int height) {
_airBomber.SetPosition(x, y, width, height);
}
@Override
public void MoveObject(Direction direction) {
_airBomber.MoveTransport(direction);
}
@Override
public void DrawningObject(Graphics g) {
_airBomber.DrawTransport(g);
}
@Override
public float[] GetCurrentPosition() {
if (_airBomber == null || _airBomber.AirBomber == null) return null;
return _airBomber.GetCurrentPosition();
}
}

42
DrawningWarplane.java Normal file
View File

@ -0,0 +1,42 @@
import java.awt.*;
public class DrawningWarplane extends DrawningBomber
{
public DrawningWarplane(int speed, float weight, Color bodyColor, Color dopColor, boolean engines, boolean weapons)
{
super(speed, weight, bodyColor, 120, 120);
AirBomber = new EntityWarplane(speed, weight, bodyColor, dopColor, engines, weapons);
}
@Override
public void DrawTransport(Graphics g)
{
if (!(AirBomber instanceof EntityWarplane warplane))
{
return;
}
Graphics2D g2d = (Graphics2D) g;
g2d.setColor(Color.BLACK);
g2d.setColor(warplane.GetDopColor());
if (warplane.GetEngines())
{
g2d.fillOval((int)_startPosX + 50, (int)_startPosY + 40, 30, 15);
g2d.fillOval( (int)_startPosX + 45, (int)_startPosY + 60, 35, 15);
g2d.fillOval( (int)_startPosX + 45, (int)_startPosY + 95, 35, 15);
g2d.fillOval( (int)_startPosX + 50, (int)_startPosY + 115, 30, 15);
}
_startPosY += 25;
super.DrawTransport(g);
_startPosY -= 25;
if (warplane.GetWeapons())
{
g2d.fillRect((int)_startPosX + 40,(int) _startPosY + 20, 30, 5);
g2d.fillRect( (int)_startPosX + 40, (int)_startPosY + 140, 30, 5);
}
}
}

24
Engines.java Normal file
View File

@ -0,0 +1,24 @@
public enum Engines
{
TwoEngines(1),
FourEngines(2),
SixEngines(6);
Engines(int i) {
}
public static Engines GetNumEngines(int i)
{
switch(i)
{
case 1:
return TwoEngines;
case 2:
return FourEngines;
case 3:
return SixEngines;
}
return null;
}
}

29
EntityAirBomber.java Normal file
View File

@ -0,0 +1,29 @@
import java.awt.*;
import java.util.*;
public class EntityAirBomber
{
private int Speed;
private float Weight;
private Color BodyColor;
private float Step;
public EntityAirBomber(int speed, float weight, Color bodyColor)
{
Random rnd = new Random();
Speed = speed <= 0 ? rnd.nextInt(50, 150) : speed;
Weight = weight <= 0 ? rnd.nextInt(40, 70) : weight;
BodyColor = bodyColor;
Step = Speed * 100 / Weight;
}
public int GetSpeed() { return Speed; }
public float GetWeight() {
return Weight;
}
public Color GetColor() { return BodyColor; }
public float GetStep() { return Step; }
}

22
EntityWarplane.java Normal file
View File

@ -0,0 +1,22 @@
import java.awt.*;
public class EntityWarplane extends EntityAirBomber
{
private Color DopColor;
private boolean Engines;
private boolean Weapons;
public EntityWarplane(int speed, float weight, Color bodyColor, Color dopColor, boolean engines, boolean weapons)
{
super(speed, weight, bodyColor);
DopColor = dopColor;
Engines = engines;
Weapons = weapons;
}
public Color GetDopColor(){return DopColor;}
public boolean GetEngines(){return Engines;}
public boolean GetWeapons(){return Weapons;}
}

107
FormAirBomber.form Normal file
View File

@ -0,0 +1,107 @@
<?xml version="1.0" encoding="UTF-8"?>
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="FormAirBomber">
<grid id="27dc6" binding="Mainpanel" layout-manager="GridLayoutManager" row-count="4" column-count="5" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<xy x="20" y="20" width="500" height="400"/>
</constraints>
<properties>
<opaque value="true"/>
<preferredSize width="800" height="600"/>
</properties>
<border type="none"/>
<children>
<component id="2ea16" class="javax.swing.JButton" binding="buttonDown">
<constraints>
<grid row="2" column="3" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="3" indent="0" use-parent-layout="false">
<minimum-size width="30" height="30"/>
<preferred-size width="30" height="30"/>
<maximum-size width="30" height="30"/>
</grid>
</constraints>
<properties>
<text value=""/>
</properties>
</component>
<component id="4eb88" class="javax.swing.JButton" binding="buttonRight">
<constraints>
<grid row="2" column="4" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="3" indent="0" use-parent-layout="false">
<minimum-size width="30" height="30"/>
<preferred-size width="30" height="30"/>
<maximum-size width="30" height="30"/>
</grid>
</constraints>
<properties>
<horizontalAlignment value="0"/>
<text value=""/>
</properties>
</component>
<component id="9f55" class="DrawningBomber" binding="pictureBomber">
<constraints>
<grid row="0" column="0" row-span="1" col-span="5" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false">
<preferred-size width="10" height="286"/>
</grid>
</constraints>
<properties/>
</component>
<component id="fb937" class="javax.swing.JButton" binding="buttonUp">
<constraints>
<grid row="1" column="3" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="3" indent="0" use-parent-layout="false">
<minimum-size width="30" height="30"/>
<preferred-size width="30" height="30"/>
<maximum-size width="30" height="30"/>
</grid>
</constraints>
<properties>
<text value=""/>
</properties>
</component>
<toolbar id="e747d" binding="statusStrip">
<constraints>
<grid row="3" column="0" row-span="1" col-span="5" vsize-policy="0" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false">
<minimum-size width="-1" height="20"/>
<preferred-size width="-1" height="20"/>
<maximum-size width="-1" height="20"/>
</grid>
</constraints>
<properties>
<enabled value="false"/>
</properties>
<border type="none"/>
<children/>
</toolbar>
<hspacer id="d6bea">
<constraints>
<grid row="1" column="1" row-span="1" col-span="2" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
</hspacer>
<hspacer id="d86ff">
<constraints>
<grid row="2" column="0" row-span="1" col-span="2" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
</hspacer>
<component id="9e2ce" class="javax.swing.JButton" binding="buttonCreate">
<constraints>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="1" indent="0" use-parent-layout="false">
<preferred-size width="118" height="30"/>
</grid>
</constraints>
<properties>
<text value="Создать"/>
</properties>
</component>
<component id="4f60a" class="javax.swing.JButton" binding="buttonLeft">
<constraints>
<grid row="2" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="3" indent="0" use-parent-layout="false">
<minimum-size width="30" height="30"/>
<preferred-size width="30" height="30"/>
<maximum-size width="30" height="30"/>
</grid>
</constraints>
<properties>
<text value=""/>
</properties>
</component>
</children>
</grid>
</form>

157
FormAirBomber.java Normal file
View File

@ -0,0 +1,157 @@
import javax.imageio.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;
import java.util.*;
public class FormAirBomber {
private JToolBar statusStrip;
public JPanel Mainpanel;
private DrawningBomber pictureBomber;
private JButton buttonRight;
private JButton buttonCreate;
private JButton buttonLeft;
private JButton buttonUp;
private JButton buttonDown;
private JPanel GraphicsOutput;
private JButton buttonCreateModif;
private JLabel JLabelSpeed = new JLabel();
private JLabel JLabelWeight = new JLabel();
private JLabel JLabelColor = new JLabel();
private void Draw()
{
if (pictureBomber.getAirBomber() == null) return;
GraphicsOutput.removeAll();
BufferedImage bmp = new BufferedImage(GraphicsOutput.getWidth(), GraphicsOutput.getHeight(),BufferedImage.TYPE_INT_RGB);
Graphics g = bmp.getGraphics();
g.setColor(new Color(238, 238, 238));
g.fillRect(0, 0, GraphicsOutput.getWidth(), GraphicsOutput.getHeight());
pictureBomber.DrawTransport(g);
JLabel imageOfShip = new JLabel();
imageOfShip.setPreferredSize(GraphicsOutput.getSize());
imageOfShip.setMinimumSize(new Dimension(1, 1));
imageOfShip.setIcon(new ImageIcon(bmp));
GraphicsOutput.add(imageOfShip,BorderLayout.CENTER);
//validate();
}
private void SetData()
{
Random random = new Random();
pictureBomber.SetPosition(random.nextInt(10, 100), random.nextInt(10, 100), GraphicsOutput.getWidth(), GraphicsOutput.getHeight());
JLabelSpeed.setText("орость: " + pictureBomber.getAirBomber().GetSpeed() + " ");
JLabelWeight.setText("Вес: " + pictureBomber.getAirBomber().GetWeight() + " ");
JLabelColor.setText(("Цвет: " + pictureBomber.getAirBomber().GetColor() + " "));
}
private void ButtonMove_Click(String name)
{
if (pictureBomber == null) return;
switch (name)
{
case "buttonLeft":
pictureBomber.MoveTransport(Direction.Left);
break;
case "buttonUp":
pictureBomber.MoveTransport(Direction.Up);
break;
case "buttonRight":
pictureBomber.MoveTransport(Direction.Right);
break;
case "buttonDown":
pictureBomber.MoveTransport(Direction.Down);
break;
}
Draw();
}
public FormAirBomber() {
Box LabelBox = Box.createHorizontalBox();
LabelBox.setMinimumSize(new Dimension(1, 20));
LabelBox.add(JLabelSpeed);
LabelBox.add(JLabelWeight);
LabelBox.add(JLabelColor);
statusStrip.add(LabelBox);
try {
Image img = ImageIO.read(FormAirBomber.class.getResource("/Images/ArrowUp.jpg"));
buttonUp.setIcon(new ImageIcon(img));
img = ImageIO.read(FormAirBomber.class.getResource("/Images/ArrowLeft.jpg"));
buttonLeft.setIcon(new ImageIcon(img));
img = ImageIO.read(FormAirBomber.class.getResource("/Images/ArrowDown.jpg"));
buttonDown.setIcon(new ImageIcon(img));
img = ImageIO.read(FormAirBomber.class.getResource("/Images/ArrowRight.jpg"));
buttonRight.setIcon(new ImageIcon(img));
} catch (Exception ex) {
System.out.println(ex);
}
buttonCreate.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
Random random = new Random();
pictureBomber = new DrawningBomber(random.nextInt(100, 300), random.nextInt(1000, 2000), new Color(random.nextInt(0, 256), random.nextInt(0, 256), random.nextInt(0, 256)));
SetData();
Draw();
}
});
buttonUp.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
ButtonMove_Click("buttonUp");
}
});
buttonLeft.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
ButtonMove_Click("buttonLeft");
}
});
buttonDown.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
ButtonMove_Click("buttonDown");
}
});
buttonRight.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
ButtonMove_Click("buttonRight");
}
});
/*pictureBomber.addComponentListener(new ComponentAdapter() {
@Override
public void componentResized(ComponentEvent e) {
super.componentResized(e);
pictureBomber.ChangeBorders(pictureBomber.getWidth(), pictureBomber.getHeight());
Draw();
}
});*/
GraphicsOutput.addComponentListener(new ComponentAdapter() {
@Override
public void componentResized(ComponentEvent e) {
super.componentResized(e);
if (pictureBomber == null || pictureBomber.getAirBomber() == null) return;
pictureBomber.ChangeBorders(GraphicsOutput.getWidth(), GraphicsOutput.getHeight());
GraphicsOutput.revalidate();
Draw();
}
});
buttonCreateModif.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
Random random = new Random();
pictureBomber = new DrawningWarplane(random.nextInt(100, 300), random.nextInt(1000, 3000),
new Color(random.nextInt(0, 256), random.nextInt(0, 256), random.nextInt(0, 256)),
new Color(random.nextInt(0, 256), random.nextInt(0, 256), random.nextInt(0, 256)),
random.nextBoolean(), random.nextBoolean());
SetData();
Draw();
}
});
}
}

6
IDrawningEngines.java Normal file
View File

@ -0,0 +1,6 @@
import java.awt.*;
public interface IDrawningEngines {
void SetNumEngines(int count);
void DrawningEngines(float _startPosX, float _startPosY, Graphics2D g2d, int _airBomberWidth, int _airBomberHeight);
}

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();
}

BIN
Images/ArrowDown.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 488 B

BIN
Images/ArrowLeft.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 493 B

BIN
Images/ArrowRight.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 491 B

BIN
Images/ArrowUp.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 484 B

13
Main.java Normal file
View File

@ -0,0 +1,13 @@
import javax.swing.*;
public class Main {
public static void main(String[] args) {
JFrame frame = new JFrame("Hard №1");
frame.setContentPane(new FormMap().Mainpanel);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setLocation(500, 200);
frame.pack();
frame.setSize(800, 600);
frame.setVisible(true);
}
}

49
SecondMap.java Normal file
View File

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

49
SimpleMap.java Normal file
View File

@ -0,0 +1,49 @@
import java.awt.*;
public class SimpleMap extends AbstractMap{
private Color barrierColor = Color.BLACK;
private 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 DrawBarrierPart(Graphics g, int i, int j)
{
Graphics2D g2d = (Graphics2D) g;
g2d.setPaint(barrierColor);
g2d.fillRect((int)Math.floor(j * _size_x), (int)Math.floor(i * _size_y),(int)Math.ceil(_size_x), (int)Math.ceil(_size_y));
}
@Override
protected void DrawRoadPart(Graphics g, int i, int j)
{
Graphics2D g2d = (Graphics2D) g;
g2d.setPaint(roadColor);
g2d.fillRect((int)Math.floor(j * _size_x), (int)Math.floor(i * _size_y),(int)Math.ceil(_size_x), (int)Math.ceil(_size_y));
}
}

48
ThirdMap.java Normal file
View File

@ -0,0 +1,48 @@
import java.awt.*;
public class ThirdMap extends AbstractMap
{
private Color barrierColor = Color.RED;
private Color roadColor = Color.GREEN;
@Override
protected void DrawBarrierPart(Graphics g, int i, int j)
{
Graphics2D g2d = (Graphics2D) g;
g2d.setPaint(barrierColor);
g2d.fillRect((int)(j * _size_x), (int)(i * _size_y), (int)_size_x, (int)_size_y);
}
@Override
protected void DrawRoadPart(Graphics g, int i, int j)
{
Graphics2D g2d = (Graphics2D) g;
g2d.setPaint(roadColor);
g.fillRect((int)(j * _size_x), (int)(i * _size_y), (int)_size_x, (int)_size_y);
}
@Override
protected void GenerateMap()
{
_map = new int[100][100];
_size_x = (float)_width / _map.length;
_size_y = (float)_height / _map[0].length;
int counter = 0;
for (int i = 0; i < _map.length; ++i)
{
for (int j = 0; j < _map[0].length; ++j)
{
_map[i][j] = _freeRoad;
}
}
while (counter < 40)
{
int x = _random.nextInt(0, 100);
int y = _random.nextInt(0, 100);
if (_map[x][y] == _freeRoad)
{
_map[x][y] = _barrier;
counter++;
}
}
}
}