Compare commits
46 Commits
Author | SHA1 | Date | |
---|---|---|---|
59a9be54ee | |||
5a12399986 | |||
b8d9d10bd8 | |||
354f9a97d0 | |||
585712ebf9 | |||
9bb8540007 | |||
5ea79c63eb | |||
e8ba3c4d51 | |||
6f24631855 | |||
7e33476f43 | |||
e781e215bc | |||
647bfc4c5b | |||
7c1dbb3751 | |||
f03bed65ed | |||
b8c40931ed | |||
b8906c0325 | |||
be38dbc017 | |||
25b615e736 | |||
deab7a4c3f | |||
88eea507fe | |||
d140d781b7 | |||
650b42c43a | |||
9f8be965e5 | |||
68903479c1 | |||
e89cbc85a2 | |||
b04f8401c3 | |||
26b0c2c0a2 | |||
0e17b7a751 | |||
9f805eeba2 | |||
45f014ceae | |||
759245f4f2 | |||
f8c531856d | |||
0c0b412737 | |||
e70dc68d7a | |||
01ca2afd90 | |||
22f37e335f | |||
049a4df69f | |||
2f1be18356 | |||
b087e5b388 | |||
9db19f8397 | |||
d0913e1f47 | |||
1435b6b56c | |||
274f82bb70 | |||
6382b11542 | |||
bf32d9a57d | |||
ba99ffcca9 |
3
.idea/.gitignore
vendored
Normal file
3
.idea/.gitignore
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
12
.idea/PIbd-21_Potapov_N.S._Stormtrooper_Hard.iml
Normal file
12
.idea/PIbd-21_Potapov_N.S._Stormtrooper_Hard.iml
Normal file
@ -0,0 +1,12 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="JAVA_MODULE" version="4">
|
||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$" isTestSource="false" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="library" name="log4j-core-2_22_0" level="project" />
|
||||
</component>
|
||||
</module>
|
6
.idea/misc.xml
Normal file
6
.idea/misc.xml
Normal file
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_20" default="true" project-jdk-name="20 (2)" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/out" />
|
||||
</component>
|
||||
</project>
|
8
.idea/modules.xml
Normal file
8
.idea/modules.xml
Normal file
@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/.idea/PIbd-21_Potapov_N.S._Stormtrooper_Hard.iml" filepath="$PROJECT_DIR$/.idea/PIbd-21_Potapov_N.S._Stormtrooper_Hard.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
6
.idea/vcs.xml
Normal file
6
.idea/vcs.xml
Normal file
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
82
ProjectStormtrooper/AbstractStrategy.java
Normal file
82
ProjectStormtrooper/AbstractStrategy.java
Normal file
@ -0,0 +1,82 @@
|
||||
package ProjectStormtrooper;
|
||||
|
||||
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
ProjectStormtrooper/DoubleParametrized.java
Normal file
41
ProjectStormtrooper/DoubleParametrized.java
Normal file
@ -0,0 +1,41 @@
|
||||
package ProjectStormtrooper;
|
||||
|
||||
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 EntityStormtrooper) {
|
||||
drawingPlane = new DrawingStormtrooper((EntityStormtrooper) entityPlane, drawingEngine, pictureWidth, pictureHeight);
|
||||
} else {
|
||||
drawingPlane = new DrawingPlane(entityPlane, drawingEngine, pictureWidth, pictureHeight);
|
||||
}
|
||||
return drawingPlane;
|
||||
}
|
||||
}
|
31
ProjectStormtrooper/DrawingEnginesEllipse.java
Normal file
31
ProjectStormtrooper/DrawingEnginesEllipse.java
Normal file
@ -0,0 +1,31 @@
|
||||
package ProjectStormtrooper;
|
||||
|
||||
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
ProjectStormtrooper/DrawingEnginesPyramid.java
Normal file
39
ProjectStormtrooper/DrawingEnginesPyramid.java
Normal file
@ -0,0 +1,39 @@
|
||||
package ProjectStormtrooper;
|
||||
|
||||
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
ProjectStormtrooper/DrawingEnginesSimple.java
Normal file
33
ProjectStormtrooper/DrawingEnginesSimple.java
Normal file
@ -0,0 +1,33 @@
|
||||
package ProjectStormtrooper;
|
||||
|
||||
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
ProjectStormtrooper/DrawingObjectPlane.java
Normal file
43
ProjectStormtrooper/DrawingObjectPlane.java
Normal file
@ -0,0 +1,43 @@
|
||||
package ProjectStormtrooper;
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
211
ProjectStormtrooper/DrawingPlane.java
Normal file
211
ProjectStormtrooper/DrawingPlane.java
Normal file
@ -0,0 +1,211 @@
|
||||
package ProjectStormtrooper;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.util.Random;
|
||||
|
||||
public class DrawingPlane extends JPanel {
|
||||
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) {
|
||||
if (_drawingEngines != null)
|
||||
_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 / 9;
|
||||
int bodyWidth = _planeWidth - _planeWidth / 8;
|
||||
|
||||
_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);
|
||||
}
|
||||
|
||||
public void SetDrawingBounds(int width, int height) {
|
||||
_pictureWidth = width;
|
||||
_pictureHeight = height;
|
||||
}
|
||||
|
||||
;
|
||||
}
|
154
ProjectStormtrooper/DrawingStormtrooper.java
Normal file
154
ProjectStormtrooper/DrawingStormtrooper.java
Normal file
@ -0,0 +1,154 @@
|
||||
package ProjectStormtrooper;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
public class DrawingStormtrooper extends DrawingPlane {
|
||||
public DrawingStormtrooper(int speed, double weight, Color bodyColor,
|
||||
Color additionalColor, boolean rockets, boolean bombs,
|
||||
int width, int height) {
|
||||
super(speed, weight, bodyColor, width, height, 140, 90);
|
||||
if (EntityPlane != null) {
|
||||
EntityPlane = new EntityStormtrooper(speed, weight, bodyColor, additionalColor, rockets, bombs);
|
||||
}
|
||||
}
|
||||
|
||||
public DrawingStormtrooper(EntityStormtrooper entityStormtrooper, IDrawingEngines drawingEngines, int width, int height) {
|
||||
super(entityStormtrooper, drawingEngines, width, height, 140, 90);
|
||||
}
|
||||
|
||||
public void DrawTransport(Graphics g) {
|
||||
if (EntityPlane == null) {
|
||||
return;
|
||||
}
|
||||
if (!(EntityPlane instanceof EntityStormtrooper entityStormtrooper)) {
|
||||
return;
|
||||
}
|
||||
Graphics2D g2d = (Graphics2D) g;
|
||||
|
||||
int bodyHeight = _planeHeight / 9;
|
||||
|
||||
Color blackColor = Color.BLACK;
|
||||
Color redColor = Color.RED;
|
||||
Color additionalColor = entityStormtrooper.AdditionalColor;
|
||||
|
||||
// Рисуем бомбы
|
||||
if (entityStormtrooper.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 (entityStormtrooper.Rockets) {
|
||||
int rocketWidth = bodyHeight * 4;
|
||||
int rocketHeight = bodyHeight / 2;
|
||||
|
||||
Polygon rocketCockPitPolygon = new Polygon();
|
||||
rocketCockPitPolygon.addPoint(_startPosX + _planeWidth / 2 - _planeWidth / 5 - rocketHeight,
|
||||
_startPosY + _planeHeight / 2 - bodyHeight - bodyHeight / 2 + rocketHeight / 2);
|
||||
rocketCockPitPolygon.addPoint(_startPosX + _planeWidth / 2 - _planeWidth / 5,
|
||||
_startPosY + _planeHeight / 2 - bodyHeight - bodyHeight / 2);
|
||||
rocketCockPitPolygon.addPoint(_startPosX + _planeWidth / 2 - _planeWidth / 5,
|
||||
_startPosY + _planeHeight / 2 - bodyHeight - bodyHeight / 2 + rocketHeight);
|
||||
|
||||
Polygon rocketTailPolygon = new Polygon();
|
||||
rocketTailPolygon.addPoint(_startPosX + _planeWidth / 2 - _planeWidth / 5 - rocketHeight + rocketWidth - 10,
|
||||
_startPosY + _planeHeight / 2 - bodyHeight - bodyHeight / 2 + rocketHeight / 2);
|
||||
rocketTailPolygon.addPoint(_startPosX + _planeWidth / 2 - _planeWidth / 5 + rocketWidth,
|
||||
_startPosY + _planeHeight / 2 - bodyHeight * 2 + rocketHeight / 2);
|
||||
rocketTailPolygon.addPoint(_startPosX + _planeWidth / 2 - _planeWidth / 5 + rocketWidth,
|
||||
_startPosY + _planeHeight / 2 - bodyHeight - bodyHeight / 2 + rocketHeight + bodyHeight / 2 - rocketHeight / 2);
|
||||
|
||||
g2d.setColor(redColor);
|
||||
g2d.fillPolygon(rocketCockPitPolygon);
|
||||
g2d.setColor(blackColor);
|
||||
g2d.drawPolygon(rocketCockPitPolygon);
|
||||
|
||||
g2d.setColor(blackColor);
|
||||
g2d.fillPolygon(rocketTailPolygon);
|
||||
|
||||
rocketCockPitPolygon.translate(0, (int) (_planeHeight - 2 * (_planeHeight / 2 - bodyHeight - bodyHeight / 2) - rocketCockPitPolygon.getBounds2D().getHeight()));
|
||||
rocketTailPolygon.translate(0, (int) (_planeHeight - 2 * (_planeHeight / 2 - bodyHeight * 2 + rocketHeight / 2) - rocketTailPolygon.getBounds2D().getHeight()));
|
||||
|
||||
g2d.setColor(redColor);
|
||||
g2d.fillPolygon(rocketCockPitPolygon);
|
||||
g2d.setColor(blackColor);
|
||||
g2d.drawPolygon(rocketCockPitPolygon);
|
||||
|
||||
g2d.setColor(blackColor);
|
||||
g2d.fillPolygon(rocketTailPolygon);
|
||||
|
||||
g2d.setColor(additionalColor);
|
||||
g2d.fillRect(
|
||||
_startPosX + _planeWidth / 2 - _planeWidth / 5,
|
||||
_startPosY + _planeHeight / 2 - bodyHeight - bodyHeight / 2,
|
||||
rocketWidth,
|
||||
rocketHeight);
|
||||
|
||||
|
||||
g2d.fillRect(
|
||||
_startPosX + _planeWidth / 2 - _planeWidth / 5,
|
||||
_startPosY + _planeHeight / 2 + bodyHeight / 2 + bodyHeight / 2,
|
||||
rocketWidth,
|
||||
rocketHeight);
|
||||
|
||||
g2d.setColor(blackColor);
|
||||
g2d.drawRect(
|
||||
_startPosX + _planeWidth / 2 - _planeWidth / 5,
|
||||
_startPosY + _planeHeight / 2 - bodyHeight - bodyHeight / 2,
|
||||
rocketWidth,
|
||||
rocketHeight);
|
||||
|
||||
g2d.drawRect(
|
||||
_startPosX + _planeWidth / 2 - _planeWidth / 5,
|
||||
_startPosY + _planeHeight / 2 + bodyHeight / 2 + bodyHeight / 2,
|
||||
rocketWidth,
|
||||
rocketHeight);
|
||||
}
|
||||
|
||||
super.DrawTransport(g);
|
||||
}
|
||||
}
|
23
ProjectStormtrooper/EntityPlane.java
Normal file
23
ProjectStormtrooper/EntityPlane.java
Normal file
@ -0,0 +1,23 @@
|
||||
package ProjectStormtrooper;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
public void SetBodyColor(Color color) {
|
||||
BodyColor = color;
|
||||
}
|
||||
}
|
21
ProjectStormtrooper/EntityStormtrooper.java
Normal file
21
ProjectStormtrooper/EntityStormtrooper.java
Normal file
@ -0,0 +1,21 @@
|
||||
package ProjectStormtrooper;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
public class EntityStormtrooper extends EntityPlane {
|
||||
public Color AdditionalColor;
|
||||
public boolean Rockets;
|
||||
public boolean Bombs;
|
||||
|
||||
public EntityStormtrooper(int speed, double weight, Color bodyColor,
|
||||
Color additionalColor, boolean rockets, boolean bombs) {
|
||||
super(speed, weight, bodyColor);
|
||||
AdditionalColor = additionalColor;
|
||||
Rockets = rockets;
|
||||
Bombs = bombs;
|
||||
}
|
||||
|
||||
public void SetAdditionalColor(Color color) {
|
||||
AdditionalColor = color;
|
||||
}
|
||||
}
|
5
ProjectStormtrooper/EnumDirectionType.java
Normal file
5
ProjectStormtrooper/EnumDirectionType.java
Normal file
@ -0,0 +1,5 @@
|
||||
package ProjectStormtrooper;
|
||||
|
||||
public enum EnumDirectionType {
|
||||
Up, Down, Left, Right
|
||||
}
|
12
ProjectStormtrooper/EnumEnginesCount.java
Normal file
12
ProjectStormtrooper/EnumEnginesCount.java
Normal file
@ -0,0 +1,12 @@
|
||||
package ProjectStormtrooper;
|
||||
|
||||
public enum EnumEnginesCount {
|
||||
Two(2),
|
||||
Four(4),
|
||||
Six(6);
|
||||
public final int count;
|
||||
|
||||
EnumEnginesCount(int count) {
|
||||
this.count = count;
|
||||
}
|
||||
}
|
87
ProjectStormtrooper/ExtensionDrawingPlane.java
Normal file
87
ProjectStormtrooper/ExtensionDrawingPlane.java
Normal file
@ -0,0 +1,87 @@
|
||||
package ProjectStormtrooper;
|
||||
|
||||
import java.awt.*;
|
||||
import java.util.Objects;
|
||||
|
||||
public class ExtensionDrawingPlane {
|
||||
public static DrawingPlane CreateDrawingPlane(String info, String separatorForObject, int width, int height) {
|
||||
String[] strs = info.split(separatorForObject);
|
||||
if (strs.length == 7) {
|
||||
DrawingPlane drawingPlane = new DrawingPlane(
|
||||
Integer.parseInt(strs[0]),
|
||||
Double.parseDouble(strs[1]),
|
||||
new Color(
|
||||
Integer.parseInt(strs[2]),
|
||||
Integer.parseInt(strs[3]),
|
||||
Integer.parseInt(strs[4])
|
||||
),
|
||||
width, height
|
||||
);
|
||||
if (Objects.equals(strs[5], "DrawingEnginesSimple")) {
|
||||
drawingPlane._drawingEngines = new DrawingEnginesSimple();
|
||||
} else if (Objects.equals(strs[5], "DrawingEnginesPyramid")) {
|
||||
drawingPlane._drawingEngines = new DrawingEnginesPyramid();
|
||||
} else if (Objects.equals(strs[5], "DrawingEnginesEllipse")) {
|
||||
drawingPlane._drawingEngines = new DrawingEnginesEllipse();
|
||||
}
|
||||
drawingPlane.SetEnginesCount(Integer.parseInt(strs[6]));
|
||||
return drawingPlane;
|
||||
}
|
||||
if (strs.length == 12) {
|
||||
DrawingPlane drawingPlane = new DrawingStormtrooper(
|
||||
Integer.parseInt(strs[0]),
|
||||
Double.parseDouble(strs[1]),
|
||||
new Color(
|
||||
Integer.parseInt(strs[2]),
|
||||
Integer.parseInt(strs[3]),
|
||||
Integer.parseInt(strs[4])
|
||||
),
|
||||
new Color(
|
||||
Integer.parseInt(strs[7]),
|
||||
Integer.parseInt(strs[8]),
|
||||
Integer.parseInt(strs[9])
|
||||
),
|
||||
Boolean.parseBoolean(strs[10]),
|
||||
Boolean.parseBoolean(strs[11]),
|
||||
width, height
|
||||
);
|
||||
if (Objects.equals(strs[5], "DrawingEnginesSimple")) {
|
||||
drawingPlane._drawingEngines = new DrawingEnginesSimple();
|
||||
} else if (Objects.equals(strs[5], "DrawingEnginesPyramid")) {
|
||||
drawingPlane._drawingEngines = new DrawingEnginesPyramid();
|
||||
} else if (Objects.equals(strs[5], "DrawingEnginesEllipse")) {
|
||||
drawingPlane._drawingEngines = new DrawingEnginesEllipse();
|
||||
}
|
||||
drawingPlane.SetEnginesCount(Integer.parseInt(strs[6]));
|
||||
return drawingPlane;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static String GetDataForSave(DrawingPlane drawingPlane, String separatorForObject) {
|
||||
var plane = drawingPlane.EntityPlane;
|
||||
if (plane == null) {
|
||||
return "";
|
||||
}
|
||||
String str = plane.Speed +
|
||||
separatorForObject +
|
||||
plane.Weight +
|
||||
separatorForObject +
|
||||
plane.BodyColor.getRed() + separatorForObject +
|
||||
plane.BodyColor.getGreen() + separatorForObject +
|
||||
plane.BodyColor.getBlue() + separatorForObject +
|
||||
(drawingPlane._drawingEngines.GetEnumEnginesCount() == null ? "null" : drawingPlane._drawingEngines.getClass()) + separatorForObject +
|
||||
(drawingPlane._drawingEngines.GetEnumEnginesCount() == null ? "0" : drawingPlane._drawingEngines.GetEnumEnginesCount().count);
|
||||
if (!(plane instanceof EntityStormtrooper stormtrooper)) {
|
||||
return str;
|
||||
}
|
||||
return str +
|
||||
separatorForObject +
|
||||
stormtrooper.AdditionalColor.getRed() + separatorForObject +
|
||||
stormtrooper.AdditionalColor.getGreen() + separatorForObject +
|
||||
stormtrooper.AdditionalColor.getBlue() + separatorForObject +
|
||||
stormtrooper.Bombs +
|
||||
separatorForObject +
|
||||
stormtrooper.Rockets;
|
||||
}
|
||||
}
|
31
ProjectStormtrooper/FormDoubleParametrized.form
Normal file
31
ProjectStormtrooper/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="ProjectStormtrooper.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
ProjectStormtrooper/FormDoubleParametrized.java
Normal file
78
ProjectStormtrooper/FormDoubleParametrized.java
Normal file
@ -0,0 +1,78 @@
|
||||
package ProjectStormtrooper;
|
||||
|
||||
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 EntityStormtrooper(
|
||||
_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);
|
||||
}
|
||||
}
|
139
ProjectStormtrooper/FormPlaneCollection.form
Normal file
139
ProjectStormtrooper/FormPlaneCollection.form
Normal file
@ -0,0 +1,139 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="ProjectStormtrooper.FormPlaneCollection">
|
||||
<grid id="27dc6" binding="PanelWrapper" layout-manager="BorderLayout" hgap="0" vgap="0">
|
||||
<constraints>
|
||||
<xy x="20" y="20" width="796" height="600"/>
|
||||
</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>
|
||||
<minimumSize width="24" height="24"/>
|
||||
</properties>
|
||||
<border type="none"/>
|
||||
<children/>
|
||||
</grid>
|
||||
<grid id="7baef" binding="GroupBoxInstruments" layout-manager="GridLayoutManager" row-count="11" 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="2" 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="8" 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="4" 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="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>
|
||||
<component id="86611" class="javax.swing.JButton" binding="buttonRefreshCollection">
|
||||
<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>
|
||||
<vspacer id="75ae2">
|
||||
<constraints>
|
||||
<grid row="3" 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="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="a5cad" class="javax.swing.JButton" binding="buttonOpenGenerateWindow">
|
||||
<constraints>
|
||||
<grid row="9" 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>
|
||||
<grid id="7e3fb" binding="storagesPanel" layout-manager="GridLayoutManager" row-count="4" 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>
|
||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<component id="f806" class="javax.swing.JTextField" binding="textFieldStorageName">
|
||||
<constraints>
|
||||
<grid row="0" 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="78225" class="javax.swing.JButton" binding="buttonAddStorage">
|
||||
<constraints>
|
||||
<grid row="1" 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="ab120" class="javax.swing.JList" binding="listBoxStorages">
|
||||
<constraints>
|
||||
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="2" anchor="0" fill="3" indent="0" use-parent-layout="false">
|
||||
<preferred-size width="150" height="50"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties/>
|
||||
</component>
|
||||
<component id="98764" class="javax.swing.JButton" binding="buttonRemoveStorage">
|
||||
<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>
|
||||
</children>
|
||||
</grid>
|
||||
<vspacer id="5d143">
|
||||
<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>
|
||||
<component id="a5c67" class="javax.swing.JButton" binding="buttonShowRemovedPlanes">
|
||||
<constraints>
|
||||
<grid row="10" 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>
|
325
ProjectStormtrooper/FormPlaneCollection.java
Normal file
325
ProjectStormtrooper/FormPlaneCollection.java
Normal file
@ -0,0 +1,325 @@
|
||||
package ProjectStormtrooper;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.event.ListSelectionEvent;
|
||||
import javax.swing.filechooser.FileNameExtensionFilter;
|
||||
import java.awt.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.io.File;
|
||||
import java.util.Objects;
|
||||
import java.util.Stack;
|
||||
|
||||
public class FormPlaneCollection {
|
||||
final PlanesGenericStorage _storage;
|
||||
FrameDoubleParametrized _frameDoubleParametrized;
|
||||
FrameStormtrooper _frameRemovedPlanes;
|
||||
private JPanel PanelWrapper;
|
||||
private JPanel GroupBoxInstruments;
|
||||
private JPanel PictureBoxCollection;
|
||||
private JButton buttonAddPlane;
|
||||
private JTextField textFieldNumber;
|
||||
private JButton buttonRemovePlane;
|
||||
private JButton buttonRefreshCollection;
|
||||
private JButton buttonOpenGenerateWindow;
|
||||
private JTextField textFieldStorageName;
|
||||
private JButton buttonAddStorage;
|
||||
private JList listBoxStorages;
|
||||
private JButton buttonRemoveStorage;
|
||||
private JPanel storagesPanel;
|
||||
private JButton buttonShowRemovedPlanes;
|
||||
public DrawingPlane SelectedPlane;
|
||||
Stack<DrawingPlane> _removedPlanes;
|
||||
|
||||
|
||||
public JPanel getPanelWrapper() {
|
||||
return PanelWrapper;
|
||||
}
|
||||
|
||||
public FormPlaneCollection() {
|
||||
PictureBoxCollection.setPreferredSize(new Dimension(800, 600));
|
||||
_storage = new PlanesGenericStorage(800, 600);
|
||||
_removedPlanes = new Stack<>();
|
||||
buttonAddPlane.addActionListener(this::buttonAddPlaneClicked);
|
||||
buttonRemovePlane.addActionListener(this::buttonRemovePlaneClicked);
|
||||
buttonRefreshCollection.addActionListener(this::buttonRefreshCollectionClicked);
|
||||
buttonOpenGenerateWindow.addActionListener(this::buttonOpenGenerateWindowClicked);
|
||||
buttonAddStorage.addActionListener(this::buttonAddStorageClicked);
|
||||
buttonRemoveStorage.addActionListener(this::buttonRemoveStorageClicked);
|
||||
listBoxStorages.addListSelectionListener(this::listBoxObjectsSelectedIndexChanged);
|
||||
buttonShowRemovedPlanes.addActionListener(this::buttonShowRemovedPlanesClicked);
|
||||
}
|
||||
|
||||
public JMenuBar getMenuBar() {
|
||||
JMenuBar menuBar = new JMenuBar();
|
||||
JMenu fileMenu = new JMenu("Файл");
|
||||
JMenuItem openItem = new JMenuItem("Загрузить");
|
||||
openItem.addActionListener(
|
||||
e -> {
|
||||
JFileChooser fileChooser = new JFileChooser();
|
||||
fileChooser.setFileFilter(new FileNameExtensionFilter("Текстовые файлы (*.txt)", "txt"));
|
||||
fileChooser.setDialogTitle("Выберите файл для загрузки данных");
|
||||
if (fileChooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) {
|
||||
File selectedFile = fileChooser.getSelectedFile();
|
||||
try {
|
||||
if (_storage.LoadData(selectedFile.getAbsolutePath())) {
|
||||
JOptionPane.showMessageDialog(null, "Загрузка прошла успешно", "Результат", JOptionPane.INFORMATION_MESSAGE);
|
||||
} else {
|
||||
JOptionPane.showMessageDialog(null, "Не загрузилось", "Результат", JOptionPane.ERROR_MESSAGE);
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
JOptionPane.showMessageDialog(
|
||||
null,
|
||||
"Ошибка при загрузке объектов" + ex.getMessage(),
|
||||
"Результат",
|
||||
JOptionPane.ERROR_MESSAGE
|
||||
);
|
||||
}
|
||||
}
|
||||
ReloadObjects();
|
||||
}
|
||||
);
|
||||
JMenuItem saveItem = new JMenuItem("Сохранить");
|
||||
saveItem.addActionListener(
|
||||
e -> {
|
||||
JFileChooser fileChooser = new JFileChooser();
|
||||
fileChooser.setDialogTitle("Выберите файл для сохранения данных");
|
||||
fileChooser.setFileFilter(new FileNameExtensionFilter("Текстовые файлы (*.txt)", "txt"));
|
||||
if (fileChooser.showSaveDialog(null) == JFileChooser.APPROVE_OPTION) {
|
||||
File selectedFile = fileChooser.getSelectedFile();
|
||||
try {
|
||||
if (_storage.SaveData(selectedFile.getAbsolutePath()))
|
||||
JOptionPane.showMessageDialog(null, "Сохранение прошло успешно", "Результат", JOptionPane.INFORMATION_MESSAGE);
|
||||
else
|
||||
JOptionPane.showMessageDialog(null, "Не сохранилось", "Результат", JOptionPane.ERROR_MESSAGE);
|
||||
} catch (Exception ex) {
|
||||
JOptionPane.showMessageDialog(
|
||||
null,
|
||||
"Ошибка при сохранении объектов" + ex.getMessage(),
|
||||
"Результат",
|
||||
JOptionPane.ERROR_MESSAGE
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
JMenuItem openItemSingle = new JMenuItem("Загрузить коллекцию");
|
||||
openItemSingle.addActionListener(
|
||||
e -> {
|
||||
JFileChooser fileChooser = new JFileChooser();
|
||||
fileChooser.setFileFilter(new FileNameExtensionFilter("Текстовые файлы (*.txt)", "txt"));
|
||||
fileChooser.setDialogTitle("Выберите файл для загрузки данных");
|
||||
if (fileChooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) {
|
||||
File selectedFile = fileChooser.getSelectedFile();
|
||||
if (_storage.LoadDataSingle(selectedFile.getAbsolutePath())) {
|
||||
JOptionPane.showMessageDialog(null, "Загрузка прошла успешно", "Результат", JOptionPane.INFORMATION_MESSAGE);
|
||||
} else {
|
||||
JOptionPane.showMessageDialog(null, "Не загрузилось", "Результат", JOptionPane.ERROR_MESSAGE);
|
||||
}
|
||||
}
|
||||
ReloadObjects();
|
||||
}
|
||||
);
|
||||
JMenuItem saveItemSingle = new JMenuItem("Сохранить коллекцию");
|
||||
saveItemSingle.addActionListener(
|
||||
e -> {
|
||||
if (listBoxStorages.getSelectedValue() == null) {
|
||||
JOptionPane.showMessageDialog(null, "Коллекция не выбрана", "Ошибка", JOptionPane.ERROR_MESSAGE);
|
||||
return;
|
||||
}
|
||||
JFileChooser fileChooser = new JFileChooser();
|
||||
fileChooser.setFileFilter(new FileNameExtensionFilter("Текстовые файлы (*.txt)", "txt"));
|
||||
fileChooser.setDialogTitle("Выберите файл для сохранения данных");
|
||||
if (fileChooser.showSaveDialog(null) == JFileChooser.APPROVE_OPTION) {
|
||||
File selectedFile = fileChooser.getSelectedFile();
|
||||
if (_storage.SaveDataSingle(selectedFile.getAbsolutePath(), (String) listBoxStorages.getSelectedValue()))
|
||||
JOptionPane.showMessageDialog(null, "Сохранение прошло успешно", "Результат", JOptionPane.INFORMATION_MESSAGE);
|
||||
else
|
||||
JOptionPane.showMessageDialog(null, "Не сохранилось", "Результат", JOptionPane.ERROR_MESSAGE);
|
||||
}
|
||||
}
|
||||
);
|
||||
fileMenu.add(openItem);
|
||||
fileMenu.add(saveItem);
|
||||
fileMenu.add(openItemSingle);
|
||||
fileMenu.add(saveItemSingle);
|
||||
menuBar.add(fileMenu);
|
||||
return menuBar;
|
||||
}
|
||||
|
||||
private void ReloadObjects() {
|
||||
int index = listBoxStorages.getSelectedIndex();
|
||||
listBoxStorages.setListData(_storage.Keys().toArray());
|
||||
if (listBoxStorages.getModel().getSize() > 0 && (index == -1 || index >= listBoxStorages.getModel().getSize())) {
|
||||
listBoxStorages.setSelectedIndex(0);
|
||||
} else if (listBoxStorages.getModel().getSize() > 0 && index > -1 && index < listBoxStorages.getModel().getSize()) {
|
||||
listBoxStorages.setSelectedIndex(index);
|
||||
}
|
||||
listBoxStorages.invalidate();
|
||||
}
|
||||
|
||||
private void buttonAddStorageClicked(ActionEvent e) {
|
||||
String storageName = textFieldStorageName.getText();
|
||||
if (Objects.equals(storageName, "")) {
|
||||
JOptionPane.showMessageDialog(this.getPanelWrapper(),
|
||||
"Введите название",
|
||||
"Ошибка",
|
||||
JOptionPane.ERROR_MESSAGE);
|
||||
return;
|
||||
}
|
||||
_storage.AddSet(storageName);
|
||||
ReloadObjects();
|
||||
}
|
||||
|
||||
private void listBoxObjectsSelectedIndexChanged(ListSelectionEvent e) {
|
||||
refreshPictureBox();
|
||||
}
|
||||
|
||||
private void buttonRemoveStorageClicked(ActionEvent e) {
|
||||
if (listBoxStorages.getSelectedIndex() == -1) {
|
||||
return;
|
||||
}
|
||||
Object[] options = {"Да", "Нет"};
|
||||
int n = JOptionPane.showOptionDialog(this.getPanelWrapper(),
|
||||
"Удалить объект?",
|
||||
"Все серьезно",
|
||||
JOptionPane.YES_NO_OPTION,
|
||||
JOptionPane.QUESTION_MESSAGE,
|
||||
null,
|
||||
options,
|
||||
options[0]
|
||||
);
|
||||
if (n == 1) {
|
||||
return;
|
||||
}
|
||||
_storage.DelSet(listBoxStorages.getSelectedValue().toString());
|
||||
ReloadObjects();
|
||||
}
|
||||
|
||||
public void buttonAddPlaneClicked(ActionEvent e) {
|
||||
FrameStormtrooper frameConfig = new FrameStormtrooper();
|
||||
FormPlaneConfig formConfig = new FormPlaneConfig();
|
||||
frameConfig.setContentPane(formConfig.panelWrapper);
|
||||
formConfig.buttonApply.addActionListener(ev -> {
|
||||
AddPlaneListener(formConfig.selectedPlane);
|
||||
frameConfig.dispose();
|
||||
});
|
||||
formConfig.buttonCancel.addActionListener(ev -> {
|
||||
frameConfig.dispose();
|
||||
});
|
||||
frameConfig.setVisible(true);
|
||||
}
|
||||
|
||||
public void AddPlaneListener(DrawingPlane plane) {
|
||||
if (listBoxStorages.getSelectedIndex() == -1) {
|
||||
return;
|
||||
}
|
||||
plane.SetDrawingBounds(PictureBoxCollection.getWidth(), PictureBoxCollection.getHeight());
|
||||
var obj = _storage.Get(listBoxStorages.getSelectedValue().toString());
|
||||
if (obj == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
SelectedPlane = plane;
|
||||
if (SelectedPlane != null) {
|
||||
if (obj.Add(SelectedPlane) > -1) {
|
||||
refreshPictureBox();
|
||||
JOptionPane.showMessageDialog(this.getPanelWrapper(),
|
||||
"Объект добавлен",
|
||||
"Успех",
|
||||
JOptionPane.INFORMATION_MESSAGE);
|
||||
} else {
|
||||
JOptionPane.showMessageDialog(this.getPanelWrapper(),
|
||||
"Не удалось добавить объект",
|
||||
"Ошибка",
|
||||
JOptionPane.ERROR_MESSAGE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void buttonRemovePlaneClicked(ActionEvent e) {
|
||||
if (listBoxStorages.getSelectedIndex() == -1) {
|
||||
return;
|
||||
}
|
||||
var obj = _storage.Get(listBoxStorages.getSelectedValue().toString());
|
||||
if (obj == null) {
|
||||
return;
|
||||
}
|
||||
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;
|
||||
}
|
||||
DrawingPlane removedPlane = obj.Sub(pos);
|
||||
if (removedPlane != null) {
|
||||
_removedPlanes.push(removedPlane);
|
||||
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 buttonShowRemovedPlanesClicked(ActionEvent e) {
|
||||
if (_removedPlanes.empty()) {
|
||||
JOptionPane.showMessageDialog(this.getPanelWrapper(),
|
||||
"Нет удаленных объектов",
|
||||
"Инфо",
|
||||
JOptionPane.INFORMATION_MESSAGE);
|
||||
return;
|
||||
}
|
||||
_frameRemovedPlanes = new FrameStormtrooper();
|
||||
_frameRemovedPlanes._formStromtrooper._drawingPlane = _removedPlanes.pop();
|
||||
_frameRemovedPlanes.setVisible(true);
|
||||
_frameRemovedPlanes._formStromtrooper.Draw();
|
||||
}
|
||||
|
||||
public void refreshPictureBox() {
|
||||
if (listBoxStorages.getSelectedIndex() == -1) {
|
||||
return;
|
||||
}
|
||||
var obj = _storage.Get(listBoxStorages.getSelectedValue().toString());
|
||||
if (obj == null) {
|
||||
return;
|
||||
}
|
||||
Graphics g = PictureBoxCollection.getGraphics();
|
||||
PictureBoxCollection.paint(g);
|
||||
obj.ShowPlanes(g);
|
||||
}
|
||||
}
|
339
ProjectStormtrooper/FormPlaneConfig.form
Normal file
339
ProjectStormtrooper/FormPlaneConfig.form
Normal file
@ -0,0 +1,339 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="ProjectStormtrooper.FormPlaneConfig">
|
||||
<grid id="27dc6" binding="panelWrapper" layout-manager="GridLayoutManager" row-count="3" 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="33" y="106" width="1116" height="569"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<grid id="4095a" binding="panelParams" layout-manager="GridLayoutManager" row-count="6" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<constraints>
|
||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<component id="58a35" class="javax.swing.JLabel" binding="labelSpeed">
|
||||
<constraints>
|
||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="Скорость"/>
|
||||
</properties>
|
||||
</component>
|
||||
<hspacer id="baa2">
|
||||
<constraints>
|
||||
<grid row="0" column="2" 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="2d1d6" class="javax.swing.JLabel" binding="labelWeight">
|
||||
<constraints>
|
||||
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="Вес"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="85fac" class="javax.swing.JSpinner" binding="spinnerSpeed">
|
||||
<constraints>
|
||||
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
</component>
|
||||
<component id="8ffa1" class="javax.swing.JSpinner" binding="spinnerWeight">
|
||||
<constraints>
|
||||
<grid row="1" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
</component>
|
||||
<component id="efbfc" class="javax.swing.JCheckBox" binding="checkBoxRockets">
|
||||
<constraints>
|
||||
<grid row="3" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<label value="Ракеты"/>
|
||||
<text value="Ракеты"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="6cca0" class="javax.swing.JCheckBox" binding="checkBoxBombs">
|
||||
<constraints>
|
||||
<grid row="4" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<label value="Бомбы"/>
|
||||
<text value="Бомбы"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="75e45" class="javax.swing.JButton" binding="buttonApply">
|
||||
<constraints>
|
||||
<grid row="5" column="0" row-span="1" col-span="2" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="Добавить"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="85e09" class="javax.swing.JButton" binding="buttonCancel">
|
||||
<constraints>
|
||||
<grid row="5" 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>
|
||||
<component id="b7976" class="javax.swing.JLabel" binding="labelEnginesCount">
|
||||
<constraints>
|
||||
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="Двигателей"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="eacb0" class="javax.swing.JSpinner" binding="spinnerEnginesCount">
|
||||
<constraints>
|
||||
<grid row="2" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
</component>
|
||||
<component id="2bd5a" class="javax.swing.JLabel" binding="labelPlane">
|
||||
<constraints>
|
||||
<grid row="1" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="Простой"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="1764d" class="javax.swing.JLabel" binding="labelStormtrooper">
|
||||
<constraints>
|
||||
<grid row="2" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="Продвинутый"/>
|
||||
</properties>
|
||||
</component>
|
||||
</children>
|
||||
</grid>
|
||||
<grid id="b5fd1" binding="panelShow" custom-create="true" 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>
|
||||
<grid row="0" column="1" row-span="3" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<vspacer id="4ecd9">
|
||||
<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>
|
||||
<grid id="503d1" binding="panelLabelColorTargetBackground" 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>
|
||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false">
|
||||
<minimum-size width="40" height="40"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<component id="60b6e" class="javax.swing.JLabel" binding="labelColorTarget" custom-create="true">
|
||||
<constraints>
|
||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="Цвет"/>
|
||||
</properties>
|
||||
</component>
|
||||
</children>
|
||||
</grid>
|
||||
<grid id="c761e" binding="panelLabelAddColorTargetBackground" 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>
|
||||
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false">
|
||||
<minimum-size width="40" height="40"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<component id="1625" class="javax.swing.JLabel" binding="labelAddColorTarget" custom-create="true">
|
||||
<constraints>
|
||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="Доп. цвет"/>
|
||||
</properties>
|
||||
</component>
|
||||
</children>
|
||||
</grid>
|
||||
</children>
|
||||
</grid>
|
||||
<grid id="d6d47" binding="panelColors" layout-manager="GridLayoutManager" row-count="2" column-count="4" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<constraints>
|
||||
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<grid id="30f6a" binding="panelColorRed" 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>
|
||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false">
|
||||
<minimum-size width="25" height="25"/>
|
||||
<preferred-size width="25" height="25"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties>
|
||||
<background color="-65536"/>
|
||||
<foreground color="-65536"/>
|
||||
</properties>
|
||||
<border type="none"/>
|
||||
<children/>
|
||||
</grid>
|
||||
<grid id="1d871" binding="panelColorGreen" 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>
|
||||
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false">
|
||||
<minimum-size width="25" height="25"/>
|
||||
<preferred-size width="25" height="25"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties>
|
||||
<background color="-16711936"/>
|
||||
<foreground color="-16711936"/>
|
||||
</properties>
|
||||
<border type="none"/>
|
||||
<children/>
|
||||
</grid>
|
||||
<grid id="e8ff7" binding="panelColorBlue" 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>
|
||||
<grid row="0" column="2" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false">
|
||||
<minimum-size width="25" height="25"/>
|
||||
<preferred-size width="25" height="25"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties>
|
||||
<background color="-16776961"/>
|
||||
<foreground color="-16776961"/>
|
||||
</properties>
|
||||
<border type="none"/>
|
||||
<children/>
|
||||
</grid>
|
||||
<grid id="cbc25" binding="panelColorYellow" 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>
|
||||
<grid row="0" column="3" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false">
|
||||
<minimum-size width="25" height="25"/>
|
||||
<preferred-size width="25" height="25"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties>
|
||||
<background color="-256"/>
|
||||
<foreground color="-256"/>
|
||||
</properties>
|
||||
<border type="none"/>
|
||||
<children/>
|
||||
</grid>
|
||||
<grid id="55334" binding="panelColorBlack" 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>
|
||||
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false">
|
||||
<minimum-size width="25" height="25"/>
|
||||
<preferred-size width="25" height="25"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties>
|
||||
<background color="-16777216"/>
|
||||
<foreground color="-16777216"/>
|
||||
</properties>
|
||||
<border type="none"/>
|
||||
<children/>
|
||||
</grid>
|
||||
<grid id="ef939" binding="panelColorPink" 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>
|
||||
<grid row="1" column="1" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false">
|
||||
<minimum-size width="25" height="25"/>
|
||||
<preferred-size width="25" height="25"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties>
|
||||
<background color="-1729845"/>
|
||||
<foreground color="-1729845"/>
|
||||
</properties>
|
||||
<border type="none"/>
|
||||
<children/>
|
||||
</grid>
|
||||
<grid id="1b9f4" binding="panelColorOrange" 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>
|
||||
<grid row="1" column="2" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false">
|
||||
<minimum-size width="25" height="25"/>
|
||||
<preferred-size width="25" height="25"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties>
|
||||
<background color="-1732047"/>
|
||||
<foreground color="-1732047"/>
|
||||
</properties>
|
||||
<border type="none"/>
|
||||
<children/>
|
||||
</grid>
|
||||
<grid id="dd803" binding="panelColorPurple" 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>
|
||||
<grid row="1" column="3" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false">
|
||||
<minimum-size width="25" height="25"/>
|
||||
<preferred-size width="25" height="25"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties>
|
||||
<background color="-1767480"/>
|
||||
<foreground color="-1767480"/>
|
||||
</properties>
|
||||
<border type="none"/>
|
||||
<children/>
|
||||
</grid>
|
||||
</children>
|
||||
</grid>
|
||||
<grid id="74e84" layout-manager="GridLayoutManager" row-count="1" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<constraints>
|
||||
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<component id="c8143" class="javax.swing.JLabel" binding="labelEllipseEngines">
|
||||
<constraints>
|
||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="Эллипс"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="1344b" class="javax.swing.JLabel" binding="labelSimpleEngines">
|
||||
<constraints>
|
||||
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="Обычный"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="c1e0e" class="javax.swing.JLabel" binding="labelPyramidEngines">
|
||||
<constraints>
|
||||
<grid row="0" column="2" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="Пирамид"/>
|
||||
</properties>
|
||||
</component>
|
||||
</children>
|
||||
</grid>
|
||||
</children>
|
||||
</grid>
|
||||
</form>
|
333
ProjectStormtrooper/FormPlaneConfig.java
Normal file
333
ProjectStormtrooper/FormPlaneConfig.java
Normal file
@ -0,0 +1,333 @@
|
||||
package ProjectStormtrooper;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.border.EmptyBorder;
|
||||
import java.awt.*;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.datatransfer.DataFlavor;
|
||||
import java.awt.datatransfer.Transferable;
|
||||
import java.awt.datatransfer.StringSelection;
|
||||
import java.awt.datatransfer.UnsupportedFlavorException;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.io.IOException;
|
||||
|
||||
public class FormPlaneConfig {
|
||||
public DrawingPlane selectedPlane;
|
||||
private JPanel panelColorRed;
|
||||
private JPanel panelColorGreen;
|
||||
private JPanel panelColorBlue;
|
||||
private JPanel panelColorYellow;
|
||||
private JPanel panelColorBlack;
|
||||
private JPanel panelColorPink;
|
||||
private JPanel panelColorOrange;
|
||||
private JPanel panelColorPurple;
|
||||
public JPanel panelWrapper;
|
||||
private JPanel panelParams;
|
||||
private JComponent panelShow;
|
||||
private JPanel panelColors;
|
||||
private JSpinner spinnerSpeed;
|
||||
private JSpinner spinnerWeight;
|
||||
private JLabel labelSpeed;
|
||||
private JLabel labelWeight;
|
||||
private JCheckBox checkBoxRockets;
|
||||
private JCheckBox checkBoxBombs;
|
||||
private JLabel labelColorTarget;
|
||||
private JLabel labelAddColorTarget;
|
||||
public JButton buttonApply;
|
||||
public JButton buttonCancel;
|
||||
private JLabel labelEllipseEngines;
|
||||
private JLabel labelSimpleEngines;
|
||||
private JLabel labelPyramidEngines;
|
||||
private JLabel labelEnginesCount;
|
||||
private JSpinner spinnerEnginesCount;
|
||||
private JLabel labelPlane;
|
||||
private JLabel labelStormtrooper;
|
||||
private JPanel panelLabelColorTargetBackground;
|
||||
private JPanel panelLabelAddColorTargetBackground;
|
||||
|
||||
public FormPlaneConfig() {
|
||||
SpinnerModel numSpeed = new SpinnerNumberModel(100, 100, 1000, 1);
|
||||
spinnerSpeed.setModel(numSpeed);
|
||||
spinnerWeight.setModel(numSpeed);
|
||||
labelPlane.setBorder(new EmptyBorder(20, 40, 20, 40));
|
||||
labelStormtrooper.setBorder(new EmptyBorder(20, 40, 20, 40));
|
||||
|
||||
labelPlane.setTransferHandler(new LabelTransferHandler());
|
||||
labelPlane.addMouseListener(new LabelMouseAdapter());
|
||||
|
||||
labelStormtrooper.setTransferHandler(new LabelTransferHandler());
|
||||
labelStormtrooper.addMouseListener(new LabelMouseAdapter());
|
||||
|
||||
labelEllipseEngines.setTransferHandler(
|
||||
new TransferHandler(){
|
||||
@Override
|
||||
public int getSourceActions(JComponent c) {
|
||||
return TransferHandler.COPY;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Transferable createTransferable(JComponent c) {
|
||||
return new EngineTransferable(new DrawingEnginesEllipse());
|
||||
}
|
||||
}
|
||||
);
|
||||
labelEllipseEngines.addMouseListener(new LabelMouseAdapter());
|
||||
|
||||
labelPyramidEngines.setTransferHandler(
|
||||
new TransferHandler(){
|
||||
@Override
|
||||
public int getSourceActions(JComponent c) {
|
||||
return TransferHandler.COPY;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Transferable createTransferable(JComponent c) {
|
||||
return new EngineTransferable(new DrawingEnginesPyramid());
|
||||
}
|
||||
}
|
||||
);
|
||||
labelPyramidEngines.addMouseListener(new LabelMouseAdapter());
|
||||
|
||||
labelSimpleEngines.setTransferHandler(
|
||||
new TransferHandler(){
|
||||
@Override
|
||||
public int getSourceActions(JComponent c) {
|
||||
return TransferHandler.COPY;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Transferable createTransferable(JComponent c) {
|
||||
return new EngineTransferable(new DrawingEnginesSimple());
|
||||
}
|
||||
}
|
||||
);
|
||||
labelSimpleEngines.addMouseListener(new LabelMouseAdapter());
|
||||
|
||||
JPanel[] colorPanels = {
|
||||
panelColorBlack,
|
||||
panelColorBlue,
|
||||
panelColorGreen,
|
||||
panelColorPink,
|
||||
panelColorPurple,
|
||||
panelColorOrange,
|
||||
panelColorRed,
|
||||
panelColorYellow
|
||||
};
|
||||
|
||||
for (var panelColor : colorPanels) {
|
||||
panelColor.setTransferHandler(new PanelTransferHandler());
|
||||
panelColor.addMouseListener(new PanelMouseAdapter());
|
||||
}
|
||||
|
||||
panelLabelColorTargetBackground.setTransferHandler(
|
||||
new TransferHandler() {
|
||||
@Override
|
||||
public boolean canImport(TransferHandler.TransferSupport support) {
|
||||
try {
|
||||
Color color = (Color) support.getTransferable().getTransferData(ColorTransferable.colorDataFlavor);
|
||||
if (selectedPlane == null) return false;
|
||||
selectedPlane.EntityPlane.SetBodyColor(color);
|
||||
panelLabelColorTargetBackground.setBackground(color);
|
||||
return true;
|
||||
} catch (UnsupportedFlavorException | IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
panelLabelAddColorTargetBackground.setTransferHandler(
|
||||
new TransferHandler() {
|
||||
@Override
|
||||
public boolean canImport(TransferHandler.TransferSupport support) {
|
||||
try {
|
||||
Color color = (Color) support.getTransferable().getTransferData(ColorTransferable.colorDataFlavor);
|
||||
panelLabelAddColorTargetBackground.setBackground(color);
|
||||
if (selectedPlane == null) return false;
|
||||
if (!(selectedPlane instanceof DrawingStormtrooper))
|
||||
return false;
|
||||
((EntityStormtrooper) selectedPlane.EntityPlane).SetAdditionalColor(color);
|
||||
return true;
|
||||
} catch (UnsupportedFlavorException | IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
);
|
||||
|
||||
panelShow.setTransferHandler(
|
||||
new TransferHandler() {
|
||||
@Override
|
||||
public boolean canImport(TransferHandler.TransferSupport support) {
|
||||
return support.isDataFlavorSupported(DataFlavor.stringFlavor) || support.isDataFlavorSupported(EngineTransferable.engineDrawingDataFlavor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean importData(TransferHandler.TransferSupport support) {
|
||||
if (canImport(support)) {
|
||||
try {
|
||||
String data = (String) support.getTransferable().getTransferData(DataFlavor.stringFlavor);
|
||||
switch (data) {
|
||||
case "Простой" -> selectedPlane = new DrawingPlane(
|
||||
(int) spinnerSpeed.getValue(),
|
||||
(int) spinnerWeight.getValue(),
|
||||
Color.WHITE,
|
||||
panelShow.getWidth(),
|
||||
panelShow.getHeight()
|
||||
);
|
||||
case "Продвинутый" -> selectedPlane = new DrawingStormtrooper(
|
||||
(int) spinnerSpeed.getValue(),
|
||||
(int) spinnerWeight.getValue(),
|
||||
Color.WHITE,
|
||||
Color.BLACK,
|
||||
checkBoxRockets.isSelected(),
|
||||
checkBoxBombs.isSelected(),
|
||||
panelShow.getWidth(),
|
||||
panelShow.getHeight()
|
||||
);
|
||||
}
|
||||
if (selectedPlane != null) {
|
||||
selectedPlane.SetPosition((panelShow.getWidth() - selectedPlane.GetWidth()) / 2, (panelShow.getHeight() - selectedPlane.GetHeight()) / 2);
|
||||
panelLabelColorTargetBackground.setBackground(null);
|
||||
panelLabelAddColorTargetBackground.setBackground(null);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} catch (UnsupportedFlavorException | IOException e) {
|
||||
}
|
||||
|
||||
try {
|
||||
IDrawingEngines drawingEngines = (IDrawingEngines) support.getTransferable().getTransferData(EngineTransferable.engineDrawingDataFlavor);
|
||||
int enginesCount = (int) spinnerEnginesCount.getValue();
|
||||
selectedPlane._drawingEngines = drawingEngines;
|
||||
selectedPlane.SetEnginesCount(enginesCount);
|
||||
}
|
||||
catch (UnsupportedFlavorException | IOException e) {
|
||||
}
|
||||
panelShow.repaint();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
private class Canvas extends JComponent {
|
||||
public Canvas() {
|
||||
}
|
||||
|
||||
public void paintComponent(Graphics g) {
|
||||
if (selectedPlane == null) {
|
||||
return;
|
||||
}
|
||||
super.paintComponents(g);
|
||||
Graphics2D g2d = (Graphics2D) g;
|
||||
selectedPlane.DrawTransport(g2d);
|
||||
super.repaint();
|
||||
}
|
||||
}
|
||||
|
||||
private class LabelTransferHandler extends TransferHandler {
|
||||
@Override
|
||||
public int getSourceActions(JComponent c) {
|
||||
return TransferHandler.COPY;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Transferable createTransferable(JComponent c) {
|
||||
return new StringSelection(((JLabel) c).getText());
|
||||
}
|
||||
}
|
||||
|
||||
private class EngineTransferable implements Transferable {
|
||||
private IDrawingEngines drawingEngines;
|
||||
private static final DataFlavor engineDrawingDataFlavor = new DataFlavor(IDrawingEngines.class, "Engine Drawing");
|
||||
|
||||
public EngineTransferable(IDrawingEngines drawingEngines) {
|
||||
this.drawingEngines = drawingEngines;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DataFlavor[] getTransferDataFlavors() {
|
||||
return new DataFlavor[]{engineDrawingDataFlavor};
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDataFlavorSupported(DataFlavor flavor) {
|
||||
return flavor.equals(engineDrawingDataFlavor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException {
|
||||
if (isDataFlavorSupported(flavor)) {
|
||||
return drawingEngines;
|
||||
} else {
|
||||
throw new UnsupportedFlavorException(flavor);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private class ColorTransferable implements Transferable {
|
||||
private Color color;
|
||||
private static final DataFlavor colorDataFlavor = new DataFlavor(Color.class, "Color");
|
||||
|
||||
public ColorTransferable(Color color) {
|
||||
this.color = color;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DataFlavor[] getTransferDataFlavors() {
|
||||
return new DataFlavor[]{colorDataFlavor};
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDataFlavorSupported(DataFlavor flavor) {
|
||||
return colorDataFlavor.equals(flavor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException {
|
||||
if (isDataFlavorSupported(flavor)) {
|
||||
return color;
|
||||
} else {
|
||||
throw new UnsupportedFlavorException(flavor);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private class PanelTransferHandler extends TransferHandler {
|
||||
@Override
|
||||
public int getSourceActions(JComponent c) {
|
||||
return TransferHandler.COPY;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Transferable createTransferable(JComponent c) {
|
||||
return new ColorTransferable(c.getBackground());
|
||||
}
|
||||
}
|
||||
|
||||
private class LabelMouseAdapter extends MouseAdapter {
|
||||
@Override
|
||||
public void mousePressed(MouseEvent e) {
|
||||
((JLabel) e.getComponent()).getTransferHandler().exportAsDrag(((JLabel) e.getComponent()), e, TransferHandler.COPY);
|
||||
}
|
||||
}
|
||||
|
||||
private class PanelMouseAdapter extends MouseAdapter {
|
||||
@Override
|
||||
public void mousePressed(MouseEvent e) {
|
||||
((JPanel) e.getComponent()).getTransferHandler().exportAsDrag(((JPanel) e.getComponent()), e, TransferHandler.COPY);
|
||||
}
|
||||
}
|
||||
|
||||
private void createUIComponents() {
|
||||
panelShow = new Canvas();
|
||||
labelColorTarget = new JLabel("Цвет");
|
||||
labelAddColorTarget = new JLabel("Доп. цвет");
|
||||
}
|
||||
}
|
124
ProjectStormtrooper/FormStormtrooper.form
Normal file
124
ProjectStormtrooper/FormStormtrooper.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="ProjectStormtrooper.FormStormtrooper">
|
||||
<grid id="27dc6" binding="pictureBox" custom-create="true" 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="buttonCreateStormtrooper">
|
||||
<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>
|
||||
<hspacer id="f9ba0">
|
||||
<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>
|
||||
<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="ProjectStormtrooper/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="ProjectStormtrooper/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="ProjectStormtrooper/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="ProjectStormtrooper/img/arrowRIGHT.png"/>
|
||||
<text value=""/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="d1f31" 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>
|
||||
<component id="aefae" 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="c79a6" 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="f339a" 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>
|
161
ProjectStormtrooper/FormStormtrooper.java
Normal file
161
ProjectStormtrooper/FormStormtrooper.java
Normal file
@ -0,0 +1,161 @@
|
||||
package ProjectStormtrooper;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import javax.swing.JColorChooser;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.util.Random;
|
||||
import java.awt.event.ActionListener;
|
||||
|
||||
public class FormStormtrooper extends JDialog {
|
||||
public DrawingPlane _drawingPlane;
|
||||
AbstractStrategy _abstractStrategy;
|
||||
private JButton buttonCreateStormtrooper;
|
||||
private JComponent pictureBox;
|
||||
private JButton buttonDown;
|
||||
private JButton buttonUp;
|
||||
private JButton buttonLeft;
|
||||
public JButton buttonRight;
|
||||
private JButton buttonCreatePlane;
|
||||
private JComboBox comboBoxStrategy;
|
||||
private JButton buttonStep;
|
||||
public JButton buttonSelectPlane;
|
||||
|
||||
public JComponent getPictureBox() {
|
||||
return pictureBox;
|
||||
}
|
||||
|
||||
private class Canvas extends JPanel{
|
||||
public Canvas(){
|
||||
}
|
||||
public void paintComponent (Graphics g){
|
||||
if (_drawingPlane == null){
|
||||
return;
|
||||
}
|
||||
|
||||
Graphics2D g2d = (Graphics2D)g;
|
||||
g2d.setColor(getBackground());
|
||||
g2d.fillRect(0, 0, getWidth(), getHeight());
|
||||
super.paintComponents(g);
|
||||
_drawingPlane.DrawTransport(g2d);
|
||||
super.repaint();
|
||||
}
|
||||
}
|
||||
|
||||
public FormStormtrooper() {
|
||||
buttonUp.setName("buttonUp");
|
||||
buttonDown.setName("buttonDown");
|
||||
buttonLeft.setName("buttonLeft");
|
||||
buttonRight.setName("buttonRight");
|
||||
|
||||
buttonCreateStormtrooper.addActionListener(e -> {
|
||||
Random random = new Random();
|
||||
|
||||
Color color = JColorChooser.showDialog(this.pictureBox, "Выберите цвет", Color.BLACK);
|
||||
Color additionalColor = JColorChooser.showDialog(this.pictureBox, "Выберите дополнительный цвет", Color.BLACK);
|
||||
|
||||
|
||||
_drawingPlane = new DrawingStormtrooper(
|
||||
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;
|
||||
}
|
||||
});
|
||||
|
||||
buttonUp.addActionListener(this::buttonMoveClickedListener);
|
||||
buttonDown.addActionListener(this::buttonMoveClickedListener);
|
||||
buttonLeft.addActionListener(this::buttonMoveClickedListener);
|
||||
buttonRight.addActionListener(this::buttonMoveClickedListener);
|
||||
}
|
||||
|
||||
public void buttonMoveClickedListener(ActionEvent 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);
|
||||
}
|
||||
default -> _drawingPlane.MoveTransport(EnumDirectionType.Right);
|
||||
}
|
||||
|
||||
Draw();
|
||||
}
|
||||
|
||||
public void Draw() {
|
||||
pictureBox.repaint();
|
||||
}
|
||||
|
||||
private void createUIComponents() {
|
||||
String[] strategiesList = {
|
||||
"MoveToCenter",
|
||||
"MoveToRightBottom"
|
||||
};
|
||||
comboBoxStrategy = new JComboBox(strategiesList);
|
||||
pictureBox = new Canvas();
|
||||
pictureBox.setBounds(new Rectangle(400, 300));
|
||||
}
|
||||
}
|
17
ProjectStormtrooper/FrameDoubleParametrized.java
Normal file
17
ProjectStormtrooper/FrameDoubleParametrized.java
Normal file
@ -0,0 +1,17 @@
|
||||
package ProjectStormtrooper;
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
18
ProjectStormtrooper/FramePlaneCollection.java
Normal file
18
ProjectStormtrooper/FramePlaneCollection.java
Normal file
@ -0,0 +1,18 @@
|
||||
package ProjectStormtrooper;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
public class FramePlaneCollection extends JFrame {
|
||||
FormPlaneCollection _formPlaneCollection;
|
||||
public FramePlaneCollection() {
|
||||
super();
|
||||
setTitle("Набор самолетов");
|
||||
setDefaultCloseOperation(EXIT_ON_CLOSE);
|
||||
_formPlaneCollection = new FormPlaneCollection();
|
||||
setContentPane(_formPlaneCollection.getPanelWrapper());
|
||||
this.setJMenuBar(_formPlaneCollection.getMenuBar());
|
||||
setDefaultLookAndFeelDecorated(false);
|
||||
setLocation(300, 100);
|
||||
pack();
|
||||
}
|
||||
}
|
17
ProjectStormtrooper/FrameStormtrooper.java
Normal file
17
ProjectStormtrooper/FrameStormtrooper.java
Normal file
@ -0,0 +1,17 @@
|
||||
package ProjectStormtrooper;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
public class FrameStormtrooper extends JFrame {
|
||||
public FormStormtrooper _formStromtrooper;
|
||||
public FrameStormtrooper() {
|
||||
super();
|
||||
setTitle("Штурмовик");
|
||||
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
|
||||
_formStromtrooper = new FormStormtrooper();
|
||||
setContentPane(_formStromtrooper.getPictureBox());
|
||||
setDefaultLookAndFeelDecorated(false);
|
||||
setLocation(300, 100);
|
||||
pack();
|
||||
}
|
||||
}
|
73
ProjectStormtrooper/IDrawingEngines.java
Normal file
73
ProjectStormtrooper/IDrawingEngines.java
Normal file
@ -0,0 +1,73 @@
|
||||
package ProjectStormtrooper;
|
||||
|
||||
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
ProjectStormtrooper/IMoveableObject.java
Normal file
8
ProjectStormtrooper/IMoveableObject.java
Normal file
@ -0,0 +1,8 @@
|
||||
package ProjectStormtrooper;
|
||||
|
||||
public interface IMoveableObject {
|
||||
ObjectParameters GetObjectPosition();
|
||||
int GetStep();
|
||||
boolean CheckCanMove(EnumDirectionType direction);
|
||||
void MoveObject(EnumDirectionType direction);
|
||||
}
|
8
ProjectStormtrooper/Main.java
Normal file
8
ProjectStormtrooper/Main.java
Normal file
@ -0,0 +1,8 @@
|
||||
package ProjectStormtrooper;
|
||||
|
||||
public class Main {
|
||||
public static void main(String[] args) {
|
||||
FramePlaneCollection framePlaneCollection = new FramePlaneCollection();
|
||||
framePlaneCollection.setVisible(true);
|
||||
}
|
||||
}
|
37
ProjectStormtrooper/MoveToCenter.java
Normal file
37
ProjectStormtrooper/MoveToCenter.java
Normal file
@ -0,0 +1,37 @@
|
||||
package ProjectStormtrooper;
|
||||
|
||||
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
ProjectStormtrooper/MoveToRightBottom.java
Normal file
26
ProjectStormtrooper/MoveToRightBottom.java
Normal file
@ -0,0 +1,26 @@
|
||||
package ProjectStormtrooper;
|
||||
|
||||
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
ProjectStormtrooper/ObjectParameters.java
Normal file
39
ProjectStormtrooper/ObjectParameters.java
Normal file
@ -0,0 +1,39 @@
|
||||
package ProjectStormtrooper;
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
22
ProjectStormtrooper/PlaneNotFoundException.java
Normal file
22
ProjectStormtrooper/PlaneNotFoundException.java
Normal file
@ -0,0 +1,22 @@
|
||||
package ProjectStormtrooper;
|
||||
|
||||
public class PlaneNotFoundException extends RuntimeException {
|
||||
public PlaneNotFoundException() {
|
||||
}
|
||||
|
||||
public PlaneNotFoundException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public PlaneNotFoundException(String message, Throwable exception) {
|
||||
super(message, exception);
|
||||
}
|
||||
|
||||
public PlaneNotFoundException(Throwable exception) {
|
||||
super(exception);
|
||||
}
|
||||
|
||||
protected PlaneNotFoundException(int pos) {
|
||||
super("Не найден объект по позиции " + pos);
|
||||
}
|
||||
}
|
86
ProjectStormtrooper/PlanesGenericCollection.java
Normal file
86
ProjectStormtrooper/PlanesGenericCollection.java
Normal file
@ -0,0 +1,86 @@
|
||||
package ProjectStormtrooper;
|
||||
|
||||
import java.awt.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Stack;
|
||||
|
||||
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 ArrayList<T> GetPlanes() {
|
||||
return _collection.GetEnumerator();
|
||||
}
|
||||
|
||||
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) {
|
||||
T obj = _collection.Get(pos);
|
||||
if (obj != null) {
|
||||
_collection.Remove(pos);
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
|
||||
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;
|
||||
int i = 0;
|
||||
for (var obj :
|
||||
_collection.GetEnumerator()) {
|
||||
// установка позиции
|
||||
if (obj != null) {
|
||||
obj.SetPosition(
|
||||
(placesRowCount - 1) * _placeSizeWidth - (i % placesColumnCount * _placeSizeWidth) + (_placeSizeWidth - obj.GetWidth()) / 2,
|
||||
i / placesColumnCount * _placeSizeHeight + (_placeSizeHeight - obj.GetHeight()) / 2
|
||||
);
|
||||
// прорисовка объекта
|
||||
obj.DrawTransport(g);
|
||||
}
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
_collection.clear();
|
||||
}
|
||||
}
|
185
ProjectStormtrooper/PlanesGenericStorage.java
Normal file
185
ProjectStormtrooper/PlanesGenericStorage.java
Normal file
@ -0,0 +1,185 @@
|
||||
package ProjectStormtrooper;
|
||||
|
||||
import java.util.*;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
|
||||
public class PlanesGenericStorage {
|
||||
final HashMap<String, PlanesGenericCollection<DrawingPlane, DrawingObjectPlane>> _planeStorages;
|
||||
private static final String _separatorForKeyValue = "@";
|
||||
private static final String _separatorRecords = ";";
|
||||
private static final String _separatorForObject = ":";
|
||||
private static final String _separatorForObjectSingle = "::";
|
||||
private static final String _keyword = "PlanesStorage";
|
||||
private static final String _keywordSingle = "PlanesStorageSingle";
|
||||
|
||||
public List<String> Keys() {
|
||||
return _planeStorages.keySet().stream().toList();
|
||||
}
|
||||
|
||||
private final int _pictureWidth;
|
||||
private final int _pictureHeight;
|
||||
|
||||
public PlanesGenericStorage(int pictureWidth, int pictureHeight) {
|
||||
_planeStorages = new HashMap<>();
|
||||
_pictureWidth = pictureWidth;
|
||||
_pictureHeight = pictureHeight;
|
||||
}
|
||||
|
||||
public void AddSet(String name) {
|
||||
_planeStorages.put(name, new PlanesGenericCollection<>(_pictureWidth, _pictureHeight));
|
||||
}
|
||||
|
||||
public void DelSet(String name) {
|
||||
_planeStorages.remove(name);
|
||||
}
|
||||
|
||||
public PlanesGenericCollection<DrawingPlane, DrawingObjectPlane> Get(String ind) {
|
||||
if (_planeStorages.containsKey(ind))
|
||||
return _planeStorages.get(ind);
|
||||
return null;
|
||||
}
|
||||
|
||||
public DrawingObjectPlane GetByDoubleParameter(String storageName, int planeIndex) {
|
||||
if (_planeStorages.containsKey(storageName)) {
|
||||
return _planeStorages.get(storageName).GetU(planeIndex);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean SaveDataSingle(String filename, String key) {
|
||||
var file = new File(filename);
|
||||
if (file.exists()) {
|
||||
file.delete();
|
||||
}
|
||||
StringBuilder data = new StringBuilder();
|
||||
data.append(key).append("\n");
|
||||
for (DrawingPlane elem : _planeStorages.get(key).GetPlanes())
|
||||
data.append(elem != null ? ExtensionDrawingPlane.GetDataForSave(elem, _separatorForObjectSingle) + "\n" : "");
|
||||
if (data.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
try (BufferedWriter writer = new BufferedWriter(new FileWriter(filename))) {
|
||||
writer.write(_keywordSingle + System.lineSeparator() + data);
|
||||
} catch (IOException e) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean LoadDataSingle(String filename) {
|
||||
if (!new File(filename).exists()) {
|
||||
return false;
|
||||
}
|
||||
try (BufferedReader reader = new BufferedReader(new FileReader(filename))) {
|
||||
String s = reader.readLine();
|
||||
if (s == null || s.isEmpty())
|
||||
return false;
|
||||
if (!s.startsWith(_keywordSingle))
|
||||
return false;
|
||||
String key = reader.readLine();
|
||||
if (key == null || key.isEmpty())
|
||||
return false;
|
||||
PlanesGenericCollection<DrawingPlane, DrawingObjectPlane> collection;
|
||||
if (_planeStorages.containsKey(key)) {
|
||||
collection = _planeStorages.get(key);
|
||||
collection.clear();
|
||||
} else
|
||||
collection = new PlanesGenericCollection<>(_pictureWidth, _pictureHeight);
|
||||
List<String> plainsStrings = new ArrayList<>();
|
||||
s = reader.readLine();
|
||||
while (s != null && !s.isEmpty()) {
|
||||
plainsStrings.add(s);
|
||||
s = reader.readLine();
|
||||
}
|
||||
Collections.reverse(plainsStrings);
|
||||
for (String elem : plainsStrings) {
|
||||
DrawingPlane plane = ExtensionDrawingPlane.CreateDrawingPlane(
|
||||
elem,
|
||||
_separatorForObjectSingle,
|
||||
_pictureWidth,
|
||||
_pictureHeight
|
||||
);
|
||||
if (plane == null || collection.Add(plane) == -1)
|
||||
return false;
|
||||
}
|
||||
_planeStorages.put(key, collection);
|
||||
} catch (IOException e) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean SaveData(String filename) throws Exception {
|
||||
var file = new File(filename);
|
||||
if (file.exists()) {
|
||||
file.delete();
|
||||
}
|
||||
StringBuilder data = new StringBuilder();
|
||||
for (Map.Entry<String, PlanesGenericCollection<DrawingPlane, DrawingObjectPlane>> record : _planeStorages.entrySet()) {
|
||||
StringBuilder records = new StringBuilder();
|
||||
for (DrawingPlane elem : record.getValue().GetPlanes()) {
|
||||
records.append(elem != null ? ExtensionDrawingPlane.GetDataForSave(elem, _separatorForObject) + _separatorRecords : "");
|
||||
}
|
||||
data.append(record.getKey()).append(_separatorForKeyValue).append(records).append("\n");
|
||||
}
|
||||
if (data.isEmpty()) {
|
||||
throw new Exception("Невалидная операция, нет данных для сохранения");
|
||||
}
|
||||
try (BufferedWriter writer = new BufferedWriter(new FileWriter(filename))) {
|
||||
writer.write(_keyword + System.lineSeparator() + data);
|
||||
} catch (IOException e) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean LoadData(String filename) throws Exception {
|
||||
var file = new File(filename);
|
||||
if (!file.exists()) {
|
||||
throw new Exception("Файл не найден");
|
||||
}
|
||||
try (BufferedReader reader = new BufferedReader(new FileReader(filename))) {
|
||||
String s = reader.readLine();
|
||||
if (s == null || s.isEmpty())
|
||||
throw new Exception("Нет данных для загрузки");
|
||||
|
||||
if (!s.startsWith(_keyword)) {
|
||||
throw new Exception("Неверный формат данных");
|
||||
}
|
||||
_planeStorages.clear();
|
||||
s = reader.readLine();
|
||||
while (s != null && !s.isEmpty()) {
|
||||
String[] record = s.split(_separatorForKeyValue);
|
||||
s = reader.readLine();
|
||||
if (record.length != 2) {
|
||||
continue;
|
||||
}
|
||||
PlanesGenericCollection<DrawingPlane, DrawingObjectPlane> collection = new PlanesGenericCollection<>(_pictureWidth, _pictureHeight);
|
||||
String[] set = record[1].split(_separatorRecords);
|
||||
List<String> reversedSet = Arrays.asList(set);
|
||||
Collections.reverse(reversedSet);
|
||||
for (String elem : reversedSet) {
|
||||
DrawingPlane plane = ExtensionDrawingPlane.CreateDrawingPlane(
|
||||
elem,
|
||||
_separatorForObject,
|
||||
_pictureWidth, _pictureHeight
|
||||
);
|
||||
if (plane != null) {
|
||||
if (collection.Add(plane) == -1) {
|
||||
throw new Exception("Ошибка добавления в коллекцию");
|
||||
}
|
||||
}
|
||||
}
|
||||
_planeStorages.put(record[0], collection);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
22
ProjectStormtrooper/PlanesStorageOverflowException.java
Normal file
22
ProjectStormtrooper/PlanesStorageOverflowException.java
Normal file
@ -0,0 +1,22 @@
|
||||
package ProjectStormtrooper;
|
||||
|
||||
public class PlanesStorageOverflowException extends RuntimeException {
|
||||
public PlanesStorageOverflowException() {
|
||||
}
|
||||
|
||||
public PlanesStorageOverflowException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public PlanesStorageOverflowException(String message, Throwable exception) {
|
||||
super(message, exception);
|
||||
}
|
||||
|
||||
protected PlanesStorageOverflowException(Throwable exception) {
|
||||
super(exception);
|
||||
}
|
||||
|
||||
public PlanesStorageOverflowException(int count) {
|
||||
super("В наборе превышено допустимое количество: " + count);
|
||||
}
|
||||
}
|
76
ProjectStormtrooper/SetGeneric.java
Normal file
76
ProjectStormtrooper/SetGeneric.java
Normal file
@ -0,0 +1,76 @@
|
||||
package ProjectStormtrooper;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class SetGeneric<T extends DrawingPlane> {
|
||||
private final ArrayList<T> _places;
|
||||
|
||||
public int Count() {
|
||||
return _places.size();
|
||||
}
|
||||
|
||||
private final int _maxCount;
|
||||
|
||||
public SetGeneric(int count) {
|
||||
_maxCount = count;
|
||||
_places = new ArrayList<>(count);
|
||||
}
|
||||
|
||||
public int Insert(T plane) {
|
||||
return Insert(plane, 0);
|
||||
}
|
||||
|
||||
public int Insert(T plane, int position) {
|
||||
// Проверка позиции
|
||||
if (position < 0 || position >= _maxCount) {
|
||||
return -1;
|
||||
}
|
||||
if (Count() == _maxCount) {
|
||||
throw new PlanesStorageOverflowException(_maxCount);
|
||||
}
|
||||
// Вставка по позиции
|
||||
_places.add(position, plane);
|
||||
return position;
|
||||
}
|
||||
|
||||
public T Remove(int position) {
|
||||
// Проверка позиции
|
||||
if (position < 0 || position >= Count()) {
|
||||
return null;
|
||||
}
|
||||
// Удаление объекта из массива, присвоив элементу массива значение null
|
||||
T plane = _places.get(position);
|
||||
if (plane == null) {
|
||||
throw new PlaneNotFoundException(position);
|
||||
}
|
||||
_places.set(position, null);
|
||||
return plane;
|
||||
}
|
||||
|
||||
public T Get(int position) {
|
||||
// Проверка позиции
|
||||
if (position < 0 || position >= Count()) {
|
||||
return null;
|
||||
}
|
||||
return _places.get(position);
|
||||
}
|
||||
|
||||
public void Set(int position, T plane) {
|
||||
// Проверка позиции
|
||||
// Проверка свободных мест в списке
|
||||
if (position < 0 || position >= _maxCount || Count() == _maxCount) {
|
||||
return;
|
||||
}
|
||||
// Вставка в список по позиции
|
||||
_places.set(position, plane);
|
||||
}
|
||||
|
||||
public ArrayList<T> GetEnumerator() {
|
||||
return _places;
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
_places.clear();
|
||||
}
|
||||
}
|
7
ProjectStormtrooper/Status.java
Normal file
7
ProjectStormtrooper/Status.java
Normal file
@ -0,0 +1,7 @@
|
||||
package ProjectStormtrooper;
|
||||
|
||||
public enum Status {
|
||||
NotInit,
|
||||
InProgress,
|
||||
Finish
|
||||
}
|
BIN
ProjectStormtrooper/img/arrowDOWN.png
Normal file
BIN
ProjectStormtrooper/img/arrowDOWN.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.5 KiB |
BIN
ProjectStormtrooper/img/arrowLEFT.png
Normal file
BIN
ProjectStormtrooper/img/arrowLEFT.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.4 KiB |
BIN
ProjectStormtrooper/img/arrowRIGHT.png
Normal file
BIN
ProjectStormtrooper/img/arrowRIGHT.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.4 KiB |
BIN
ProjectStormtrooper/img/arrowUP.png
Normal file
BIN
ProjectStormtrooper/img/arrowUP.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.5 KiB |
Loading…
Reference in New Issue
Block a user