Реализована основная часть работы
This commit is contained in:
parent
f8c531856d
commit
759245f4f2
@ -35,6 +35,7 @@ public class DrawingPlane {
|
||||
_pictureWidth = width;
|
||||
_pictureHeight = height;
|
||||
EntityPlane = new EntityPlane(speed, weight, bodyColor);
|
||||
_drawingEngines = new DrawingEngines();
|
||||
}
|
||||
|
||||
protected DrawingPlane(int speed, double weight, Color bodyColor,
|
||||
@ -47,6 +48,7 @@ public class DrawingPlane {
|
||||
_planeWidth = planeWidth;
|
||||
_planeHeight = planeHeight;
|
||||
EntityPlane = new EntityPlane(speed, weight, bodyColor);
|
||||
_drawingEngines = new DrawingEngines();
|
||||
}
|
||||
public void SetEnginesCount(int enginesCount) {
|
||||
_drawingEngines.SetEnumEnginesCount(enginesCount);
|
||||
|
@ -1,6 +1,6 @@
|
||||
<?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" layout-manager="GridLayoutManager" row-count="3" column-count="5" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<grid id="27dc6" binding="pictureBox" layout-manager="GridLayoutManager" row-count="5" column-count="6" 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"/>
|
||||
@ -11,27 +11,27 @@
|
||||
</properties>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<component id="35f01" class="javax.swing.JButton" binding="buttonCreate">
|
||||
<component id="35f01" class="javax.swing.JButton" binding="buttonCreateStormtrooper">
|
||||
<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"/>
|
||||
<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="Создать"/>
|
||||
<text value="Создать штурмовик"/>
|
||||
</properties>
|
||||
</component>
|
||||
<hspacer id="f9ba0">
|
||||
<constraints>
|
||||
<grid row="2" column="1" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
<grid row="4" 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>
|
||||
<vspacer id="ce5ea">
|
||||
<constraints>
|
||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
|
||||
<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="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">
|
||||
<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"/>
|
||||
@ -46,7 +46,7 @@
|
||||
</component>
|
||||
<component id="b1382" class="javax.swing.JButton" binding="buttonUp">
|
||||
<constraints>
|
||||
<grid row="1" column="3" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="0" indent="0" use-parent-layout="false">
|
||||
<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"/>
|
||||
@ -61,7 +61,7 @@
|
||||
</component>
|
||||
<component id="8b2ff" class="javax.swing.JButton" binding="buttonLeft">
|
||||
<constraints>
|
||||
<grid row="2" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="0" indent="0" use-parent-layout="false">
|
||||
<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"/>
|
||||
@ -77,7 +77,7 @@
|
||||
</component>
|
||||
<component id="25771" class="javax.swing.JButton" binding="buttonRight">
|
||||
<constraints>
|
||||
<grid row="2" column="4" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="0" indent="0" use-parent-layout="false">
|
||||
<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"/>
|
||||
@ -89,6 +89,28 @@
|
||||
<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="3" 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="3" 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>
|
||||
</children>
|
||||
</grid>
|
||||
</form>
|
||||
|
@ -6,13 +6,17 @@ import java.util.Random;
|
||||
import java.awt.event.ActionListener;
|
||||
|
||||
public class FormStormtrooper {
|
||||
DrawingStormtrooper _drawingStormtrooper = new DrawingStormtrooper();
|
||||
private JButton buttonCreate;
|
||||
DrawingPlane _drawingPlane;
|
||||
AbstractStrategy _abstractStrategy;
|
||||
private JButton buttonCreateStormtrooper;
|
||||
private JPanel pictureBox;
|
||||
private JButton buttonDown;
|
||||
private JButton buttonUp;
|
||||
private JButton buttonLeft;
|
||||
private JButton buttonRight;
|
||||
private JButton buttonCreatePlane;
|
||||
private JComboBox comboBoxStrategy;
|
||||
private JButton buttonStep;
|
||||
|
||||
public JPanel getPictureBox() {
|
||||
return pictureBox;
|
||||
@ -24,11 +28,11 @@ public class FormStormtrooper {
|
||||
buttonLeft.setName("buttonLeft");
|
||||
buttonRight.setName("buttonRight");
|
||||
|
||||
buttonCreate.addActionListener(e -> {
|
||||
_drawingStormtrooper = new DrawingStormtrooper();
|
||||
|
||||
buttonCreateStormtrooper.addActionListener(e -> {
|
||||
Random random = new Random();
|
||||
|
||||
_drawingStormtrooper.Init(
|
||||
_drawingPlane = new DrawingStormtrooper(
|
||||
random.nextInt(100, 300),
|
||||
random.nextInt(1000, 3000),
|
||||
new Color(random.nextInt(256), random.nextInt(256), random.nextInt(256)),
|
||||
@ -39,27 +43,70 @@ public class FormStormtrooper {
|
||||
pictureBox.getHeight()
|
||||
);
|
||||
|
||||
_drawingStormtrooper.SetEnginesCount(random.nextInt(2, 7));
|
||||
_drawingStormtrooper.SetPosition(random.nextInt(10, 100), random.nextInt(10, 100));
|
||||
_drawingPlane.SetEnginesCount(random.nextInt(2, 7));
|
||||
_drawingPlane.SetPosition(random.nextInt(10, 100), random.nextInt(10, 100));
|
||||
|
||||
Draw();
|
||||
});
|
||||
|
||||
buttonCreatePlane.addActionListener(e -> {
|
||||
Random random = new Random();
|
||||
|
||||
_drawingPlane = new DrawingPlane(
|
||||
random.nextInt(100, 300),
|
||||
random.nextInt(1000, 3000),
|
||||
new Color(random.nextInt(256), random.nextInt(256), random.nextInt(256)),
|
||||
pictureBox.getWidth(),
|
||||
pictureBox.getHeight()
|
||||
);
|
||||
|
||||
_drawingPlane.SetEnginesCount(random.nextInt(2, 7));
|
||||
_drawingPlane.SetPosition(random.nextInt(10, 100), random.nextInt(10, 100));
|
||||
|
||||
Draw();
|
||||
});
|
||||
|
||||
buttonStep.addActionListener(e -> {
|
||||
if (_drawingPlane == null)
|
||||
return;
|
||||
if (comboBoxStrategy.isEnabled()) {
|
||||
_abstractStrategy = null;
|
||||
int comboBoxStrategySelectedIndex = comboBoxStrategy.getSelectedIndex();
|
||||
if (comboBoxStrategySelectedIndex == 0) {
|
||||
_abstractStrategy = new MoveToCenter();
|
||||
} else if (comboBoxStrategySelectedIndex == 1) {
|
||||
_abstractStrategy = new MoveToRightBottom();
|
||||
}
|
||||
if (_abstractStrategy == null)
|
||||
return;
|
||||
_abstractStrategy.SetData(new DrawingObjectPlane(_drawingPlane), pictureBox.getWidth(), pictureBox.getHeight());
|
||||
comboBoxStrategy.setEnabled(false);
|
||||
}
|
||||
if (_abstractStrategy == null)
|
||||
return;
|
||||
_abstractStrategy.MakeStep();
|
||||
Draw();
|
||||
if (_abstractStrategy.GetStatus() == Status.Finish) {
|
||||
comboBoxStrategy.setEnabled(true);
|
||||
_abstractStrategy = null;
|
||||
}
|
||||
});
|
||||
|
||||
ActionListener buttonMoveClickedListener = e -> {
|
||||
String buttonName = ((JButton) e.getSource()).getName();
|
||||
|
||||
switch (buttonName) {
|
||||
case ("buttonUp") -> {
|
||||
_drawingStormtrooper.MoveTransport(EnumDirectionType.Up);
|
||||
_drawingPlane.MoveTransport(EnumDirectionType.Up);
|
||||
}
|
||||
case ("buttonDown") -> {
|
||||
_drawingStormtrooper.MoveTransport(EnumDirectionType.Down);
|
||||
_drawingPlane.MoveTransport(EnumDirectionType.Down);
|
||||
}
|
||||
case ("buttonLeft") -> {
|
||||
_drawingStormtrooper.MoveTransport(EnumDirectionType.Left);
|
||||
_drawingPlane.MoveTransport(EnumDirectionType.Left);
|
||||
}
|
||||
case ("buttonRight") -> {
|
||||
_drawingStormtrooper.MoveTransport(EnumDirectionType.Right);
|
||||
_drawingPlane.MoveTransport(EnumDirectionType.Right);
|
||||
}
|
||||
}
|
||||
|
||||
@ -73,12 +120,20 @@ public class FormStormtrooper {
|
||||
}
|
||||
|
||||
public void Draw() {
|
||||
if (_drawingStormtrooper.EntityStormtrooper == null) {
|
||||
if (_drawingPlane == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
Graphics g = pictureBox.getGraphics();
|
||||
pictureBox.paint(g);
|
||||
_drawingStormtrooper.DrawTransport(g);
|
||||
_drawingPlane.DrawTransport(g);
|
||||
}
|
||||
|
||||
private void createUIComponents() {
|
||||
String[] strategiesList = {
|
||||
"MoveToCenter",
|
||||
"MoveToRightBottom"
|
||||
};
|
||||
comboBoxStrategy = new JComboBox(strategiesList);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user