Compare commits
8 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
53693d9d08 | ||
|
fba2fe80be | ||
|
8945d1c2cc | ||
|
471fd18960 | ||
|
ae2b1c951d | ||
|
ded836d6bb | ||
|
d8ef359431 | ||
|
6028922e21 |
@ -3,6 +3,7 @@
|
||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/ProjectAirFighter/Resources" type="java-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/ProjectAirFighter/src" isTestSource="false" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
|
124
.idea/uiDesigner.xml
Normal file
@ -0,0 +1,124 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="Palette2">
|
||||
<group name="Swing">
|
||||
<item class="com.intellij.uiDesigner.HSpacer" tooltip-text="Horizontal Spacer" icon="/com/intellij/uiDesigner/icons/hspacer.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="1" hsize-policy="6" anchor="0" fill="1" />
|
||||
</item>
|
||||
<item class="com.intellij.uiDesigner.VSpacer" tooltip-text="Vertical Spacer" icon="/com/intellij/uiDesigner/icons/vspacer.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="6" hsize-policy="1" anchor="0" fill="2" />
|
||||
</item>
|
||||
<item class="javax.swing.JPanel" icon="/com/intellij/uiDesigner/icons/panel.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3" />
|
||||
</item>
|
||||
<item class="javax.swing.JScrollPane" icon="/com/intellij/uiDesigner/icons/scrollPane.svg" removable="false" auto-create-binding="false" can-attach-label="true">
|
||||
<default-constraints vsize-policy="7" hsize-policy="7" anchor="0" fill="3" />
|
||||
</item>
|
||||
<item class="javax.swing.JButton" icon="/com/intellij/uiDesigner/icons/button.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="3" anchor="0" fill="1" />
|
||||
<initial-values>
|
||||
<property name="text" value="Button" />
|
||||
</initial-values>
|
||||
</item>
|
||||
<item class="javax.swing.JRadioButton" icon="/com/intellij/uiDesigner/icons/radioButton.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
|
||||
<initial-values>
|
||||
<property name="text" value="RadioButton" />
|
||||
</initial-values>
|
||||
</item>
|
||||
<item class="javax.swing.JCheckBox" icon="/com/intellij/uiDesigner/icons/checkBox.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
|
||||
<initial-values>
|
||||
<property name="text" value="CheckBox" />
|
||||
</initial-values>
|
||||
</item>
|
||||
<item class="javax.swing.JLabel" icon="/com/intellij/uiDesigner/icons/label.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="0" anchor="8" fill="0" />
|
||||
<initial-values>
|
||||
<property name="text" value="Label" />
|
||||
</initial-values>
|
||||
</item>
|
||||
<item class="javax.swing.JTextField" icon="/com/intellij/uiDesigner/icons/textField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
|
||||
<preferred-size width="150" height="-1" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JPasswordField" icon="/com/intellij/uiDesigner/icons/passwordField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
|
||||
<preferred-size width="150" height="-1" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JFormattedTextField" icon="/com/intellij/uiDesigner/icons/formattedTextField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
|
||||
<preferred-size width="150" height="-1" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JTextArea" icon="/com/intellij/uiDesigner/icons/textArea.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||
<preferred-size width="150" height="50" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JTextPane" icon="/com/intellij/uiDesigner/icons/textPane.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||
<preferred-size width="150" height="50" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JEditorPane" icon="/com/intellij/uiDesigner/icons/editorPane.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||
<preferred-size width="150" height="50" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JComboBox" icon="/com/intellij/uiDesigner/icons/comboBox.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="0" hsize-policy="2" anchor="8" fill="1" />
|
||||
</item>
|
||||
<item class="javax.swing.JTable" icon="/com/intellij/uiDesigner/icons/table.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||
<preferred-size width="150" height="50" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JList" icon="/com/intellij/uiDesigner/icons/list.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="6" hsize-policy="2" anchor="0" fill="3">
|
||||
<preferred-size width="150" height="50" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JTree" icon="/com/intellij/uiDesigner/icons/tree.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||
<preferred-size width="150" height="50" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JTabbedPane" icon="/com/intellij/uiDesigner/icons/tabbedPane.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
|
||||
<preferred-size width="200" height="200" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JSplitPane" icon="/com/intellij/uiDesigner/icons/splitPane.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
|
||||
<preferred-size width="200" height="200" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JSpinner" icon="/com/intellij/uiDesigner/icons/spinner.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
|
||||
</item>
|
||||
<item class="javax.swing.JSlider" icon="/com/intellij/uiDesigner/icons/slider.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
|
||||
</item>
|
||||
<item class="javax.swing.JSeparator" icon="/com/intellij/uiDesigner/icons/separator.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3" />
|
||||
</item>
|
||||
<item class="javax.swing.JProgressBar" icon="/com/intellij/uiDesigner/icons/progressbar.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1" />
|
||||
</item>
|
||||
<item class="javax.swing.JToolBar" icon="/com/intellij/uiDesigner/icons/toolbar.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1">
|
||||
<preferred-size width="-1" height="20" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JToolBar$Separator" icon="/com/intellij/uiDesigner/icons/toolbarSeparator.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="0" anchor="0" fill="1" />
|
||||
</item>
|
||||
<item class="javax.swing.JScrollBar" icon="/com/intellij/uiDesigner/icons/scrollbar.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="6" hsize-policy="0" anchor="0" fill="2" />
|
||||
</item>
|
||||
</group>
|
||||
</component>
|
||||
</project>
|
@ -2,5 +2,6 @@
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="" vcs="Git" />
|
||||
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
BIN
ProjectAirFighter/Resources/arrowDown.png
Normal file
After Width: | Height: | Size: 965 B |
BIN
ProjectAirFighter/Resources/arrowLeft.png
Normal file
After Width: | Height: | Size: 1005 B |
BIN
ProjectAirFighter/Resources/arrowRight.png
Normal file
After Width: | Height: | Size: 978 B |
BIN
ProjectAirFighter/Resources/arrowUp.png
Normal file
After Width: | Height: | Size: 1012 B |
202
ProjectAirFighter/src/Drawnings/DrawningAirCraft.java
Normal file
@ -0,0 +1,202 @@
|
||||
package Drawnings;
|
||||
|
||||
import Entities.EntityAirCraft;
|
||||
import MovementStrategy.MovementDirection;
|
||||
|
||||
import java.awt.*;
|
||||
import java.util.Random;
|
||||
|
||||
public class DrawningAirCraft {
|
||||
private final EntityAirCraft entityAirCraft;
|
||||
|
||||
public EntityAirCraft getEntityAirCraft() {
|
||||
return entityAirCraft;
|
||||
}
|
||||
|
||||
private Integer _pictureWidth;
|
||||
private Integer _pictureHeight;
|
||||
protected Integer _startPosX;
|
||||
protected Integer _startPosY;
|
||||
private int _drawingAirCraftWidth = 66;
|
||||
private int _drawingAirCraftHeight = 74;
|
||||
|
||||
public int GetPosX() {
|
||||
return _startPosX;
|
||||
}
|
||||
|
||||
public int GetPosY() {
|
||||
return _startPosY;
|
||||
}
|
||||
|
||||
public int GetWidth() {
|
||||
return _drawingAirCraftWidth;
|
||||
}
|
||||
|
||||
public int GetHeight() {
|
||||
return _drawingAirCraftHeight;
|
||||
}
|
||||
|
||||
private IDrawEngine drawEngine;
|
||||
|
||||
public DrawningAirCraft(int speed, float weight, Color bodyColor, int engineType) {
|
||||
entityAirCraft = new EntityAirCraft(speed, weight, bodyColor);
|
||||
_startPosY = null;
|
||||
_startPosX = null;
|
||||
_pictureWidth = null;
|
||||
_pictureHeight = null;
|
||||
switch (engineType) {
|
||||
case 0:
|
||||
drawEngine = new DrawningEngine();
|
||||
break;
|
||||
case 1:
|
||||
drawEngine = new DrawningOvalEngine();
|
||||
break;
|
||||
case 2:
|
||||
drawEngine = new DrawningLongEngine();
|
||||
break;
|
||||
}
|
||||
|
||||
Random random = new Random();
|
||||
int[] countengine = {2, 4, 6};
|
||||
int engineCount = countengine[random.nextInt(countengine.length)];
|
||||
drawEngine.setNumber(engineCount);
|
||||
}
|
||||
|
||||
protected DrawningAirCraft(int speed, float weight, Color bodyColor, int EngineType, int aircraftWidth, int aircraftHeight) {
|
||||
this(speed, weight, bodyColor, EngineType);
|
||||
_drawingAirCraftHeight = aircraftHeight;
|
||||
_drawingAirCraftWidth = aircraftWidth;
|
||||
}
|
||||
|
||||
public void setPosition(int x, int y) {
|
||||
if (_pictureHeight == null || _pictureWidth == null)
|
||||
return;
|
||||
_startPosX = x;
|
||||
_startPosY = y;
|
||||
|
||||
if (_drawingAirCraftWidth + x > _pictureWidth || x < 0) {
|
||||
_startPosX = 0;
|
||||
}
|
||||
if (_drawingAirCraftHeight + y > _pictureHeight || y < 0) {
|
||||
_startPosY = 0;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean setPictureSize(int width, int height) {
|
||||
|
||||
if (_drawingAirCraftHeight > height || _drawingAirCraftWidth > width)
|
||||
return false;
|
||||
_pictureHeight = height;
|
||||
_pictureWidth = width;
|
||||
|
||||
if (_startPosX != null && _startPosY != null) {
|
||||
if (_startPosX + _drawingAirCraftWidth > width)
|
||||
_startPosX = width - _drawingAirCraftWidth;
|
||||
if (_startPosY + _drawingAirCraftHeight > height)
|
||||
_startPosY = height - _drawingAirCraftHeight;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean moveTransport(MovementDirection direction) {
|
||||
if (entityAirCraft == null || _pictureWidth == null || _pictureHeight == null)
|
||||
return false;
|
||||
switch (direction) {
|
||||
case MovementDirection.Left:
|
||||
if (_startPosX - entityAirCraft.getStep() > 0)
|
||||
_startPosX -= (int) entityAirCraft.getStep();
|
||||
return true;
|
||||
case MovementDirection.Up:
|
||||
if (_startPosY - entityAirCraft.getStep() > 0)
|
||||
_startPosY -= (int) entityAirCraft.getStep();
|
||||
return true;
|
||||
case MovementDirection.Right:
|
||||
if (_startPosX + entityAirCraft.getStep() < _pictureWidth - _drawingAirCraftWidth)
|
||||
_startPosX += (int) entityAirCraft.getStep();
|
||||
return true;
|
||||
case MovementDirection.Down:
|
||||
if (_startPosY + entityAirCraft.getStep() < _pictureHeight - _drawingAirCraftHeight)
|
||||
_startPosY += (int) entityAirCraft.getStep();
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public void drawAirCraft(Graphics g) {
|
||||
if (entityAirCraft == null || _startPosX == null || _startPosY == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
Graphics2D g2d = (Graphics2D) g;
|
||||
|
||||
Point[] rtail = new Point[]{
|
||||
new Point(_startPosX + 10, _startPosY + 25),
|
||||
new Point(_startPosX + 10, _startPosY + 8),
|
||||
new Point(_startPosX + 20, _startPosY + 17),
|
||||
new Point(_startPosX + 20, _startPosY + 25),
|
||||
};
|
||||
Polygon rtailPolygon = new Polygon();
|
||||
for (Point point : rtail)
|
||||
rtailPolygon.addPoint(point.x, point.y);
|
||||
|
||||
g2d.setColor(entityAirCraft.getBodyColor());
|
||||
g2d.fillPolygon(rtailPolygon);
|
||||
|
||||
Point[] ltail = new Point[]{
|
||||
new Point(_startPosX + 10, _startPosY + 49),
|
||||
new Point(_startPosX + 10, _startPosY + 66),
|
||||
new Point(_startPosX + 20, _startPosY + 57),
|
||||
new Point(_startPosX + 20, _startPosY + 49),
|
||||
};
|
||||
Polygon ltailPolygon = new Polygon();
|
||||
for (Point point : ltail)
|
||||
ltailPolygon.addPoint(point.x, point.y);
|
||||
|
||||
g2d.setColor(entityAirCraft.getBodyColor());
|
||||
g2d.fillPolygon(ltailPolygon);
|
||||
|
||||
Point[] rwing = new Point[]{
|
||||
new Point(_startPosX + 45, _startPosY + 49),
|
||||
new Point(_startPosX + 45, _startPosY + 74),
|
||||
new Point(_startPosX + 37, _startPosY + 74),
|
||||
new Point(_startPosX + 30, _startPosY + 49),
|
||||
};
|
||||
Polygon rwingPolygon = new Polygon();
|
||||
for (Point point : rwing)
|
||||
rwingPolygon.addPoint(point.x, point.y);
|
||||
|
||||
g2d.setColor(entityAirCraft.getBodyColor());
|
||||
g2d.fillPolygon(rwingPolygon);
|
||||
|
||||
Point[] lwing = new Point[]{
|
||||
new Point(_startPosX + 45, _startPosY + 25),
|
||||
new Point(_startPosX + 45, _startPosY),
|
||||
new Point(_startPosX + 37, _startPosY),
|
||||
new Point(_startPosX + 30, _startPosY + 25),
|
||||
};
|
||||
Polygon lwingPolygon = new Polygon();
|
||||
for (Point point : lwing)
|
||||
lwingPolygon.addPoint(point.x, point.y);
|
||||
|
||||
g2d.setColor(entityAirCraft.getBodyColor());
|
||||
g2d.fillPolygon(lwingPolygon);
|
||||
|
||||
g2d.drawRect(_startPosX + 10, _startPosY + 25, 50, 24);
|
||||
g2d.fillRect(_startPosX + 10, _startPosY + 25, 50, 24);
|
||||
|
||||
Point[] nose = new Point[]{
|
||||
new Point(_startPosX + 60, _startPosY + 25),
|
||||
new Point(_startPosX + 76, _startPosY + 37),
|
||||
new Point(_startPosX + 60, _startPosY + 49),
|
||||
};
|
||||
Polygon nosePolygon = new Polygon();
|
||||
for (Point point : nose)
|
||||
nosePolygon.addPoint(point.x, point.y);
|
||||
|
||||
g2d.setColor(Color.GRAY);
|
||||
g2d.fillPolygon(nosePolygon);
|
||||
|
||||
drawEngine.drawEngine(g2d, entityAirCraft.getBodyColor(), _startPosX, _startPosY);
|
||||
}
|
||||
}
|
82
ProjectAirFighter/src/Drawnings/DrawningAirFighter.java
Normal file
@ -0,0 +1,82 @@
|
||||
package Drawnings;
|
||||
|
||||
import Entities.EntityAirFighter;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
public class DrawningAirFighter extends DrawningAirCraft {
|
||||
private EntityAirFighter entityAirFighter;
|
||||
|
||||
public DrawningAirFighter(int speed, float weight, Color bodyColor, int engineType, Color additionalColor, boolean pgo, boolean rockets) {
|
||||
super(speed, weight, bodyColor, engineType, 76, 80);
|
||||
entityAirFighter = new EntityAirFighter(speed, weight, bodyColor, additionalColor, pgo, rockets);
|
||||
}
|
||||
|
||||
public void drawAirCraft(Graphics g) {
|
||||
if (entityAirFighter == null || _startPosX == null || _startPosY == null) {
|
||||
return;
|
||||
}
|
||||
super.drawAirCraft(g);
|
||||
Graphics2D g2d = (Graphics2D) g;
|
||||
|
||||
if (entityAirFighter.getPgo()) {
|
||||
Point[] pgo1 = new Point[]{
|
||||
new Point(_startPosX + 50, _startPosY + 25),
|
||||
new Point(_startPosX + 50, _startPosY + 15),
|
||||
new Point(_startPosX + 55, _startPosY + 25),
|
||||
};
|
||||
Polygon pgo1Polygon = new Polygon();
|
||||
for (Point point : pgo1)
|
||||
pgo1Polygon.addPoint(point.x, point.y);
|
||||
|
||||
g2d.setColor(entityAirFighter.getAdditionalColor());
|
||||
g2d.fillPolygon(pgo1Polygon);
|
||||
|
||||
Point[] pgo2 = new Point[]{
|
||||
new Point(_startPosX + 50, _startPosY + 49),
|
||||
new Point(_startPosX + 50, _startPosY + 59),
|
||||
new Point(_startPosX + 55, _startPosY + 49),
|
||||
};
|
||||
Polygon pgo2Polygon = new Polygon();
|
||||
for (Point point : pgo2)
|
||||
pgo2Polygon.addPoint(point.x, point.y);
|
||||
|
||||
g2d.setColor(entityAirFighter.getAdditionalColor());
|
||||
g2d.fillPolygon(pgo2Polygon);
|
||||
}
|
||||
|
||||
if (entityAirFighter.getRockets()) {
|
||||
Point[] rocket1 = new Point[]{
|
||||
new Point(_startPosX + 50, _startPosY + 71),
|
||||
new Point(_startPosX + 50, _startPosY + 74),
|
||||
new Point(_startPosX + 55, _startPosY + 69),
|
||||
new Point(_startPosX + 50, _startPosY + 64),
|
||||
};
|
||||
Polygon rocket1Polygon = new Polygon();
|
||||
for (Point point : rocket1)
|
||||
rocket1Polygon.addPoint(point.x, point.y);
|
||||
|
||||
g2d.setColor(entityAirFighter.getAdditionalColor());
|
||||
g2d.fillPolygon(rocket1Polygon);
|
||||
|
||||
g.drawRect(_startPosX + 45, _startPosY + 67, 5, 4);
|
||||
g.fillRect(_startPosX + 45, _startPosY + 67, 5, 4);
|
||||
|
||||
Point[] rocket2 = new Point[]{
|
||||
new Point(_startPosX + 50, _startPosY + 7),
|
||||
new Point(_startPosX + 50, _startPosY + 10),
|
||||
new Point(_startPosX + 55, _startPosY + 5),
|
||||
new Point(_startPosX + 50, _startPosY),
|
||||
};
|
||||
Polygon rocket2Polygon = new Polygon();
|
||||
for (Point point : rocket2)
|
||||
rocket2Polygon.addPoint(point.x, point.y);
|
||||
|
||||
g2d.setColor(entityAirFighter.getAdditionalColor());
|
||||
g2d.fillPolygon(rocket2Polygon);
|
||||
|
||||
g.drawRect(_startPosX + 45, _startPosY + 3, 5, 4);
|
||||
g.fillRect(_startPosX + 45, _startPosY + 3, 5, 4);
|
||||
}
|
||||
}
|
||||
}
|
38
ProjectAirFighter/src/Drawnings/DrawningEngine.java
Normal file
@ -0,0 +1,38 @@
|
||||
package Drawnings;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
public class DrawningEngine implements IDrawEngine {
|
||||
private EngineCount _engineCount;
|
||||
|
||||
@Override
|
||||
public void setNumber(int engineCount) {
|
||||
for (EngineCount value : EngineCount.values()) {
|
||||
if (value.getEnumNumber() == engineCount) {
|
||||
_engineCount = value;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawEngine(Graphics2D g2d, Color color, int _startX, int _startY) {
|
||||
g2d.setColor(color);
|
||||
g2d.setStroke(new BasicStroke(4));
|
||||
|
||||
if (_engineCount.getEnumNumber() >= 2){
|
||||
g2d.drawRect(_startX + 30, _startY + 69, 10, 2 );
|
||||
g2d.drawRect(_startX + 30, _startY + 3, 10, 2 );
|
||||
}
|
||||
|
||||
if (_engineCount.getEnumNumber() >= 4){
|
||||
g2d.drawRect(_startX + 30, _startY + 62, 10, 2 );
|
||||
g2d.drawRect(_startX + 30, _startY + 10, 10, 2 );
|
||||
}
|
||||
|
||||
if (_engineCount.getEnumNumber() >= 6){
|
||||
g2d.drawRect(_startX + 30, _startY + 55, 10, 2 );
|
||||
g2d.drawRect(_startX + 30, _startY + 17, 10, 2 );
|
||||
}
|
||||
}
|
||||
}
|
38
ProjectAirFighter/src/Drawnings/DrawningLongEngine.java
Normal file
@ -0,0 +1,38 @@
|
||||
package Drawnings;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
public class DrawningLongEngine implements IDrawEngine {
|
||||
private EngineCount _engineCount;
|
||||
|
||||
@Override
|
||||
public void setNumber(int engineCount) {
|
||||
for (EngineCount value : EngineCount.values()) {
|
||||
if (value.getEnumNumber() == engineCount) {
|
||||
_engineCount = value;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawEngine(Graphics2D g2d, Color color, int _startX, int _startY) {
|
||||
g2d.setColor(color);
|
||||
g2d.setStroke(new BasicStroke(4));
|
||||
|
||||
if (_engineCount.getEnumNumber() >= 2) {
|
||||
g2d.drawRoundRect(_startX + 25, _startY + 69, 15, 2, 5, 5);
|
||||
g2d.drawRoundRect(_startX + 25, _startY + 3, 15, 2, 5, 5);
|
||||
}
|
||||
|
||||
if (_engineCount.getEnumNumber() >= 4) {
|
||||
g2d.drawRoundRect(_startX + 25, _startY + 62, 15, 2, 5, 5);
|
||||
g2d.drawRoundRect(_startX + 25, _startY + 10, 15, 2, 5, 5);
|
||||
}
|
||||
|
||||
if (_engineCount.getEnumNumber() >= 6) {
|
||||
g2d.drawRoundRect(_startX + 25, _startY + 55, 15, 2, 5, 5);
|
||||
g2d.drawRoundRect(_startX + 25, _startY + 17, 15, 2, 5, 5);
|
||||
}
|
||||
}
|
||||
}
|
38
ProjectAirFighter/src/Drawnings/DrawningOvalEngine.java
Normal file
@ -0,0 +1,38 @@
|
||||
package Drawnings;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
public class DrawningOvalEngine implements IDrawEngine {
|
||||
private EngineCount _engineCount;
|
||||
|
||||
@Override
|
||||
public void setNumber(int engineCount) {
|
||||
for (EngineCount value : EngineCount.values()) {
|
||||
if (value.getEnumNumber() == engineCount) {
|
||||
_engineCount = value;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawEngine(Graphics2D g2d, Color color, int _startX, int _startY) {
|
||||
g2d.setColor(color);
|
||||
g2d.setStroke(new BasicStroke(4));
|
||||
|
||||
if (_engineCount.getEnumNumber() >= 2) {
|
||||
g2d.drawOval(_startX + 30, _startY + 69, 10, 2);
|
||||
g2d.drawOval(_startX + 30, _startY + 3, 10, 2);
|
||||
}
|
||||
|
||||
if (_engineCount.getEnumNumber() >= 4) {
|
||||
g2d.drawOval(_startX + 30, _startY + 62, 10, 2);
|
||||
g2d.drawOval(_startX + 30, _startY + 10, 10, 2);
|
||||
}
|
||||
|
||||
if (_engineCount.getEnumNumber() >= 6) {
|
||||
g2d.drawOval(_startX + 30, _startY + 55, 10, 2);
|
||||
g2d.drawOval(_startX + 30, _startY + 17, 10, 2);
|
||||
}
|
||||
}
|
||||
}
|
14
ProjectAirFighter/src/Drawnings/EngineCount.java
Normal file
@ -0,0 +1,14 @@
|
||||
package Drawnings;
|
||||
|
||||
public enum EngineCount {
|
||||
Two(2),
|
||||
Three(4),
|
||||
Four(6);
|
||||
final private int EnumNumber;
|
||||
EngineCount(int enumNumber) {
|
||||
EnumNumber = enumNumber;
|
||||
}
|
||||
public int getEnumNumber() {
|
||||
return EnumNumber;
|
||||
}
|
||||
}
|
8
ProjectAirFighter/src/Drawnings/IDrawEngine.java
Normal file
@ -0,0 +1,8 @@
|
||||
package Drawnings;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
public interface IDrawEngine {
|
||||
void setNumber(int x);
|
||||
void drawEngine(Graphics2D graphics2D, Color color, int _startX, int _startY);
|
||||
}
|
28
ProjectAirFighter/src/Entities/EntityAirCraft.java
Normal file
@ -0,0 +1,28 @@
|
||||
package Entities;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
public class EntityAirCraft {
|
||||
private int Speed;
|
||||
public int getSpeed() {
|
||||
return Speed;
|
||||
}
|
||||
private double Weight;
|
||||
public double getWeight() {
|
||||
return Weight;
|
||||
}
|
||||
private Color BodyColor;
|
||||
public Color getBodyColor() {
|
||||
return BodyColor;
|
||||
}
|
||||
private double Step;
|
||||
public double getStep() {
|
||||
return Speed*100/Weight;
|
||||
}
|
||||
|
||||
public EntityAirCraft(int speed, double weight, Color bodyColor) {
|
||||
Speed = speed;
|
||||
Weight = weight;
|
||||
BodyColor = bodyColor;
|
||||
}
|
||||
}
|
24
ProjectAirFighter/src/Entities/EntityAirFighter.java
Normal file
@ -0,0 +1,24 @@
|
||||
package Entities;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
public class EntityAirFighter extends EntityAirCraft {
|
||||
private Color AdditionalColor;
|
||||
public Color getAdditionalColor() {
|
||||
return AdditionalColor;
|
||||
}
|
||||
private boolean Pgo;
|
||||
public boolean getPgo() {
|
||||
return Pgo;
|
||||
}
|
||||
private boolean Rockets;
|
||||
public boolean getRockets() {
|
||||
return Rockets;
|
||||
}
|
||||
public EntityAirFighter(int speed, double weight, Color bodyColor, Color additionalColor, boolean pgo, boolean rockets) {
|
||||
super(speed, weight, bodyColor);
|
||||
AdditionalColor = additionalColor;
|
||||
Pgo = pgo;
|
||||
Rockets = rockets;
|
||||
}
|
||||
}
|
131
ProjectAirFighter/src/FormAirFighter.form
Normal file
@ -0,0 +1,131 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="FormAirFighter">
|
||||
<grid id="27dc6" binding="PanelWrapper" 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>
|
||||
<xy x="20" y="20" width="599" height="476"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<grid id="1ff9a" binding="PictureBox" layout-manager="GridLayoutManager" row-count="6" column-count="5" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<constraints>
|
||||
<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>
|
||||
<toolTipText value=""/>
|
||||
</properties>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<vspacer id="7b40c">
|
||||
<constraints>
|
||||
<grid row="2" column="0" row-span="2" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false">
|
||||
<preferred-size width="88" height="14"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
</vspacer>
|
||||
<hspacer id="e0b21">
|
||||
<constraints>
|
||||
<grid row="4" column="1" 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="a8c2" class="javax.swing.JButton" binding="buttonCreateAirFighter">
|
||||
<constraints>
|
||||
<grid row="5" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="2" fill="1" indent="0" use-parent-layout="false">
|
||||
<minimum-size width="150" height="30"/>
|
||||
<preferred-size width="150" height="30"/>
|
||||
<maximum-size width="150" height="30"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="Создать истребитель"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="79b3e" class="javax.swing.JButton" binding="buttonCreateAirCraft">
|
||||
<constraints>
|
||||
<grid row="5" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="10" fill="0" indent="0" use-parent-layout="false">
|
||||
<minimum-size width="150" height="30"/>
|
||||
<preferred-size width="150" height="30"/>
|
||||
<maximum-size width="150" height="30"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="Создать самолёт"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="fe25b" class="javax.swing.JButton" binding="buttonLeft">
|
||||
<constraints>
|
||||
<grid row="5" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="4" 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>
|
||||
<icon value="arrowLeft.png"/>
|
||||
<text value=""/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="3eabd" class="javax.swing.JButton" binding="buttonStrategyStep">
|
||||
<constraints>
|
||||
<grid row="1" column="3" 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="86d84" class="javax.swing.JButton" binding="buttonRight">
|
||||
<constraints>
|
||||
<grid row="5" 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>
|
||||
<icon value="arrowRight.png"/>
|
||||
<text value=""/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="3dc0" class="javax.swing.JButton" binding="buttonDown">
|
||||
<constraints>
|
||||
<grid row="5" column="3" 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>
|
||||
<icon value="arrowDown.png"/>
|
||||
<text value=""/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="ccb2a" class="javax.swing.JButton" binding="buttonUp">
|
||||
<constraints>
|
||||
<grid row="4" column="3" 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>
|
||||
<icon value="arrowUp.png"/>
|
||||
<text value=""/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="988c8" class="javax.swing.JComboBox" binding="comboBoxStrategy">
|
||||
<constraints>
|
||||
<grid row="0" column="2" row-span="1" col-span="3" vsize-policy="0" hsize-policy="2" anchor="9" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<actionCommand value=""/>
|
||||
<doubleBuffered value="false"/>
|
||||
<toolTipText value=""/>
|
||||
</properties>
|
||||
</component>
|
||||
</children>
|
||||
</grid>
|
||||
</children>
|
||||
</grid>
|
||||
</form>
|
176
ProjectAirFighter/src/FormAirFighter.java
Normal file
@ -0,0 +1,176 @@
|
||||
import Drawnings.DrawningAirCraft;
|
||||
import Drawnings.DrawningAirFighter;
|
||||
import MovementStrategy.*;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.util.LinkedList;
|
||||
import java.util.Random;
|
||||
import java.util.List;
|
||||
|
||||
public class FormAirFighter extends JFrame {
|
||||
protected DrawningAirCraft _drawningAirCraft;
|
||||
JPanel PanelWrapper;
|
||||
private JPanel PictureBox;
|
||||
private JButton buttonCreateAirFighter;
|
||||
private JButton buttonCreateAirCraft;
|
||||
private JButton buttonRight;
|
||||
private JButton buttonDown;
|
||||
private JButton buttonLeft;
|
||||
private JButton buttonUp;
|
||||
private JComboBox comboBoxStrategy;
|
||||
private JButton buttonStrategyStep;
|
||||
private AbstractStrategy _strategy;
|
||||
private List<JComponent> controls;
|
||||
|
||||
private void createObject(String type) {
|
||||
Random random = new Random();
|
||||
switch (type) {
|
||||
case "Drawnings.DrawningAirCraft":
|
||||
_drawningAirCraft = new DrawningAirCraft(random.nextInt(30,100), random.nextInt(100,500),
|
||||
new Color(random.nextInt(256), random.nextInt(256), random.nextInt(256)), random.nextInt(3));
|
||||
break;
|
||||
case "Drawnings.DrawningAirFighter":
|
||||
_drawningAirCraft = new DrawningAirFighter(random.nextInt(30,100), random.nextInt(100,500),
|
||||
new Color(random.nextInt(256), random.nextInt(256), random.nextInt(256)), random.nextInt(3),
|
||||
new Color(random.nextInt(256), random.nextInt(256), random.nextInt(256)),
|
||||
random.nextBoolean(), random.nextBoolean());
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
_drawningAirCraft.setPictureSize(PictureBox.getWidth(), PictureBox.getHeight());
|
||||
_drawningAirCraft.setPosition(random.nextInt(25, 100),
|
||||
random.nextInt(25, 100));
|
||||
_strategy = null;
|
||||
comboBoxStrategy.setEnabled(true);
|
||||
|
||||
Draw();
|
||||
}
|
||||
|
||||
public FormAirFighter() {
|
||||
buttonUp.setName("buttonUp");
|
||||
buttonDown.setName("buttonDown");
|
||||
buttonLeft.setName("buttonLeft");
|
||||
buttonRight.setName("buttonRight");
|
||||
|
||||
InitializeControlsRepaintList();
|
||||
|
||||
buttonCreateAirFighter.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
createObject("Drawnings.DrawningAirFighter");
|
||||
|
||||
}
|
||||
});
|
||||
buttonCreateAirCraft.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
createObject("Drawnings.DrawningAirCraft");
|
||||
}
|
||||
});
|
||||
ActionListener buttonMoveClickedListener = new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
String buttonName = ((JButton) e.getSource()).getName();
|
||||
boolean result = false;
|
||||
|
||||
switch (buttonName) {
|
||||
case "buttonUp": {
|
||||
result = _drawningAirCraft.moveTransport(MovementDirection.Up);
|
||||
}
|
||||
break;
|
||||
case "buttonDown": {
|
||||
result = _drawningAirCraft.moveTransport(MovementDirection.Down);
|
||||
}
|
||||
break;
|
||||
case "buttonLeft": {
|
||||
result = _drawningAirCraft.moveTransport(MovementDirection.Left);
|
||||
}
|
||||
break;
|
||||
case "buttonRight": {
|
||||
result = _drawningAirCraft.moveTransport(MovementDirection.Right);
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (result)
|
||||
Draw();
|
||||
}
|
||||
};
|
||||
buttonRight.addActionListener(buttonMoveClickedListener);
|
||||
buttonDown.addActionListener(buttonMoveClickedListener);
|
||||
buttonLeft.addActionListener(buttonMoveClickedListener);
|
||||
buttonUp.addActionListener(buttonMoveClickedListener);
|
||||
comboBoxStrategy.addItem("К центру");
|
||||
comboBoxStrategy.addItem("К краю");
|
||||
buttonStrategyStep.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
if (_drawningAirCraft == null)
|
||||
return;
|
||||
if (comboBoxStrategy.isEnabled()) {
|
||||
switch (comboBoxStrategy.getSelectedIndex()) {
|
||||
case 0:
|
||||
_strategy = new MoveToCenter();
|
||||
break;
|
||||
case 1:
|
||||
_strategy = new MoveToBorder();
|
||||
break;
|
||||
|
||||
default:
|
||||
_strategy = null;
|
||||
break;
|
||||
|
||||
}
|
||||
if (_strategy == null) {
|
||||
return;
|
||||
}
|
||||
_strategy.SetData(new MoveableAirCraft(_drawningAirCraft), PictureBox.getWidth(), PictureBox.getHeight());
|
||||
}
|
||||
if (_strategy == null) {
|
||||
return;
|
||||
}
|
||||
_strategy.MakeStep();
|
||||
Draw();
|
||||
comboBoxStrategy.setEnabled(false);
|
||||
|
||||
if (_strategy.GetStatus() == StrategyStatus.Finish) {
|
||||
comboBoxStrategy.setEnabled(true);
|
||||
_strategy = null;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
private void Draw() {
|
||||
if (_drawningAirCraft.getEntityAirCraft() == null)
|
||||
return;
|
||||
if (PictureBox.getWidth() == 0 || PictureBox.getHeight() == 0) {
|
||||
return;
|
||||
}
|
||||
Graphics g = PictureBox.getGraphics();
|
||||
g.setColor(PictureBox.getBackground());
|
||||
g.fillRect(0,0, PictureBox.getWidth(), PictureBox.getHeight());
|
||||
_drawningAirCraft.drawAirCraft(g);
|
||||
|
||||
RepaintControls();
|
||||
}
|
||||
private void RepaintControls() {
|
||||
for (JComponent control : controls) {
|
||||
control.repaint();
|
||||
}
|
||||
}
|
||||
|
||||
private void InitializeControlsRepaintList() {
|
||||
controls = new LinkedList<>();
|
||||
controls.add(buttonCreateAirFighter);
|
||||
controls.add(buttonCreateAirCraft);
|
||||
controls.add(buttonUp);
|
||||
controls.add(buttonDown);
|
||||
controls.add(buttonLeft);
|
||||
controls.add(buttonRight);
|
||||
controls.add(comboBoxStrategy);
|
||||
controls.add(buttonStrategyStep);
|
||||
}
|
||||
}
|
@ -1,4 +1,13 @@
|
||||
import javax.swing.*;
|
||||
public class Main {
|
||||
public static void main(String[] args) {
|
||||
JFrame.setDefaultLookAndFeelDecorated(false);
|
||||
JFrame frame = new JFrame("Истребитель");
|
||||
frame.setContentPane(new FormAirFighter().PanelWrapper);
|
||||
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
frame.setLocation(500, 200);
|
||||
frame.pack();
|
||||
frame.setSize(700, 500);
|
||||
frame.setVisible(true);
|
||||
}
|
||||
}
|
66
ProjectAirFighter/src/MovementStrategy/AbstractStrategy.java
Normal file
@ -0,0 +1,66 @@
|
||||
package MovementStrategy;
|
||||
|
||||
public abstract class AbstractStrategy {
|
||||
private IMoveableObject _moveableObject;
|
||||
private StrategyStatus _state = StrategyStatus.NotInit;
|
||||
protected int FieldWidth;
|
||||
protected int FieldHeight;
|
||||
public StrategyStatus GetStatus() { return _state; }
|
||||
|
||||
public void SetData(IMoveableObject moveableObject, int width, int height)
|
||||
{
|
||||
if (moveableObject == null)
|
||||
{
|
||||
_state = StrategyStatus.NotInit;
|
||||
return;
|
||||
}
|
||||
_state = StrategyStatus.InProgress;
|
||||
_moveableObject = moveableObject;
|
||||
FieldWidth = width;
|
||||
FieldHeight = height;
|
||||
}
|
||||
|
||||
public void MakeStep()
|
||||
{
|
||||
if (_state != StrategyStatus.InProgress)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (IsTargetDestination())
|
||||
{
|
||||
_state = StrategyStatus.Finish;
|
||||
return;
|
||||
}
|
||||
MoveToTarget();
|
||||
}
|
||||
|
||||
protected boolean MoveLeft() { return MoveTo(MovementDirection.Left); }
|
||||
protected boolean MoveRight() { return MoveTo(MovementDirection.Right); }
|
||||
protected boolean MoveUp() { return MoveTo(MovementDirection.Up); }
|
||||
protected boolean MoveDown() { return MoveTo(MovementDirection.Down); }
|
||||
protected ObjectParameters GetObjectParameters() { return _moveableObject.GetObjectPosition(); }
|
||||
|
||||
protected int GetStep()
|
||||
{
|
||||
if (_state != StrategyStatus.InProgress)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
return _moveableObject.GetStep();
|
||||
}
|
||||
protected abstract void MoveToTarget();
|
||||
protected abstract boolean IsTargetDestination();
|
||||
private boolean MoveTo(MovementDirection directionType)
|
||||
{
|
||||
if (_state != StrategyStatus.InProgress)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (_moveableObject.TryMoveObject(directionType))
|
||||
{
|
||||
_moveableObject.MoveObject(directionType);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
package MovementStrategy;
|
||||
|
||||
public interface IMoveableObject {
|
||||
ObjectParameters GetObjectPosition();
|
||||
int GetStep();
|
||||
boolean TryMoveObject(MovementDirection direction);
|
||||
void MoveObject(MovementDirection direction);
|
||||
}
|
47
ProjectAirFighter/src/MovementStrategy/MoveToBorder.java
Normal file
@ -0,0 +1,47 @@
|
||||
package MovementStrategy;
|
||||
|
||||
public class MoveToBorder extends AbstractStrategy {
|
||||
protected boolean IsTargetDestination()
|
||||
{
|
||||
var objParams = GetObjectParameters();
|
||||
if (objParams == null) {
|
||||
return false;
|
||||
}
|
||||
return objParams.RightBorder() <= FieldWidth &&
|
||||
objParams.RightBorder() + GetStep() >= FieldWidth &&
|
||||
objParams.DownBorder() <= FieldHeight &&
|
||||
objParams.DownBorder() + GetStep() >= FieldHeight;
|
||||
}
|
||||
|
||||
protected void MoveToTarget()
|
||||
{
|
||||
var objParams = GetObjectParameters();
|
||||
if (objParams == null) {
|
||||
return;
|
||||
}
|
||||
int diffX = objParams.RightBorder() - FieldWidth;
|
||||
if (Math.abs(diffX) > GetStep())
|
||||
{
|
||||
if (diffX > 0)
|
||||
{
|
||||
MoveLeft();
|
||||
}
|
||||
else
|
||||
{
|
||||
MoveRight();
|
||||
}
|
||||
}
|
||||
int diffY = objParams.DownBorder() - FieldHeight;
|
||||
if (Math.abs(diffY) > GetStep())
|
||||
{
|
||||
if (diffY > 0)
|
||||
{
|
||||
MoveUp();
|
||||
}
|
||||
else
|
||||
{
|
||||
MoveDown();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
46
ProjectAirFighter/src/MovementStrategy/MoveToCenter.java
Normal file
@ -0,0 +1,46 @@
|
||||
package MovementStrategy;
|
||||
|
||||
public class MoveToCenter extends AbstractStrategy {
|
||||
protected boolean IsTargetDestination()
|
||||
{
|
||||
var objParams = GetObjectParameters();
|
||||
if (objParams == null) {
|
||||
return false;
|
||||
}
|
||||
return (objParams.ObjectMiddleHorizontal() - GetStep() <= FieldWidth / 2 &&
|
||||
objParams.ObjectMiddleHorizontal() + GetStep() >= FieldWidth / 2 &&
|
||||
objParams.ObjectMiddleVertical() - GetStep() <= FieldHeight / 2 &&
|
||||
objParams.ObjectMiddleVertical() + GetStep() >= FieldHeight / 2);
|
||||
}
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
24
ProjectAirFighter/src/MovementStrategy/MoveableAirCraft.java
Normal file
@ -0,0 +1,24 @@
|
||||
package MovementStrategy;
|
||||
|
||||
import Drawnings.DrawningAirCraft;
|
||||
|
||||
public class MoveableAirCraft implements IMoveableObject {
|
||||
private DrawningAirCraft _airCraft = null;
|
||||
public MoveableAirCraft(DrawningAirCraft drawningAirCraft)
|
||||
{
|
||||
_airCraft = drawningAirCraft;
|
||||
}
|
||||
|
||||
public ObjectParameters GetObjectPosition()
|
||||
{
|
||||
if (_airCraft == null || _airCraft.getEntityAirCraft() == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new ObjectParameters(_airCraft.GetPosX(), _airCraft.GetPosY(), _airCraft.GetWidth(), _airCraft.GetHeight());
|
||||
}
|
||||
|
||||
public int GetStep() { return (int) _airCraft.getEntityAirCraft().getStep(); }
|
||||
public boolean TryMoveObject(MovementDirection direction) { return _airCraft.moveTransport(direction); }
|
||||
public void MoveObject(MovementDirection direction) { _airCraft.moveTransport(direction); }
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
package MovementStrategy;
|
||||
|
||||
public enum MovementDirection {
|
||||
Up,
|
||||
Down,
|
||||
Left,
|
||||
Right;
|
||||
}
|
25
ProjectAirFighter/src/MovementStrategy/ObjectParameters.java
Normal file
@ -0,0 +1,25 @@
|
||||
package MovementStrategy;
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
@ -0,0 +1,7 @@
|
||||
package MovementStrategy;
|
||||
|
||||
public enum StrategyStatus {
|
||||
NotInit,
|
||||
InProgress,
|
||||
Finish
|
||||
}
|
After Width: | Height: | Size: 965 B |
After Width: | Height: | Size: 1005 B |
After Width: | Height: | Size: 978 B |
After Width: | Height: | Size: 1012 B |