lab2
This commit is contained in:
parent
5980b6eb32
commit
2ab74c38dc
124
.idea/uiDesigner.xml
generated
Normal file
124
.idea/uiDesigner.xml
generated
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>
|
56
.idea/workspace.xml
generated
56
.idea/workspace.xml
generated
@ -4,7 +4,27 @@
|
||||
<option name="autoReloadType" value="SELECTIVE" />
|
||||
</component>
|
||||
<component name="ChangeListManager">
|
||||
<list default="true" id="4ad590c0-5ac3-4af8-9d5f-82f5c307cd9c" name="Changes" comment="clean" />
|
||||
<list default="true" id="4ad590c0-5ac3-4af8-9d5f-82f5c307cd9c" name="Changes" comment="">
|
||||
<change afterPath="$PROJECT_DIR$/.idea/uiDesigner.xml" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/src/Drawnings/DrawningPlane.java" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/src/Drawnings/DrawningPortholesHeart.java" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/src/Drawnings/DrawningPortholesSquare.java" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/src/Drawnings/IDrawningPortholes.java" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/src/Entities/EntityPlane.java" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/src/MovementStrategy/AbstractStrategy.java" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/src/MovementStrategy/DrawningObjectAirbus.java" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/src/MovementStrategy/IMoveableObject.java" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/src/MovementStrategy/MoveToBorder.java" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/src/MovementStrategy/MoveToCenter.java" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/src/MovementStrategy/ObjectParameters.java" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/src/MovementStrategy/Status.java" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/src/Drawnings/DrawingAirbus.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/Drawnings/DrawningAirbus.java" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/src/Drawnings/DrawingPortholes.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/Drawnings/DrawningPortholesCircle.java" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/src/Entities/EntityAirbus.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/Entities/EntityAirbus.java" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/src/FormAirbus.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/FormAirbus.java" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/src/Main.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/Main.java" afterDir="false" />
|
||||
</list>
|
||||
<option name="SHOW_DIALOG" value="false" />
|
||||
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
||||
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
|
||||
@ -13,7 +33,7 @@
|
||||
<component name="Git.Settings">
|
||||
<option name="RECENT_BRANCH_BY_REPOSITORY">
|
||||
<map>
|
||||
<entry key="$PROJECT_DIR$" value="main" />
|
||||
<entry key="$PROJECT_DIR$" value="lab1" />
|
||||
</map>
|
||||
</option>
|
||||
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
|
||||
@ -21,9 +41,9 @@
|
||||
<component name="MarkdownSettingsMigration">
|
||||
<option name="stateVersion" value="1" />
|
||||
</component>
|
||||
<component name="ProjectColorInfo"><![CDATA[{
|
||||
"associatedIndex": 8
|
||||
}]]></component>
|
||||
<component name="ProjectColorInfo">{
|
||||
"associatedIndex": 8
|
||||
}</component>
|
||||
<component name="ProjectId" id="2YLEaNaqu94PwzQjd2r7Rir4Z96" />
|
||||
<component name="ProjectViewState">
|
||||
<option name="hideEmptyMiddlePackages" value="true" />
|
||||
@ -33,15 +53,35 @@
|
||||
"keyToString": {
|
||||
"RunOnceActivity.OpenProjectViewOnStart": "true",
|
||||
"RunOnceActivity.ShowReadmeOnStart": "true",
|
||||
"git-widget-placeholder": "lab1",
|
||||
"last_opened_file_path": "E:/GitLab/PIbd-22_Isaeva_A.I._Airbus_Hard"
|
||||
"SHARE_PROJECT_CONFIGURATION_FILES": "true",
|
||||
"git-widget-placeholder": "lab2",
|
||||
"last_opened_file_path": "E:/GitLab/PIbd-22_Isaeva_A.I._Airbus_Hard/src/MovementStrategy"
|
||||
}
|
||||
}]]></component>
|
||||
<component name="RecentsManager">
|
||||
<key name="CopyFile.RECENT_KEYS">
|
||||
<recent name="E:\GitLab\PIbd-22_Isaeva_A.I._Airbus_Hard\src\MovementStrategy" />
|
||||
<recent name="E:\GitLab\PIbd-22_Isaeva_A.I._Airbus_Hard\src\Entities" />
|
||||
<recent name="E:\GitLab\PIbd-22_Isaeva_A.I._Airbus_Hard\src\Drawnings" />
|
||||
</key>
|
||||
<key name="MoveFile.RECENT_KEYS">
|
||||
<recent name="E:\GitLab\PIbd-22_Isaeva_A.I._Airbus_Hard" />
|
||||
</key>
|
||||
</component>
|
||||
<component name="RunManager">
|
||||
<configuration name="Main" type="Application" factoryName="Application" temporary="true" nameIsGenerated="true">
|
||||
<option name="MAIN_CLASS_NAME" value="Main" />
|
||||
<module name="PIbd-22_Isaeva_A.I._Airbus_Hard" />
|
||||
<method v="2">
|
||||
<option name="Make" enabled="true" />
|
||||
</method>
|
||||
</configuration>
|
||||
<recent_temporary>
|
||||
<list>
|
||||
<item itemvalue="Application.Main" />
|
||||
</list>
|
||||
</recent_temporary>
|
||||
</component>
|
||||
<component name="SpellCheckerSettings" RuntimeDictionaries="0" Folders="0" CustomDictionaries="0" DefaultDictionary="application-level" UseSingleDictionary="true" transferred="true" />
|
||||
<component name="TaskManager">
|
||||
<task active="true" id="Default" summary="Default task">
|
||||
@ -64,6 +104,6 @@
|
||||
</component>
|
||||
<component name="VcsManagerConfiguration">
|
||||
<MESSAGE value="clean" />
|
||||
<option name="LAST_COMMIT_MESSAGE" value="clean" />
|
||||
<option name="LAST_COMMIT_MESSAGE" value="" />
|
||||
</component>
|
||||
</project>
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
out/production/PIbd-22_Isaeva_A.I._Airbus_Hard/FormAirbus.class
Normal file
BIN
out/production/PIbd-22_Isaeva_A.I._Airbus_Hard/FormAirbus.class
Normal file
Binary file not shown.
BIN
out/production/PIbd-22_Isaeva_A.I._Airbus_Hard/Main.class
Normal file
BIN
out/production/PIbd-22_Isaeva_A.I._Airbus_Hard/Main.class
Normal file
Binary file not shown.
Binary file not shown.
@ -1,29 +1,48 @@
|
||||
package Drawnings;
|
||||
|
||||
import java.awt.*;
|
||||
import java.util.Random;
|
||||
import Entities.*;
|
||||
import MovementStrategy.*;
|
||||
|
||||
public class DrawingAirbus {
|
||||
public class DrawningAirbus {
|
||||
|
||||
public EntityAirbus entityAirbus;
|
||||
public DrawingPortholes _portholes;
|
||||
public IDrawningPortholes _portholes;
|
||||
private int _pictureWidth;
|
||||
private int _pictureHeight;
|
||||
private int _startPosX;
|
||||
private int _startPosY;
|
||||
private int _airbusWidth = 123;
|
||||
protected int _startPosX;
|
||||
protected int _startPosY;
|
||||
private int _airbusWidth = 124;
|
||||
private int _airbusHeight = 44;
|
||||
|
||||
public void Init(int speed, float weight, Color bodyColor, Color additionalColor, boolean isCompartment, boolean isadditionalEngine, int countPortholes, int width, int height) {
|
||||
public int GetPosX() { return _startPosX; }
|
||||
public int GetPosY() { return _startPosY; }
|
||||
public int GetWidth() { return _airbusWidth; }
|
||||
public int GetHeight() { return _airbusHeight; }
|
||||
|
||||
public DrawningAirbus(int speed, float weight, Color bodyColor, int countPortholes, int width, int height) {
|
||||
if (width < _airbusHeight || height < _airbusWidth)
|
||||
return;
|
||||
_pictureWidth = width;
|
||||
_pictureHeight = height;
|
||||
entityAirbus = new EntityAirbus();
|
||||
entityAirbus.Init(speed, weight, bodyColor, additionalColor, isCompartment, isadditionalEngine);
|
||||
entityAirbus = new EntityAirbus(speed, weight, bodyColor);
|
||||
|
||||
_portholes = new DrawingPortholes();
|
||||
Random random = new Random();
|
||||
switch (random.nextInt(0,3)) {
|
||||
case 0:
|
||||
_portholes = new DrawningPortholesCircle();
|
||||
break;
|
||||
case 1:
|
||||
_portholes = new DrawningPortholesHeart();
|
||||
break;
|
||||
case 2:
|
||||
_portholes = new DrawningPortholesSquare();
|
||||
break;
|
||||
default:
|
||||
_portholes = new DrawningPortholesCircle();
|
||||
break;
|
||||
}
|
||||
_portholes.SetCount(countPortholes);
|
||||
}
|
||||
|
||||
@ -39,6 +58,27 @@ public class DrawingAirbus {
|
||||
}
|
||||
}
|
||||
|
||||
public boolean CanMove(Direction direction)
|
||||
{
|
||||
if (entityAirbus == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
switch (direction)
|
||||
{
|
||||
case Left:
|
||||
return _startPosX - entityAirbus.Step > 0;
|
||||
case Right:
|
||||
return _startPosX + _airbusWidth + entityAirbus.Step < _pictureWidth;
|
||||
case Up:
|
||||
return _startPosY - entityAirbus.Step > 0;
|
||||
case Down:
|
||||
return _startPosY + _airbusHeight + entityAirbus.Step < _pictureHeight;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public void MoveTransport(Direction direction){
|
||||
if (entityAirbus == null) {
|
||||
return;
|
||||
@ -46,28 +86,16 @@ public class DrawingAirbus {
|
||||
|
||||
switch (direction) {
|
||||
case Left:
|
||||
if (_startPosX - entityAirbus.Step > 0)
|
||||
{
|
||||
_startPosX -= entityAirbus.Step;
|
||||
}
|
||||
_startPosX -= entityAirbus.Step;
|
||||
break;
|
||||
case Right:
|
||||
if (_startPosX + _airbusWidth + entityAirbus.Step < _pictureWidth)
|
||||
{
|
||||
_startPosX += entityAirbus.Step;
|
||||
}
|
||||
_startPosX += entityAirbus.Step;
|
||||
break;
|
||||
case Up:
|
||||
if (_startPosY - entityAirbus.Step > 0)
|
||||
{
|
||||
_startPosY -= entityAirbus.Step;
|
||||
}
|
||||
_startPosY -= entityAirbus.Step;
|
||||
break;
|
||||
case Down:
|
||||
if (_startPosY + _airbusHeight + entityAirbus.Step < _pictureHeight)
|
||||
{
|
||||
_startPosY += entityAirbus.Step;
|
||||
}
|
||||
_startPosY += entityAirbus.Step;
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -122,23 +150,5 @@ public class DrawingAirbus {
|
||||
g.drawOval(_startPosX+25,_startPosY+38, 6, 6);
|
||||
g.drawOval(_startPosX+30,_startPosY+38, 6, 6);
|
||||
g.drawOval(_startPosX+100,_startPosY+38, 6, 6);
|
||||
|
||||
// пассажирский отсек
|
||||
if (entityAirbus.IsCompartment())
|
||||
{
|
||||
g.setColor(entityAirbus.getAdditionalColor());
|
||||
g.fillOval(_startPosX+57, _startPosY+11, 39, 9);
|
||||
g.setColor(Color.BLACK);
|
||||
g.drawOval(_startPosX+57, _startPosY+11, 39, 9);
|
||||
}
|
||||
|
||||
// доп двигатель
|
||||
if (entityAirbus.IsAdditionalEngine())
|
||||
{
|
||||
g.setColor(entityAirbus.getAdditionalColor());
|
||||
g.fillOval(_startPosX, _startPosY + 25, 11, 5);
|
||||
g.setColor(Color.BLACK);
|
||||
g.drawOval(_startPosX, _startPosY + 25, 11, 5);
|
||||
}
|
||||
}
|
||||
}
|
43
src/Drawnings/DrawningPlane.java
Normal file
43
src/Drawnings/DrawningPlane.java
Normal file
@ -0,0 +1,43 @@
|
||||
package Drawnings;
|
||||
|
||||
import Entities.EntityPlane;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
public class DrawningPlane extends DrawningAirbus {
|
||||
|
||||
public DrawningPlane(int speed, float weight, Color bodyColor, int countPortholes, Color additionalColor, boolean isCompartment, boolean isAdditionalEngine, int width, int height)
|
||||
{
|
||||
super(speed, weight, bodyColor, countPortholes, width, height);
|
||||
if (entityAirbus != null) {
|
||||
entityAirbus = new EntityPlane(speed, weight, bodyColor, additionalColor, isCompartment, isAdditionalEngine);
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void DrawTransport(Graphics2D g) {
|
||||
|
||||
if (entityAirbus == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Color additionalColor = ((EntityPlane)entityAirbus).getAdditionalColor();
|
||||
// пассажирский отсек
|
||||
if (((EntityPlane)entityAirbus).IsCompartment()) {
|
||||
g.setColor(additionalColor);
|
||||
g.fillOval(_startPosX + 57, _startPosY + 11, 39, 9);
|
||||
g.setColor(Color.BLACK);
|
||||
g.drawOval(_startPosX + 57, _startPosY + 11, 39, 9);
|
||||
}
|
||||
|
||||
super.DrawTransport(g);
|
||||
|
||||
// доп двигатель
|
||||
if (((EntityPlane)entityAirbus).IsAdditionalEngine()) {
|
||||
g.setColor(additionalColor);
|
||||
g.fillOval(_startPosX, _startPosY + 25, 11, 5);
|
||||
g.setColor(Color.BLACK);
|
||||
g.drawOval(_startPosX, _startPosY + 25, 11, 5);
|
||||
}
|
||||
}
|
||||
}
|
@ -3,17 +3,15 @@ package Drawnings;
|
||||
import java.awt.*;
|
||||
import Entities.*;
|
||||
|
||||
public class DrawingPortholes {
|
||||
public class DrawningPortholesCircle implements IDrawningPortholes {
|
||||
private CountPortholes _porthole;
|
||||
public int Count;
|
||||
|
||||
public CountPortholes getCount()
|
||||
{
|
||||
return _porthole;
|
||||
}
|
||||
public void SetCount (int count) {
|
||||
Count = count;
|
||||
switch (Count) {
|
||||
switch (count) {
|
||||
case 10:
|
||||
_porthole = CountPortholes.Ten;
|
||||
break;
|
||||
@ -29,69 +27,69 @@ public class DrawingPortholes {
|
||||
}
|
||||
}
|
||||
|
||||
public void Draw (Graphics2D g, int _startPosx, int _startPoxY) {
|
||||
public void Draw (Graphics2D g, int _startPosX, int _startPosY) {
|
||||
g.setColor(Color.BLACK);
|
||||
if (_porthole == CountPortholes.Ten) {
|
||||
// цикл
|
||||
for (int i = 0; i < 10; ++i)
|
||||
{
|
||||
g.setColor(Color.cyan);
|
||||
g.fillOval(_startPosx + 19 + i*8, _startPoxY+21, 3, 3);
|
||||
g.fillOval(_startPosX + 19 + i*8, _startPosY+21, 3, 3);
|
||||
g.setColor(Color.black);
|
||||
g.drawOval(_startPosx + 19 + i*8, _startPoxY+21, 3, 3);
|
||||
g.drawOval(_startPosX + 19 + i*8, _startPosY+21, 3, 3);
|
||||
}
|
||||
}
|
||||
if (_porthole == CountPortholes.Twenty) {
|
||||
for (int i = 0; i < 10; ++i)
|
||||
{
|
||||
g.setColor(Color.cyan);
|
||||
g.fillOval(_startPosx + 19 + i*8, _startPoxY+21, 3, 3);
|
||||
g.fillOval(_startPosX + 19 + i*8, _startPosY+21, 3, 3);
|
||||
g.setColor(Color.black);
|
||||
g.drawOval(_startPosx + 19 + i*8, _startPoxY+21, 3, 3);
|
||||
g.drawOval(_startPosX + 19 + i*8, _startPosY+21, 3, 3);
|
||||
}
|
||||
for (int i=0; i < 5; ++i)
|
||||
{
|
||||
g.setColor(Color.cyan);
|
||||
g.fillOval(_startPosx + 15 + i*5, _startPoxY+26, 3, 3);
|
||||
g.fillOval(_startPosX + 15 + i*5, _startPosY+26, 3, 3);
|
||||
g.setColor(Color.black);
|
||||
g.drawOval(_startPosx + 15 + i*5, _startPoxY+26, 3, 3);
|
||||
g.drawOval(_startPosX + 15 + i*5, _startPosY+26, 3, 3);
|
||||
}
|
||||
for (int i=0; i < 5; ++i)
|
||||
{
|
||||
g.setColor(Color.cyan);
|
||||
g.fillOval(_startPosx + 70 + i*5, _startPoxY+26, 3, 3);
|
||||
g.fillOval(_startPosX + 70 + i*5, _startPosY+26, 3, 3);
|
||||
g.setColor(Color.black);
|
||||
g.drawOval(_startPosx + 70 + i*5, _startPoxY+26, 3, 3);
|
||||
g.drawOval(_startPosX + 70 + i*5, _startPosY+26, 3, 3);
|
||||
}
|
||||
}
|
||||
if (_porthole == CountPortholes.Thirty){
|
||||
for (int i = 0; i < 10; ++i)
|
||||
{
|
||||
g.setColor(Color.cyan);
|
||||
g.fillOval(_startPosx + 19 + i*8, _startPoxY+21, 3, 3);
|
||||
g.fillOval(_startPosX + 19 + i*8, _startPosY+21, 3, 3);
|
||||
g.setColor(Color.black);
|
||||
g.drawOval(_startPosx + 19 + i*8, _startPoxY+21, 3, 3);
|
||||
g.drawOval(_startPosX + 19 + i*8, _startPosY+21, 3, 3);
|
||||
}
|
||||
for (int i=0; i < 5; ++i)
|
||||
{
|
||||
g.setColor(Color.cyan);
|
||||
g.fillOval(_startPosx + 15 + i*5, _startPoxY+26, 3, 3);
|
||||
g.fillOval(_startPosX + 15 + i*5, _startPosY+26, 3, 3);
|
||||
g.setColor(Color.black);
|
||||
g.drawOval(_startPosx + 15 + i*5, _startPoxY+26, 3, 3);
|
||||
g.drawOval(_startPosX + 15 + i*5, _startPosY+26, 3, 3);
|
||||
}
|
||||
for (int i=0; i < 5; ++i)
|
||||
{
|
||||
g.setColor(Color.cyan);
|
||||
g.fillOval(_startPosx + 70 + i*5, _startPoxY+26, 3, 3);
|
||||
g.fillOval(_startPosX + 70 + i*5, _startPosY+26, 3, 3);
|
||||
g.setColor(Color.black);
|
||||
g.drawOval(_startPosx + 70 + i*5, _startPoxY+26, 3, 3);
|
||||
g.drawOval(_startPosX + 70 + i*5, _startPosY+26, 3, 3);
|
||||
}
|
||||
for (int i = 0; i < 10; ++i)
|
||||
{
|
||||
g.setColor(Color.cyan);
|
||||
g.fillOval(_startPosx + 19 + i*8, _startPoxY+31, 3, 3);
|
||||
g.fillOval(_startPosX + 19 + i*8, _startPosY+31, 3, 3);
|
||||
g.setColor(Color.black);
|
||||
g.drawOval(_startPosx + 19 + i*8, _startPoxY+31, 3, 3);
|
||||
g.drawOval(_startPosX + 19 + i*8, _startPosY+31, 3, 3);
|
||||
}
|
||||
}
|
||||
}
|
81
src/Drawnings/DrawningPortholesHeart.java
Normal file
81
src/Drawnings/DrawningPortholesHeart.java
Normal file
@ -0,0 +1,81 @@
|
||||
package Drawnings;
|
||||
|
||||
import Entities.CountPortholes;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
public class DrawningPortholesHeart implements IDrawningPortholes {
|
||||
private CountPortholes _porthole;
|
||||
|
||||
public CountPortholes getCount()
|
||||
{
|
||||
return _porthole;
|
||||
}
|
||||
public void SetCount (int count) {
|
||||
switch (count) {
|
||||
case 10:
|
||||
_porthole = CountPortholes.Ten;
|
||||
break;
|
||||
case 20:
|
||||
_porthole = CountPortholes.Twenty;
|
||||
break;
|
||||
case 30:
|
||||
_porthole = CountPortholes.Thirty;
|
||||
break;
|
||||
default:
|
||||
_porthole = CountPortholes.Ten;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void Draw (Graphics2D g, int _startPosX, int _startPosY) {
|
||||
g.setColor(Color.BLACK);
|
||||
if (_porthole == CountPortholes.Ten) {
|
||||
for (int i = 0; i < 10; ++i)
|
||||
{
|
||||
drawHeart(g, _startPosX + 19 + i*8, _startPosY + 20);
|
||||
}
|
||||
}
|
||||
if (_porthole == CountPortholes.Twenty) {
|
||||
for (int i = 0; i < 10; ++i)
|
||||
{
|
||||
drawHeart(g, _startPosX + 19 + i*8, _startPosY + 20);
|
||||
}
|
||||
for (int i=0; i < 5; ++i)
|
||||
{
|
||||
drawHeart(g, _startPosX + 12 + i*6, _startPosY + 26);
|
||||
}
|
||||
for (int i=0; i < 5; ++i)
|
||||
{
|
||||
drawHeart(g, _startPosX + 70 + i*6, _startPosY + 26);
|
||||
}
|
||||
}
|
||||
if (_porthole == CountPortholes.Thirty){
|
||||
for (int i = 0; i < 10; ++i)
|
||||
{
|
||||
drawHeart(g, _startPosX + 19 + i*8, _startPosY + 20);
|
||||
}
|
||||
for (int i=0; i < 5; ++i)
|
||||
{
|
||||
drawHeart(g, _startPosX + 12 + i*6, _startPosY + 26);
|
||||
}
|
||||
for (int i=0; i < 5; ++i)
|
||||
{
|
||||
drawHeart(g, _startPosX + 70 + i*6, _startPosY + 26);
|
||||
}
|
||||
for (int i = 0; i < 10; ++i)
|
||||
{
|
||||
drawHeart(g, _startPosX + 19 + i*8, _startPosY+32);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void drawHeart(Graphics2D g, int _startPosX, int _startPosY){
|
||||
int[] HeartX = {_startPosX+2, _startPosX, _startPosX, _startPosX+1, _startPosX+2, _startPosX+3, _startPosX+5, _startPosX+5};
|
||||
int[] HeartY = {_startPosY+4, _startPosY+2, _startPosY, _startPosY, _startPosY+1, _startPosY, _startPosY, _startPosY+2};
|
||||
g.setColor(Color.cyan);
|
||||
g.fillPolygon(HeartX, HeartY, HeartX.length);
|
||||
g.setColor(Color.black);
|
||||
g.drawPolygon(HeartX, HeartY, HeartX.length);
|
||||
}
|
||||
}
|
97
src/Drawnings/DrawningPortholesSquare.java
Normal file
97
src/Drawnings/DrawningPortholesSquare.java
Normal file
@ -0,0 +1,97 @@
|
||||
package Drawnings;
|
||||
|
||||
import Entities.CountPortholes;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
public class DrawningPortholesSquare implements IDrawningPortholes {
|
||||
private CountPortholes _porthole;
|
||||
|
||||
public CountPortholes getCount()
|
||||
{
|
||||
return _porthole;
|
||||
}
|
||||
public void SetCount (int count) {
|
||||
switch (count) {
|
||||
case 10:
|
||||
_porthole = CountPortholes.Ten;
|
||||
break;
|
||||
case 20:
|
||||
_porthole = CountPortholes.Twenty;
|
||||
break;
|
||||
case 30:
|
||||
_porthole = CountPortholes.Thirty;
|
||||
break;
|
||||
default:
|
||||
_porthole = CountPortholes.Ten;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void Draw (Graphics2D g, int _startPosX, int _startPosY) {
|
||||
g.setColor(Color.BLACK);
|
||||
if (_porthole == CountPortholes.Ten) {
|
||||
// цикл
|
||||
for (int i = 0; i < 10; ++i)
|
||||
{
|
||||
g.setColor(Color.cyan);
|
||||
g.fillRect(_startPosX + 19 + i*8, _startPosY+21, 3, 3);
|
||||
g.setColor(Color.black);
|
||||
g.drawRect(_startPosX + 19 + i*8, _startPosY+21, 3, 3);
|
||||
}
|
||||
}
|
||||
if (_porthole == CountPortholes.Twenty) {
|
||||
for (int i = 0; i < 10; ++i)
|
||||
{
|
||||
g.setColor(Color.cyan);
|
||||
g.fillRect(_startPosX + 19 + i*8, _startPosY+21, 3, 3);
|
||||
g.setColor(Color.black);
|
||||
g.drawRect(_startPosX + 19 + i*8, _startPosY+21, 3, 3);
|
||||
}
|
||||
for (int i=0; i < 5; ++i)
|
||||
{
|
||||
g.setColor(Color.cyan);
|
||||
g.fillRect(_startPosX + 15 + i*5, _startPosY+26, 3, 3);
|
||||
g.setColor(Color.black);
|
||||
g.drawRect(_startPosX + 15 + i*5, _startPosY+26, 3, 3);
|
||||
}
|
||||
for (int i=0; i < 5; ++i)
|
||||
{
|
||||
g.setColor(Color.cyan);
|
||||
g.fillRect(_startPosX + 70 + i*5, _startPosY+26, 3, 3);
|
||||
g.setColor(Color.black);
|
||||
g.drawRect(_startPosX + 70 + i*5, _startPosY+26, 3, 3);
|
||||
}
|
||||
}
|
||||
if (_porthole == CountPortholes.Thirty){
|
||||
for (int i = 0; i < 10; ++i)
|
||||
{
|
||||
g.setColor(Color.cyan);
|
||||
g.fillRect(_startPosX + 19 + i*8, _startPosY+21, 3, 3);
|
||||
g.setColor(Color.black);
|
||||
g.drawRect(_startPosX + 19 + i*8, _startPosY+21, 3, 3);
|
||||
}
|
||||
for (int i=0; i < 5; ++i)
|
||||
{
|
||||
g.setColor(Color.cyan);
|
||||
g.fillRect(_startPosX + 15 + i*5, _startPosY+26, 3, 3);
|
||||
g.setColor(Color.black);
|
||||
g.drawRect(_startPosX + 15 + i*5, _startPosY+26, 3, 3);
|
||||
}
|
||||
for (int i=0; i < 5; ++i)
|
||||
{
|
||||
g.setColor(Color.cyan);
|
||||
g.fillRect(_startPosX + 70 + i*5, _startPosY+26, 3, 3);
|
||||
g.setColor(Color.black);
|
||||
g.drawRect(_startPosX + 70 + i*5, _startPosY+26, 3, 3);
|
||||
}
|
||||
for (int i = 0; i < 10; ++i)
|
||||
{
|
||||
g.setColor(Color.cyan);
|
||||
g.fillRect(_startPosX + 19 + i*8, _startPosY+31, 3, 3);
|
||||
g.setColor(Color.black);
|
||||
g.drawRect(_startPosX + 19 + i*8, _startPosY+31, 3, 3);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
10
src/Drawnings/IDrawningPortholes.java
Normal file
10
src/Drawnings/IDrawningPortholes.java
Normal file
@ -0,0 +1,10 @@
|
||||
package Drawnings;
|
||||
|
||||
import java.awt.*;
|
||||
import Entities.CountPortholes;
|
||||
|
||||
public interface IDrawningPortholes {
|
||||
public CountPortholes getCount();
|
||||
public void SetCount (int count);
|
||||
public void Draw (Graphics2D g, int _startPosX, int _startPoxY);
|
||||
}
|
@ -6,11 +6,7 @@ public class EntityAirbus {
|
||||
private int Speed;
|
||||
private float Weight;
|
||||
private Color BodyColor;
|
||||
private Color AdditionalColor;
|
||||
private boolean IsCompartment;
|
||||
private boolean IsAdditionalEngine;
|
||||
|
||||
public int Step;
|
||||
public float Step;
|
||||
|
||||
public int getSpeed() {
|
||||
return Speed;
|
||||
@ -21,27 +17,14 @@ public class EntityAirbus {
|
||||
public Color getBodyColor() {
|
||||
return BodyColor;
|
||||
}
|
||||
public Color getAdditionalColor() {
|
||||
return AdditionalColor;
|
||||
}
|
||||
public boolean IsCompartment() {
|
||||
return IsCompartment;
|
||||
}
|
||||
public boolean IsAdditionalEngine() {
|
||||
return IsAdditionalEngine;
|
||||
}
|
||||
|
||||
|
||||
public void Init(int speed, float weight, Color bodyColor, Color additionalColor, boolean isCompartment, boolean isAdditionalEngine)
|
||||
public EntityAirbus(int speed, float weight, Color bodyColor)
|
||||
{
|
||||
Weight = weight;
|
||||
Speed = speed;
|
||||
BodyColor = bodyColor;
|
||||
|
||||
Weight = weight;
|
||||
Speed = speed;
|
||||
BodyColor = bodyColor;
|
||||
AdditionalColor = additionalColor;
|
||||
IsCompartment = isCompartment;
|
||||
IsAdditionalEngine = isAdditionalEngine;
|
||||
|
||||
Step = Speed * 100 / (int) Weight;
|
||||
Step = Speed * 100 / (int) Weight;
|
||||
}
|
||||
}
|
||||
|
21
src/Entities/EntityPlane.java
Normal file
21
src/Entities/EntityPlane.java
Normal file
@ -0,0 +1,21 @@
|
||||
package Entities;
|
||||
|
||||
import javax.swing.text.AttributeSet;
|
||||
import java.awt.*;
|
||||
|
||||
public class EntityPlane extends EntityAirbus {
|
||||
private Color AdditionalColor;
|
||||
private boolean IsCompartment;
|
||||
private boolean IsAdditionalEngine;
|
||||
|
||||
public EntityPlane(int speed, float weight, Color bodyColor, Color additionalColor, boolean isCompartment, boolean isAdditionalEngine) {
|
||||
super(speed, weight, bodyColor);
|
||||
AdditionalColor = additionalColor;
|
||||
IsCompartment = isCompartment;
|
||||
IsAdditionalEngine = isAdditionalEngine;
|
||||
}
|
||||
|
||||
public Color getAdditionalColor() { return AdditionalColor; }
|
||||
public boolean IsCompartment() { return IsCompartment; }
|
||||
public boolean IsAdditionalEngine() { return IsAdditionalEngine; }
|
||||
}
|
@ -7,12 +7,23 @@ import MovementStrategy.*;
|
||||
|
||||
public class FormAirbus extends JFrame {
|
||||
|
||||
private DrawingAirbus _drawningAirbus;
|
||||
private Canvas canvas = new Canvas();
|
||||
private int width;
|
||||
private int height;
|
||||
private DrawningAirbus _drawningAirbus;
|
||||
private AbstractStrategy _abstractStrategy;
|
||||
private Canvas canvas;
|
||||
|
||||
JLabel labelCount = new JLabel("Введите число иллюминаторов:");
|
||||
private JTextField fieldCount = new JTextField();
|
||||
private JButton buttonCreate;
|
||||
// выбор кол-ва иллюминаторов
|
||||
JLabel labelCount;
|
||||
private JTextField fieldCount;
|
||||
|
||||
// выбор стратегии
|
||||
JLabel labelStrategy;
|
||||
JComboBox comboBoxStrategy;
|
||||
JButton buttonStrategy;
|
||||
|
||||
private JButton buttonCreateAirbus;
|
||||
private JButton buttonCreatePlane;
|
||||
private JButton buttonUp;
|
||||
private JButton buttonDown;
|
||||
private JButton buttonRight;
|
||||
@ -26,43 +37,67 @@ public class FormAirbus extends JFrame {
|
||||
|
||||
private void InitializeComponent()
|
||||
{
|
||||
buttonCreate = new JButton("Создать самолёт");
|
||||
canvas = new Canvas();
|
||||
|
||||
labelCount = new JLabel("Введите число иллюминаторов:");
|
||||
fieldCount = new JTextField();
|
||||
|
||||
labelStrategy = new JLabel("Шаг стратегии:");
|
||||
comboBoxStrategy = new JComboBox(new Integer[] {0, 1});
|
||||
buttonStrategy = new JButton("Выбрать стратегию");
|
||||
buttonStrategy.setMargin(new Insets(0, 0, 0, 0));
|
||||
|
||||
buttonCreateAirbus = new JButton("Создать аэробус");
|
||||
buttonCreateAirbus.setMargin(new Insets(0, 0, 0, 0));
|
||||
|
||||
buttonCreatePlane = new JButton("Создать самолёт");
|
||||
buttonCreatePlane.setMargin(new Insets(0, 0, 0, 0));
|
||||
|
||||
buttonUp = new JButton();
|
||||
buttonUp.setName("up");
|
||||
buttonUp.setIcon(new ImageIcon("images\\KeyUp.png"));
|
||||
buttonUp.setSize(48, 44);
|
||||
|
||||
buttonRight = new JButton();
|
||||
buttonRight.setName("right");
|
||||
buttonRight.setIcon(new ImageIcon("images\\KeyRight.png"));
|
||||
buttonRight.setSize(48, 44);
|
||||
|
||||
buttonLeft = new JButton();
|
||||
|
||||
buttonLeft.setName("left");
|
||||
buttonLeft.setIcon(new ImageIcon("images\\KeyLeft.png"));
|
||||
buttonLeft.setSize(48, 44);
|
||||
|
||||
buttonDown = new JButton();
|
||||
buttonDown.setName("down");
|
||||
buttonDown.setIcon(new ImageIcon("images\\KeyDown.png"));
|
||||
buttonDown.setSize(48, 44);
|
||||
|
||||
setSize(800,500);
|
||||
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
setLayout(null);
|
||||
|
||||
buttonCreate.setBounds(12, 355, 170, 44);
|
||||
buttonCreateAirbus.setBounds(12, 355, 146, 33);
|
||||
buttonCreatePlane.setBounds(182, 355, 146, 33);
|
||||
|
||||
labelCount.setBounds(42, 405, 240, 20);
|
||||
fieldCount.setBounds(240, 407, 48, 20);
|
||||
|
||||
labelStrategy.setBounds(630, 20, 146, 33);
|
||||
comboBoxStrategy.setBounds(630, 50, 146, 20);
|
||||
buttonStrategy.setBounds(630, 80, 146, 33);
|
||||
|
||||
buttonUp.setBounds(679, 313, 48, 44);
|
||||
buttonRight.setBounds( 728, 358, 48, 44);
|
||||
buttonLeft.setBounds(630, 358, 48, 44);
|
||||
buttonDown.setBounds( 679, 358, 48, 44);
|
||||
labelCount.setBounds(12, 405, 240, 20);
|
||||
fieldCount.setBounds(210, 407, 48, 20);
|
||||
canvas.setBounds(0,0,800, 460);
|
||||
canvas.setBounds(0,0,790, 460);
|
||||
|
||||
add(buttonCreate);
|
||||
add(buttonCreateAirbus);
|
||||
add(buttonCreatePlane);
|
||||
add(labelCount);
|
||||
add(fieldCount);
|
||||
add(labelStrategy);
|
||||
add(comboBoxStrategy);
|
||||
add(buttonStrategy);
|
||||
add(buttonUp);
|
||||
add(buttonRight);
|
||||
add(buttonDown);
|
||||
@ -71,14 +106,18 @@ public class FormAirbus extends JFrame {
|
||||
add(fieldCount);
|
||||
add(canvas);
|
||||
|
||||
buttonCreate.addActionListener(buttonCreateListener);
|
||||
// логика формы
|
||||
buttonCreateAirbus.addActionListener(buttonCreateAirbusListener);
|
||||
buttonCreatePlane.addActionListener(buttonCreatePlaneListener);
|
||||
buttonStrategy.addActionListener(buttonStrategyListener);
|
||||
buttonUp.addActionListener(buttonsMoveListener);
|
||||
buttonRight.addActionListener(buttonsMoveListener);
|
||||
buttonDown.addActionListener(buttonsMoveListener);
|
||||
buttonLeft.addActionListener(buttonsMoveListener);
|
||||
}
|
||||
|
||||
ActionListener buttonCreateListener = new ActionListener() {
|
||||
ActionListener buttonCreateAirbusListener = new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
int countPortholes;
|
||||
try
|
||||
@ -96,15 +135,86 @@ public class FormAirbus extends JFrame {
|
||||
}
|
||||
|
||||
Random rand = new Random();
|
||||
_drawningAirbus = new DrawingAirbus();
|
||||
_drawningAirbus.Init(rand.nextInt(200) + 100, rand.nextInt(2000) + 1000,
|
||||
_drawningAirbus = new DrawningAirbus(rand.nextInt(200) + 100, rand.nextInt(2000) + 1000,
|
||||
new Color(rand.nextInt(256),rand.nextInt(256),rand.nextInt(256)),
|
||||
new Color(rand.nextInt(256), rand.nextInt(256), rand.nextInt(256)),
|
||||
rand.nextBoolean(), rand.nextBoolean(),
|
||||
countPortholes,
|
||||
canvas.getWidth(), canvas.getHeight());
|
||||
|
||||
_drawningAirbus.SetPosition(rand.nextInt(100) + 10, rand.nextInt(100) + 10);
|
||||
comboBoxStrategy.setEnabled(true);
|
||||
canvas.repaint();
|
||||
}
|
||||
};
|
||||
|
||||
ActionListener buttonCreatePlaneListener = new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
int countPortholes;
|
||||
try
|
||||
{
|
||||
countPortholes = Integer.parseInt(fieldCount.getText());
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
countPortholes = 0;
|
||||
}
|
||||
if (countPortholes != 10 && countPortholes != 20 && countPortholes != 30)
|
||||
{
|
||||
JOptionPane.showMessageDialog(null, "Число должно быть равно 10, 20 или 30.\nКол-во иллюминаторов приравнено к 10");
|
||||
countPortholes = 10;
|
||||
}
|
||||
|
||||
Random rand = new Random();
|
||||
_drawningAirbus = new DrawningPlane(rand.nextInt(200) + 100, rand.nextInt(2000) + 1000,
|
||||
new Color(rand.nextInt(256),rand.nextInt(256),rand.nextInt(256)),
|
||||
countPortholes,
|
||||
new Color(rand.nextInt(256), rand.nextInt(256), rand.nextInt(256)),
|
||||
rand.nextBoolean(), rand.nextBoolean(),
|
||||
canvas.getWidth(), canvas.getHeight());
|
||||
|
||||
_drawningAirbus.SetPosition(rand.nextInt(100) + 10, rand.nextInt(100) + 10);
|
||||
comboBoxStrategy.setEnabled(true);
|
||||
canvas.repaint();
|
||||
}
|
||||
};
|
||||
|
||||
ActionListener buttonStrategyListener = new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
if (_drawningAirbus == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (comboBoxStrategy.isEnabled()) {
|
||||
|
||||
switch (comboBoxStrategy.getSelectedIndex()) {
|
||||
case 0:
|
||||
_abstractStrategy = new MoveToCenter();
|
||||
break;
|
||||
case 1:
|
||||
_abstractStrategy = new MoveToBorder();
|
||||
break;
|
||||
default:
|
||||
_abstractStrategy = null;
|
||||
break;
|
||||
}
|
||||
;
|
||||
if (_abstractStrategy == null) {
|
||||
return;
|
||||
}
|
||||
_abstractStrategy.SetData(new DrawningObjectAirbus(_drawningAirbus), canvas.getWidth(), canvas.getHeight());
|
||||
comboBoxStrategy.setEnabled(false);
|
||||
}
|
||||
if (_abstractStrategy == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_abstractStrategy.MakeStep();
|
||||
if (_abstractStrategy.GetStatus() == Status.Finish)
|
||||
{
|
||||
comboBoxStrategy.setEnabled(true);
|
||||
_abstractStrategy = null;
|
||||
}
|
||||
canvas.repaint();
|
||||
}
|
||||
};
|
||||
@ -136,8 +246,7 @@ public class FormAirbus extends JFrame {
|
||||
};
|
||||
|
||||
class Canvas extends JComponent{
|
||||
public Canvas(){
|
||||
}
|
||||
public Canvas() {}
|
||||
public void paintComponent (Graphics g){
|
||||
if (_drawningAirbus == null){
|
||||
return;
|
||||
|
@ -1,4 +1,5 @@
|
||||
public class Main {
|
||||
|
||||
public static void main(String[] args) {
|
||||
new FormAirbus();
|
||||
}
|
||||
|
76
src/MovementStrategy/AbstractStrategy.java
Normal file
76
src/MovementStrategy/AbstractStrategy.java
Normal file
@ -0,0 +1,76 @@
|
||||
package MovementStrategy;
|
||||
|
||||
public abstract class AbstractStrategy {
|
||||
private IMoveableObject _moveableObject;
|
||||
private Status _state = Status.NotInit;
|
||||
protected int FieldWidth;
|
||||
protected int FieldHeight;
|
||||
public Status GetStatus() { return _state; }
|
||||
|
||||
// Изменить статус, установить поля
|
||||
public void SetData(IMoveableObject moveableObject, int width, int height)
|
||||
{
|
||||
if (moveableObject == null)
|
||||
{
|
||||
_state = Status.NotInit;
|
||||
return;
|
||||
}
|
||||
_state = Status.InProgress;
|
||||
_moveableObject = moveableObject;
|
||||
FieldWidth = width;
|
||||
FieldHeight = height;
|
||||
}
|
||||
|
||||
// сделать шаг
|
||||
public void MakeStep()
|
||||
{
|
||||
if (_state != Status.InProgress)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (IsTargetDestination())
|
||||
{
|
||||
_state = Status.Finish;
|
||||
return;
|
||||
}
|
||||
MoveToTarget();
|
||||
}
|
||||
|
||||
// перемещения
|
||||
protected boolean MoveLeft() { return MoveTo(Direction.Left); }
|
||||
protected boolean MoveRight() { return MoveTo(Direction.Right); }
|
||||
protected boolean MoveUp() { return MoveTo(Direction.Up); }
|
||||
protected boolean MoveDown() { return MoveTo(Direction.Down); }
|
||||
|
||||
// параметры
|
||||
protected ObjectParameters GetObjectParameters() { return _moveableObject.GetObjectPosition(); }
|
||||
// шаг
|
||||
protected int GetStep()
|
||||
{
|
||||
if (_state != Status.InProgress)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
return _moveableObject.GetStep();
|
||||
}
|
||||
// перемещение
|
||||
protected abstract void MoveToTarget();
|
||||
|
||||
// достигнута ли цель
|
||||
protected abstract boolean IsTargetDestination();
|
||||
|
||||
// попытка перемещения по направлению
|
||||
private boolean MoveTo(Direction directionType)
|
||||
{
|
||||
if (_state != Status.InProgress)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (_moveableObject.CheckCanMove(directionType))
|
||||
{
|
||||
_moveableObject.MoveObject(directionType);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
24
src/MovementStrategy/DrawningObjectAirbus.java
Normal file
24
src/MovementStrategy/DrawningObjectAirbus.java
Normal file
@ -0,0 +1,24 @@
|
||||
package MovementStrategy;
|
||||
import Drawnings.*;
|
||||
|
||||
public class DrawningObjectAirbus implements IMoveableObject {
|
||||
private DrawningAirbus _drawningAirbus = null;
|
||||
|
||||
public DrawningObjectAirbus(DrawningAirbus drawningAirbus)
|
||||
{
|
||||
_drawningAirbus = drawningAirbus;
|
||||
}
|
||||
|
||||
public ObjectParameters GetObjectPosition()
|
||||
{
|
||||
if (_drawningAirbus == null || _drawningAirbus.entityAirbus == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new ObjectParameters(_drawningAirbus.GetPosX(), _drawningAirbus.GetPosY(), _drawningAirbus.GetWidth(), _drawningAirbus.GetHeight());
|
||||
}
|
||||
|
||||
public int GetStep() { return (int)_drawningAirbus.entityAirbus.Step; }
|
||||
public boolean CheckCanMove(Direction direction) { return _drawningAirbus.CanMove(direction); }
|
||||
public void MoveObject(Direction direction) { _drawningAirbus.MoveTransport(direction); }
|
||||
}
|
8
src/MovementStrategy/IMoveableObject.java
Normal file
8
src/MovementStrategy/IMoveableObject.java
Normal file
@ -0,0 +1,8 @@
|
||||
package MovementStrategy;
|
||||
|
||||
public interface IMoveableObject {
|
||||
ObjectParameters GetObjectPosition();
|
||||
int GetStep();
|
||||
boolean CheckCanMove(Direction direction);
|
||||
void MoveObject(Direction direction);
|
||||
}
|
53
src/MovementStrategy/MoveToBorder.java
Normal file
53
src/MovementStrategy/MoveToBorder.java
Normal file
@ -0,0 +1,53 @@
|
||||
package MovementStrategy;
|
||||
|
||||
public class MoveToBorder extends AbstractStrategy {
|
||||
@Override
|
||||
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;
|
||||
}
|
||||
|
||||
// движение к цели
|
||||
@Override
|
||||
protected void MoveToTarget()
|
||||
{
|
||||
var objParams = GetObjectParameters();
|
||||
if (objParams == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var diffX = FieldWidth;
|
||||
if (Math.abs(diffX) > GetStep())
|
||||
{
|
||||
if (diffX < 0)
|
||||
{
|
||||
MoveLeft();
|
||||
}
|
||||
else
|
||||
{
|
||||
MoveRight();
|
||||
}
|
||||
}
|
||||
|
||||
var diffY = FieldHeight;
|
||||
if (Math.abs(diffY) > GetStep())
|
||||
{
|
||||
if (diffY < 0)
|
||||
{
|
||||
MoveUp();
|
||||
}
|
||||
else
|
||||
{
|
||||
MoveDown();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
53
src/MovementStrategy/MoveToCenter.java
Normal file
53
src/MovementStrategy/MoveToCenter.java
Normal file
@ -0,0 +1,53 @@
|
||||
package MovementStrategy;
|
||||
|
||||
public class MoveToCenter extends AbstractStrategy {
|
||||
@Override
|
||||
protected boolean IsTargetDestination()
|
||||
{
|
||||
var objParams = GetObjectParameters();
|
||||
if (objParams == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return objParams.ObjectMiddleHorizontal() <= FieldWidth / 2 &&
|
||||
objParams.ObjectMiddleHorizontal() + GetStep() >= FieldWidth / 2 &&
|
||||
objParams.ObjectMiddleVertical() <= FieldHeight / 2 &&
|
||||
objParams.ObjectMiddleVertical() + GetStep() >= FieldHeight / 2;
|
||||
}
|
||||
|
||||
// движение к цели
|
||||
@Override
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
25
src/MovementStrategy/ObjectParameters.java
Normal file
25
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;
|
||||
}
|
||||
}
|
7
src/MovementStrategy/Status.java
Normal file
7
src/MovementStrategy/Status.java
Normal file
@ -0,0 +1,7 @@
|
||||
package MovementStrategy;
|
||||
|
||||
public enum Status {
|
||||
NotInit,
|
||||
InProgress,
|
||||
Finish
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user