Compare commits
4 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
dc25d1861e | ||
|
5d4d809278 | ||
|
8877e99dc0 | ||
|
36a0d583bd |
1
.gitignore
vendored
1
.gitignore
vendored
@ -76,4 +76,5 @@ fabric.properties
|
|||||||
|
|
||||||
# Android studio 3.1+ serialized cache file
|
# Android studio 3.1+ serialized cache file
|
||||||
.idea/caches/build_file_checksums.ser
|
.idea/caches/build_file_checksums.ser
|
||||||
|
.idea
|
||||||
|
|
||||||
|
11
ProjectBomber/ProjectBomber.iml
Normal file
11
ProjectBomber/ProjectBomber.iml
Normal 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$/src" isTestSource="false" />
|
||||||
|
</content>
|
||||||
|
<orderEntry type="jdk" jdkName="openjdk-20" jdkType="JavaSDK" />
|
||||||
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
|
</component>
|
||||||
|
</module>
|
82
ProjectBomber/src/ProjectBomber/AbstractStrategy.java
Normal file
82
ProjectBomber/src/ProjectBomber/AbstractStrategy.java
Normal file
@ -0,0 +1,82 @@
|
|||||||
|
package ProjectBomber;
|
||||||
|
|
||||||
|
public abstract class AbstractStrategy {
|
||||||
|
private IMoveableObject _moveableObject;
|
||||||
|
private Status _state = Status.NotInit;
|
||||||
|
protected int FieldWidth;
|
||||||
|
protected int FieldHeight;
|
||||||
|
|
||||||
|
public Status GetStatus() {
|
||||||
|
return _state;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SetData(IMoveableObject moveableObject, int width, int height) {
|
||||||
|
if (moveableObject == null) {
|
||||||
|
_state = Status.NotInit;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_state = Status.InProgress;
|
||||||
|
_moveableObject = moveableObject;
|
||||||
|
FieldWidth = width;
|
||||||
|
FieldHeight = height;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void MakeStep() {
|
||||||
|
if (_state != Status.InProgress) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (IsTargetDestination()) {
|
||||||
|
_state = Status.Finish;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
MoveToTarget();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected boolean MoveLeft() {
|
||||||
|
return MoveTo(EnumDirectionType.Left);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected boolean MoveRight() {
|
||||||
|
return MoveTo(EnumDirectionType.Right);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected boolean MoveUp() {
|
||||||
|
return MoveTo(EnumDirectionType.Up);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected boolean MoveDown() {
|
||||||
|
return MoveTo(EnumDirectionType.Down);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected ObjectParameters GetObjectParameters() {
|
||||||
|
if (_moveableObject == null)
|
||||||
|
return null;
|
||||||
|
return _moveableObject.GetObjectPosition();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected Integer GetStep() {
|
||||||
|
if (_state != Status.InProgress) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
if (_moveableObject == null)
|
||||||
|
return null;
|
||||||
|
return _moveableObject.GetStep();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected abstract void MoveToTarget();
|
||||||
|
|
||||||
|
protected abstract boolean IsTargetDestination();
|
||||||
|
|
||||||
|
private boolean MoveTo(EnumDirectionType directionType) {
|
||||||
|
if (_state != Status.InProgress) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (_moveableObject == null)
|
||||||
|
return false;
|
||||||
|
if (_moveableObject.CheckCanMove(directionType)) {
|
||||||
|
_moveableObject.MoveObject(directionType);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
41
ProjectBomber/src/ProjectBomber/DoubleParametrized.java
Normal file
41
ProjectBomber/src/ProjectBomber/DoubleParametrized.java
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
package ProjectBomber;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
|
public class DoubleParametrized<T extends EntityPlane, U extends IDrawingEngines> {
|
||||||
|
ArrayList<T> _entityPlanes;
|
||||||
|
ArrayList<U> _drawingEngines;
|
||||||
|
|
||||||
|
public DoubleParametrized() {
|
||||||
|
_entityPlanes = new ArrayList<>();
|
||||||
|
_drawingEngines = new ArrayList<>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Add(T entityPlaneObject) {
|
||||||
|
_entityPlanes.add(entityPlaneObject);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Add(U drawingEnginesObject) {
|
||||||
|
_drawingEngines.add(drawingEnginesObject);
|
||||||
|
}
|
||||||
|
|
||||||
|
public DrawingPlane GeneratePlane(int pictureWidth, int pictureHeight) {
|
||||||
|
Random random = new Random();
|
||||||
|
if (_entityPlanes.isEmpty()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
T entityPlane = _entityPlanes.get(random.nextInt(_entityPlanes.size()));
|
||||||
|
U drawingEngine = null;
|
||||||
|
if (!_drawingEngines.isEmpty()) {
|
||||||
|
drawingEngine = _drawingEngines.get(random.nextInt(_drawingEngines.size()));
|
||||||
|
}
|
||||||
|
DrawingPlane drawingPlane;
|
||||||
|
if (entityPlane instanceof EntityBomber) {
|
||||||
|
drawingPlane = new DrawingBomber((EntityBomber) entityPlane, drawingEngine, pictureWidth, pictureHeight);
|
||||||
|
} else {
|
||||||
|
drawingPlane = new DrawingPlane(entityPlane, drawingEngine, pictureWidth, pictureHeight);
|
||||||
|
}
|
||||||
|
return drawingPlane;
|
||||||
|
}
|
||||||
|
}
|
113
ProjectBomber/src/ProjectBomber/DrawingBomber.java
Normal file
113
ProjectBomber/src/ProjectBomber/DrawingBomber.java
Normal file
@ -0,0 +1,113 @@
|
|||||||
|
package ProjectBomber;
|
||||||
|
|
||||||
|
import java.awt.*;
|
||||||
|
|
||||||
|
public class DrawingBomber extends DrawingPlane {
|
||||||
|
public DrawingBomber(int speed, double weight, Color bodyColor,
|
||||||
|
Color additionalColor, boolean fuelTanks, boolean bombs,
|
||||||
|
int width, int height) {
|
||||||
|
super(speed, weight, bodyColor, width, height, 140, 90);
|
||||||
|
if (EntityPlane != null) {
|
||||||
|
EntityPlane = new EntityBomber(speed, weight, bodyColor, additionalColor, fuelTanks, bombs);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public DrawingBomber(EntityBomber entityBomber, IDrawingEngines drawingEngines, int width, int height) {
|
||||||
|
super(entityBomber, drawingEngines, width, height, 140, 90);
|
||||||
|
}
|
||||||
|
public void DrawTransport(Graphics g) {
|
||||||
|
if (EntityPlane == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!(EntityPlane instanceof EntityBomber EntityBomber)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Graphics2D g2d = (Graphics2D) g;
|
||||||
|
|
||||||
|
int bodyHeight = _planeHeight / 9;
|
||||||
|
|
||||||
|
Color blackColor = Color.BLACK;
|
||||||
|
Color redColor = Color.RED;
|
||||||
|
Color additionalColor = EntityBomber.AdditionalColor;
|
||||||
|
|
||||||
|
// Рисуем бомбы
|
||||||
|
if (EntityBomber.Bombs) {
|
||||||
|
Polygon bombTailPolygon = new Polygon();
|
||||||
|
bombTailPolygon.addPoint(_startPosX + _planeWidth / 2 - _planeWidth / 8 + bodyHeight * 3 - 5,
|
||||||
|
_startPosY + _planeHeight / 2 - bodyHeight / 2 - _planeHeight / 3 + bodyHeight / 2);
|
||||||
|
bombTailPolygon.addPoint(_startPosX + _planeWidth / 2 - _planeWidth / 8 + bodyHeight * 3 + 5,
|
||||||
|
_startPosY + _planeHeight / 2 - bodyHeight / 2 - _planeHeight / 3 + bodyHeight / 2 - 5);
|
||||||
|
bombTailPolygon.addPoint(_startPosX + _planeWidth / 2 - _planeWidth / 8 + bodyHeight * 3 + 5,
|
||||||
|
_startPosY + _planeHeight / 2 - bodyHeight / 2 - _planeHeight / 3 + bodyHeight / 2 + 5);
|
||||||
|
bombTailPolygon.addPoint(_startPosX + _planeWidth / 2 - _planeWidth / 8 + bodyHeight * 3 - 5,
|
||||||
|
_startPosY + _planeHeight / 2 - bodyHeight / 2 - _planeHeight / 3 + bodyHeight / 2);
|
||||||
|
|
||||||
|
g2d.setColor(additionalColor);
|
||||||
|
g2d.fillPolygon(bombTailPolygon);
|
||||||
|
g2d.setColor(blackColor);
|
||||||
|
g2d.drawPolygon(bombTailPolygon);
|
||||||
|
|
||||||
|
bombTailPolygon.translate(0, (int) (_planeHeight - 2 * (_planeHeight / 2 - bodyHeight / 2 - _planeHeight / 3 + bodyHeight / 2 - 5) - bombTailPolygon.getBounds2D().getHeight()));
|
||||||
|
|
||||||
|
g2d.setColor(additionalColor);
|
||||||
|
g2d.fillPolygon(bombTailPolygon);
|
||||||
|
g2d.setColor(blackColor);
|
||||||
|
g2d.drawPolygon(bombTailPolygon);
|
||||||
|
|
||||||
|
g2d.setColor(additionalColor);
|
||||||
|
g2d.fillOval(
|
||||||
|
_startPosX + _planeWidth / 2 - _planeWidth / 8,
|
||||||
|
_startPosY + _planeHeight / 2 - bodyHeight / 2 - _planeHeight / 3,
|
||||||
|
bodyHeight * 3,
|
||||||
|
bodyHeight);
|
||||||
|
|
||||||
|
g2d.fillOval(
|
||||||
|
_startPosX + _planeWidth / 2 - _planeWidth / 8,
|
||||||
|
_startPosY + _planeHeight / 2 - bodyHeight / 2 + _planeHeight / 3,
|
||||||
|
bodyHeight * 3,
|
||||||
|
bodyHeight);
|
||||||
|
|
||||||
|
g2d.setColor(blackColor);
|
||||||
|
g2d.drawOval(
|
||||||
|
_startPosX + _planeWidth / 2 - _planeWidth / 8,
|
||||||
|
_startPosY + _planeHeight / 2 - bodyHeight / 2 - _planeHeight / 3,
|
||||||
|
bodyHeight * 3,
|
||||||
|
bodyHeight);
|
||||||
|
g2d.drawOval(
|
||||||
|
_startPosX + _planeWidth / 2 - _planeWidth / 8,
|
||||||
|
_startPosY + _planeHeight / 2 - bodyHeight / 2 + _planeHeight / 3,
|
||||||
|
bodyHeight * 3,
|
||||||
|
bodyHeight);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Рисуем топливные баки
|
||||||
|
if (EntityBomber.FuelTanks) {
|
||||||
|
int fuelTanksWidth = bodyHeight * 2;
|
||||||
|
int fuelTanksHeight = bodyHeight / 2;
|
||||||
|
g2d.setColor(additionalColor);
|
||||||
|
g2d.fillRect(
|
||||||
|
_startPosX + _planeWidth / 2 - _planeWidth / 7,
|
||||||
|
_startPosY + _planeHeight / 2 - bodyHeight - bodyHeight / 2,
|
||||||
|
fuelTanksWidth,
|
||||||
|
fuelTanksHeight);
|
||||||
|
g2d.fillRect(
|
||||||
|
_startPosX + _planeWidth / 2 - _planeWidth / 7,
|
||||||
|
_startPosY + _planeHeight / 2 + bodyHeight / 2 + bodyHeight / 2,
|
||||||
|
fuelTanksWidth,
|
||||||
|
fuelTanksHeight);
|
||||||
|
g2d.setColor(blackColor);
|
||||||
|
g2d.drawRect(
|
||||||
|
_startPosX + _planeWidth / 2 - _planeWidth / 7,
|
||||||
|
_startPosY + _planeHeight / 2 - bodyHeight - bodyHeight / 2,
|
||||||
|
fuelTanksWidth,
|
||||||
|
fuelTanksHeight);
|
||||||
|
g2d.drawRect(
|
||||||
|
_startPosX + _planeWidth / 2 - _planeWidth / 7,
|
||||||
|
_startPosY + _planeHeight / 2 + bodyHeight / 2 + bodyHeight / 2,
|
||||||
|
fuelTanksWidth,
|
||||||
|
fuelTanksHeight);
|
||||||
|
}
|
||||||
|
|
||||||
|
super.DrawTransport(g);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
31
ProjectBomber/src/ProjectBomber/DrawingEnginesEllipse.java
Normal file
31
ProjectBomber/src/ProjectBomber/DrawingEnginesEllipse.java
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
package ProjectBomber;
|
||||||
|
|
||||||
|
import java.awt.*;
|
||||||
|
|
||||||
|
public class DrawingEnginesEllipse implements IDrawingEngines {
|
||||||
|
private EnumEnginesCount _enumEnginesCount;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void SetEnumEnginesCount(int enginesCount) {
|
||||||
|
for (EnumEnginesCount val : EnumEnginesCount.values()) {
|
||||||
|
if (val.count == enginesCount) {
|
||||||
|
this._enumEnginesCount = val;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this._enumEnginesCount = EnumEnginesCount.Two;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public EnumEnginesCount GetEnumEnginesCount() {
|
||||||
|
return _enumEnginesCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void DrawEngine(Graphics2D g2d, Color color, int x, int y, int w, int h) {
|
||||||
|
g2d.setColor(Color.WHITE);
|
||||||
|
g2d.fillOval(x, y, w, h);
|
||||||
|
g2d.setColor(Color.BLACK);
|
||||||
|
g2d.drawOval(x, y, w, h);
|
||||||
|
}
|
||||||
|
}
|
39
ProjectBomber/src/ProjectBomber/DrawingEnginesPyramid.java
Normal file
39
ProjectBomber/src/ProjectBomber/DrawingEnginesPyramid.java
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
package ProjectBomber;
|
||||||
|
|
||||||
|
import java.awt.*;
|
||||||
|
|
||||||
|
public class DrawingEnginesPyramid implements IDrawingEngines {
|
||||||
|
private EnumEnginesCount _enumEnginesCount;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void SetEnumEnginesCount(int enginesCount) {
|
||||||
|
for (EnumEnginesCount val : EnumEnginesCount.values()) {
|
||||||
|
if (val.count == enginesCount) {
|
||||||
|
this._enumEnginesCount = val;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this._enumEnginesCount = EnumEnginesCount.Two;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public EnumEnginesCount GetEnumEnginesCount() {
|
||||||
|
return _enumEnginesCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void DrawEngine(Graphics2D g2d, Color color, int x, int y, int w, int h) {
|
||||||
|
Polygon enginePolygon = new Polygon();
|
||||||
|
enginePolygon.addPoint(x, y + h / 2);
|
||||||
|
enginePolygon.addPoint(x + w / 10, y);
|
||||||
|
enginePolygon.addPoint(x + w - w / 2, y + h / 2);
|
||||||
|
enginePolygon.addPoint(x + w, y);
|
||||||
|
enginePolygon.addPoint(x + w, y + h);
|
||||||
|
enginePolygon.addPoint(x + w - w / 2, y + h / 2);
|
||||||
|
enginePolygon.addPoint(x + w / 10, y + h);
|
||||||
|
g2d.setColor(Color.WHITE);
|
||||||
|
g2d.fillPolygon(enginePolygon);
|
||||||
|
g2d.setColor(Color.BLACK);
|
||||||
|
g2d.drawPolygon(enginePolygon);
|
||||||
|
}
|
||||||
|
}
|
33
ProjectBomber/src/ProjectBomber/DrawingEnginesSimple.java
Normal file
33
ProjectBomber/src/ProjectBomber/DrawingEnginesSimple.java
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
package ProjectBomber;
|
||||||
|
|
||||||
|
import java.awt.*;
|
||||||
|
|
||||||
|
public class DrawingEnginesSimple implements IDrawingEngines {
|
||||||
|
private EnumEnginesCount _enumEnginesCount;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void SetEnumEnginesCount(int enginesCount) {
|
||||||
|
for (EnumEnginesCount val : EnumEnginesCount.values()) {
|
||||||
|
if (val.count == enginesCount) {
|
||||||
|
this._enumEnginesCount = val;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this._enumEnginesCount = EnumEnginesCount.Two;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public EnumEnginesCount GetEnumEnginesCount() {
|
||||||
|
return _enumEnginesCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void DrawEngine(Graphics2D g2d, Color color, int x, int y, int w, int h) {
|
||||||
|
g2d.setColor(Color.WHITE);
|
||||||
|
g2d.fillRect(x, y, w, h);
|
||||||
|
g2d.setColor(Color.BLACK);
|
||||||
|
g2d.drawRect(x, y, w, h);
|
||||||
|
g2d.setColor(color);
|
||||||
|
g2d.fillRect(x, y, 6, h);
|
||||||
|
}
|
||||||
|
}
|
43
ProjectBomber/src/ProjectBomber/DrawingObjectPlane.java
Normal file
43
ProjectBomber/src/ProjectBomber/DrawingObjectPlane.java
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
package ProjectBomber;
|
||||||
|
|
||||||
|
public class DrawingObjectPlane implements IMoveableObject {
|
||||||
|
private DrawingPlane _drawingPlane;
|
||||||
|
|
||||||
|
public DrawingObjectPlane(DrawingPlane drawingPlane) {
|
||||||
|
_drawingPlane = drawingPlane;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ObjectParameters GetObjectPosition() {
|
||||||
|
if (_drawingPlane == null || _drawingPlane.EntityPlane == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return new ObjectParameters(
|
||||||
|
_drawingPlane.GetPosX(),
|
||||||
|
_drawingPlane.GetPosY(),
|
||||||
|
_drawingPlane.GetWidth(),
|
||||||
|
_drawingPlane.GetHeight()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int GetStep() {
|
||||||
|
if (_drawingPlane != null)
|
||||||
|
if (_drawingPlane.EntityPlane != null)
|
||||||
|
return (int) _drawingPlane.EntityPlane.Step();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean CheckCanMove(EnumDirectionType direction) {
|
||||||
|
if (_drawingPlane == null)
|
||||||
|
return false;
|
||||||
|
return _drawingPlane.CanMove(direction);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void MoveObject(EnumDirectionType direction) {
|
||||||
|
if (_drawingPlane != null)
|
||||||
|
_drawingPlane.MoveTransport(direction);
|
||||||
|
}
|
||||||
|
}
|
200
ProjectBomber/src/ProjectBomber/DrawingPlane.java
Normal file
200
ProjectBomber/src/ProjectBomber/DrawingPlane.java
Normal file
@ -0,0 +1,200 @@
|
|||||||
|
package ProjectBomber;
|
||||||
|
|
||||||
|
import java.awt.*;
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
|
public class DrawingPlane {
|
||||||
|
public EntityPlane EntityPlane;
|
||||||
|
protected IDrawingEngines _drawingEngines;
|
||||||
|
protected int _pictureWidth;
|
||||||
|
protected int _pictureHeight;
|
||||||
|
protected int _startPosX;
|
||||||
|
protected int _startPosY;
|
||||||
|
protected int _planeWidth = 110;
|
||||||
|
protected int _planeHeight = 110;
|
||||||
|
|
||||||
|
public int GetPosX() {
|
||||||
|
return _startPosX;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int GetPosY() {
|
||||||
|
return _startPosY;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int GetWidth() {
|
||||||
|
return _planeWidth;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int GetHeight() {
|
||||||
|
return _planeHeight;
|
||||||
|
}
|
||||||
|
|
||||||
|
public DrawingPlane(int speed, double weight, Color bodyColor, int width, int height) {
|
||||||
|
if (width < _planeWidth && height < _planeHeight) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_pictureWidth = width;
|
||||||
|
_pictureHeight = height;
|
||||||
|
EntityPlane = new EntityPlane(speed, weight, bodyColor);
|
||||||
|
Random random = new Random();
|
||||||
|
int drawingEnginesType = random.nextInt(0, 3);
|
||||||
|
if (drawingEnginesType == 0)
|
||||||
|
_drawingEngines = new DrawingEnginesSimple();
|
||||||
|
else if (drawingEnginesType == 1)
|
||||||
|
_drawingEngines = new DrawingEnginesPyramid();
|
||||||
|
else if (drawingEnginesType == 2)
|
||||||
|
_drawingEngines = new DrawingEnginesEllipse();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected DrawingPlane(int speed, double weight, Color bodyColor,
|
||||||
|
int width, int height, int planeWidth, int planeHeight) {
|
||||||
|
this(speed, weight, bodyColor, width, height);
|
||||||
|
_planeWidth = planeWidth;
|
||||||
|
_planeHeight = planeHeight;
|
||||||
|
}
|
||||||
|
protected DrawingPlane(EntityPlane entityPlane, IDrawingEngines drawingEngines, int width, int height) {
|
||||||
|
EntityPlane = entityPlane;
|
||||||
|
_drawingEngines = drawingEngines;
|
||||||
|
_pictureWidth = width;
|
||||||
|
_pictureHeight = height;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected DrawingPlane(EntityPlane entityPlane, IDrawingEngines drawingEngines, int width, int height, int planeWidth, int planeHeight) {
|
||||||
|
this(entityPlane, drawingEngines, width, height);
|
||||||
|
_planeWidth = planeWidth;
|
||||||
|
_planeHeight = planeHeight;
|
||||||
|
}
|
||||||
|
public void SetEnginesCount(int enginesCount) {
|
||||||
|
_drawingEngines.SetEnumEnginesCount(enginesCount);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean CanMove(EnumDirectionType direction) {
|
||||||
|
if (EntityPlane == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
boolean result = false;
|
||||||
|
switch (direction) {
|
||||||
|
case Up -> result = _startPosY - EntityPlane.Step() > 0;
|
||||||
|
case Down -> result = _startPosY + _planeHeight + EntityPlane.Step() < _pictureHeight;
|
||||||
|
case Left -> result = _startPosX - EntityPlane.Step() > 0;
|
||||||
|
case Right -> result = _startPosX + _planeWidth + EntityPlane.Step() < _pictureWidth;
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SetPosition(int x, int y) {
|
||||||
|
if (x < 0) {
|
||||||
|
x = 0;
|
||||||
|
} else if (x > _pictureWidth - _planeWidth) {
|
||||||
|
x = _pictureWidth - _planeWidth;
|
||||||
|
}
|
||||||
|
_startPosX = x;
|
||||||
|
|
||||||
|
if (y < 0) {
|
||||||
|
y = 0;
|
||||||
|
} else if (y > _pictureHeight - _planeHeight) {
|
||||||
|
y = _pictureHeight - _planeHeight;
|
||||||
|
}
|
||||||
|
_startPosY = y;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void MoveTransport(EnumDirectionType direction) {
|
||||||
|
if (EntityPlane == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
switch (direction) {
|
||||||
|
case Up -> {
|
||||||
|
if (_startPosY - EntityPlane.Step() >= 0) {
|
||||||
|
_startPosY -= (int) EntityPlane.Step();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
case Down -> {
|
||||||
|
if (_startPosY + _planeHeight + EntityPlane.Step() <= _pictureHeight) {
|
||||||
|
_startPosY += (int) EntityPlane.Step();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
case Left -> {
|
||||||
|
if (_startPosX - EntityPlane.Step() >= 0) {
|
||||||
|
_startPosX -= (int) EntityPlane.Step();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
case Right -> {
|
||||||
|
if (_startPosX + _planeWidth + EntityPlane.Step() <= _pictureWidth) {
|
||||||
|
_startPosX += (int) EntityPlane.Step();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void DrawTransport(Graphics g) {
|
||||||
|
if (EntityPlane == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Graphics2D g2d = (Graphics2D) g;
|
||||||
|
g2d.setStroke(new BasicStroke(2));
|
||||||
|
Color bodyColor = EntityPlane.BodyColor;
|
||||||
|
Color blackColor = Color.BLACK;
|
||||||
|
|
||||||
|
// Длина фюзеляжа
|
||||||
|
int bodyHeight = _planeHeight / 8;
|
||||||
|
int bodyWidth = _planeWidth - _planeWidth / 7;
|
||||||
|
|
||||||
|
_drawingEngines.DrawEngines(g, bodyColor, _startPosX, _startPosY, _planeWidth, _planeHeight);
|
||||||
|
|
||||||
|
// Рисуем нос
|
||||||
|
Polygon cockPitPolygon = new Polygon();
|
||||||
|
cockPitPolygon.addPoint(_startPosX, _startPosY + _planeHeight / 2);
|
||||||
|
cockPitPolygon.addPoint(_startPosX + _planeWidth / 8, _startPosY + _planeHeight / 2 - bodyHeight / 2);
|
||||||
|
cockPitPolygon.addPoint(_startPosX + _planeWidth / 8, _startPosY + _planeHeight / 2 + bodyHeight / 2);
|
||||||
|
|
||||||
|
g2d.setColor(blackColor);
|
||||||
|
g2d.fillPolygon(cockPitPolygon);
|
||||||
|
|
||||||
|
// Рисуем крылья
|
||||||
|
Polygon wingsPolygon = new Polygon();
|
||||||
|
wingsPolygon.addPoint(_startPosX + _planeWidth / 2, _startPosY);
|
||||||
|
wingsPolygon.addPoint(_startPosX + _planeWidth / 2 + _planeWidth / 15, _startPosY);
|
||||||
|
wingsPolygon.addPoint(_startPosX + _planeWidth / 2 + _planeWidth / 6, _startPosY + _planeHeight / 2);
|
||||||
|
wingsPolygon.addPoint(_startPosX + _planeWidth / 2 + _planeWidth / 15, _startPosY + _planeHeight);
|
||||||
|
wingsPolygon.addPoint(_startPosX + _planeWidth / 2, _startPosY + _planeHeight);
|
||||||
|
|
||||||
|
g2d.setColor(bodyColor);
|
||||||
|
g.fillPolygon(wingsPolygon);
|
||||||
|
g2d.setColor(blackColor);
|
||||||
|
g.drawPolygon(wingsPolygon);
|
||||||
|
|
||||||
|
// Рисуем хвостовое оперение
|
||||||
|
Polygon tailPolygon = new Polygon();
|
||||||
|
tailPolygon.addPoint(_startPosX + _planeWidth, _startPosY + _planeHeight / 2 - _planeHeight / 3);
|
||||||
|
tailPolygon.addPoint(_startPosX + bodyWidth, _startPosY + _planeHeight / 2 - _planeHeight / 8);
|
||||||
|
tailPolygon.addPoint(_startPosX + bodyWidth, _startPosY + _planeHeight / 2 + _planeHeight / 8);
|
||||||
|
tailPolygon.addPoint(_startPosX + _planeWidth, _startPosY + _planeHeight / 2 + _planeHeight / 3);
|
||||||
|
|
||||||
|
g2d.setColor(bodyColor);
|
||||||
|
g.fillPolygon(tailPolygon);
|
||||||
|
g2d.setColor(blackColor);
|
||||||
|
g.drawPolygon(tailPolygon);
|
||||||
|
|
||||||
|
// Рисуем фюзеляж
|
||||||
|
g2d.setColor(bodyColor);
|
||||||
|
g2d.fillRect(
|
||||||
|
_startPosX + _planeWidth / 8,
|
||||||
|
_startPosY + _planeHeight / 2 - bodyHeight / 2,
|
||||||
|
bodyWidth,
|
||||||
|
bodyHeight
|
||||||
|
);
|
||||||
|
g2d.setColor(blackColor);
|
||||||
|
g2d.drawRect(
|
||||||
|
_startPosX + _planeWidth / 8,
|
||||||
|
_startPosY + _planeHeight / 2 - bodyHeight / 2,
|
||||||
|
bodyWidth,
|
||||||
|
bodyHeight
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public IMoveableObject GetMoveableObject() {
|
||||||
|
return new DrawingObjectPlane(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
;
|
||||||
|
}
|
17
ProjectBomber/src/ProjectBomber/EntityBomber.java
Normal file
17
ProjectBomber/src/ProjectBomber/EntityBomber.java
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
package ProjectBomber;
|
||||||
|
|
||||||
|
import java.awt.*;
|
||||||
|
|
||||||
|
public class EntityBomber extends EntityPlane {
|
||||||
|
public Color AdditionalColor;
|
||||||
|
public boolean FuelTanks;
|
||||||
|
public boolean Bombs;
|
||||||
|
|
||||||
|
public EntityBomber(int speed, double weight, Color bodyColor,
|
||||||
|
Color additionalColor, boolean fuelTanks, boolean bombs) {
|
||||||
|
super(speed, weight, bodyColor);
|
||||||
|
AdditionalColor = additionalColor;
|
||||||
|
FuelTanks = fuelTanks;
|
||||||
|
Bombs = bombs;
|
||||||
|
}
|
||||||
|
}
|
19
ProjectBomber/src/ProjectBomber/EntityPlane.java
Normal file
19
ProjectBomber/src/ProjectBomber/EntityPlane.java
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
package ProjectBomber;
|
||||||
|
|
||||||
|
import java.awt.*;
|
||||||
|
|
||||||
|
public class EntityPlane {
|
||||||
|
public int Speed;
|
||||||
|
public double Weight;
|
||||||
|
public Color BodyColor;
|
||||||
|
|
||||||
|
public double Step() {
|
||||||
|
return (double) Speed * 250 / Weight;
|
||||||
|
}
|
||||||
|
|
||||||
|
public EntityPlane(int speed, double weight, Color bodyColor) {
|
||||||
|
Speed = speed;
|
||||||
|
Weight = weight;
|
||||||
|
BodyColor = bodyColor;
|
||||||
|
}
|
||||||
|
}
|
5
ProjectBomber/src/ProjectBomber/EnumDirectionType.java
Normal file
5
ProjectBomber/src/ProjectBomber/EnumDirectionType.java
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
package ProjectBomber;
|
||||||
|
|
||||||
|
public enum EnumDirectionType {
|
||||||
|
Up, Down, Left, Right
|
||||||
|
}
|
11
ProjectBomber/src/ProjectBomber/EnumEnginesCount.java
Normal file
11
ProjectBomber/src/ProjectBomber/EnumEnginesCount.java
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
package ProjectBomber;
|
||||||
|
|
||||||
|
public enum EnumEnginesCount {
|
||||||
|
Two(2),
|
||||||
|
Four(4),
|
||||||
|
Six(6);
|
||||||
|
public final int count;
|
||||||
|
EnumEnginesCount(int count) {
|
||||||
|
this.count = count;
|
||||||
|
}
|
||||||
|
}
|
124
ProjectBomber/src/ProjectBomber/FormBomber.form
Normal file
124
ProjectBomber/src/ProjectBomber/FormBomber.form
Normal file
@ -0,0 +1,124 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="ProjectBomber.FormBomber">
|
||||||
|
<grid id="27dc6" binding="pictureBox" layout-manager="GridLayoutManager" row-count="5" column-count="7" 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="900" height="500"/>
|
||||||
|
</constraints>
|
||||||
|
<properties>
|
||||||
|
<minimumSize width="900" height="500"/>
|
||||||
|
<preferredSize width="900" height="500"/>
|
||||||
|
</properties>
|
||||||
|
<border type="none"/>
|
||||||
|
<children>
|
||||||
|
<component id="35f01" class="javax.swing.JButton" binding="buttonCreateBomber">
|
||||||
|
<constraints>
|
||||||
|
<grid row="4" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
<properties>
|
||||||
|
<text value="Создать бомбардировщик"/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
<vspacer id="ce5ea">
|
||||||
|
<constraints>
|
||||||
|
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
</vspacer>
|
||||||
|
<component id="ac2ff" class="javax.swing.JButton" binding="buttonDown">
|
||||||
|
<constraints>
|
||||||
|
<grid row="4" column="5" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="0" indent="0" use-parent-layout="false">
|
||||||
|
<minimum-size width="30" height="30"/>
|
||||||
|
<preferred-size width="30" height="30"/>
|
||||||
|
<maximum-size width="30" height="30"/>
|
||||||
|
</grid>
|
||||||
|
</constraints>
|
||||||
|
<properties>
|
||||||
|
<hideActionText value="true"/>
|
||||||
|
<horizontalTextPosition value="0"/>
|
||||||
|
<icon value="ProjectBomber/img/arrowDOWN.png"/>
|
||||||
|
<text value=""/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
<component id="b1382" class="javax.swing.JButton" binding="buttonUp">
|
||||||
|
<constraints>
|
||||||
|
<grid row="3" column="5" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="0" indent="0" use-parent-layout="false">
|
||||||
|
<minimum-size width="30" height="30"/>
|
||||||
|
<preferred-size width="30" height="30"/>
|
||||||
|
<maximum-size width="30" height="30"/>
|
||||||
|
</grid>
|
||||||
|
</constraints>
|
||||||
|
<properties>
|
||||||
|
<hideActionText value="true"/>
|
||||||
|
<horizontalTextPosition value="0"/>
|
||||||
|
<icon value="ProjectBomber/img/arrowUP.png"/>
|
||||||
|
<text value=""/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
<component id="8b2ff" class="javax.swing.JButton" binding="buttonLeft">
|
||||||
|
<constraints>
|
||||||
|
<grid row="4" column="4" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="0" indent="0" use-parent-layout="false">
|
||||||
|
<minimum-size width="30" height="30"/>
|
||||||
|
<preferred-size width="30" height="30"/>
|
||||||
|
<maximum-size width="30" height="30"/>
|
||||||
|
</grid>
|
||||||
|
</constraints>
|
||||||
|
<properties>
|
||||||
|
<hideActionText value="true"/>
|
||||||
|
<horizontalTextPosition value="0"/>
|
||||||
|
<icon value="ProjectBomber/img/arrowLEFT.png"/>
|
||||||
|
<text value=""/>
|
||||||
|
<verticalAlignment value="0"/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
<component id="25771" class="javax.swing.JButton" binding="buttonRight">
|
||||||
|
<constraints>
|
||||||
|
<grid row="4" column="6" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="0" indent="0" use-parent-layout="false">
|
||||||
|
<minimum-size width="30" height="30"/>
|
||||||
|
<preferred-size width="30" height="30"/>
|
||||||
|
<maximum-size width="30" height="30"/>
|
||||||
|
</grid>
|
||||||
|
</constraints>
|
||||||
|
<properties>
|
||||||
|
<horizontalTextPosition value="0"/>
|
||||||
|
<icon value="ProjectBomber/img/arrowRIGHT.png"/>
|
||||||
|
<text value=""/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
<component id="57f51" class="javax.swing.JButton" binding="buttonCreatePlane">
|
||||||
|
<constraints>
|
||||||
|
<grid row="4" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
<properties>
|
||||||
|
<text value="Создать самолет"/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
<hspacer id="80ae3">
|
||||||
|
<constraints>
|
||||||
|
<grid row="4" column="3" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
</hspacer>
|
||||||
|
<component id="9ddde" class="javax.swing.JComboBox" binding="comboBoxStrategy" custom-create="true">
|
||||||
|
<constraints>
|
||||||
|
<grid row="0" column="4" row-span="1" col-span="3" vsize-policy="0" hsize-policy="2" anchor="8" fill="1" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
<properties/>
|
||||||
|
</component>
|
||||||
|
<component id="848b4" class="javax.swing.JButton" binding="buttonStep">
|
||||||
|
<constraints>
|
||||||
|
<grid row="1" column="4" row-span="1" col-span="3" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
<properties>
|
||||||
|
<text value="Шаг"/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
<component id="ddb72" class="javax.swing.JButton" binding="buttonSelectPlane">
|
||||||
|
<constraints>
|
||||||
|
<grid row="4" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
<properties>
|
||||||
|
<text value="Выбрать"/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
</children>
|
||||||
|
</grid>
|
||||||
|
</form>
|
144
ProjectBomber/src/ProjectBomber/FormBomber.java
Normal file
144
ProjectBomber/src/ProjectBomber/FormBomber.java
Normal file
@ -0,0 +1,144 @@
|
|||||||
|
package ProjectBomber;
|
||||||
|
|
||||||
|
import javax.swing.*;
|
||||||
|
import java.awt.*;
|
||||||
|
import java.util.Random;
|
||||||
|
import java.awt.event.ActionListener;
|
||||||
|
import javax.swing.JColorChooser;
|
||||||
|
|
||||||
|
public class FormBomber extends JDialog{
|
||||||
|
public DrawingPlane _drawingPlane;
|
||||||
|
AbstractStrategy _abstractStrategy;
|
||||||
|
private JButton buttonCreateBomber;
|
||||||
|
private JPanel pictureBox;
|
||||||
|
private JButton buttonDown;
|
||||||
|
private JButton buttonUp;
|
||||||
|
private JButton buttonLeft;
|
||||||
|
private JButton buttonRight;
|
||||||
|
private JButton buttonCreatePlane;
|
||||||
|
private JComboBox comboBoxStrategy;
|
||||||
|
private JButton buttonStep;
|
||||||
|
public JButton buttonSelectPlane;
|
||||||
|
|
||||||
|
public JPanel getPictureBox() {
|
||||||
|
return pictureBox;
|
||||||
|
}
|
||||||
|
|
||||||
|
public FormBomber() {
|
||||||
|
buttonUp.setName("buttonUp");
|
||||||
|
buttonDown.setName("buttonDown");
|
||||||
|
buttonLeft.setName("buttonLeft");
|
||||||
|
buttonRight.setName("buttonRight");
|
||||||
|
|
||||||
|
|
||||||
|
buttonCreateBomber.addActionListener(e -> {
|
||||||
|
Random random = new Random();
|
||||||
|
|
||||||
|
Color color = JColorChooser.showDialog(this.pictureBox, "Выберите цвет", Color.BLACK);
|
||||||
|
Color additionalColor = JColorChooser.showDialog(this.pictureBox, "Выберите дополнительный цвет", Color.BLACK);
|
||||||
|
|
||||||
|
_drawingPlane = new DrawingBomber(
|
||||||
|
random.nextInt(100, 300),
|
||||||
|
random.nextInt(1000, 3000),
|
||||||
|
color,
|
||||||
|
additionalColor,
|
||||||
|
random.nextBoolean(),
|
||||||
|
random.nextBoolean(),
|
||||||
|
pictureBox.getWidth(),
|
||||||
|
pictureBox.getHeight()
|
||||||
|
);
|
||||||
|
|
||||||
|
_drawingPlane.SetEnginesCount(random.nextInt(2, 7));
|
||||||
|
_drawingPlane.SetPosition(random.nextInt(10, 100), random.nextInt(10, 100));
|
||||||
|
|
||||||
|
Draw();
|
||||||
|
});
|
||||||
|
|
||||||
|
buttonCreatePlane.addActionListener(e -> {
|
||||||
|
Random random = new Random();
|
||||||
|
Color color = JColorChooser.showDialog(this.pictureBox, "Выберите цвет", Color.BLACK);
|
||||||
|
_drawingPlane = new DrawingPlane(
|
||||||
|
random.nextInt(100, 300),
|
||||||
|
random.nextInt(1000, 3000),
|
||||||
|
color,
|
||||||
|
pictureBox.getWidth(),
|
||||||
|
pictureBox.getHeight()
|
||||||
|
);
|
||||||
|
|
||||||
|
_drawingPlane.SetEnginesCount(random.nextInt(2, 7));
|
||||||
|
_drawingPlane.SetPosition(random.nextInt(10, 100), random.nextInt(10, 100));
|
||||||
|
|
||||||
|
Draw();
|
||||||
|
});
|
||||||
|
|
||||||
|
buttonStep.addActionListener(e -> {
|
||||||
|
if (_drawingPlane == null)
|
||||||
|
return;
|
||||||
|
if (comboBoxStrategy.isEnabled()) {
|
||||||
|
_abstractStrategy = null;
|
||||||
|
int comboBoxStrategySelectedIndex = comboBoxStrategy.getSelectedIndex();
|
||||||
|
if (comboBoxStrategySelectedIndex == 0) {
|
||||||
|
_abstractStrategy = new MoveToCenter();
|
||||||
|
} else if (comboBoxStrategySelectedIndex == 1) {
|
||||||
|
_abstractStrategy = new MoveToRightBottom();
|
||||||
|
}
|
||||||
|
if (_abstractStrategy == null)
|
||||||
|
return;
|
||||||
|
_abstractStrategy.SetData(new DrawingObjectPlane(_drawingPlane), pictureBox.getWidth(), pictureBox.getHeight());
|
||||||
|
comboBoxStrategy.setEnabled(false);
|
||||||
|
}
|
||||||
|
if (_abstractStrategy == null)
|
||||||
|
return;
|
||||||
|
_abstractStrategy.MakeStep();
|
||||||
|
Draw();
|
||||||
|
if (_abstractStrategy.GetStatus() == Status.Finish) {
|
||||||
|
comboBoxStrategy.setEnabled(true);
|
||||||
|
_abstractStrategy = null;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
ActionListener buttonMoveClickedListener = e -> {
|
||||||
|
String buttonName = ((JButton) e.getSource()).getName();
|
||||||
|
|
||||||
|
switch (buttonName) {
|
||||||
|
case ("buttonUp") -> {
|
||||||
|
_drawingPlane.MoveTransport(EnumDirectionType.Up);
|
||||||
|
}
|
||||||
|
case ("buttonDown") -> {
|
||||||
|
_drawingPlane.MoveTransport(EnumDirectionType.Down);
|
||||||
|
}
|
||||||
|
case ("buttonLeft") -> {
|
||||||
|
_drawingPlane.MoveTransport(EnumDirectionType.Left);
|
||||||
|
}
|
||||||
|
case ("buttonRight") -> {
|
||||||
|
_drawingPlane.MoveTransport(EnumDirectionType.Right);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Draw();
|
||||||
|
};
|
||||||
|
|
||||||
|
buttonUp.addActionListener(buttonMoveClickedListener);
|
||||||
|
buttonDown.addActionListener(buttonMoveClickedListener);
|
||||||
|
buttonLeft.addActionListener(buttonMoveClickedListener);
|
||||||
|
buttonRight.addActionListener(buttonMoveClickedListener);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Draw() {
|
||||||
|
if (_drawingPlane == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Graphics g = pictureBox.getGraphics();
|
||||||
|
pictureBox.paint(g);
|
||||||
|
_drawingPlane.DrawTransport(g);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void createUIComponents() {
|
||||||
|
String[] strategiesList = {
|
||||||
|
"MoveToCenter",
|
||||||
|
"MoveToRightBottom"
|
||||||
|
};
|
||||||
|
comboBoxStrategy = new JComboBox(strategiesList);
|
||||||
|
}
|
||||||
|
}
|
31
ProjectBomber/src/ProjectBomber/FormDoubleParametrized.form
Normal file
31
ProjectBomber/src/ProjectBomber/FormDoubleParametrized.form
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="ProjectBomber.FormDoubleParametrized">
|
||||||
|
<grid id="27dc6" binding="PictureBox" layout-manager="GridLayoutManager" row-count="2" column-count="2" 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/>
|
||||||
|
<border type="none"/>
|
||||||
|
<children>
|
||||||
|
<component id="d5201" class="javax.swing.JButton" binding="buttonGeneratePlane">
|
||||||
|
<constraints>
|
||||||
|
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
<properties>
|
||||||
|
<text value="Сгенерировать"/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
<hspacer id="25591">
|
||||||
|
<constraints>
|
||||||
|
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
</hspacer>
|
||||||
|
<vspacer id="1328a">
|
||||||
|
<constraints>
|
||||||
|
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
</vspacer>
|
||||||
|
</children>
|
||||||
|
</grid>
|
||||||
|
</form>
|
78
ProjectBomber/src/ProjectBomber/FormDoubleParametrized.java
Normal file
78
ProjectBomber/src/ProjectBomber/FormDoubleParametrized.java
Normal file
@ -0,0 +1,78 @@
|
|||||||
|
package ProjectBomber;
|
||||||
|
|
||||||
|
import javax.swing.*;
|
||||||
|
import java.awt.*;
|
||||||
|
import java.awt.event.ActionEvent;
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
|
public class FormDoubleParametrized {
|
||||||
|
private JPanel PictureBox;
|
||||||
|
private JButton buttonGeneratePlane;
|
||||||
|
Random _random;
|
||||||
|
DrawingPlane _drawingPlane;
|
||||||
|
DoubleParametrized<EntityPlane, IDrawingEngines> _doubleParametrized;
|
||||||
|
|
||||||
|
public JPanel getPictureBox() {
|
||||||
|
return PictureBox;
|
||||||
|
}
|
||||||
|
|
||||||
|
public FormDoubleParametrized() {
|
||||||
|
_random = new Random();
|
||||||
|
_doubleParametrized = new DoubleParametrized<>();
|
||||||
|
PictureBox.setPreferredSize(new Dimension(400, 400));
|
||||||
|
buttonGeneratePlane.addActionListener(this::buttonGeneratePlaneClicked);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void addRandomEntityPlane() {
|
||||||
|
EntityPlane entityPlane;
|
||||||
|
if (_random.nextBoolean()) {
|
||||||
|
entityPlane = new EntityPlane(
|
||||||
|
_random.nextInt(100, 300),
|
||||||
|
_random.nextInt(1000, 3000),
|
||||||
|
new Color(_random.nextInt(256), _random.nextInt(256), _random.nextInt(256))
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
entityPlane = new EntityBomber(
|
||||||
|
_random.nextInt(100, 300),
|
||||||
|
_random.nextInt(1000, 3000),
|
||||||
|
new Color(_random.nextInt(256), _random.nextInt(256), _random.nextInt(256)),
|
||||||
|
new Color(_random.nextInt(256), _random.nextInt(256), _random.nextInt(256)),
|
||||||
|
_random.nextBoolean(),
|
||||||
|
_random.nextBoolean()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
_doubleParametrized.Add(entityPlane);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void addRandomDrawingEngine() {
|
||||||
|
int choice = _random.nextInt(3);
|
||||||
|
IDrawingEngines drawingEngines;
|
||||||
|
if (choice == 0) {
|
||||||
|
drawingEngines = new DrawingEnginesSimple();
|
||||||
|
} else if (choice == 1) {
|
||||||
|
drawingEngines = new DrawingEnginesEllipse();
|
||||||
|
} else {
|
||||||
|
drawingEngines = new DrawingEnginesPyramid();
|
||||||
|
}
|
||||||
|
drawingEngines.SetEnumEnginesCount(_random.nextInt(2, 7));
|
||||||
|
_doubleParametrized.Add(drawingEngines);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void buttonGeneratePlaneClicked(ActionEvent e) {
|
||||||
|
addRandomEntityPlane();
|
||||||
|
addRandomDrawingEngine();
|
||||||
|
_drawingPlane = _doubleParametrized.GeneratePlane(PictureBox.getWidth(), PictureBox.getHeight());
|
||||||
|
_drawingPlane.SetPosition((PictureBox.getWidth() - _drawingPlane._planeWidth) / 2, (PictureBox.getHeight() - _drawingPlane._planeHeight) / 2);
|
||||||
|
Draw();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Draw() {
|
||||||
|
if (_drawingPlane == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Graphics g = PictureBox.getGraphics();
|
||||||
|
PictureBox.paint(g);
|
||||||
|
_drawingPlane.DrawTransport(g);
|
||||||
|
}
|
||||||
|
}
|
82
ProjectBomber/src/ProjectBomber/FormPlaneCollection.form
Normal file
82
ProjectBomber/src/ProjectBomber/FormPlaneCollection.form
Normal file
@ -0,0 +1,82 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="ProjectBomber.FormPlaneCollection">
|
||||||
|
<grid id="27dc6" binding="PanelWrapper" layout-manager="BorderLayout" hgap="0" vgap="0">
|
||||||
|
<constraints>
|
||||||
|
<xy x="20" y="20" width="666" height="454"/>
|
||||||
|
</constraints>
|
||||||
|
<properties/>
|
||||||
|
<border type="none"/>
|
||||||
|
<children>
|
||||||
|
<grid id="5f693" binding="PictureBoxCollection" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||||
|
<margin top="0" left="0" bottom="0" right="0"/>
|
||||||
|
<constraints border-constraint="Center"/>
|
||||||
|
<properties/>
|
||||||
|
<border type="none"/>
|
||||||
|
<children/>
|
||||||
|
</grid>
|
||||||
|
<grid id="7baef" binding="GroupBoxInstruments" layout-manager="GridLayoutManager" row-count="8" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||||
|
<margin top="0" left="0" bottom="0" right="0"/>
|
||||||
|
<constraints border-constraint="East"/>
|
||||||
|
<properties/>
|
||||||
|
<border type="none"/>
|
||||||
|
<children>
|
||||||
|
<component id="c9ec0" class="javax.swing.JButton" binding="buttonAddPlane">
|
||||||
|
<constraints>
|
||||||
|
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
<properties>
|
||||||
|
<text value="Добавить самолет"/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
<vspacer id="82bd6">
|
||||||
|
<constraints>
|
||||||
|
<grid row="6" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
</vspacer>
|
||||||
|
<component id="17d80" class="javax.swing.JTextField" binding="textFieldNumber">
|
||||||
|
<constraints>
|
||||||
|
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
|
||||||
|
<preferred-size width="150" height="-1"/>
|
||||||
|
</grid>
|
||||||
|
</constraints>
|
||||||
|
<properties/>
|
||||||
|
</component>
|
||||||
|
<component id="639f2" class="javax.swing.JButton" binding="buttonRemovePlane">
|
||||||
|
<constraints>
|
||||||
|
<grid row="3" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
<properties>
|
||||||
|
<text value="Удалить самолет"/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
<component id="86611" class="javax.swing.JButton" binding="buttonRefreshCollection">
|
||||||
|
<constraints>
|
||||||
|
<grid row="5" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
<properties>
|
||||||
|
<text value="Обновить коллекцию"/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
<vspacer id="75ae2">
|
||||||
|
<constraints>
|
||||||
|
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
</vspacer>
|
||||||
|
<vspacer id="7b32d">
|
||||||
|
<constraints>
|
||||||
|
<grid row="4" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
</vspacer>
|
||||||
|
<component id="a5cad" class="javax.swing.JButton" binding="buttonOpenGenerateWindow">
|
||||||
|
<constraints>
|
||||||
|
<grid row="7" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
<properties>
|
||||||
|
<text value="Генерировать самолеты"/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
</children>
|
||||||
|
</grid>
|
||||||
|
</children>
|
||||||
|
</grid>
|
||||||
|
</form>
|
112
ProjectBomber/src/ProjectBomber/FormPlaneCollection.java
Normal file
112
ProjectBomber/src/ProjectBomber/FormPlaneCollection.java
Normal file
@ -0,0 +1,112 @@
|
|||||||
|
package ProjectBomber;
|
||||||
|
|
||||||
|
import javax.swing.*;
|
||||||
|
import java.awt.*;
|
||||||
|
import java.awt.event.ActionEvent;
|
||||||
|
|
||||||
|
public class FormPlaneCollection {
|
||||||
|
PlanesGenericCollection<DrawingPlane, DrawingObjectPlane> _planes;
|
||||||
|
FrameDoubleParametrized _frameDoubleParametrized;
|
||||||
|
private JPanel PanelWrapper;
|
||||||
|
private JPanel GroupBoxInstruments;
|
||||||
|
private JPanel PictureBoxCollection;
|
||||||
|
private JButton buttonAddPlane;
|
||||||
|
private JTextField textFieldNumber;
|
||||||
|
private JButton buttonRemovePlane;
|
||||||
|
private JButton buttonRefreshCollection;
|
||||||
|
private JButton buttonOpenGenerateWindow;
|
||||||
|
public DrawingPlane SelectedPlane;
|
||||||
|
|
||||||
|
|
||||||
|
public JPanel getPanelWrapper() {
|
||||||
|
return PanelWrapper;
|
||||||
|
}
|
||||||
|
|
||||||
|
public FormPlaneCollection() {
|
||||||
|
PictureBoxCollection.setPreferredSize(new Dimension(600, 500));
|
||||||
|
_planes = new PlanesGenericCollection<>(600, 500);
|
||||||
|
buttonAddPlane.addActionListener(this::buttonAddPlaneClicked);
|
||||||
|
buttonRemovePlane.addActionListener(this::buttonRemovePlaneClicked);
|
||||||
|
buttonRefreshCollection.addActionListener(this::buttonRefreshCollectionClicked);
|
||||||
|
buttonOpenGenerateWindow.addActionListener(this::buttonOpenGenerateWindowClicked);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void buttonAddPlaneClicked(ActionEvent e) {
|
||||||
|
FrameBomber frameBomber = new FrameBomber();
|
||||||
|
frameBomber.setVisible(true);
|
||||||
|
frameBomber._formPlaneCollection.buttonSelectPlane.addActionListener(ev -> {
|
||||||
|
SelectedPlane = frameBomber._formPlaneCollection._drawingPlane;
|
||||||
|
frameBomber.dispose();
|
||||||
|
if (SelectedPlane != null) {
|
||||||
|
if (_planes.Add(SelectedPlane) > -1) {
|
||||||
|
refreshPictureBox();
|
||||||
|
JOptionPane.showMessageDialog(this.getPanelWrapper(),
|
||||||
|
"Объект добавлен",
|
||||||
|
"Успех",
|
||||||
|
JOptionPane.INFORMATION_MESSAGE);
|
||||||
|
} else {
|
||||||
|
JOptionPane.showMessageDialog(this.getPanelWrapper(),
|
||||||
|
"Не удалось добавить объект",
|
||||||
|
"Ошибка",
|
||||||
|
JOptionPane.ERROR_MESSAGE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public void buttonRemovePlaneClicked(ActionEvent e) {
|
||||||
|
int pos;
|
||||||
|
try {
|
||||||
|
pos = Integer.parseInt(textFieldNumber.getText());
|
||||||
|
} catch (NumberFormatException ex) {
|
||||||
|
JOptionPane.showMessageDialog(this.getPanelWrapper(),
|
||||||
|
"Неверное значение",
|
||||||
|
"Ошибка",
|
||||||
|
JOptionPane.ERROR_MESSAGE);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Object[] options = {"Да", "Нет"};
|
||||||
|
int n = JOptionPane.showOptionDialog(this.getPanelWrapper(),
|
||||||
|
"Удалить объект?",
|
||||||
|
"Все серьезно",
|
||||||
|
JOptionPane.YES_NO_OPTION,
|
||||||
|
JOptionPane.QUESTION_MESSAGE,
|
||||||
|
null,
|
||||||
|
options,
|
||||||
|
options[0]
|
||||||
|
);
|
||||||
|
if (n == 1) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (_planes.Sub(pos) != null) {
|
||||||
|
refreshPictureBox();
|
||||||
|
JOptionPane.showMessageDialog(this.getPanelWrapper(),
|
||||||
|
"Объект удален",
|
||||||
|
"Успех",
|
||||||
|
JOptionPane.INFORMATION_MESSAGE);
|
||||||
|
} else {
|
||||||
|
JOptionPane.showMessageDialog(this.getPanelWrapper(),
|
||||||
|
"Не удалось удалить объект",
|
||||||
|
"Ошибка",
|
||||||
|
JOptionPane.ERROR_MESSAGE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void buttonRefreshCollectionClicked(ActionEvent e) {
|
||||||
|
refreshPictureBox();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void buttonOpenGenerateWindowClicked(ActionEvent e) {
|
||||||
|
if (_frameDoubleParametrized != null) {
|
||||||
|
_frameDoubleParametrized.dispose();
|
||||||
|
}
|
||||||
|
_frameDoubleParametrized = new FrameDoubleParametrized();
|
||||||
|
_frameDoubleParametrized.setVisible(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void refreshPictureBox() {
|
||||||
|
Graphics g = PictureBoxCollection.getGraphics();
|
||||||
|
PictureBoxCollection.paint(g);
|
||||||
|
_planes.ShowPlanes(g);
|
||||||
|
}
|
||||||
|
}
|
17
ProjectBomber/src/ProjectBomber/FrameBomber.java
Normal file
17
ProjectBomber/src/ProjectBomber/FrameBomber.java
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
package ProjectBomber;
|
||||||
|
|
||||||
|
import javax.swing.*;
|
||||||
|
|
||||||
|
public class FrameBomber extends JFrame {
|
||||||
|
public FormBomber _formPlaneCollection;
|
||||||
|
public FrameBomber() {
|
||||||
|
super();
|
||||||
|
setTitle("Бомбардировщик");
|
||||||
|
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
|
||||||
|
_formPlaneCollection = new FormBomber();
|
||||||
|
setContentPane(_formPlaneCollection.getPictureBox());
|
||||||
|
setDefaultLookAndFeelDecorated(false);
|
||||||
|
setLocation(300, 100);
|
||||||
|
pack();
|
||||||
|
}
|
||||||
|
}
|
17
ProjectBomber/src/ProjectBomber/FrameDoubleParametrized.java
Normal file
17
ProjectBomber/src/ProjectBomber/FrameDoubleParametrized.java
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
package ProjectBomber;
|
||||||
|
|
||||||
|
import javax.swing.*;
|
||||||
|
|
||||||
|
public class FrameDoubleParametrized extends JFrame {
|
||||||
|
public FormDoubleParametrized _formDoubleParametrized;
|
||||||
|
public FrameDoubleParametrized() {
|
||||||
|
super();
|
||||||
|
setTitle("Генерация самолетов");
|
||||||
|
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
|
||||||
|
_formDoubleParametrized = new FormDoubleParametrized();
|
||||||
|
setContentPane(_formDoubleParametrized.getPictureBox());
|
||||||
|
setDefaultLookAndFeelDecorated(false);
|
||||||
|
setLocation(300, 100);
|
||||||
|
pack();
|
||||||
|
}
|
||||||
|
}
|
17
ProjectBomber/src/ProjectBomber/FramePlaneCollection.java
Normal file
17
ProjectBomber/src/ProjectBomber/FramePlaneCollection.java
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
package ProjectBomber;
|
||||||
|
|
||||||
|
import javax.swing.*;
|
||||||
|
|
||||||
|
public class FramePlaneCollection extends JFrame {
|
||||||
|
FormPlaneCollection _formPlaneCollection;
|
||||||
|
public FramePlaneCollection() {
|
||||||
|
super();
|
||||||
|
setTitle("Набор самолетов");
|
||||||
|
setDefaultCloseOperation(EXIT_ON_CLOSE);
|
||||||
|
_formPlaneCollection = new FormPlaneCollection();
|
||||||
|
setContentPane(_formPlaneCollection.getPanelWrapper());
|
||||||
|
setDefaultLookAndFeelDecorated(false);
|
||||||
|
setLocation(300, 100);
|
||||||
|
pack();
|
||||||
|
}
|
||||||
|
}
|
71
ProjectBomber/src/ProjectBomber/IDrawingEngines.java
Normal file
71
ProjectBomber/src/ProjectBomber/IDrawingEngines.java
Normal file
@ -0,0 +1,71 @@
|
|||||||
|
package ProjectBomber;
|
||||||
|
|
||||||
|
import java.awt.*;
|
||||||
|
|
||||||
|
public interface IDrawingEngines {
|
||||||
|
void SetEnumEnginesCount(int enginesCount);
|
||||||
|
|
||||||
|
EnumEnginesCount GetEnumEnginesCount();
|
||||||
|
|
||||||
|
void DrawEngine(Graphics2D g2d, Color color, int x, int y, int w, int h);
|
||||||
|
|
||||||
|
default void DrawEngines(Graphics g, Color color, int startPosX, int startPosY, int drawingWidth, int drawingHeight) {
|
||||||
|
EnumEnginesCount enginesCount = GetEnumEnginesCount();
|
||||||
|
if (enginesCount == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Graphics2D g2d = (Graphics2D) g;
|
||||||
|
g2d.setStroke(new BasicStroke(2));
|
||||||
|
int engineWidth = 20;
|
||||||
|
int engineHeight = 6;
|
||||||
|
|
||||||
|
if (enginesCount.count >= EnumEnginesCount.Two.count) {
|
||||||
|
DrawEngine(
|
||||||
|
g2d, color,
|
||||||
|
startPosX + drawingWidth - drawingWidth / 5,
|
||||||
|
startPosY + drawingHeight / 2 - drawingHeight / 6,
|
||||||
|
engineWidth,
|
||||||
|
engineHeight
|
||||||
|
);
|
||||||
|
DrawEngine(
|
||||||
|
g2d, color,
|
||||||
|
startPosX + drawingWidth - drawingWidth / 5,
|
||||||
|
startPosY + drawingHeight / 2 + drawingHeight / 6 - engineHeight,
|
||||||
|
engineWidth,
|
||||||
|
engineHeight
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if (enginesCount.count >= EnumEnginesCount.Four.count) {
|
||||||
|
DrawEngine(
|
||||||
|
g2d, color,
|
||||||
|
startPosX + drawingWidth - drawingWidth / 5 + 5,
|
||||||
|
startPosY + drawingHeight / 2 - drawingHeight / 6 - 10,
|
||||||
|
engineWidth - 5,
|
||||||
|
engineHeight
|
||||||
|
);
|
||||||
|
DrawEngine(
|
||||||
|
g2d, color,
|
||||||
|
startPosX + drawingWidth - drawingWidth / 5 + 5,
|
||||||
|
startPosY + drawingHeight / 2 + drawingHeight / 6 - engineHeight + 10,
|
||||||
|
engineWidth - 5,
|
||||||
|
engineHeight
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if (enginesCount.count >= EnumEnginesCount.Six.count) {
|
||||||
|
DrawEngine(
|
||||||
|
g2d, color,
|
||||||
|
startPosX + drawingWidth / 2 - 10,
|
||||||
|
startPosY + drawingHeight / 2 - drawingHeight / 6 - 10,
|
||||||
|
engineWidth,
|
||||||
|
engineHeight
|
||||||
|
);
|
||||||
|
DrawEngine(
|
||||||
|
g2d, color,
|
||||||
|
startPosX + drawingWidth / 2 - 10,
|
||||||
|
startPosY + drawingHeight / 2 + drawingHeight / 6 + 3,
|
||||||
|
engineWidth,
|
||||||
|
engineHeight
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
8
ProjectBomber/src/ProjectBomber/IMoveableObject.java
Normal file
8
ProjectBomber/src/ProjectBomber/IMoveableObject.java
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
package ProjectBomber;
|
||||||
|
|
||||||
|
public interface IMoveableObject {
|
||||||
|
ObjectParameters GetObjectPosition();
|
||||||
|
int GetStep();
|
||||||
|
boolean CheckCanMove(EnumDirectionType direction);
|
||||||
|
void MoveObject(EnumDirectionType direction);
|
||||||
|
}
|
8
ProjectBomber/src/ProjectBomber/Main.java
Normal file
8
ProjectBomber/src/ProjectBomber/Main.java
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
package ProjectBomber;
|
||||||
|
|
||||||
|
public class Main {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
FramePlaneCollection framePlaneCollection = new FramePlaneCollection();
|
||||||
|
framePlaneCollection.setVisible(true);
|
||||||
|
}
|
||||||
|
}
|
37
ProjectBomber/src/ProjectBomber/MoveToCenter.java
Normal file
37
ProjectBomber/src/ProjectBomber/MoveToCenter.java
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
package ProjectBomber;
|
||||||
|
|
||||||
|
public class MoveToCenter extends AbstractStrategy {
|
||||||
|
@Override
|
||||||
|
protected void MoveToTarget() {
|
||||||
|
var objParams = GetObjectParameters();
|
||||||
|
if (objParams == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var diffX = objParams.ObjectMiddleHorizontal() - FieldWidth / 2;
|
||||||
|
if (Math.abs(diffX) > GetStep()) {
|
||||||
|
if (diffX > 0) {
|
||||||
|
MoveLeft();
|
||||||
|
} else {
|
||||||
|
MoveRight();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
var diffY = objParams.ObjectMiddleVertical() - FieldHeight / 2;
|
||||||
|
if (Math.abs(diffY) > GetStep()) {
|
||||||
|
if (diffY > 0) {
|
||||||
|
MoveUp();
|
||||||
|
} else {
|
||||||
|
MoveDown();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected boolean IsTargetDestination() {
|
||||||
|
var objParams = GetObjectParameters();
|
||||||
|
if (objParams == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return objParams.ObjectMiddleHorizontal() <= FieldWidth / 2 && objParams.ObjectMiddleHorizontal() + GetStep() >= FieldWidth / 2 &&
|
||||||
|
objParams.ObjectMiddleVertical() <= FieldHeight / 2 && objParams.ObjectMiddleVertical() + GetStep() >= FieldHeight / 2;
|
||||||
|
}
|
||||||
|
}
|
26
ProjectBomber/src/ProjectBomber/MoveToRightBottom.java
Normal file
26
ProjectBomber/src/ProjectBomber/MoveToRightBottom.java
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
package ProjectBomber;
|
||||||
|
|
||||||
|
public class MoveToRightBottom extends AbstractStrategy {
|
||||||
|
@Override
|
||||||
|
protected void MoveToTarget() {
|
||||||
|
var objParams = GetObjectParameters();
|
||||||
|
if (objParams == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (objParams.RightBorder() < FieldWidth - GetStep()) {
|
||||||
|
MoveRight();
|
||||||
|
}
|
||||||
|
if (objParams.TopBorder() < FieldHeight - GetStep()) {
|
||||||
|
MoveDown();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected boolean IsTargetDestination() {
|
||||||
|
var objParams = GetObjectParameters();
|
||||||
|
if (objParams == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return objParams.RightBorder() >= FieldWidth - GetStep() && objParams.DownBorder() >= FieldHeight - GetStep();
|
||||||
|
}
|
||||||
|
}
|
39
ProjectBomber/src/ProjectBomber/ObjectParameters.java
Normal file
39
ProjectBomber/src/ProjectBomber/ObjectParameters.java
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
package ProjectBomber;
|
||||||
|
|
||||||
|
public class ObjectParameters {
|
||||||
|
private int _x;
|
||||||
|
private int _y;
|
||||||
|
private int _width;
|
||||||
|
private int _height;
|
||||||
|
|
||||||
|
public int LeftBorder() {
|
||||||
|
return _x;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int TopBorder() {
|
||||||
|
return _y;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int RightBorder() {
|
||||||
|
return _x + _width;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int DownBorder() {
|
||||||
|
return _y + _height;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int ObjectMiddleHorizontal() {
|
||||||
|
return _x + _width / 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int ObjectMiddleVertical() {
|
||||||
|
return _y + _height / 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ObjectParameters(int x, int y, int width, int height) {
|
||||||
|
_x = x;
|
||||||
|
_y = y;
|
||||||
|
_width = width;
|
||||||
|
_height = height;
|
||||||
|
}
|
||||||
|
}
|
72
ProjectBomber/src/ProjectBomber/PlanesGenericCollection.java
Normal file
72
ProjectBomber/src/ProjectBomber/PlanesGenericCollection.java
Normal file
@ -0,0 +1,72 @@
|
|||||||
|
package ProjectBomber;
|
||||||
|
|
||||||
|
import java.awt.*;
|
||||||
|
|
||||||
|
public class PlanesGenericCollection<T extends DrawingPlane, U extends IMoveableObject> {
|
||||||
|
private int _pictureWidth;
|
||||||
|
private int _pictureHeight;
|
||||||
|
private final int _placeSizeWidth = 160;
|
||||||
|
private final int _placeSizeHeight = 120;
|
||||||
|
private SetGeneric<T> _collection;
|
||||||
|
|
||||||
|
public PlanesGenericCollection(int picWidth, int picHeight) {
|
||||||
|
int horizontalObjectsCount = picWidth / _placeSizeWidth;
|
||||||
|
int verticalObjectsCount = picHeight / _placeSizeHeight;
|
||||||
|
_pictureWidth = picWidth;
|
||||||
|
_pictureHeight = picHeight;
|
||||||
|
_collection = new SetGeneric<T>(horizontalObjectsCount * verticalObjectsCount);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int Add(T obj) {
|
||||||
|
if (obj == null) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
return _collection.Insert(obj);
|
||||||
|
}
|
||||||
|
|
||||||
|
public T Sub(int pos) {
|
||||||
|
return _collection.Remove(pos);
|
||||||
|
}
|
||||||
|
|
||||||
|
public U GetU(int pos) {
|
||||||
|
if (_collection.Get(pos) != null)
|
||||||
|
return (U) _collection.Get(pos).GetMoveableObject();
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void ShowPlanes(Graphics g) {
|
||||||
|
DrawBackground(g);
|
||||||
|
DrawObjects(g);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void DrawBackground(Graphics g) {
|
||||||
|
Graphics2D g2d = (Graphics2D) g;
|
||||||
|
g2d.setColor(Color.BLACK);
|
||||||
|
g2d.setStroke(new BasicStroke(3));
|
||||||
|
for (int i = 0; i < _pictureWidth / _placeSizeWidth; i++) {
|
||||||
|
for (int j = 0; j < _pictureHeight / _placeSizeHeight + 1; ++j) {
|
||||||
|
// Линия разметки места
|
||||||
|
g.drawLine(i * _placeSizeWidth, j * _placeSizeHeight, i * _placeSizeWidth + _placeSizeWidth / 2, j * _placeSizeHeight);
|
||||||
|
}
|
||||||
|
g.drawLine(i * _placeSizeWidth, 0, i * _placeSizeWidth, _pictureHeight / _placeSizeHeight * _placeSizeHeight);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void DrawObjects(Graphics g) {
|
||||||
|
int placesColumnCount = _pictureHeight / _placeSizeHeight;
|
||||||
|
int placesRowCount = _pictureWidth / _placeSizeWidth;
|
||||||
|
for (int i = 0; i < _collection.Count; i++) {
|
||||||
|
// получение объекта
|
||||||
|
var obj = _collection.Get(i);
|
||||||
|
// установка позиции
|
||||||
|
if (obj == null)
|
||||||
|
continue;
|
||||||
|
obj.SetPosition(
|
||||||
|
(placesRowCount - 1) * _placeSizeWidth - (i % placesColumnCount * _placeSizeWidth) + (_placeSizeWidth - obj.GetWidth()) / 2,
|
||||||
|
i / placesColumnCount * _placeSizeHeight + (_placeSizeHeight - obj.GetHeight()) / 2
|
||||||
|
);
|
||||||
|
// прорисовка объекта
|
||||||
|
obj.DrawTransport(g);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
65
ProjectBomber/src/ProjectBomber/SetGeneric.java
Normal file
65
ProjectBomber/src/ProjectBomber/SetGeneric.java
Normal file
@ -0,0 +1,65 @@
|
|||||||
|
package ProjectBomber;
|
||||||
|
|
||||||
|
public class SetGeneric<T extends DrawingPlane> {
|
||||||
|
private T[] _places;
|
||||||
|
public int Count;
|
||||||
|
|
||||||
|
public SetGeneric(int count) {
|
||||||
|
_places = (T[]) new DrawingPlane[count];
|
||||||
|
Count = count;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int Insert(T plane) {
|
||||||
|
return Insert(plane, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int Insert(T plane, int position) {
|
||||||
|
// Проверка позиции
|
||||||
|
if (position < 0 || position >= Count) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
// Проверка, что элемент массива по этой позиции пустой
|
||||||
|
if (_places[position] != null) {
|
||||||
|
// Проверка, что после вставляемого элемента в массиве есть пустой элемент
|
||||||
|
int nullIndex = -1;
|
||||||
|
for (int i = position + 1; i < Count; i++) {
|
||||||
|
if (_places[i] == null) {
|
||||||
|
nullIndex = i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Если пустого элемента нет, то выходим
|
||||||
|
if (nullIndex < 0) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
// Сдвиг всех объектов, находящихся справа от позиции до первого пустого элемента
|
||||||
|
int j = nullIndex - 1;
|
||||||
|
while (j >= position) {
|
||||||
|
_places[j + 1] = _places[j];
|
||||||
|
j--;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Вставка по позиции
|
||||||
|
_places[position] = plane;
|
||||||
|
return position;
|
||||||
|
}
|
||||||
|
|
||||||
|
public T Remove(int position) {
|
||||||
|
// Проверка позиции
|
||||||
|
if (position < 0 || position >= Count) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
// Удаление объекта из массива, присвоив элементу массива значение null
|
||||||
|
T plane = _places[position];
|
||||||
|
_places[position] = null;
|
||||||
|
return plane;
|
||||||
|
}
|
||||||
|
|
||||||
|
public T Get(int position) {
|
||||||
|
// Проверка позиции
|
||||||
|
if (position < 0 || position >= Count) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return _places[position];
|
||||||
|
}
|
||||||
|
}
|
7
ProjectBomber/src/ProjectBomber/Status.java
Normal file
7
ProjectBomber/src/ProjectBomber/Status.java
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
package ProjectBomber;
|
||||||
|
|
||||||
|
public enum Status {
|
||||||
|
NotInit,
|
||||||
|
InProgress,
|
||||||
|
Finish
|
||||||
|
}
|
BIN
ProjectBomber/src/ProjectBomber/img/arrowDOWN.png
Normal file
BIN
ProjectBomber/src/ProjectBomber/img/arrowDOWN.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.5 KiB |
BIN
ProjectBomber/src/ProjectBomber/img/arrowLEFT.png
Normal file
BIN
ProjectBomber/src/ProjectBomber/img/arrowLEFT.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.4 KiB |
BIN
ProjectBomber/src/ProjectBomber/img/arrowRIGHT.png
Normal file
BIN
ProjectBomber/src/ProjectBomber/img/arrowRIGHT.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.4 KiB |
BIN
ProjectBomber/src/ProjectBomber/img/arrowUP.png
Normal file
BIN
ProjectBomber/src/ProjectBomber/img/arrowUP.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.5 KiB |
Loading…
Reference in New Issue
Block a user