лаба 2, готовая
This commit is contained in:
parent
89e34392e0
commit
aef1bb171a
124
.idea/uiDesigner.xml
Normal file
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>
|
@ -4,24 +4,45 @@
|
|||||||
<option name="autoReloadType" value="SELECTIVE" />
|
<option name="autoReloadType" value="SELECTIVE" />
|
||||||
</component>
|
</component>
|
||||||
<component name="ChangeListManager">
|
<component name="ChangeListManager">
|
||||||
<list default="true" id="d76a7414-ef61-4559-85d8-aee9cbb6c975" name="Changes" comment="Создание проекта">
|
<list default="true" id="d76a7414-ef61-4559-85d8-aee9cbb6c975" name="Changes" comment="лаба 1, готовая">
|
||||||
<change afterPath="$PROJECT_DIR$/src/DirectionType.java" afterDir="false" />
|
<change afterPath="$PROJECT_DIR$/.idea/uiDesigner.xml" afterDir="false" />
|
||||||
<change afterPath="$PROJECT_DIR$/src/DrawningAirplaneWithRadar.java" afterDir="false" />
|
<change afterPath="$PROJECT_DIR$/src/DrawningObjects/DrawningAirplaneWithRadar.java" afterDir="false" />
|
||||||
<change afterPath="$PROJECT_DIR$/src/DrawningIlluminators.java" afterDir="false" />
|
<change afterPath="$PROJECT_DIR$/src/DrawningObjects/DrawningIlluminatorsCirc.java" afterDir="false" />
|
||||||
<change afterPath="$PROJECT_DIR$/src/EntityAirplaneWithRadar.java" afterDir="false" />
|
<change afterPath="$PROJECT_DIR$/src/DrawningObjects/DrawningIlluminatorsQuad.java" afterDir="false" />
|
||||||
<change afterPath="$PROJECT_DIR$/src/NumberType.java" afterDir="false" />
|
<change afterPath="$PROJECT_DIR$/src/DrawningObjects/IDraw.java" afterDir="false" />
|
||||||
<change afterPath="$PROJECT_DIR$/src/images/down-arrow.png" afterDir="false" />
|
<change afterPath="$PROJECT_DIR$/src/Entities/EntityAirplane.java" afterDir="false" />
|
||||||
<change afterPath="$PROJECT_DIR$/src/images/left-arrow.png" afterDir="false" />
|
<change afterPath="$PROJECT_DIR$/src/Entities/EntityAirplaneWithRadar.java" afterDir="false" />
|
||||||
<change afterPath="$PROJECT_DIR$/src/images/right-arrow.png" afterDir="false" />
|
<change afterPath="$PROJECT_DIR$/src/FormAirplaneWithRadar.java" afterDir="false" />
|
||||||
<change afterPath="$PROJECT_DIR$/src/images/upper-arrow.png" afterDir="false" />
|
<change afterPath="$PROJECT_DIR$/src/MovementStrategy/AbstractStrategy.java" afterDir="false" />
|
||||||
|
<change afterPath="$PROJECT_DIR$/src/MovementStrategy/DrawningObjectAirplane.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$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
||||||
|
<change beforePath="$PROJECT_DIR$/src/DirectionType.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/DirectionType.java" afterDir="false" />
|
||||||
|
<change beforePath="$PROJECT_DIR$/src/DrawningAirplaneWithRadar.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/DrawningObjects/DrawningAirplane.java" afterDir="false" />
|
||||||
|
<change beforePath="$PROJECT_DIR$/src/DrawningIlluminators.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/DrawningObjects/DrawningIlluminators.java" afterDir="false" />
|
||||||
|
<change beforePath="$PROJECT_DIR$/src/EntityAirplaneWithRadar.java" beforeDir="false" />
|
||||||
<change beforePath="$PROJECT_DIR$/src/Main.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/Main.java" afterDir="false" />
|
<change beforePath="$PROJECT_DIR$/src/Main.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/Main.java" afterDir="false" />
|
||||||
|
<change beforePath="$PROJECT_DIR$/src/NumberType.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/NumberType.java" afterDir="false" />
|
||||||
</list>
|
</list>
|
||||||
<option name="SHOW_DIALOG" value="false" />
|
<option name="SHOW_DIALOG" value="false" />
|
||||||
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
||||||
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
|
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
|
||||||
<option name="LAST_RESOLUTION" value="IGNORE" />
|
<option name="LAST_RESOLUTION" value="IGNORE" />
|
||||||
</component>
|
</component>
|
||||||
|
<component name="CodeInsightWorkspaceSettings">
|
||||||
|
<option name="optimizeImportsOnTheFly" value="true" />
|
||||||
|
</component>
|
||||||
|
<component name="FileTemplateManagerImpl">
|
||||||
|
<option name="RECENT_TEMPLATES">
|
||||||
|
<list>
|
||||||
|
<option value="Class" />
|
||||||
|
</list>
|
||||||
|
</option>
|
||||||
|
</component>
|
||||||
<component name="Git.Settings">
|
<component name="Git.Settings">
|
||||||
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
|
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
|
||||||
</component>
|
</component>
|
||||||
@ -29,7 +50,9 @@
|
|||||||
<option name="stateVersion" value="1" />
|
<option name="stateVersion" value="1" />
|
||||||
</component>
|
</component>
|
||||||
<component name="ProjectId" id="2Zzag09YMkXgcrrL97rYHmYPGZX" />
|
<component name="ProjectId" id="2Zzag09YMkXgcrrL97rYHmYPGZX" />
|
||||||
<component name="ProjectLevelVcsManager" settingsEditedManually="true" />
|
<component name="ProjectLevelVcsManager" settingsEditedManually="true">
|
||||||
|
<ConfirmationsSetting value="2" id="Add" />
|
||||||
|
</component>
|
||||||
<component name="ProjectViewState">
|
<component name="ProjectViewState">
|
||||||
<option name="hideEmptyMiddlePackages" value="true" />
|
<option name="hideEmptyMiddlePackages" value="true" />
|
||||||
<option name="showLibraryContents" value="true" />
|
<option name="showLibraryContents" value="true" />
|
||||||
@ -38,12 +61,14 @@
|
|||||||
"keyToString": {
|
"keyToString": {
|
||||||
"RunOnceActivity.OpenProjectViewOnStart": "true",
|
"RunOnceActivity.OpenProjectViewOnStart": "true",
|
||||||
"RunOnceActivity.ShowReadmeOnStart": "true",
|
"RunOnceActivity.ShowReadmeOnStart": "true",
|
||||||
|
"SHARE_PROJECT_CONFIGURATION_FILES": "true",
|
||||||
"last_opened_file_path": "D:/Проекты Idea/ProjectAirplaneWithRadar_HARD/src"
|
"last_opened_file_path": "D:/Проекты Idea/ProjectAirplaneWithRadar_HARD/src"
|
||||||
}
|
}
|
||||||
}]]></component>
|
}]]></component>
|
||||||
<component name="RecentsManager">
|
<component name="RecentsManager">
|
||||||
<key name="CopyFile.RECENT_KEYS">
|
<key name="CopyFile.RECENT_KEYS">
|
||||||
<recent name="D:\Проекты Idea\ProjectAirplaneWithRadar_HARD\src" />
|
<recent name="D:\Проекты Idea\ProjectAirplaneWithRadar_HARD\src" />
|
||||||
|
<recent name="D:\Проекты Idea\ProjectAirplaneWithRadar_HARD\src\DrawningObjects" />
|
||||||
<recent name="D:\Проекты Idea\ProjectAirplaneWithRadar_HARD\src\images" />
|
<recent name="D:\Проекты Idea\ProjectAirplaneWithRadar_HARD\src\images" />
|
||||||
</key>
|
</key>
|
||||||
</component>
|
</component>
|
||||||
@ -63,11 +88,19 @@
|
|||||||
<option name="project" value="LOCAL" />
|
<option name="project" value="LOCAL" />
|
||||||
<updated>1703427528828</updated>
|
<updated>1703427528828</updated>
|
||||||
</task>
|
</task>
|
||||||
<option name="localTasksCounter" value="2" />
|
<task id="LOCAL-00002" summary="лаба 1, готовая">
|
||||||
|
<created>1703428105944</created>
|
||||||
|
<option name="number" value="00002" />
|
||||||
|
<option name="presentableId" value="LOCAL-00002" />
|
||||||
|
<option name="project" value="LOCAL" />
|
||||||
|
<updated>1703428105944</updated>
|
||||||
|
</task>
|
||||||
|
<option name="localTasksCounter" value="3" />
|
||||||
<servers />
|
<servers />
|
||||||
</component>
|
</component>
|
||||||
<component name="VcsManagerConfiguration">
|
<component name="VcsManagerConfiguration">
|
||||||
<MESSAGE value="Создание проекта" />
|
<MESSAGE value="Создание проекта" />
|
||||||
<option name="LAST_COMMIT_MESSAGE" value="Создание проекта" />
|
<MESSAGE value="лаба 1, готовая" />
|
||||||
|
<option name="LAST_COMMIT_MESSAGE" value="лаба 1, готовая" />
|
||||||
</component>
|
</component>
|
||||||
</project>
|
</project>
|
@ -1,3 +1,4 @@
|
|||||||
|
package src;
|
||||||
public enum DirectionType {
|
public enum DirectionType {
|
||||||
Up,
|
Up,
|
||||||
Down,
|
Down,
|
||||||
|
@ -1,92 +1,146 @@
|
|||||||
import javax.swing.*;
|
package DrawningObjects;
|
||||||
|
|
||||||
|
import Entities.EntityAirplane;
|
||||||
|
import src.DirectionType;
|
||||||
|
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
public class DrawningAirplaneWithRadar {
|
public class DrawningAirplane {
|
||||||
JPanel AirplaneWithRadarPanel;
|
protected EntityAirplane EntityAirplane;
|
||||||
private EntityAirplaneWithRadar EntityAirplaneWithRadar;
|
|
||||||
private int _pictureWidth;
|
private int _pictureWidth;
|
||||||
private int _pictureHeight;
|
private int _pictureHeight;
|
||||||
private int _startPosX = 0;
|
protected int _startPosX;
|
||||||
private int _startPosY = 0;
|
protected int _startPosY;
|
||||||
private int _airplaneWidth = 200;
|
protected IDraw DrawningIlluminators;
|
||||||
private int _airplaneHeight = 85;
|
private int _airplaneWidth = 190;
|
||||||
private DrawningIlluminators DrawningIlluminators;
|
private int _airplaneHeight = 80;
|
||||||
public EntityAirplaneWithRadar EntityAirplaneWithRadar(){
|
public EntityAirplane EntityAirplane(){
|
||||||
return EntityAirplaneWithRadar;
|
return EntityAirplane;
|
||||||
}
|
}
|
||||||
public boolean Init(int speed, double weight, Color bodyColor, Color illuminatorColor, Color additionalColor, int illuminatorNumb,
|
public DrawningAirplane(int speed, double weight, Color bodyColor, int width, int height){
|
||||||
int width, int height, boolean radar, boolean tank, JPanel airplaneWithRadarPanel){
|
|
||||||
if(width <= _airplaneWidth || height <= _airplaneHeight)
|
if(width <= _airplaneWidth || height <= _airplaneHeight)
|
||||||
return false;
|
return;
|
||||||
_startPosY=0;
|
_startPosY=0;
|
||||||
_startPosX = 0;
|
_startPosX = 0;
|
||||||
airplaneWithRadarPanel.setSize(width, height);
|
|
||||||
AirplaneWithRadarPanel = airplaneWithRadarPanel;
|
|
||||||
airplaneWithRadarPanel.paint(AirplaneWithRadarPanel.getGraphics());
|
|
||||||
_pictureWidth = width;
|
_pictureWidth = width;
|
||||||
_pictureHeight = height;
|
_pictureHeight = height;
|
||||||
EntityAirplaneWithRadar = new EntityAirplaneWithRadar();
|
EntityAirplane = new EntityAirplane(speed, weight, bodyColor);
|
||||||
EntityAirplaneWithRadar.Init(speed, weight, bodyColor, illuminatorColor, additionalColor, illuminatorNumb, radar, tank);
|
DrawningIlluminators = new DrawningIlluminators(_airplaneWidth, _airplaneHeight,_startPosX,_startPosY);
|
||||||
DrawningIlluminators = new DrawningIlluminators();
|
|
||||||
DrawningIlluminators.Init(_airplaneWidth, _airplaneHeight,_startPosX,_startPosY,illuminatorColor,airplaneWithRadarPanel);
|
|
||||||
Random rand = new Random();
|
Random rand = new Random();
|
||||||
|
int variant = rand.nextInt(0,3);
|
||||||
|
if(variant ==0){
|
||||||
|
DrawningIlluminators = new DrawningIlluminators(_airplaneWidth, _airplaneHeight,_startPosX,_startPosY);
|
||||||
|
} else{
|
||||||
|
if(variant ==1){
|
||||||
|
DrawningIlluminators = new DrawningIlluminatorsQuad(_airplaneWidth, _airplaneHeight,_startPosX,_startPosY);
|
||||||
|
}
|
||||||
|
else if(variant==2){
|
||||||
|
DrawningIlluminators = new DrawningIlluminatorsCirc(_airplaneWidth, _airplaneHeight,_startPosX,_startPosY);
|
||||||
|
}}
|
||||||
|
DrawningIlluminators.ChangeIlluminatorNumb(rand.nextInt(1, 5));
|
||||||
|
}
|
||||||
|
protected DrawningAirplane(int speed, double weight, Color bodyColor, int width, int height,int airplaneWidth, int airplaneHeight){
|
||||||
|
if(width <= _airplaneWidth || height <= _airplaneHeight)
|
||||||
|
return;
|
||||||
|
_startPosY=0;
|
||||||
|
_startPosX = 0;
|
||||||
|
_pictureWidth = width;
|
||||||
|
_pictureHeight = height;
|
||||||
|
_airplaneWidth = airplaneWidth;
|
||||||
|
_airplaneHeight = airplaneHeight;
|
||||||
|
EntityAirplane = new EntityAirplane(speed, weight, bodyColor);
|
||||||
|
DrawningIlluminators = new DrawningIlluminators(_airplaneWidth, _airplaneHeight,_startPosX,_startPosY);
|
||||||
|
Random rand = new Random();
|
||||||
|
int variant = rand.nextInt(0,3);
|
||||||
|
if(variant ==0){
|
||||||
|
DrawningIlluminators = new DrawningIlluminators(_airplaneWidth, _airplaneHeight,_startPosX,_startPosY);
|
||||||
|
} else{
|
||||||
|
if(variant ==1){
|
||||||
|
DrawningIlluminators = new DrawningIlluminatorsQuad(_airplaneWidth, _airplaneHeight,_startPosX,_startPosY);
|
||||||
|
} else if(variant==2){
|
||||||
|
DrawningIlluminators = new DrawningIlluminatorsCirc(_airplaneWidth, _airplaneHeight,_startPosX,_startPosY);
|
||||||
|
}
|
||||||
|
}
|
||||||
DrawningIlluminators.ChangeIlluminatorNumb(rand.nextInt(1, 5));
|
DrawningIlluminators.ChangeIlluminatorNumb(rand.nextInt(1, 5));
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
public void SetPosition(int x, int y){
|
public void SetPosition(int x, int y){
|
||||||
|
if(EntityAirplane == null)
|
||||||
|
return;
|
||||||
|
_startPosX = x;
|
||||||
|
_startPosY = y;
|
||||||
if (x < 0 || y < 0 || x + _airplaneWidth >= _pictureWidth || y + _airplaneHeight >= _pictureHeight)
|
if (x < 0 || y < 0 || x + _airplaneWidth >= _pictureWidth || y + _airplaneHeight >= _pictureHeight)
|
||||||
{
|
{
|
||||||
x = y = 10;
|
x = y = 10;
|
||||||
_startPosX = x;
|
_startPosX = x;
|
||||||
_startPosY = y;
|
_startPosY = y;
|
||||||
}
|
}
|
||||||
_startPosX = x;
|
|
||||||
_startPosY = y;
|
|
||||||
DrawningIlluminators.CurX = _startPosX;
|
|
||||||
DrawningIlluminators.CurY = _startPosY;
|
|
||||||
}
|
}
|
||||||
public void MoveTransport(DirectionType direction){
|
public int GetPosX(){return _startPosX;}
|
||||||
if (EntityAirplaneWithRadar == null)
|
public int GetPosY(){return _startPosY;}
|
||||||
return;
|
public int GetWidth(){return _airplaneWidth;}
|
||||||
AirplaneWithRadarPanel.paint(AirplaneWithRadarPanel.getGraphics());
|
public int GetHeight(){return _airplaneHeight;}
|
||||||
|
public boolean CanMove(DirectionType direction)
|
||||||
|
{
|
||||||
|
if (EntityAirplane == null)
|
||||||
|
return false;
|
||||||
|
boolean can = false;
|
||||||
switch (direction)
|
switch (direction)
|
||||||
{
|
{
|
||||||
case Left:
|
case Left:
|
||||||
if (_startPosX - EntityAirplaneWithRadar.Step() >= 0)
|
can = _startPosX - EntityAirplane.Step() >= 0;
|
||||||
_startPosX -= (int)EntityAirplaneWithRadar.Step();
|
break;
|
||||||
|
case Right:
|
||||||
|
can = _startPosX + EntityAirplane.Step() + _airplaneWidth< _pictureWidth;
|
||||||
|
break;
|
||||||
|
case Down:
|
||||||
|
can = _startPosY + EntityAirplane.Step() + _airplaneHeight < _pictureHeight;
|
||||||
|
break;
|
||||||
|
case Up:
|
||||||
|
can = _startPosY - EntityAirplane.Step() >= 0;
|
||||||
|
break;
|
||||||
|
};
|
||||||
|
return can;
|
||||||
|
}
|
||||||
|
public void MoveTransport(DirectionType direction){
|
||||||
|
if (!CanMove(direction) || EntityAirplane == null)
|
||||||
|
return;
|
||||||
|
switch (direction)
|
||||||
|
{
|
||||||
|
case Left:
|
||||||
|
if (_startPosX - EntityAirplane.Step() >= 0)
|
||||||
|
_startPosX -= (int)EntityAirplane.Step();
|
||||||
else
|
else
|
||||||
_startPosX = 0;
|
_startPosX = 0;
|
||||||
break;
|
break;
|
||||||
case Up:
|
case Up:
|
||||||
if (_startPosY - EntityAirplaneWithRadar.Step() >= 0)
|
if (_startPosY - EntityAirplane.Step() >= 0)
|
||||||
_startPosY -= (int)EntityAirplaneWithRadar.Step();
|
_startPosY -= (int)EntityAirplane.Step();
|
||||||
else
|
else
|
||||||
_startPosY = 0;
|
_startPosY = 0;
|
||||||
break;
|
break;
|
||||||
case Right:
|
case Right:
|
||||||
if (_startPosX + EntityAirplaneWithRadar.Step() + _airplaneWidth < _pictureWidth)
|
if (_startPosX + EntityAirplane.Step() + _airplaneWidth < _pictureWidth)
|
||||||
_startPosX += (int)EntityAirplaneWithRadar.Step();
|
_startPosX += (int)EntityAirplane.Step();
|
||||||
else
|
else
|
||||||
_startPosX = _pictureWidth - _airplaneWidth;
|
_startPosX = _pictureWidth - _airplaneWidth;
|
||||||
break;
|
break;
|
||||||
case Down:
|
case Down:
|
||||||
if (_startPosY + EntityAirplaneWithRadar.Step() + _airplaneHeight < _pictureHeight)
|
if (_startPosY + EntityAirplane.Step() + _airplaneHeight < _pictureHeight)
|
||||||
_startPosY += (int)EntityAirplaneWithRadar.Step();
|
_startPosY += (int)EntityAirplane.Step();
|
||||||
else
|
else
|
||||||
_startPosY = _pictureHeight - _airplaneHeight;
|
_startPosY = _pictureHeight - _airplaneHeight;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
DrawningIlluminators.CurX = _startPosX;
|
DrawningIlluminators.ChangeX(_startPosX);
|
||||||
DrawningIlluminators.CurY = _startPosY;
|
DrawningIlluminators.ChangeY(_startPosY);
|
||||||
}
|
}
|
||||||
public void DrawAirplaneWithRadar(){
|
public void DrawAirplane(Graphics2D g2d){
|
||||||
Graphics2D g2d = (Graphics2D)AirplaneWithRadarPanel.getGraphics();
|
if (EntityAirplane == null)
|
||||||
if (EntityAirplaneWithRadar == null)
|
|
||||||
return;
|
return;
|
||||||
g2d.setColor(Color.BLACK);
|
g2d.setColor(Color.BLACK);
|
||||||
g2d.setStroke(new BasicStroke(1));
|
g2d.setStroke(new BasicStroke(1));
|
||||||
//фюззеляж
|
//фюззеляж
|
||||||
g2d.setColor(EntityAirplaneWithRadar.BodyColor());
|
g2d.setColor(EntityAirplane.BodyColor());
|
||||||
g2d.fillRect(_startPosX + 4, _startPosY + 40, 150, 30);
|
g2d.fillRect(_startPosX + 4, _startPosY + 40, 150, 30);
|
||||||
g2d.setColor(Color.BLACK);
|
g2d.setColor(Color.BLACK);
|
||||||
g2d.drawRect(_startPosX + 4, _startPosY + 40, 150, 30);
|
g2d.drawRect(_startPosX + 4, _startPosY + 40, 150, 30);
|
||||||
@ -104,7 +158,7 @@ public class DrawningAirplaneWithRadar {
|
|||||||
_startPosY + 40,
|
_startPosY + 40,
|
||||||
};
|
};
|
||||||
// киль
|
// киль
|
||||||
g2d.setColor(EntityAirplaneWithRadar.AdditionalColor());
|
g2d.setColor(EntityAirplane.BodyColor());
|
||||||
g2d.fillPolygon(curvePointsX, curvePointsY, curvePointsY.length);
|
g2d.fillPolygon(curvePointsX, curvePointsY, curvePointsY.length);
|
||||||
g2d.setColor(Color.BLACK);
|
g2d.setColor(Color.BLACK);
|
||||||
g2d.drawPolygon(curvePointsX, curvePointsY, curvePointsY.length);
|
g2d.drawPolygon(curvePointsX, curvePointsY, curvePointsY.length);
|
||||||
@ -125,7 +179,7 @@ public class DrawningAirplaneWithRadar {
|
|||||||
g2d.fillRect(_startPosX + 138, _startPosY + 80, 5, 5);
|
g2d.fillRect(_startPosX + 138, _startPosY + 80, 5, 5);
|
||||||
|
|
||||||
// кабина
|
// кабина
|
||||||
g2d.setColor(EntityAirplaneWithRadar.AdditionalColor());
|
g2d.setColor(EntityAirplane.BodyColor());
|
||||||
int[] curvePoints2X =
|
int[] curvePoints2X =
|
||||||
{
|
{
|
||||||
_startPosX + 150,
|
_startPosX + 150,
|
||||||
@ -160,41 +214,6 @@ public class DrawningAirplaneWithRadar {
|
|||||||
g2d.drawLine(_startPosX + 190, _startPosY + 55, _startPosX + 150, _startPosY + 55);
|
g2d.drawLine(_startPosX + 190, _startPosY + 55, _startPosX + 150, _startPosY + 55);
|
||||||
g2d.drawLine(_startPosX + 150, _startPosY + 72,_startPosX + 150, _startPosY + 55);
|
g2d.drawLine(_startPosX + 150, _startPosY + 72,_startPosX + 150, _startPosY + 55);
|
||||||
g2d.drawLine(_startPosX + 150, _startPosY + 72,_startPosX + 190, _startPosY + 55);
|
g2d.drawLine(_startPosX + 150, _startPosY + 72,_startPosX + 190, _startPosY + 55);
|
||||||
|
DrawningIlluminators.DrawIlluminators(g2d);
|
||||||
// радар
|
|
||||||
if (EntityAirplaneWithRadar.Radar())
|
|
||||||
{
|
|
||||||
g2d.setColor(EntityAirplaneWithRadar.AdditionalColor());
|
|
||||||
g2d.fillOval(_startPosX + 65, _startPosY + 25, 50, 10);
|
|
||||||
g2d.drawOval(_startPosX + 65, _startPosY + 25, 50, 10);
|
|
||||||
g2d.fillRect(_startPosX + 85, _startPosY + 35, 10, 5);
|
|
||||||
g2d.drawRect(_startPosX + 85, _startPosY + 35, 10, 5);
|
|
||||||
}
|
|
||||||
// бак
|
|
||||||
if (EntityAirplaneWithRadar.Tank())
|
|
||||||
{
|
|
||||||
g2d.fillRect(_startPosX + 70, _startPosY + 65, 45, 15);
|
|
||||||
int[] curvePoints4X =
|
|
||||||
{
|
|
||||||
_startPosX + 70,
|
|
||||||
_startPosX + 60,
|
|
||||||
_startPosX + 70,
|
|
||||||
};
|
|
||||||
int[] curvePoints4Y =
|
|
||||||
{
|
|
||||||
_startPosY + 65,
|
|
||||||
_startPosY + 72,
|
|
||||||
_startPosY + 80,
|
|
||||||
};
|
|
||||||
g2d.fillPolygon(curvePoints4X, curvePoints4Y, curvePoints4Y.length);
|
|
||||||
int[] curvePoints5X =
|
|
||||||
{
|
|
||||||
_startPosX + 115,
|
|
||||||
_startPosX + 125,
|
|
||||||
_startPosX + 115,
|
|
||||||
};
|
|
||||||
g2d.fillPolygon(curvePoints5X, curvePoints4Y, curvePoints4Y.length);
|
|
||||||
}
|
|
||||||
DrawningIlluminators.DrawIlluminators();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
55
src/DrawningObjects/DrawningAirplaneWithRadar.java
Normal file
55
src/DrawningObjects/DrawningAirplaneWithRadar.java
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
package DrawningObjects;
|
||||||
|
|
||||||
|
import Entities.EntityAirplaneWithRadar;
|
||||||
|
|
||||||
|
import java.awt.*;
|
||||||
|
|
||||||
|
public class DrawningAirplaneWithRadar extends DrawningAirplane {
|
||||||
|
public DrawningAirplaneWithRadar(int speed, double weight, Color bodyColor, Color additionalColor,
|
||||||
|
boolean radar, boolean tank,int width,int height ){
|
||||||
|
super(speed,weight,bodyColor,width,height);
|
||||||
|
if(EntityAirplane!=null){
|
||||||
|
EntityAirplane = new EntityAirplaneWithRadar(speed, weight, bodyColor, additionalColor, radar,tank);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public void DrawAirplane(Graphics2D g2d) {
|
||||||
|
if (!(EntityAirplane instanceof EntityAirplaneWithRadar)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
super.DrawAirplane(g2d);
|
||||||
|
EntityAirplaneWithRadar _airplaneWithRadar = (EntityAirplaneWithRadar) EntityAirplane;
|
||||||
|
// радар
|
||||||
|
if (_airplaneWithRadar.Radar()) {
|
||||||
|
g2d.setColor(_airplaneWithRadar.AdditionalColor());
|
||||||
|
g2d.fillOval(_startPosX + 65, _startPosY + 25, 50, 10);
|
||||||
|
g2d.drawOval(_startPosX + 65, _startPosY + 25, 50, 10);
|
||||||
|
g2d.fillRect(_startPosX + 85, _startPosY + 35, 10, 5);
|
||||||
|
g2d.drawRect(_startPosX + 85, _startPosY + 35, 10, 5);
|
||||||
|
}
|
||||||
|
// бак
|
||||||
|
if (_airplaneWithRadar.Tank()) {
|
||||||
|
g2d.fillRect(_startPosX + 70, _startPosY + 65, 45, 15);
|
||||||
|
int[] curvePoints4X =
|
||||||
|
{
|
||||||
|
_startPosX + 70,
|
||||||
|
_startPosX + 60,
|
||||||
|
_startPosX + 70,
|
||||||
|
};
|
||||||
|
int[] curvePoints4Y =
|
||||||
|
{
|
||||||
|
_startPosY + 65,
|
||||||
|
_startPosY + 72,
|
||||||
|
_startPosY + 80,
|
||||||
|
};
|
||||||
|
g2d.fillPolygon(curvePoints4X, curvePoints4Y, curvePoints4Y.length);
|
||||||
|
int[] curvePoints5X =
|
||||||
|
{
|
||||||
|
_startPosX + 115,
|
||||||
|
_startPosX + 125,
|
||||||
|
_startPosX + 115,
|
||||||
|
};
|
||||||
|
g2d.fillPolygon(curvePoints5X, curvePoints4Y, curvePoints4Y.length);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,19 +1,22 @@
|
|||||||
import javax.swing.*;
|
package DrawningObjects;
|
||||||
|
import src.NumberType;
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
public class DrawningIlluminators {
|
public class DrawningIlluminators implements IDraw{
|
||||||
JPanel AirplaneWithRadarPanel;
|
|
||||||
private NumberType IlluminatorNumb;
|
private NumberType IlluminatorNumb;
|
||||||
private Color IlluminatorColor;
|
private Color IlluminatorColor;
|
||||||
private int Width, Height;
|
private int Width, Height;
|
||||||
public int CurX, CurY;
|
protected int CurX, CurY;
|
||||||
boolean Init(int width, int height, int curX, int curY, Color illuminatorColor, JPanel airplaneWithRadarPanel){
|
public DrawningIlluminators(int width, int height, int curX, int curY){
|
||||||
Width = width;
|
Width = width;
|
||||||
Height = height;
|
Height = height;
|
||||||
CurX = curX;
|
CurX = curX;
|
||||||
CurY = curY;
|
CurY = curY;
|
||||||
IlluminatorColor = illuminatorColor;
|
}
|
||||||
AirplaneWithRadarPanel = airplaneWithRadarPanel;
|
public void ChangeX(int x){
|
||||||
return true;
|
CurX = x;
|
||||||
|
}
|
||||||
|
public void ChangeY(int y){
|
||||||
|
CurY = y;
|
||||||
}
|
}
|
||||||
public void ChangeIlluminatorNumb(int x){
|
public void ChangeIlluminatorNumb(int x){
|
||||||
if(x <= 2)
|
if(x <= 2)
|
||||||
@ -26,9 +29,8 @@ public class DrawningIlluminators {
|
|||||||
public NumberType IlluminatorNumb(){
|
public NumberType IlluminatorNumb(){
|
||||||
return IlluminatorNumb;
|
return IlluminatorNumb;
|
||||||
}
|
}
|
||||||
public void DrawIlluminators(){
|
public void DrawIlluminators(Graphics2D g2d){
|
||||||
Graphics2D g2d = (Graphics2D)AirplaneWithRadarPanel.getGraphics();
|
g2d.setColor(Color.cyan);
|
||||||
g2d.setColor(IlluminatorColor);
|
|
||||||
int x = CurX;
|
int x = CurX;
|
||||||
int y = CurY;
|
int y = CurY;
|
||||||
for( int i =0; i<10;i++){
|
for( int i =0; i<10;i++){
|
61
src/DrawningObjects/DrawningIlluminatorsCirc.java
Normal file
61
src/DrawningObjects/DrawningIlluminatorsCirc.java
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
package DrawningObjects;
|
||||||
|
|
||||||
|
import src.NumberType;
|
||||||
|
|
||||||
|
import java.awt.*;
|
||||||
|
public class DrawningIlluminatorsCirc implements IDraw {
|
||||||
|
private NumberType IlluminatorNumb;
|
||||||
|
private Color IlluminatorColor;
|
||||||
|
private int Width, Height;
|
||||||
|
protected int CurX, CurY;
|
||||||
|
public DrawningIlluminatorsCirc(int width, int height, int curX, int curY){
|
||||||
|
Width = width;
|
||||||
|
Height = height;
|
||||||
|
CurX = curX;
|
||||||
|
CurY = curY;
|
||||||
|
}
|
||||||
|
public void ChangeX(int x){
|
||||||
|
CurX = x;
|
||||||
|
}
|
||||||
|
public void ChangeY(int y){
|
||||||
|
CurY = y;
|
||||||
|
}
|
||||||
|
public void ChangeIlluminatorNumb(int x){
|
||||||
|
if(x <= 2)
|
||||||
|
IlluminatorNumb = NumberType.Ten;
|
||||||
|
if(x == 3)
|
||||||
|
IlluminatorNumb = NumberType.Twenty;
|
||||||
|
if(x >= 4)
|
||||||
|
IlluminatorNumb = NumberType.Thirty;
|
||||||
|
}
|
||||||
|
public NumberType IlluminatorNumb(){
|
||||||
|
return IlluminatorNumb;
|
||||||
|
}
|
||||||
|
public void DrawIlluminators(Graphics2D g2d){
|
||||||
|
g2d.setColor(Color.BLUE);
|
||||||
|
int x = CurX;
|
||||||
|
int y = CurY;
|
||||||
|
for( int i =0; i<10;i++){
|
||||||
|
g2d.drawOval(x+53 , y+43 , 5, 5);
|
||||||
|
x+=7;
|
||||||
|
}
|
||||||
|
//20 иллюминаторов
|
||||||
|
if (IlluminatorNumb == NumberType.Twenty || IlluminatorNumb == NumberType.Thirty)
|
||||||
|
{
|
||||||
|
x = CurX;
|
||||||
|
for( int i =0; i<10;i++){
|
||||||
|
g2d.drawOval(x+53 , y+51 , 5, 5);
|
||||||
|
x+=7;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//30 иллюминаторов
|
||||||
|
if (IlluminatorNumb == NumberType.Thirty)
|
||||||
|
{
|
||||||
|
x = CurX;
|
||||||
|
for( int i =0; i<10;i++){
|
||||||
|
g2d.drawOval( x+53 , y+59 , 5, 5);
|
||||||
|
x+=7;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
60
src/DrawningObjects/DrawningIlluminatorsQuad.java
Normal file
60
src/DrawningObjects/DrawningIlluminatorsQuad.java
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
package DrawningObjects;
|
||||||
|
|
||||||
|
import src.NumberType;
|
||||||
|
|
||||||
|
import java.awt.*;
|
||||||
|
|
||||||
|
public class DrawningIlluminatorsQuad implements IDraw {
|
||||||
|
private NumberType IlluminatorNumb;
|
||||||
|
private Color IlluminatorColor;
|
||||||
|
private int Width, Height;
|
||||||
|
protected int CurX, CurY;
|
||||||
|
public DrawningIlluminatorsQuad(int width, int height, int curX, int curY){
|
||||||
|
Width = width;
|
||||||
|
Height = height;
|
||||||
|
CurX = curX;
|
||||||
|
CurY = curY;
|
||||||
|
}
|
||||||
|
public void ChangeIlluminatorNumb(int x){
|
||||||
|
if(x <= 2)
|
||||||
|
IlluminatorNumb = NumberType.Ten;
|
||||||
|
if(x == 3)
|
||||||
|
IlluminatorNumb = NumberType.Twenty;
|
||||||
|
if(x >= 4)
|
||||||
|
IlluminatorNumb = NumberType.Thirty;
|
||||||
|
}
|
||||||
|
public void ChangeX(int x){
|
||||||
|
CurX = x;
|
||||||
|
}
|
||||||
|
public void ChangeY(int y){
|
||||||
|
CurY = y;
|
||||||
|
}
|
||||||
|
public NumberType IlluminatorNumb(){
|
||||||
|
return IlluminatorNumb;
|
||||||
|
}
|
||||||
|
public void DrawIlluminators(Graphics2D g2d) {
|
||||||
|
g2d.setColor(Color.BLUE);
|
||||||
|
int x = CurX;
|
||||||
|
int y = CurY;
|
||||||
|
for (int i = 0; i < 10; i++) {
|
||||||
|
g2d.fillRect(x+53 , y+43 , 5, 5);
|
||||||
|
x += 7;
|
||||||
|
}
|
||||||
|
//20 иллюминаторов
|
||||||
|
if (IlluminatorNumb == NumberType.Twenty || IlluminatorNumb == NumberType.Thirty) {
|
||||||
|
x = CurX;
|
||||||
|
for (int i = 0; i < 10; i++) {
|
||||||
|
g2d.fillRect(x+53 , y+51 , 5, 5);
|
||||||
|
x += 7;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//30 иллюминаторов
|
||||||
|
if (IlluminatorNumb == NumberType.Thirty) {
|
||||||
|
x = CurX;
|
||||||
|
for (int i = 0; i < 10; i++) {
|
||||||
|
g2d.fillRect(x+53 , y+59 , 5, 5);
|
||||||
|
x += 7;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
10
src/DrawningObjects/IDraw.java
Normal file
10
src/DrawningObjects/IDraw.java
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
package DrawningObjects;
|
||||||
|
import java.awt.*;
|
||||||
|
public interface IDraw {
|
||||||
|
public void ChangeIlluminatorNumb(int x);
|
||||||
|
//public NumberType IlluminatorNumb();
|
||||||
|
public void DrawIlluminators(Graphics2D g2d);
|
||||||
|
//public void DrawIlluminatorsQuad(Graphics2D g2d);
|
||||||
|
public void ChangeX(int x);
|
||||||
|
public void ChangeY(int y);
|
||||||
|
}
|
26
src/Entities/EntityAirplane.java
Normal file
26
src/Entities/EntityAirplane.java
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
package Entities;
|
||||||
|
|
||||||
|
import java.awt.*;
|
||||||
|
public class EntityAirplane {
|
||||||
|
private int Speed;
|
||||||
|
private double Weight, Step;
|
||||||
|
private Color BodyColor;
|
||||||
|
public int Speed(){
|
||||||
|
return Speed;
|
||||||
|
}
|
||||||
|
public double Weight(){
|
||||||
|
return Weight;
|
||||||
|
}
|
||||||
|
public double Step(){
|
||||||
|
return Step;
|
||||||
|
}
|
||||||
|
public Color BodyColor(){
|
||||||
|
return BodyColor;
|
||||||
|
}
|
||||||
|
public EntityAirplane(int speed, double weight, Color bodyColor){
|
||||||
|
Speed = speed;
|
||||||
|
Weight = weight;
|
||||||
|
Step = (double)Speed * 100 / Weight;
|
||||||
|
BodyColor = bodyColor;
|
||||||
|
}
|
||||||
|
}
|
18
src/Entities/EntityAirplaneWithRadar.java
Normal file
18
src/Entities/EntityAirplaneWithRadar.java
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
package Entities;
|
||||||
|
import java.awt.*;
|
||||||
|
|
||||||
|
public class EntityAirplaneWithRadar extends EntityAirplane{
|
||||||
|
private Color AdditionalColor;
|
||||||
|
private boolean Radar;
|
||||||
|
private boolean Tank;
|
||||||
|
public Color AdditionalColor(){return AdditionalColor;}
|
||||||
|
public boolean Radar(){return Radar;}
|
||||||
|
public boolean Tank(){return Tank;}
|
||||||
|
public EntityAirplaneWithRadar(int speed, double weight, Color bodyColor, Color additionalColor,
|
||||||
|
boolean radar, boolean tank ){
|
||||||
|
super(speed, weight, bodyColor);
|
||||||
|
AdditionalColor=additionalColor;
|
||||||
|
Radar = radar;
|
||||||
|
Tank = tank;
|
||||||
|
}
|
||||||
|
}
|
@ -1,43 +0,0 @@
|
|||||||
import java.awt.*;
|
|
||||||
public class EntityAirplaneWithRadar {
|
|
||||||
private int Speed, IlluminatorNumb;
|
|
||||||
private double Weight, Step;
|
|
||||||
private Color BodyColor, AdditionalColor, IlluminatorColor;
|
|
||||||
private boolean Radar;
|
|
||||||
private boolean Tank;
|
|
||||||
public int Speed(){
|
|
||||||
return Speed;
|
|
||||||
}
|
|
||||||
public int IlluminatorNumb(){
|
|
||||||
return IlluminatorNumb;
|
|
||||||
}
|
|
||||||
public double Weight(){
|
|
||||||
return Weight;
|
|
||||||
}
|
|
||||||
public double Step(){
|
|
||||||
return Step;
|
|
||||||
}
|
|
||||||
public Color BodyColor(){
|
|
||||||
return BodyColor;
|
|
||||||
}
|
|
||||||
public Color AdditionalColor(){
|
|
||||||
return AdditionalColor;
|
|
||||||
}
|
|
||||||
public Color IlluminatorColor(){
|
|
||||||
return IlluminatorColor;
|
|
||||||
}
|
|
||||||
public boolean Radar(){return Radar;}
|
|
||||||
public boolean Tank(){return Tank;}
|
|
||||||
public void Init(int speed, double weight, Color bodyColor, Color illuminatorColor, Color additionalColor, int illuminatorNumb,
|
|
||||||
boolean radar, boolean tank ){
|
|
||||||
Speed = speed;
|
|
||||||
Weight = weight;
|
|
||||||
Step = (double)Speed * 100 / Weight;
|
|
||||||
BodyColor = bodyColor;
|
|
||||||
IlluminatorColor=illuminatorColor;
|
|
||||||
AdditionalColor = additionalColor;
|
|
||||||
IlluminatorNumb = illuminatorNumb;
|
|
||||||
Radar = radar;
|
|
||||||
Tank = tank;
|
|
||||||
}
|
|
||||||
}
|
|
191
src/FormAirplaneWithRadar.java
Normal file
191
src/FormAirplaneWithRadar.java
Normal file
@ -0,0 +1,191 @@
|
|||||||
|
import DrawningObjects.DrawningAirplane;
|
||||||
|
import src.DirectionType;
|
||||||
|
import MovementStrategy.*;
|
||||||
|
import DrawningObjects.DrawningAirplaneWithRadar;
|
||||||
|
|
||||||
|
import javax.swing.*;
|
||||||
|
import java.awt.*;
|
||||||
|
import java.awt.event.ActionEvent;
|
||||||
|
import java.awt.event.ActionListener;
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
|
public class FormAirplaneWithRadar {
|
||||||
|
private DrawningAirplane DrawningAirplane;
|
||||||
|
private AbstractStrategy _abstractStrategy;
|
||||||
|
Canvas canv;
|
||||||
|
static int pictureBoxWidth = 882;
|
||||||
|
static int pictureBoxHeight = 453;
|
||||||
|
|
||||||
|
public void Draw(){
|
||||||
|
canv.repaint();
|
||||||
|
}
|
||||||
|
|
||||||
|
public FormAirplaneWithRadar(){
|
||||||
|
JFrame AirplaneFrame =new JFrame ();
|
||||||
|
JButton buttonCreate = new JButton("Создать");
|
||||||
|
JButton buttonCreateLocomotive = new JButton("Создать самолет с радаром");
|
||||||
|
JButton buttonStep = new JButton("Шаг");
|
||||||
|
JComboBox comboBoxStrategy = new JComboBox(
|
||||||
|
new String[]{
|
||||||
|
"Довести до центра",
|
||||||
|
"Довести до края",
|
||||||
|
});
|
||||||
|
JButton UpButton = new JButton();
|
||||||
|
UpButton.setIcon(new ImageIcon("src\\images\\upper-arrow.png"));
|
||||||
|
JButton DownButton = new JButton();
|
||||||
|
DownButton.setIcon(new ImageIcon("src\\images\\down-arrow.png"));
|
||||||
|
JButton LeftButton = new JButton();
|
||||||
|
LeftButton.setIcon(new ImageIcon("src\\images\\left-arrow.png"));
|
||||||
|
JButton RightButton = new JButton();
|
||||||
|
RightButton.setIcon(new ImageIcon("src\\images\\right-arrow.png"));
|
||||||
|
buttonStep.addActionListener(
|
||||||
|
new ActionListener() {
|
||||||
|
public void actionPerformed(ActionEvent e){
|
||||||
|
if (DrawningAirplane == 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
|
||||||
|
DrawningObjectAirplane(DrawningAirplane), pictureBoxWidth,
|
||||||
|
pictureBoxHeight);
|
||||||
|
comboBoxStrategy.setEnabled(false);
|
||||||
|
}
|
||||||
|
if (_abstractStrategy == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_abstractStrategy.MakeStep();
|
||||||
|
Draw();
|
||||||
|
if (_abstractStrategy.GetStatus() == Status.Finish)
|
||||||
|
{
|
||||||
|
comboBoxStrategy.setEnabled(true);
|
||||||
|
_abstractStrategy = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
buttonCreate.addActionListener(
|
||||||
|
new ActionListener() {
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
Random random = new Random();
|
||||||
|
DrawningAirplane = new DrawningAirplane(random.nextInt(100, 300), random.nextDouble(1000, 3000),
|
||||||
|
Color.getHSBColor(random.nextInt(0, 301), random.nextInt(0, 301), random.nextInt(0, 301)),
|
||||||
|
pictureBoxWidth, pictureBoxHeight);
|
||||||
|
canv.DrawningAirplane = DrawningAirplane;
|
||||||
|
comboBoxStrategy.enable(true);
|
||||||
|
Draw();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
buttonCreateLocomotive.addActionListener(
|
||||||
|
new ActionListener() {
|
||||||
|
public void actionPerformed(ActionEvent e){
|
||||||
|
Random random = new Random();
|
||||||
|
DrawningAirplane = new DrawningAirplaneWithRadar(random.nextInt(100, 300), random.nextDouble(1000, 3000),
|
||||||
|
Color.getHSBColor(random.nextInt(0, 301), random.nextInt(0, 301), random.nextInt(0, 301)),
|
||||||
|
Color.getHSBColor(random.nextInt(0, 301), random.nextInt(0, 301), random.nextInt(0, 301)),
|
||||||
|
random.nextBoolean(), random.nextBoolean(),
|
||||||
|
pictureBoxWidth, pictureBoxHeight);
|
||||||
|
canv.DrawningAirplane = DrawningAirplane;
|
||||||
|
comboBoxStrategy.enable(true);
|
||||||
|
Draw();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
RightButton.addActionListener(new ActionListener() {
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
if(DrawningAirplane.EntityAirplane() == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
DrawningAirplane.MoveTransport(DirectionType.Right);
|
||||||
|
Draw();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
LeftButton.addActionListener(new ActionListener() {
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
if(DrawningAirplane.EntityAirplane() == null)
|
||||||
|
return;
|
||||||
|
DrawningAirplane.MoveTransport(DirectionType.Left);
|
||||||
|
Draw();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
UpButton.addActionListener(new ActionListener() {
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
if(DrawningAirplane.EntityAirplane() == null)
|
||||||
|
return;
|
||||||
|
DrawningAirplane.MoveTransport(DirectionType.Up);
|
||||||
|
Draw();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
DownButton.addActionListener(new ActionListener() {
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
if(DrawningAirplane.EntityAirplane() == null)
|
||||||
|
return;
|
||||||
|
DrawningAirplane.MoveTransport(DirectionType.Down);
|
||||||
|
Draw();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
AirplaneFrame.setSize (900, 500);
|
||||||
|
AirplaneFrame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
|
||||||
|
AirplaneFrame.setLayout(null);
|
||||||
|
canv = new Canvas();
|
||||||
|
canv.setSize(pictureBoxWidth, pictureBoxHeight);
|
||||||
|
buttonCreate.setBounds(198, 401, 180, 40);
|
||||||
|
buttonCreateLocomotive.setBounds(12, 401, 180, 40);
|
||||||
|
RightButton.setBounds(840,411,30,30);
|
||||||
|
LeftButton.setBounds(768,411,30,30);
|
||||||
|
UpButton.setBounds(804,375,30,30);
|
||||||
|
DownButton.setBounds(804,411,30,30);
|
||||||
|
comboBoxStrategy.setBounds(719,12,151,28);
|
||||||
|
buttonStep.setBounds(768, 46, 94, 29);
|
||||||
|
AirplaneFrame.add(canv);
|
||||||
|
AirplaneFrame.add(buttonCreate);
|
||||||
|
AirplaneFrame.add(buttonCreateLocomotive);
|
||||||
|
AirplaneFrame.add(UpButton);
|
||||||
|
AirplaneFrame.add(DownButton);
|
||||||
|
AirplaneFrame.add(LeftButton);
|
||||||
|
AirplaneFrame.add(RightButton);
|
||||||
|
AirplaneFrame.add(comboBoxStrategy);
|
||||||
|
AirplaneFrame.add(buttonStep);
|
||||||
|
AirplaneFrame.setVisible(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
class Canvas extends JComponent{
|
||||||
|
public DrawningAirplane DrawningAirplane;
|
||||||
|
public Canvas(){
|
||||||
|
}
|
||||||
|
public void paintComponent (Graphics g){
|
||||||
|
if (DrawningAirplane == null){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
super.paintComponents (g) ;
|
||||||
|
Graphics2D g2d = (Graphics2D)g;
|
||||||
|
DrawningAirplane.DrawAirplane(g2d);
|
||||||
|
super.repaint();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,95 +1,7 @@
|
|||||||
import java.awt.*;
|
|
||||||
import java.awt.event.ActionEvent;
|
|
||||||
import java.awt.event.ActionListener;
|
|
||||||
import java.awt.image.BufferedImage;
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Random;
|
|
||||||
import javax.imageio.ImageIO;
|
|
||||||
import javax.swing.*;
|
|
||||||
public class Main {
|
public class Main {
|
||||||
public static void main(String[] args) throws IOException {
|
public static void main(String[] args) throws IOException {
|
||||||
JFrame AirplaneWithRadarFrame = new JFrame();
|
FormAirplaneWithRadar form = new FormAirplaneWithRadar();
|
||||||
JPanel AirplaneWithRadarPanel = new JPanel();
|
|
||||||
AirplaneWithRadarFrame.setLayout(new BorderLayout());
|
|
||||||
AirplaneWithRadarFrame.setSize(900, 500);
|
|
||||||
AirplaneWithRadarFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
|
||||||
AirplaneWithRadarFrame.setLayout(new BorderLayout(1,1));
|
|
||||||
AirplaneWithRadarFrame.setResizable(false);
|
|
||||||
DrawningAirplaneWithRadar DrawningEntityAirplaneWithRadar = new DrawningAirplaneWithRadar();
|
|
||||||
AirplaneWithRadarPanel.setLayout(null);
|
|
||||||
BufferedImage RightIcon = ImageIO.read(new File("src\\images\\right-arrow.png"));
|
|
||||||
BufferedImage LeftIcon = ImageIO.read(new File("src\\images\\left-arrow.png"));
|
|
||||||
BufferedImage UpIcon = ImageIO.read(new File("src\\images\\upper-arrow.png"));
|
|
||||||
BufferedImage DownIcon = ImageIO.read(new File("src\\images\\down-arrow.png"));
|
|
||||||
JButton RightButton = new JButton(new ImageIcon(RightIcon));
|
|
||||||
JButton LeftButton = new JButton(new ImageIcon(LeftIcon));
|
|
||||||
JButton UpButton = new JButton(new ImageIcon(UpIcon));
|
|
||||||
JButton DownButton = new JButton(new ImageIcon(DownIcon));
|
|
||||||
JButton CreateButton = new JButton();
|
|
||||||
CreateButton.setText("Создать");
|
|
||||||
CreateButton.setBounds(12, 401, 90, 40);
|
|
||||||
RightButton.setBounds(840,411,30,30);
|
|
||||||
LeftButton.setBounds(768,411,30,30);
|
|
||||||
UpButton.setBounds(804,375,30,30);
|
|
||||||
DownButton.setBounds(804,411,30,30);
|
|
||||||
AirplaneWithRadarPanel.add(CreateButton);
|
|
||||||
AirplaneWithRadarPanel.add(RightButton);
|
|
||||||
AirplaneWithRadarPanel.add(LeftButton);
|
|
||||||
AirplaneWithRadarPanel.add(UpButton);
|
|
||||||
AirplaneWithRadarPanel.add(DownButton);
|
|
||||||
AirplaneWithRadarFrame.add(AirplaneWithRadarPanel, BorderLayout.CENTER);
|
|
||||||
Random random = new Random();
|
|
||||||
CreateButton.addActionListener(new ActionListener() {
|
|
||||||
@Override
|
|
||||||
public void actionPerformed(ActionEvent e) {
|
|
||||||
DrawningEntityAirplaneWithRadar.Init(random.nextInt(100, 300), random.nextDouble(1000, 3000),
|
|
||||||
Color.getHSBColor(random.nextInt(0, 301), random.nextInt(0, 301), random.nextInt(0, 301)),
|
|
||||||
Color.getHSBColor(random.nextInt(0, 301), random.nextInt(0, 301), random.nextInt(0, 301)),
|
|
||||||
Color.getHSBColor(random.nextInt(0, 301), random.nextInt(0, 301), random.nextInt(0, 301)),
|
|
||||||
random.nextInt(1, 4)*10,
|
|
||||||
AirplaneWithRadarPanel.getWidth(), AirplaneWithRadarPanel.getHeight(), random.nextBoolean(), random.nextBoolean(), AirplaneWithRadarPanel);
|
|
||||||
|
|
||||||
DrawningEntityAirplaneWithRadar.SetPosition(random.nextInt(90) + 10, random.nextInt(90) + 10);
|
|
||||||
DrawningEntityAirplaneWithRadar.DrawAirplaneWithRadar();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
RightButton.addActionListener(new ActionListener() {
|
|
||||||
@Override
|
|
||||||
public void actionPerformed(ActionEvent e) {
|
|
||||||
if(DrawningEntityAirplaneWithRadar.EntityAirplaneWithRadar() == null)
|
|
||||||
return;
|
|
||||||
DrawningEntityAirplaneWithRadar.MoveTransport(DirectionType.Right);
|
|
||||||
DrawningEntityAirplaneWithRadar.DrawAirplaneWithRadar();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
LeftButton.addActionListener(new ActionListener() {
|
|
||||||
@Override
|
|
||||||
public void actionPerformed(ActionEvent e) {
|
|
||||||
if(DrawningEntityAirplaneWithRadar.EntityAirplaneWithRadar() == null)
|
|
||||||
return;
|
|
||||||
DrawningEntityAirplaneWithRadar.MoveTransport(DirectionType.Left);
|
|
||||||
DrawningEntityAirplaneWithRadar.DrawAirplaneWithRadar();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
UpButton.addActionListener(new ActionListener() {
|
|
||||||
@Override
|
|
||||||
public void actionPerformed(ActionEvent e) {
|
|
||||||
if(DrawningEntityAirplaneWithRadar.EntityAirplaneWithRadar() == null)
|
|
||||||
return;
|
|
||||||
DrawningEntityAirplaneWithRadar.MoveTransport(DirectionType.Up);
|
|
||||||
DrawningEntityAirplaneWithRadar.DrawAirplaneWithRadar();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
DownButton.addActionListener(new ActionListener() {
|
|
||||||
@Override
|
|
||||||
public void actionPerformed(ActionEvent e) {
|
|
||||||
if(DrawningEntityAirplaneWithRadar.EntityAirplaneWithRadar() == null)
|
|
||||||
return;
|
|
||||||
DrawningEntityAirplaneWithRadar.MoveTransport(DirectionType.Down);
|
|
||||||
DrawningEntityAirplaneWithRadar.DrawAirplaneWithRadar();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
AirplaneWithRadarFrame.setVisible(true);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
69
src/MovementStrategy/AbstractStrategy.java
Normal file
69
src/MovementStrategy/AbstractStrategy.java
Normal file
@ -0,0 +1,69 @@
|
|||||||
|
package MovementStrategy;
|
||||||
|
import src.DirectionType;
|
||||||
|
|
||||||
|
public abstract class AbstractStrategy {
|
||||||
|
private IMoveableObject _moveableObject;
|
||||||
|
private Status _state = Status.NotInit;
|
||||||
|
private int FieldWidth;
|
||||||
|
protected int FieldWidth(){return FieldWidth;}
|
||||||
|
private int FieldHeight;
|
||||||
|
protected int FieldHeight(){return 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(DirectionType.Left);}
|
||||||
|
protected boolean MoveRight() {return MoveTo(DirectionType.Right);}
|
||||||
|
protected boolean MoveUp() {return MoveTo(DirectionType.Up);}
|
||||||
|
protected boolean MoveDown() {return MoveTo(DirectionType.Down);}
|
||||||
|
protected ObjectParameters GetObjectParameters(){
|
||||||
|
if(_moveableObject != null)
|
||||||
|
return _moveableObject.GetObjectParameters();
|
||||||
|
else return null;
|
||||||
|
}
|
||||||
|
protected Integer GetStep()
|
||||||
|
{
|
||||||
|
if (_state != Status.InProgress)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return _moveableObject.GetStep();
|
||||||
|
}
|
||||||
|
protected abstract void MoveToTarget();
|
||||||
|
protected abstract boolean IsTargetDestination();
|
||||||
|
private boolean MoveTo(DirectionType directionType) {
|
||||||
|
if (_state != Status.InProgress)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (_moveableObject.CheckCanMove(directionType))
|
||||||
|
{
|
||||||
|
_moveableObject.MoveObject(directionType);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
31
src/MovementStrategy/DrawningObjectAirplane.java
Normal file
31
src/MovementStrategy/DrawningObjectAirplane.java
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
package MovementStrategy;
|
||||||
|
import src.DirectionType;
|
||||||
|
import DrawningObjects.DrawningAirplane;
|
||||||
|
|
||||||
|
public class DrawningObjectAirplane implements IMoveableObject{
|
||||||
|
private final DrawningAirplane _drawningAirplane;
|
||||||
|
public DrawningObjectAirplane(DrawningAirplane drawningAirplane){
|
||||||
|
_drawningAirplane = drawningAirplane;
|
||||||
|
}
|
||||||
|
public ObjectParameters GetObjectParameters(){
|
||||||
|
if(_drawningAirplane == null || _drawningAirplane.EntityAirplane() == null)
|
||||||
|
return null;
|
||||||
|
return new ObjectParameters(_drawningAirplane.GetPosX(), _drawningAirplane.GetPosY(),
|
||||||
|
_drawningAirplane.GetWidth(), _drawningAirplane.GetHeight());
|
||||||
|
}
|
||||||
|
public int GetStep(){
|
||||||
|
if(_drawningAirplane.EntityAirplane() == null)
|
||||||
|
return 0;
|
||||||
|
return (int)_drawningAirplane.EntityAirplane().Step();
|
||||||
|
}
|
||||||
|
public boolean CheckCanMove(DirectionType direction){
|
||||||
|
if(_drawningAirplane == null)
|
||||||
|
return false;
|
||||||
|
return _drawningAirplane.CanMove(direction);
|
||||||
|
}
|
||||||
|
public void MoveObject(DirectionType direction){
|
||||||
|
if(_drawningAirplane == null)
|
||||||
|
return;
|
||||||
|
_drawningAirplane.MoveTransport(direction);
|
||||||
|
}
|
||||||
|
}
|
10
src/MovementStrategy/IMoveableObject.java
Normal file
10
src/MovementStrategy/IMoveableObject.java
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
package MovementStrategy;
|
||||||
|
|
||||||
|
import src.DirectionType;
|
||||||
|
|
||||||
|
public interface IMoveableObject {
|
||||||
|
public ObjectParameters GetObjectParameters();
|
||||||
|
public int GetStep();
|
||||||
|
boolean CheckCanMove(DirectionType direction);
|
||||||
|
void MoveObject(DirectionType direction);
|
||||||
|
}
|
36
src/MovementStrategy/MoveToBorder.java
Normal file
36
src/MovementStrategy/MoveToBorder.java
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
package MovementStrategy;
|
||||||
|
|
||||||
|
public class MoveToBorder extends AbstractStrategy {
|
||||||
|
@Override
|
||||||
|
protected boolean IsTargetDestination() {
|
||||||
|
var objParams = GetObjectParameters();
|
||||||
|
if (objParams == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
int a = FieldWidth();
|
||||||
|
int b = FieldHeight();
|
||||||
|
int q = GetStep();
|
||||||
|
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 = objParams.RightBorder - FieldWidth();
|
||||||
|
if (Math.abs(diffX) >= GetStep()) {
|
||||||
|
if (diffX < 0) {
|
||||||
|
MoveRight();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
var diffY = objParams.DownBorder - FieldHeight();
|
||||||
|
if (Math.abs(diffY) >= GetStep()) {
|
||||||
|
if (diffY < 0) {
|
||||||
|
MoveDown();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
52
src/MovementStrategy/MoveToCenter.java
Normal file
52
src/MovementStrategy/MoveToCenter.java
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
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.ObjectMiddleHorizontal >= FieldWidth() / 2 &&
|
||||||
|
objParams.ObjectMiddleHorizontal - GetStep() <= FieldWidth() / 2)) &&
|
||||||
|
|
||||||
|
((objParams.ObjectMiddleVertical <= FieldHeight() / 2 &&
|
||||||
|
objParams.ObjectMiddleVertical + GetStep() >= FieldHeight() / 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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
27
src/MovementStrategy/ObjectParameters.java
Normal file
27
src/MovementStrategy/ObjectParameters.java
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
package MovementStrategy;
|
||||||
|
|
||||||
|
public class ObjectParameters {
|
||||||
|
private final int _x;
|
||||||
|
private final int _y;
|
||||||
|
private final int _width;
|
||||||
|
private final int _height;
|
||||||
|
public int LeftBorder;
|
||||||
|
public int TopBorder;
|
||||||
|
public int RightBorder;
|
||||||
|
public int DownBorder;
|
||||||
|
public int ObjectMiddleHorizontal;
|
||||||
|
public int ObjectMiddleVertical;
|
||||||
|
public ObjectParameters(int x, int y, int width, int height)
|
||||||
|
{
|
||||||
|
_x = x;
|
||||||
|
_y = y;
|
||||||
|
_width = width;
|
||||||
|
_height = height;
|
||||||
|
LeftBorder = _x;
|
||||||
|
TopBorder = _y;
|
||||||
|
RightBorder = _x + width;
|
||||||
|
DownBorder = _y + height;
|
||||||
|
ObjectMiddleHorizontal = _x + _width / 2;
|
||||||
|
ObjectMiddleVertical = _y + _height / 2;
|
||||||
|
}
|
||||||
|
}
|
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
|
||||||
|
}
|
@ -1,3 +1,4 @@
|
|||||||
|
package src;
|
||||||
public enum NumberType {
|
public enum NumberType {
|
||||||
Ten,
|
Ten,
|
||||||
Twenty,
|
Twenty,
|
||||||
|
Loading…
Reference in New Issue
Block a user