Реализована основная часть работы
This commit is contained in:
parent
f8c531856d
commit
759245f4f2
@ -35,6 +35,7 @@ public class DrawingPlane {
|
|||||||
_pictureWidth = width;
|
_pictureWidth = width;
|
||||||
_pictureHeight = height;
|
_pictureHeight = height;
|
||||||
EntityPlane = new EntityPlane(speed, weight, bodyColor);
|
EntityPlane = new EntityPlane(speed, weight, bodyColor);
|
||||||
|
_drawingEngines = new DrawingEngines();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected DrawingPlane(int speed, double weight, Color bodyColor,
|
protected DrawingPlane(int speed, double weight, Color bodyColor,
|
||||||
@ -47,6 +48,7 @@ public class DrawingPlane {
|
|||||||
_planeWidth = planeWidth;
|
_planeWidth = planeWidth;
|
||||||
_planeHeight = planeHeight;
|
_planeHeight = planeHeight;
|
||||||
EntityPlane = new EntityPlane(speed, weight, bodyColor);
|
EntityPlane = new EntityPlane(speed, weight, bodyColor);
|
||||||
|
_drawingEngines = new DrawingEngines();
|
||||||
}
|
}
|
||||||
public void SetEnginesCount(int enginesCount) {
|
public void SetEnginesCount(int enginesCount) {
|
||||||
_drawingEngines.SetEnumEnginesCount(enginesCount);
|
_drawingEngines.SetEnumEnginesCount(enginesCount);
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="ProjectStormtrooper.FormStormtrooper">
|
<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"/>
|
<margin top="0" left="0" bottom="0" right="0"/>
|
||||||
<constraints>
|
<constraints>
|
||||||
<xy x="20" y="20" width="900" height="500"/>
|
<xy x="20" y="20" width="900" height="500"/>
|
||||||
@ -11,27 +11,27 @@
|
|||||||
</properties>
|
</properties>
|
||||||
<border type="none"/>
|
<border type="none"/>
|
||||||
<children>
|
<children>
|
||||||
<component id="35f01" class="javax.swing.JButton" binding="buttonCreate">
|
<component id="35f01" class="javax.swing.JButton" binding="buttonCreateStormtrooper">
|
||||||
<constraints>
|
<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>
|
</constraints>
|
||||||
<properties>
|
<properties>
|
||||||
<text value="Создать"/>
|
<text value="Создать штурмовик"/>
|
||||||
</properties>
|
</properties>
|
||||||
</component>
|
</component>
|
||||||
<hspacer id="f9ba0">
|
<hspacer id="f9ba0">
|
||||||
<constraints>
|
<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>
|
</constraints>
|
||||||
</hspacer>
|
</hspacer>
|
||||||
<vspacer id="ce5ea">
|
<vspacer id="ce5ea">
|
||||||
<constraints>
|
<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>
|
</constraints>
|
||||||
</vspacer>
|
</vspacer>
|
||||||
<component id="ac2ff" class="javax.swing.JButton" binding="buttonDown">
|
<component id="ac2ff" class="javax.swing.JButton" binding="buttonDown">
|
||||||
<constraints>
|
<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"/>
|
<minimum-size width="30" height="30"/>
|
||||||
<preferred-size width="30" height="30"/>
|
<preferred-size width="30" height="30"/>
|
||||||
<maximum-size width="30" height="30"/>
|
<maximum-size width="30" height="30"/>
|
||||||
@ -46,7 +46,7 @@
|
|||||||
</component>
|
</component>
|
||||||
<component id="b1382" class="javax.swing.JButton" binding="buttonUp">
|
<component id="b1382" class="javax.swing.JButton" binding="buttonUp">
|
||||||
<constraints>
|
<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"/>
|
<minimum-size width="30" height="30"/>
|
||||||
<preferred-size width="30" height="30"/>
|
<preferred-size width="30" height="30"/>
|
||||||
<maximum-size width="30" height="30"/>
|
<maximum-size width="30" height="30"/>
|
||||||
@ -61,7 +61,7 @@
|
|||||||
</component>
|
</component>
|
||||||
<component id="8b2ff" class="javax.swing.JButton" binding="buttonLeft">
|
<component id="8b2ff" class="javax.swing.JButton" binding="buttonLeft">
|
||||||
<constraints>
|
<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"/>
|
<minimum-size width="30" height="30"/>
|
||||||
<preferred-size width="30" height="30"/>
|
<preferred-size width="30" height="30"/>
|
||||||
<maximum-size width="30" height="30"/>
|
<maximum-size width="30" height="30"/>
|
||||||
@ -77,7 +77,7 @@
|
|||||||
</component>
|
</component>
|
||||||
<component id="25771" class="javax.swing.JButton" binding="buttonRight">
|
<component id="25771" class="javax.swing.JButton" binding="buttonRight">
|
||||||
<constraints>
|
<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"/>
|
<minimum-size width="30" height="30"/>
|
||||||
<preferred-size width="30" height="30"/>
|
<preferred-size width="30" height="30"/>
|
||||||
<maximum-size width="30" height="30"/>
|
<maximum-size width="30" height="30"/>
|
||||||
@ -89,6 +89,28 @@
|
|||||||
<text value=""/>
|
<text value=""/>
|
||||||
</properties>
|
</properties>
|
||||||
</component>
|
</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>
|
</children>
|
||||||
</grid>
|
</grid>
|
||||||
</form>
|
</form>
|
||||||
|
@ -6,13 +6,17 @@ import java.util.Random;
|
|||||||
import java.awt.event.ActionListener;
|
import java.awt.event.ActionListener;
|
||||||
|
|
||||||
public class FormStormtrooper {
|
public class FormStormtrooper {
|
||||||
DrawingStormtrooper _drawingStormtrooper = new DrawingStormtrooper();
|
DrawingPlane _drawingPlane;
|
||||||
private JButton buttonCreate;
|
AbstractStrategy _abstractStrategy;
|
||||||
|
private JButton buttonCreateStormtrooper;
|
||||||
private JPanel pictureBox;
|
private JPanel pictureBox;
|
||||||
private JButton buttonDown;
|
private JButton buttonDown;
|
||||||
private JButton buttonUp;
|
private JButton buttonUp;
|
||||||
private JButton buttonLeft;
|
private JButton buttonLeft;
|
||||||
private JButton buttonRight;
|
private JButton buttonRight;
|
||||||
|
private JButton buttonCreatePlane;
|
||||||
|
private JComboBox comboBoxStrategy;
|
||||||
|
private JButton buttonStep;
|
||||||
|
|
||||||
public JPanel getPictureBox() {
|
public JPanel getPictureBox() {
|
||||||
return pictureBox;
|
return pictureBox;
|
||||||
@ -24,11 +28,11 @@ public class FormStormtrooper {
|
|||||||
buttonLeft.setName("buttonLeft");
|
buttonLeft.setName("buttonLeft");
|
||||||
buttonRight.setName("buttonRight");
|
buttonRight.setName("buttonRight");
|
||||||
|
|
||||||
buttonCreate.addActionListener(e -> {
|
|
||||||
_drawingStormtrooper = new DrawingStormtrooper();
|
buttonCreateStormtrooper.addActionListener(e -> {
|
||||||
Random random = new Random();
|
Random random = new Random();
|
||||||
|
|
||||||
_drawingStormtrooper.Init(
|
_drawingPlane = new DrawingStormtrooper(
|
||||||
random.nextInt(100, 300),
|
random.nextInt(100, 300),
|
||||||
random.nextInt(1000, 3000),
|
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)),
|
||||||
@ -39,27 +43,70 @@ public class FormStormtrooper {
|
|||||||
pictureBox.getHeight()
|
pictureBox.getHeight()
|
||||||
);
|
);
|
||||||
|
|
||||||
_drawingStormtrooper.SetEnginesCount(random.nextInt(2, 7));
|
_drawingPlane.SetEnginesCount(random.nextInt(2, 7));
|
||||||
_drawingStormtrooper.SetPosition(random.nextInt(10, 100), random.nextInt(10, 100));
|
_drawingPlane.SetPosition(random.nextInt(10, 100), random.nextInt(10, 100));
|
||||||
|
|
||||||
Draw();
|
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 -> {
|
ActionListener buttonMoveClickedListener = e -> {
|
||||||
String buttonName = ((JButton) e.getSource()).getName();
|
String buttonName = ((JButton) e.getSource()).getName();
|
||||||
|
|
||||||
switch (buttonName) {
|
switch (buttonName) {
|
||||||
case ("buttonUp") -> {
|
case ("buttonUp") -> {
|
||||||
_drawingStormtrooper.MoveTransport(EnumDirectionType.Up);
|
_drawingPlane.MoveTransport(EnumDirectionType.Up);
|
||||||
}
|
}
|
||||||
case ("buttonDown") -> {
|
case ("buttonDown") -> {
|
||||||
_drawingStormtrooper.MoveTransport(EnumDirectionType.Down);
|
_drawingPlane.MoveTransport(EnumDirectionType.Down);
|
||||||
}
|
}
|
||||||
case ("buttonLeft") -> {
|
case ("buttonLeft") -> {
|
||||||
_drawingStormtrooper.MoveTransport(EnumDirectionType.Left);
|
_drawingPlane.MoveTransport(EnumDirectionType.Left);
|
||||||
}
|
}
|
||||||
case ("buttonRight") -> {
|
case ("buttonRight") -> {
|
||||||
_drawingStormtrooper.MoveTransport(EnumDirectionType.Right);
|
_drawingPlane.MoveTransport(EnumDirectionType.Right);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -73,12 +120,20 @@ public class FormStormtrooper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void Draw() {
|
public void Draw() {
|
||||||
if (_drawingStormtrooper.EntityStormtrooper == null) {
|
if (_drawingPlane == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Graphics g = pictureBox.getGraphics();
|
Graphics g = pictureBox.getGraphics();
|
||||||
pictureBox.paint(g);
|
pictureBox.paint(g);
|
||||||
_drawingStormtrooper.DrawTransport(g);
|
_drawingPlane.DrawTransport(g);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void createUIComponents() {
|
||||||
|
String[] strategiesList = {
|
||||||
|
"MoveToCenter",
|
||||||
|
"MoveToRightBottom"
|
||||||
|
};
|
||||||
|
comboBoxStrategy = new JComboBox(strategiesList);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user