PIbd-14_Calimullin_A.R._Lab01_Hard #1
@ -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>
|
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 |
6
ProjectAirFighter/src/DirectionType.java
Normal file
@ -0,0 +1,6 @@
|
||||
public enum DirectionType {
|
||||
Up,
|
||||
Down,
|
||||
Left,
|
||||
Right
|
||||
}
|
230
ProjectAirFighter/src/DrawningAirFighter.java
Normal file
@ -0,0 +1,230 @@
|
||||
import java.awt.*;
|
||||
import java.util.Random;
|
||||
|
||||
public class DrawningAirFighter {
|
||||
private EntityAirFighter entityAirFighter;
|
||||
|
||||
public EntityAirFighter getEntityAirFighter() {
|
||||
return entityAirFighter;
|
||||
}
|
||||
|
||||
private Integer _pictureWidth;
|
||||
private Integer _pictureHeight;
|
||||
private Integer _startPosX;
|
||||
private Integer _startPosY;
|
||||
private final int _drawingAirFighterWidth = 76;
|
||||
private final int _drawingAirFighterHeight = 80;
|
||||
public DrawningAirFighterEngine drawningAirFighterEngine;
|
||||
|
||||
public void Init(int speed, float weight, Color bodyColor, Color additionalColor, boolean pgo, boolean rockets) {
|
||||
entityAirFighter = new EntityAirFighter();
|
||||
entityAirFighter.Init(speed, weight, bodyColor, additionalColor, pgo, rockets);
|
||||
_startPosY = null;
|
||||
_startPosX = null;
|
||||
_pictureWidth = null;
|
||||
_pictureHeight = null;
|
||||
|
||||
drawningAirFighterEngine = new DrawningAirFighterEngine();
|
||||
Random random = new Random();
|
||||
int[] countengine = {2, 4, 6};
|
||||
int paddlesCount = countengine[random.nextInt(countengine.length)];
|
||||
drawningAirFighterEngine.setEnumNumber(paddlesCount);
|
||||
|
||||
}
|
||||
public void setPosition(int x, int y) {
|
||||
if (_pictureHeight == null || _pictureWidth == null)
|
||||
return;
|
||||
_startPosX = x;
|
||||
_startPosY = y;
|
||||
|
||||
if (_drawingAirFighterWidth + x > _pictureWidth || x < 0) {
|
||||
_startPosX = 0;
|
||||
}
|
||||
if (_drawingAirFighterHeight + y > _pictureHeight || y < 0) {
|
||||
_startPosY = 0;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean setPictureSize(int width, int height) {
|
||||
|
||||
if (_drawingAirFighterHeight > height || _drawingAirFighterWidth > width)
|
||||
return false;
|
||||
_pictureHeight = height;
|
||||
_pictureWidth = width;
|
||||
|
||||
if (_startPosX != null && _startPosY != null) {
|
||||
if (_startPosX + _drawingAirFighterWidth > width)
|
||||
_startPosX = width - _drawingAirFighterWidth;
|
||||
if (_startPosY + _drawingAirFighterHeight > height)
|
||||
_startPosY = height - _drawingAirFighterHeight;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean moveTransport(DirectionType direction) {
|
||||
if (entityAirFighter == null || _pictureWidth == null || _pictureHeight == null)
|
||||
return false;
|
||||
switch (direction) {
|
||||
case Left:
|
||||
if (_startPosX - entityAirFighter.Step() > 0)
|
||||
_startPosX -= (int) entityAirFighter.Step();
|
||||
return true;
|
||||
case Up:
|
||||
if (_startPosY - entityAirFighter.Step() > 0)
|
||||
_startPosY -= (int) entityAirFighter.Step();
|
||||
return true;
|
||||
case Right:
|
||||
if (_startPosX + entityAirFighter.Step() < _pictureWidth - _drawingAirFighterWidth)
|
||||
_startPosX += (int) entityAirFighter.Step();
|
||||
return true;
|
||||
case Down:
|
||||
if (_startPosY + entityAirFighter.Step() < _pictureHeight - _drawingAirFighterHeight)
|
||||
_startPosY += (int) entityAirFighter.Step();
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public void drawAirFighter(Graphics g) {
|
||||
if (entityAirFighter == 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(entityAirFighter.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(entityAirFighter.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(entityAirFighter.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(entityAirFighter.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);
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
drawningAirFighterEngine.drawAirFighterEngine(g, entityAirFighter.getAdditionalColor(), _startPosX, _startPosY);
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
40
ProjectAirFighter/src/DrawningAirFighterEngine.java
Normal file
@ -0,0 +1,40 @@
|
||||
import java.awt.*;
|
||||
|
||||
public class DrawningAirFighterEngine {
|
||||
private EngineCount engineCount;
|
||||
|
||||
public void setEnumNumber(int wheelCount) {
|
||||
for (EngineCount value : EngineCount.values()) {
|
||||
if (value.getEnumNumber() == wheelCount) {
|
||||
engineCount = value;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void drawAirFighterEngine(Graphics g, Color color, float startPosX, float startPosY) {
|
||||
Graphics2D g2d = (Graphics2D) g;
|
||||
g2d.setColor(color);
|
||||
g2d.setStroke(new BasicStroke(4));
|
||||
if (engineCount.getEnumNumber() == 2){
|
||||
g2d.drawRect((int)startPosX + 30, (int) startPosY + 69, 10, 2 );
|
||||
g2d.drawRect((int)startPosX + 30, (int) startPosY + 3, 10, 2 );
|
||||
}
|
||||
|
||||
if (engineCount.getEnumNumber() == 4){
|
||||
g2d.drawRect((int)startPosX + 30, (int) startPosY + 69, 10, 2 );
|
||||
g2d.drawRect((int)startPosX + 30, (int) startPosY + 62, 10, 2 );
|
||||
g2d.drawRect((int)startPosX + 30, (int) startPosY + 3, 10, 2 );
|
||||
g2d.drawRect((int)startPosX + 30, (int) startPosY + 10, 10, 2 );
|
||||
}
|
||||
|
||||
if (engineCount.getEnumNumber() == 6){
|
||||
g2d.drawRect((int)startPosX + 30, (int) startPosY + 69, 10, 2 );
|
||||
g2d.drawRect((int)startPosX + 30, (int) startPosY + 62, 10, 2 );
|
||||
g2d.drawRect((int)startPosX + 30, (int) startPosY + 55, 10, 2 );
|
||||
g2d.drawRect((int)startPosX + 30, (int) startPosY + 3, 10, 2 );
|
||||
g2d.drawRect((int)startPosX + 30, (int) startPosY + 10, 10, 2 );
|
||||
g2d.drawRect((int)startPosX + 30, (int) startPosY + 17, 10, 2 );
|
||||
}
|
||||
}
|
||||
}
|
14
ProjectAirFighter/src/EngineCount.java
Normal file
@ -0,0 +1,14 @@
|
||||
public enum EngineCount {
|
||||
Two(2),
|
||||
Three(4),
|
||||
Four(6);
|
||||
|
||||
final private int EnumNumber;
|
||||
EngineCount(int enumNumber) {
|
||||
EnumNumber = enumNumber;
|
||||
}
|
||||
public int getEnumNumber() {
|
||||
return EnumNumber;
|
||||
}
|
||||
|
||||
}
|
41
ProjectAirFighter/src/EntityAirFighter.java
Normal file
@ -0,0 +1,41 @@
|
||||
import java.awt.*;
|
||||
|
||||
public class EntityAirFighter {
|
||||
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 Color AdditionalColor;
|
||||
public Color getAdditionalColor() {
|
||||
return AdditionalColor;
|
||||
}
|
||||
|
||||
|
||||
public double Step() {
|
||||
return Speed*100/Weight;
|
||||
}
|
||||
private boolean Pgo;
|
||||
public boolean getPgo() {
|
||||
return Pgo;
|
||||
}
|
||||
private boolean Rockets;
|
||||
public boolean getRockets() {
|
||||
return Rockets;
|
||||
}
|
||||
public void Init(int speed, double weight, Color bodyColor, Color additionalColor, boolean pgo, boolean rockets) {
|
||||
Speed = speed;
|
||||
Weight = weight;
|
||||
BodyColor = bodyColor;
|
||||
AdditionalColor = additionalColor;
|
||||
Pgo = pgo;
|
||||
Rockets = rockets;
|
||||
}
|
||||
}
|
93
ProjectAirFighter/src/FormAirFighter.form
Normal file
@ -0,0 +1,93 @@
|
||||
<?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="4" column-count="5" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<constraints>
|
||||
<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="a8c2" class="javax.swing.JButton" binding="buttonCreate">
|
||||
<constraints>
|
||||
<grid row="2" column="0" row-span="2" col-span="1" vsize-policy="0" hsize-policy="3" anchor="2" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="Создать"/>
|
||||
</properties>
|
||||
</component>
|
||||
<vspacer id="7b40c">
|
||||
<constraints>
|
||||
<grid row="0" column="0" row-span="2" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
</vspacer>
|
||||
<component id="3dc0" class="javax.swing.JButton" binding="buttonDown">
|
||||
<constraints>
|
||||
<grid row="3" 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>
|
||||
<hspacer id="abaeb">
|
||||
<constraints>
|
||||
<grid row="2" column="1" row-span="2" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
</hspacer>
|
||||
<component id="ccb2a" class="javax.swing.JButton" binding="buttonUp">
|
||||
<constraints>
|
||||
<grid row="2" 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="fe25b" class="javax.swing.JButton" binding="buttonLeft">
|
||||
<constraints>
|
||||
<grid row="3" column="2" 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="arrowLeft.png"/>
|
||||
<text value=""/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="86d84" class="javax.swing.JButton" binding="buttonRight">
|
||||
<constraints>
|
||||
<grid row="3" 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>
|
||||
</children>
|
||||
</grid>
|
||||
</children>
|
||||
</grid>
|
||||
</form>
|
114
ProjectAirFighter/src/FormAirFighter.java
Normal file
@ -0,0 +1,114 @@
|
||||
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 DrawningAirFighter _drawningAirFighter = new DrawningAirFighter();
|
||||
JPanel PanelWrapper;
|
||||
private JPanel PictureBox;
|
||||
private JButton buttonCreate;
|
||||
private JButton buttonRight;
|
||||
private JButton buttonDown;
|
||||
private JButton buttonLeft;
|
||||
private JButton buttonUp;
|
||||
|
||||
private List<JComponent> controls;
|
||||
public FormAirFighter() {
|
||||
buttonUp.setName("buttonUp");
|
||||
buttonDown.setName("buttonDown");
|
||||
buttonLeft.setName("buttonLeft");
|
||||
buttonRight.setName("buttonRight");
|
||||
|
||||
InitializeControlsRepaintList();
|
||||
|
||||
buttonCreate.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
_drawningAirFighter = new DrawningAirFighter();
|
||||
Random random = new Random();
|
||||
|
||||
_drawningAirFighter.Init(random.nextInt(30, 100),
|
||||
random.nextInt(100, 500),
|
||||
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() );
|
||||
_drawningAirFighter.setPictureSize(PictureBox.getWidth(), PictureBox.getHeight());
|
||||
_drawningAirFighter.setPosition(random.nextInt(25, 100),
|
||||
random.nextInt(25, 100));
|
||||
|
||||
Draw();
|
||||
|
||||
}
|
||||
});
|
||||
ActionListener buttonMoveClickedListener = new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
String buttonName = ((JButton) e.getSource()).getName();
|
||||
boolean result = false;
|
||||
|
||||
switch (buttonName) {
|
||||
case "buttonUp": {
|
||||
result = _drawningAirFighter.moveTransport(DirectionType.Up);
|
||||
}
|
||||
break;
|
||||
case "buttonDown": {
|
||||
result = _drawningAirFighter.moveTransport(DirectionType.Down);
|
||||
}
|
||||
break;
|
||||
case "buttonLeft": {
|
||||
result = _drawningAirFighter.moveTransport(DirectionType.Left);
|
||||
}
|
||||
break;
|
||||
case "buttonRight": {
|
||||
result = _drawningAirFighter.moveTransport(DirectionType.Right);
|
||||
}
|
||||
break;
|
||||
|
||||
}
|
||||
if (result)
|
||||
Draw();
|
||||
|
||||
}
|
||||
};
|
||||
buttonRight.addActionListener(buttonMoveClickedListener);
|
||||
buttonDown.addActionListener(buttonMoveClickedListener);
|
||||
buttonLeft.addActionListener(buttonMoveClickedListener);
|
||||
buttonUp.addActionListener(buttonMoveClickedListener);
|
||||
|
||||
}
|
||||
private void Draw() {
|
||||
if (_drawningAirFighter.getEntityAirFighter() == 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());
|
||||
_drawningAirFighter.drawAirFighter(g);
|
||||
|
||||
RepaintControls();
|
||||
|
||||
}
|
||||
private void RepaintControls() {
|
||||
for (JComponent control : controls) {
|
||||
control.repaint();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void InitializeControlsRepaintList() {
|
||||
controls = new LinkedList<>();
|
||||
controls.add(buttonCreate);
|
||||
controls.add(buttonUp);
|
||||
controls.add(buttonDown);
|
||||
controls.add(buttonLeft);
|
||||
controls.add(buttonRight);
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -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);
|
||||
}
|
||||
}
|
After Width: | Height: | Size: 965 B |
After Width: | Height: | Size: 1005 B |
After Width: | Height: | Size: 978 B |
After Width: | Height: | Size: 1012 B |