refactoring form and make hard part

This commit is contained in:
MaxKarme 2022-10-28 20:18:49 +03:00
parent 86f553ca83
commit 685b97e188
8 changed files with 131 additions and 72 deletions

View File

@ -1,8 +1,10 @@
import java.awt.*; import java.awt.*;
import java.util.Random;
class DrawingAircraft class DrawingAircraft
{ {
public EntityAircraft AirFighter; public EntityAircraft AirFighter;
public DrawingEngines drawingEngines = new DrawingEngines();
private float _startPosX; private float _startPosX;
private float _startPosY; private float _startPosY;
@ -15,8 +17,11 @@ class DrawingAircraft
public void Init(int speed, float weight, Color bodyColor) public void Init(int speed, float weight, Color bodyColor)
{ {
Random rnd = new Random();
AirFighter = new EntityAircraft(); AirFighter = new EntityAircraft();
AirFighter.Init(speed, weight, bodyColor); AirFighter.Init(speed, weight, bodyColor);
drawingEngines.Init(rnd.nextInt(1, 8), bodyColor);
} }
public void SetPosition(int x, int y, int width, int height) public void SetPosition(int x, int y, int width, int height)
@ -120,6 +125,8 @@ class DrawingAircraft
g.drawPolygon(wingTop); g.drawPolygon(wingTop);
g.drawPolygon(wingBottom); g.drawPolygon(wingBottom);
g.drawRect((int)_startPosX, (int)_startPosY + 70, 160, 26); g.drawRect((int)_startPosX, (int)_startPosY + 70, 160, 26);
drawingEngines.draw(g, (int)_startPosX, (int)_startPosY);
} }
public void ChangeBorders(int width, int height) public void ChangeBorders(int width, int height)

30
DrawingEngines.java Normal file
View File

@ -0,0 +1,30 @@
import java.awt.*;
public class DrawingEngines {
private EnginesCount enginesCount;
private Color color;
public void Init(int count, Color bodyColor) {
if(count <= 2) enginesCount = EnginesCount.Two;
else if(count >= 6) enginesCount = EnginesCount.Six;
else enginesCount = EnginesCount.Four;
color = bodyColor;
}
public void draw(Graphics2D g, int startPosX, int startPosY) {
g.setPaint(color);
g.fillOval(startPosX + 90, startPosY + 10, 30, 15);
g.fillOval(startPosX + 90, startPosY + 141, 30, 15);
if(enginesCount == EnginesCount.Two) return;
g.fillOval(startPosX + 90, startPosY + 30, 30, 15);
g.fillOval(startPosX + 90, startPosY + 121, 30, 15);
if(enginesCount == EnginesCount.Four) return;
g.fillOval(startPosX + 90, startPosY + 50, 30, 15);
g.fillOval(startPosX + 90, startPosY + 101, 30, 15);
}
}

5
EnginesCount.java Normal file
View File

@ -0,0 +1,5 @@
public enum EnginesCount {
Two,
Four,
Six
}

View File

@ -1,6 +1,7 @@
<?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="FormAircraft"> <form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="FormAircraft">
<grid id="27dc6" binding="mainPanel" layout-manager="GridBagLayout"> <grid id="27dc6" binding="mainPanel" layout-manager="GridLayoutManager" row-count="3" column-count="7" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints> <constraints>
<xy x="20" y="20" width="745" height="400"/> <xy x="20" y="20" width="745" height="400"/>
</constraints> </constraints>
@ -10,106 +11,122 @@
<grid id="c3c1c" binding="DrawPlace" layout-manager="CardLayout" hgap="0" vgap="0"> <grid id="c3c1c" binding="DrawPlace" layout-manager="CardLayout" hgap="0" vgap="0">
<constraints> <constraints>
<grid row="0" column="0" row-span="1" col-span="7" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/> <grid row="0" column="0" row-span="1" col-span="7" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
<gridbag weightx="2.0" weighty="2.0"/>
</constraints> </constraints>
<properties/> <properties/>
<border type="none"/> <border type="none"/>
<children/> <children/>
</grid> </grid>
<component id="df504" class="javax.swing.JButton" binding="createButton"> <grid id="7cdea" layout-manager="GridLayoutManager" row-count="1" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints> <constraints>
<grid row="1" column="0" row-span="1" col-span="3" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/> <grid row="2" column="0" row-span="1" col-span="7" vsize-policy="0" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false">
<gridbag weightx="0.0" weighty="0.0"/> <minimum-size width="-1" height="20"/>
</constraints> </grid>
<properties>
<text value="создание"/>
</properties>
</component>
<grid id="e091d" layout-manager="GridBagLayout">
<constraints>
<grid row="1" column="3" row-span="1" col-span="4" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
<gridbag weightx="2.0" weighty="0.0"/>
</constraints> </constraints>
<properties/> <properties/>
<border type="none"/> <border type="none"/>
<children> <children>
<hspacer id="323b6"> <component id="5d314" class="javax.swing.JLabel" binding="weightLabel">
<constraints> <constraints>
<grid row="0" 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="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
<gridbag weightx="0.0" weighty="0.0"/>
</constraints>
</hspacer>
<vspacer id="cc4bd">
<constraints>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
<gridbag weightx="0.0" weighty="0.0"/>
</constraints>
</vspacer>
<component id="5bf4f" class="javax.swing.JButton" binding="upButton" default-binding="true">
<constraints>
<grid row="0" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
<gridbag weightx="0.0" weighty="0.0"/>
</constraints> </constraints>
<properties> <properties>
<text value="up"/> <text value="Вес: "/>
</properties> </properties>
</component> </component>
<component id="b31a8" class="javax.swing.JButton" binding="downButton" default-binding="true"> <component id="fa09a" class="javax.swing.JLabel" binding="speedLabel">
<constraints> <constraints>
<grid row="1" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/> <grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
<gridbag weightx="0.0" weighty="0.0"/>
</constraints> </constraints>
<properties> <properties>
<text value="down"/> <text value="Скорость: "/>
</properties> </properties>
</component> </component>
<component id="1d949" class="javax.swing.JButton" binding="leftButton" default-binding="true"> <component id="9494b" class="javax.swing.JLabel" binding="colorLabel">
<constraints> <constraints>
<grid row="1" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/> <grid row="0" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
<gridbag weightx="0.0" weighty="0.0"/>
</constraints> </constraints>
<properties> <properties>
<text value="left"/> <text value="Цвет"/>
</properties>
</component>
<component id="527d2" class="javax.swing.JButton" binding="rightButton" default-binding="true">
<constraints>
<grid row="1" column="3" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
<gridbag weightx="0.0" weighty="0.0"/>
</constraints>
<properties>
<text value="right"/>
</properties> </properties>
</component> </component>
</children> </children>
</grid> </grid>
<component id="fa09a" class="javax.swing.JLabel" binding="speedLabel"> <grid id="b5cf" layout-manager="GridLayoutManager" row-count="2" 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> <constraints>
<grid row="2" column="3" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/> <grid row="1" column="0" row-span="1" col-span="7" vsize-policy="0" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
<gridbag weightx="0.0" weighty="0.0"/>
</constraints> </constraints>
<properties> <properties/>
<text value="Скорость: "/> <border type="none"/>
</properties> <children>
</component> <hspacer id="eb27d">
<component id="5d314" class="javax.swing.JLabel" binding="weightLabel"> <constraints>
<constraints> <grid row="1" 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="2" column="4" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/> </constraints>
<gridbag weightx="0.0" weighty="0.0"/> </hspacer>
</constraints> <component id="df504" class="javax.swing.JButton" binding="createButton">
<properties> <constraints>
<text value="Вес: "/> <grid row="1" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="0" indent="0" use-parent-layout="false"/>
</properties> </constraints>
</component> <properties>
<component id="9494b" class="javax.swing.JLabel" binding="colorLabel"> <text value="создание"/>
<constraints> </properties>
<grid row="2" column="5" row-span="1" col-span="2" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/> </component>
<gridbag weightx="0.0" weighty="0.0"/> <component id="b31a8" class="javax.swing.JButton" binding="downButton" default-binding="true">
</constraints> <constraints>
<properties> <grid row="1" column="3" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false">
<text value="Цвет"/> <minimum-size width="30" height="30"/>
</properties> <preferred-size width="30" height="30"/>
</component> <maximum-size width="30" height="30"/>
</grid>
</constraints>
<properties>
<icon value="Resources/down.png"/>
<text value=""/>
</properties>
</component>
<component id="1d949" class="javax.swing.JButton" binding="leftButton" default-binding="true">
<constraints>
<grid row="1" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" 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="Resources/left.png"/>
<text value=""/>
</properties>
</component>
<component id="527d2" class="javax.swing.JButton" binding="rightButton" default-binding="true">
<constraints>
<grid row="1" column="4" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" 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="Resources/right.png"/>
<text value=""/>
</properties>
</component>
<component id="5bf4f" class="javax.swing.JButton" binding="upButton" default-binding="true">
<constraints>
<grid row="0" column="3" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" 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="Resources/up.png"/>
<text value=""/>
</properties>
</component>
</children>
</grid>
</children> </children>
</grid> </grid>
</form> </form>

BIN
Resources/down.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 451 B

BIN
Resources/left.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 367 B

BIN
Resources/right.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 366 B

BIN
Resources/up.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 360 B