Compare commits
9 Commits
Author | SHA1 | Date | |
---|---|---|---|
083c28bd97 | |||
2b82b9c861 | |||
66e78a4fbf | |||
4e19e9e451 | |||
078b5ffac5 | |||
bf32a6b99a | |||
4874beae78 | |||
c815fc49e8 | |||
6bd0eb1d8c |
9
.idea/PIbd-22_Fedorenko_G.Y._Hydroplane_HARD.iml
generated
Normal file
9
.idea/PIbd-22_Fedorenko_G.Y._Hydroplane_HARD.iml
generated
Normal file
@ -0,0 +1,9 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="JAVA_MODULE" version="4">
|
||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$" />
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
6
.idea/misc.xml
generated
Normal file
6
.idea/misc.xml
generated
Normal file
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectRootManager">
|
||||
<output url="file://$PROJECT_DIR$/out" />
|
||||
</component>
|
||||
</project>
|
8
.idea/modules.xml
generated
Normal file
8
.idea/modules.xml
generated
Normal file
@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/.idea/PIbd-22_Fedorenko_G.Y._Hydroplane_HARD.iml" filepath="$PROJECT_DIR$/.idea/PIbd-22_Fedorenko_G.Y._Hydroplane_HARD.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
6
.idea/vcs.xml
generated
Normal file
6
.idea/vcs.xml
generated
Normal file
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
72
.idea/workspace.xml
generated
Normal file
72
.idea/workspace.xml
generated
Normal file
@ -0,0 +1,72 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="AutoImportSettings">
|
||||
<option name="autoReloadType" value="SELECTIVE" />
|
||||
</component>
|
||||
<component name="ChangeListManager">
|
||||
<list default="true" id="91fba623-49d8-4a60-90d5-98344ab7724a" name="Changes" comment="">
|
||||
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
||||
</list>
|
||||
<option name="SHOW_DIALOG" value="false" />
|
||||
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
||||
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
|
||||
<option name="LAST_RESOLUTION" value="IGNORE" />
|
||||
</component>
|
||||
<component name="Git.Settings">
|
||||
<option name="RECENT_BRANCH_BY_REPOSITORY">
|
||||
<map>
|
||||
<entry key="$PROJECT_DIR$" value="main" />
|
||||
</map>
|
||||
</option>
|
||||
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
|
||||
</component>
|
||||
<component name="MarkdownSettingsMigration">
|
||||
<option name="stateVersion" value="1" />
|
||||
</component>
|
||||
<component name="ProjectId" id="2X54F8kO9n4Aar8mYbPV5a6SUzU" />
|
||||
<component name="ProjectViewState">
|
||||
<option name="hideEmptyMiddlePackages" value="true" />
|
||||
<option name="showLibraryContents" value="true" />
|
||||
</component>
|
||||
<component name="PropertiesComponent"><![CDATA[{
|
||||
"keyToString": {
|
||||
"RunOnceActivity.OpenProjectViewOnStart": "true",
|
||||
"RunOnceActivity.ShowReadmeOnStart": "true",
|
||||
"last_opened_file_path": "C:/RPP HARD/PIbd-22_Fedorenko_G.Y._Hydroplane_HARD/Hydroplane"
|
||||
}
|
||||
}]]></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">
|
||||
<changelist id="91fba623-49d8-4a60-90d5-98344ab7724a" name="Changes" comment="" />
|
||||
<created>1697905501231</created>
|
||||
<option name="number" value="Default" />
|
||||
<option name="presentableId" value="Default" />
|
||||
<updated>1697905501231</updated>
|
||||
</task>
|
||||
<servers />
|
||||
</component>
|
||||
<component name="Vcs.Log.Tabs.Properties">
|
||||
<option name="TAB_STATES">
|
||||
<map>
|
||||
<entry key="MAIN">
|
||||
<value>
|
||||
<State>
|
||||
<option name="FILTERS">
|
||||
<map>
|
||||
<entry key="branch">
|
||||
<value>
|
||||
<list>
|
||||
<option value="origin/lab1" />
|
||||
</list>
|
||||
</value>
|
||||
</entry>
|
||||
</map>
|
||||
</option>
|
||||
</State>
|
||||
</value>
|
||||
</entry>
|
||||
</map>
|
||||
</option>
|
||||
</component>
|
||||
</project>
|
3
Hydroplane/.idea/.gitignore
generated
vendored
Normal file
3
Hydroplane/.idea/.gitignore
generated
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
13
Hydroplane/.idea/compiler.xml
generated
Normal file
13
Hydroplane/.idea/compiler.xml
generated
Normal file
@ -0,0 +1,13 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="CompilerConfiguration">
|
||||
<annotationProcessing>
|
||||
<profile name="Maven default annotation processors profile" enabled="true">
|
||||
<sourceOutputDir name="target/generated-sources/annotations" />
|
||||
<sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
|
||||
<outputRelativeToContentRoot value="true" />
|
||||
<module name="Hydroplane" />
|
||||
</profile>
|
||||
</annotationProcessing>
|
||||
</component>
|
||||
</project>
|
7
Hydroplane/.idea/encodings.xml
generated
Normal file
7
Hydroplane/.idea/encodings.xml
generated
Normal file
@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="Encoding">
|
||||
<file url="file://$PROJECT_DIR$/src/main/java" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/src/main/resources" charset="UTF-8" />
|
||||
</component>
|
||||
</project>
|
20
Hydroplane/.idea/jarRepositories.xml
generated
Normal file
20
Hydroplane/.idea/jarRepositories.xml
generated
Normal file
@ -0,0 +1,20 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="RemoteRepositoriesConfiguration">
|
||||
<remote-repository>
|
||||
<option name="id" value="central" />
|
||||
<option name="name" value="Central Repository" />
|
||||
<option name="url" value="https://repo.maven.apache.org/maven2" />
|
||||
</remote-repository>
|
||||
<remote-repository>
|
||||
<option name="id" value="central" />
|
||||
<option name="name" value="Maven Central repository" />
|
||||
<option name="url" value="https://repo1.maven.org/maven2" />
|
||||
</remote-repository>
|
||||
<remote-repository>
|
||||
<option name="id" value="jboss.community" />
|
||||
<option name="name" value="JBoss Community repository" />
|
||||
<option name="url" value="https://repository.jboss.org/nexus/content/repositories/public/" />
|
||||
</remote-repository>
|
||||
</component>
|
||||
</project>
|
14
Hydroplane/.idea/misc.xml
generated
Normal file
14
Hydroplane/.idea/misc.xml
generated
Normal file
@ -0,0 +1,14 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
||||
<component name="MavenProjectsManager">
|
||||
<option name="originalFiles">
|
||||
<list>
|
||||
<option value="$PROJECT_DIR$/pom.xml" />
|
||||
</list>
|
||||
</option>
|
||||
</component>
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_19" default="true" project-jdk-name="19" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/out" />
|
||||
</component>
|
||||
</project>
|
124
Hydroplane/.idea/uiDesigner.xml
generated
Normal file
124
Hydroplane/.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>
|
6
Hydroplane/.idea/vcs.xml
generated
Normal file
6
Hydroplane/.idea/vcs.xml
generated
Normal file
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="$PROJECT_DIR$/.." vcs="Git" />
|
||||
</component>
|
||||
</project>
|
17
Hydroplane/pom.xml
Normal file
17
Hydroplane/pom.xml
Normal file
@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>org.example</groupId>
|
||||
<artifactId>Hydroplane</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>19</maven.compiler.source>
|
||||
<maven.compiler.target>19</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
</project>
|
79
Hydroplane/src/main/java/org/example/AbstractStrategy.java
Normal file
79
Hydroplane/src/main/java/org/example/AbstractStrategy.java
Normal file
@ -0,0 +1,79 @@
|
||||
package org.example;
|
||||
|
||||
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 (IsTargetDestinaion())
|
||||
{
|
||||
_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 IsTargetDestinaion();
|
||||
|
||||
private boolean MoveTo(Direction Direction)
|
||||
{
|
||||
if (_state != Status.InProgress)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (_moveableObject.CheckCanMove(Direction))
|
||||
{
|
||||
_moveableObject.MoveObject(Direction);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
9
Hydroplane/src/main/java/org/example/Direction.java
Normal file
9
Hydroplane/src/main/java/org/example/Direction.java
Normal file
@ -0,0 +1,9 @@
|
||||
package org.example;
|
||||
|
||||
public enum Direction {
|
||||
Up,
|
||||
Down,
|
||||
Left,
|
||||
Right;
|
||||
}
|
||||
|
80
Hydroplane/src/main/java/org/example/DrawingHydroplane.java
Normal file
80
Hydroplane/src/main/java/org/example/DrawingHydroplane.java
Normal file
@ -0,0 +1,80 @@
|
||||
package org.example;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
public class DrawingHydroplane extends DrawingPlane{
|
||||
|
||||
public DrawingHydroplane(int speed, double weight, Color bodyColor, Color
|
||||
additionalColor, boolean boat, boolean bobber, int _numWindow, int width, int height)
|
||||
{
|
||||
super(speed, weight, bodyColor, _numWindow, width, height);
|
||||
_EntityPlane = new EntityHydroplane(speed, weight, bodyColor, additionalColor, boat, bobber, _numWindow);
|
||||
|
||||
}
|
||||
|
||||
public DrawingHydroplane(EntityPlane plane, IWindowDrawing _windowDrawing, int width, int height ){
|
||||
super(plane, _windowDrawing, width, height);
|
||||
if (height < _pictureHeight || width < _pictureWidth)
|
||||
return;
|
||||
}
|
||||
|
||||
public void SetPosition(int x, int y)
|
||||
{
|
||||
_startPosX = Math.min(x, _pictureWidth-_planeWidth);
|
||||
_startPosY = Math.min(y, _pictureHeight-_planeHeight);
|
||||
}
|
||||
|
||||
public void DrawTransport(Graphics2D g)
|
||||
{
|
||||
|
||||
if (_EntityPlane == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
super.DrawTransport(g);
|
||||
|
||||
g.setColor(((EntityHydroplane)_EntityPlane).AdditionalColor);
|
||||
|
||||
g.fillPolygon(
|
||||
new int[]{ _startPosX + 160, _startPosX + 130, _startPosX + 130 },
|
||||
new int[]{ _startPosY + 40, _startPosY + 40, _startPosY + 25 },
|
||||
3
|
||||
);
|
||||
|
||||
g.fillRect(_startPosX + 65, _startPosY + 55, 5, 15);
|
||||
g.fillRect(_startPosX + 125, _startPosY + 55, 5, 15);
|
||||
|
||||
g.drawLine(_startPosX + 65, _startPosY + 55, _startPosX + 65, _startPosY + 70);
|
||||
g.drawLine(_startPosX + 70, _startPosY + 55, _startPosX + 70, _startPosY + 70);
|
||||
g.drawLine(_startPosX + 125, _startPosY + 55, _startPosX + 125, _startPosY + 70);
|
||||
g.drawLine(_startPosX + 130, _startPosY + 55, _startPosX + 130, _startPosY + 70);
|
||||
|
||||
windowDrawing.Draw(_startPosX, _startPosY, ((EntityHydroplane)_EntityPlane).AdditionalColor, g);
|
||||
|
||||
if (((EntityHydroplane)_EntityPlane).Bobber) {
|
||||
g.fillPolygon(
|
||||
new int[]{ _startPosX + 55, _startPosX + 55, _startPosX + 155, _startPosX + 175 },
|
||||
new int[]{ _startPosY + 70, _startPosY + 80, _startPosY + 80, _startPosY + 70 },
|
||||
4
|
||||
);
|
||||
g.drawPolygon(
|
||||
new int[]{ _startPosX + 55, _startPosX + 55, _startPosX + 155, _startPosX + 175 },
|
||||
new int[]{ _startPosY + 70, _startPosY + 80, _startPosY + 80, _startPosY + 70 },
|
||||
4
|
||||
);
|
||||
}
|
||||
else {
|
||||
g.fillOval(_startPosX + 60, _startPosY + 70, 15, 15);
|
||||
g.fillOval(_startPosX + 120, _startPosY + 70, 15, 15);
|
||||
|
||||
g.drawOval(_startPosX + 60, _startPosY + 70, 15, 15);
|
||||
g.drawOval(_startPosX + 120, _startPosY + 70, 15, 15);
|
||||
}
|
||||
|
||||
if (((EntityHydroplane)_EntityPlane).Boat){
|
||||
g.fillOval(_startPosX, _startPosY + 21, 32, 8);
|
||||
g.drawOval(_startPosX, _startPosY + 21, 32, 8);
|
||||
}
|
||||
}
|
||||
}
|
149
Hydroplane/src/main/java/org/example/DrawingPlane.java
Normal file
149
Hydroplane/src/main/java/org/example/DrawingPlane.java
Normal file
@ -0,0 +1,149 @@
|
||||
package org.example;
|
||||
|
||||
import java.awt.*;
|
||||
import java.util.*;
|
||||
|
||||
public class DrawingPlane{
|
||||
|
||||
public IMoveableObject GetMoveableObject() { return new DrawningObjectPlane(this);}
|
||||
|
||||
protected IWindowDrawing windowDrawing;
|
||||
|
||||
public EntityPlane _EntityPlane;
|
||||
|
||||
protected int _pictureWidth;
|
||||
|
||||
protected int _pictureHeight;
|
||||
|
||||
protected int _startPosX;
|
||||
|
||||
protected int _startPosY;
|
||||
|
||||
protected int _planeWidth = 175;
|
||||
|
||||
protected int _planeHeight = 90;
|
||||
|
||||
public DrawingPlane(int speed, double weight, Color bodyColor, int _numWindow, int width, int height)
|
||||
{
|
||||
_pictureWidth = width;
|
||||
_pictureHeight = height;
|
||||
if (_pictureHeight < _planeHeight || _pictureWidth < _planeWidth)
|
||||
return;
|
||||
_EntityPlane = new EntityPlane(speed, weight, bodyColor, _numWindow);
|
||||
|
||||
Random random = new Random();
|
||||
switch(random.nextInt(0, 3)){
|
||||
case 0:
|
||||
windowDrawing = new WindowDrawing();
|
||||
break;
|
||||
case 1:
|
||||
windowDrawing = new WindowDrawingRect();
|
||||
break;
|
||||
case 2:
|
||||
windowDrawing = new WindowDrawingTringle();
|
||||
break;
|
||||
default:
|
||||
windowDrawing = new WindowDrawing();
|
||||
break;
|
||||
}
|
||||
windowDrawing.setNumWindow(_numWindow);
|
||||
|
||||
}
|
||||
|
||||
public DrawingPlane(EntityPlane plane, IWindowDrawing _windowDrawing, int width, int height)
|
||||
{
|
||||
if (height < _planeHeight || width < _planeWidth)
|
||||
return;
|
||||
_pictureWidth = width;
|
||||
_pictureHeight = height;
|
||||
_EntityPlane = plane;
|
||||
windowDrawing = _windowDrawing;
|
||||
windowDrawing.setNumWindow(_EntityPlane.numWindow);
|
||||
}
|
||||
|
||||
public void SetPosition(int x, int y)
|
||||
{
|
||||
_startPosX = Math.min(x, _pictureWidth-_planeWidth);
|
||||
_startPosY = Math.min(y, _pictureHeight-_planeHeight);
|
||||
}
|
||||
|
||||
public int GetPosX (){return _startPosX;}
|
||||
|
||||
public int GetPosY (){return _startPosY;}
|
||||
|
||||
public int GetWidth (){return _planeWidth;}
|
||||
|
||||
public int GetHeight (){return _planeHeight;}
|
||||
|
||||
public boolean CanMove(Direction direction)
|
||||
{
|
||||
if (_EntityPlane == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
switch (direction)
|
||||
{
|
||||
case Left:
|
||||
return _startPosX - _EntityPlane.Step > 0;
|
||||
case Right:
|
||||
return _startPosX + _planeWidth + _EntityPlane.Step < _pictureWidth;
|
||||
case Up:
|
||||
return _startPosY - _EntityPlane.Step > 0;
|
||||
case Down:
|
||||
return _startPosY + _planeHeight + _EntityPlane.Step < _pictureHeight;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public void MoveTransport(Direction direction)
|
||||
{
|
||||
if (!CanMove(direction) || _EntityPlane == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
switch (direction)
|
||||
{
|
||||
case Left:
|
||||
_startPosX -= (int)_EntityPlane.Step;
|
||||
break;
|
||||
case Up:
|
||||
_startPosY -= (int)_EntityPlane.Step;
|
||||
break;
|
||||
case Right:
|
||||
_startPosX += (int)_EntityPlane.Step;
|
||||
break;
|
||||
case Down:
|
||||
_startPosY += (int)_EntityPlane.Step;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void DrawTransport(Graphics2D g)
|
||||
{
|
||||
|
||||
if (_EntityPlane == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
g.setColor(_EntityPlane.BodyColor);
|
||||
g.fillPolygon(
|
||||
new int[]{ _startPosX + 5, _startPosX + 5, _startPosX + 130, _startPosX + 160, _startPosX + 130, _startPosX + 130, _startPosX + 55 },
|
||||
new int[]{ _startPosY, _startPosY + 55, _startPosY + 55, _startPosY + 40, _startPosY + 40, _startPosY + 25, _startPosY + 25 },
|
||||
7);
|
||||
|
||||
g.setColor(Color.black);
|
||||
|
||||
g.drawRect(_startPosX + 5, _startPosY + 25, 125, 30);
|
||||
|
||||
g.drawLine(_startPosX + 130, _startPosY + 25, _startPosX + 160, _startPosY + 40);
|
||||
g.drawLine(_startPosX + 130, _startPosY + 55, _startPosX + 160, _startPosY + 40);
|
||||
g.drawLine(_startPosX + 130, _startPosY + 40, _startPosX + 160, _startPosY + 40);
|
||||
|
||||
g.drawOval(_startPosX + 35, _startPosY + 43, 80, 7);
|
||||
|
||||
windowDrawing.Draw(_startPosX, _startPosY, Color.white, g);
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
package org.example;
|
||||
|
||||
public class DrawningObjectPlane implements IMoveableObject {
|
||||
|
||||
private DrawingPlane _drawingPlane = null;
|
||||
|
||||
public DrawningObjectPlane(DrawingPlane drawingPlane)
|
||||
{
|
||||
_drawingPlane = drawingPlane;
|
||||
}
|
||||
|
||||
public ObjectParameters GetObjectPosition(){
|
||||
if (_drawingPlane == null || _drawingPlane._EntityPlane ==
|
||||
null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new ObjectParameters(_drawingPlane.GetPosX(),
|
||||
_drawingPlane.GetPosY(), _drawingPlane.GetWidth(), _drawingPlane.GetHeight());
|
||||
}
|
||||
public int GetStep(){ return (int)_drawingPlane._EntityPlane.Step; }
|
||||
|
||||
public boolean CheckCanMove(Direction direction) { return _drawingPlane.CanMove(direction);}
|
||||
|
||||
public void MoveObject(Direction direction) { _drawingPlane.MoveTransport(direction); }
|
||||
|
||||
}
|
21
Hydroplane/src/main/java/org/example/EntityHydroplane.java
Normal file
21
Hydroplane/src/main/java/org/example/EntityHydroplane.java
Normal file
@ -0,0 +1,21 @@
|
||||
package org.example;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
public class EntityHydroplane extends EntityPlane{
|
||||
|
||||
public Color AdditionalColor;
|
||||
|
||||
public boolean Boat;
|
||||
|
||||
public boolean Bobber;
|
||||
|
||||
public EntityHydroplane(int speed, double weight, Color bodyColor, Color
|
||||
additionalColor, boolean boat, boolean bobber, int _numWindow)
|
||||
{
|
||||
super(speed, weight, bodyColor, _numWindow);
|
||||
AdditionalColor = additionalColor;
|
||||
Boat = boat;
|
||||
Bobber = bobber;
|
||||
}
|
||||
}
|
25
Hydroplane/src/main/java/org/example/EntityPlane.java
Normal file
25
Hydroplane/src/main/java/org/example/EntityPlane.java
Normal file
@ -0,0 +1,25 @@
|
||||
package org.example;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
public class EntityPlane{
|
||||
|
||||
public int Speed;
|
||||
|
||||
public double Weight;
|
||||
|
||||
public Color BodyColor;
|
||||
|
||||
public double Step;
|
||||
|
||||
public int numWindow;
|
||||
|
||||
public EntityPlane(int speed, double weight, Color bodyColor, int _numWindow)
|
||||
{
|
||||
numWindow = _numWindow;
|
||||
Speed = speed;
|
||||
Weight = weight;
|
||||
BodyColor = bodyColor;
|
||||
Step = (double)Speed * 100 / Weight;
|
||||
}
|
||||
}
|
@ -0,0 +1,63 @@
|
||||
package org.example;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JComponent;
|
||||
import javax.swing.JFrame;
|
||||
|
||||
public class Form4GenericDopClass extends JFrame {
|
||||
static int pictureBoxWidth = 980;
|
||||
static int pictureBoxHeight = 560;
|
||||
public DrawingPlane _drawingPlane;
|
||||
private class Canvas extends JComponent{
|
||||
public Canvas(){
|
||||
}
|
||||
public void paintComponent (Graphics g){
|
||||
if (_drawingPlane == null){
|
||||
return;
|
||||
}
|
||||
super.paintComponents (g) ;
|
||||
Graphics2D g2d = (Graphics2D)g;
|
||||
_drawingPlane.SetPosition(50, 50);
|
||||
_drawingPlane.DrawTransport(g2d);
|
||||
super.repaint();
|
||||
}
|
||||
}
|
||||
GenericDopClass<EntityPlane, IWindowDrawing> genericDopClass;
|
||||
public Form4GenericDopClass(){
|
||||
_drawingPlane = null;
|
||||
Canvas canv = new Canvas();
|
||||
setSize (1000, 600);
|
||||
setLayout(null);
|
||||
canv.setBounds(0,0,pictureBoxWidth, pictureBoxHeight);
|
||||
|
||||
genericDopClass = new GenericDopClass<>(100, 100, pictureBoxWidth, pictureBoxHeight);
|
||||
genericDopClass.Add(new EntityPlane(100, 100, Color.BLUE, 30));
|
||||
genericDopClass.Add(new EntityPlane(100, 100, Color.RED, 10));
|
||||
genericDopClass.Add(new EntityPlane(100, 100, Color.GRAY, 20));
|
||||
genericDopClass.Add(new EntityHydroplane(100, 100, Color.BLUE, Color.ORANGE, true, true, 20));
|
||||
genericDopClass.Add(new WindowDrawing());
|
||||
genericDopClass.Add(new WindowDrawingTringle());
|
||||
|
||||
JButton creatButton = new JButton("createButton");
|
||||
creatButton.addActionListener(
|
||||
new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e){
|
||||
_drawingPlane = genericDopClass.getRDrawingObject();
|
||||
canv.repaint();
|
||||
}
|
||||
}
|
||||
);
|
||||
creatButton.setBounds(pictureBoxWidth/2, pictureBoxHeight-20, 120, 20);
|
||||
|
||||
add(canv);
|
||||
add(creatButton);
|
||||
setVisible(true);
|
||||
}
|
||||
}
|
||||
|
215
Hydroplane/src/main/java/org/example/FormHydroplane.java
Normal file
215
Hydroplane/src/main/java/org/example/FormHydroplane.java
Normal file
@ -0,0 +1,215 @@
|
||||
package org.example;
|
||||
|
||||
import java.awt.*;
|
||||
import java.util.*;
|
||||
import javax.swing.*;
|
||||
import java.awt.event.*;
|
||||
|
||||
public class FormHydroplane{
|
||||
|
||||
public DrawingPlane _drawingPlane;
|
||||
public DrawingPlane SelectedPlane;
|
||||
public boolean DialogResult = false;
|
||||
public JButton buttonSelectPlane;
|
||||
private AbstractStrategy abstractStrategy;
|
||||
Canvas canv;
|
||||
static int pictureBoxWidth = 980;
|
||||
static int pictureBoxHeight = 580;
|
||||
public JFrame w;
|
||||
|
||||
public void Draw(){
|
||||
canv.repaint();
|
||||
}
|
||||
|
||||
public void ChangePlane(DrawingPlane newPlane){
|
||||
newPlane.SetPosition(0,0);
|
||||
_drawingPlane = newPlane;
|
||||
canv._drawingPlane = _drawingPlane;
|
||||
|
||||
}
|
||||
|
||||
public FormHydroplane(){
|
||||
w=new JFrame ("Hydroplane");
|
||||
JButton buttonCreatePlane = new JButton("createPlane");
|
||||
JButton buttonCreateHydroplane = new JButton("createHydroplane");
|
||||
buttonSelectPlane = new JButton("select plane");
|
||||
JButton buttonStrategysStep = new JButton("strategys step");
|
||||
JComboBox comboBoxStrategy = new JComboBox(
|
||||
new String[]{
|
||||
"к центру",
|
||||
"к краю",
|
||||
});
|
||||
JButton up = new JButton();
|
||||
up.setBorderPainted(false);
|
||||
up.setFocusPainted(false);
|
||||
up.setContentAreaFilled(false);
|
||||
up.setName("up");
|
||||
up.setIcon(new ImageIcon("C:\\RPP HARD\\PIbd-22_Fedorenko_G.Y._Hydroplane_HARD\\Hydroplane\\src\\main\\java\\org\\example\\images\\up.png"));
|
||||
JButton down = new JButton();
|
||||
down.setBorderPainted(false);
|
||||
down.setFocusPainted(false);
|
||||
down.setContentAreaFilled(false);
|
||||
down.setName("down");
|
||||
down.setIcon(new ImageIcon("C:\\RPP HARD\\PIbd-22_Fedorenko_G.Y._Hydroplane_HARD\\Hydroplane\\src\\main\\java\\org\\example\\images\\down.png"));
|
||||
JButton left = new JButton();
|
||||
left.setBorderPainted(false);
|
||||
left.setFocusPainted(false);
|
||||
left.setContentAreaFilled(false);
|
||||
left.setName("left");
|
||||
left.setIcon(new ImageIcon("C:\\RPP HARD\\PIbd-22_Fedorenko_G.Y._Hydroplane_HARD\\Hydroplane\\src\\main\\java\\org\\example\\images\\left.png"));
|
||||
JButton right = new JButton();
|
||||
right.setBorderPainted(false);
|
||||
right.setFocusPainted(false);
|
||||
right.setContentAreaFilled(false);
|
||||
right.setName("right");
|
||||
right.setIcon(new ImageIcon("C:\\RPP HARD\\PIbd-22_Fedorenko_G.Y._Hydroplane_HARD\\Hydroplane\\src\\main\\java\\org\\example\\images\\right.png"));
|
||||
|
||||
buttonCreatePlane.addActionListener(
|
||||
new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e){
|
||||
Random random = new Random();
|
||||
_drawingPlane = new DrawingPlane(
|
||||
random.nextInt(100, 300),
|
||||
random.nextInt(1000, 3000),
|
||||
new Color(random.nextInt(0, 256), random.nextInt(0, 256), random.nextInt(0, 256)),
|
||||
random.nextInt(1, 4) * 10,
|
||||
pictureBoxWidth,
|
||||
pictureBoxHeight);
|
||||
_drawingPlane.SetPosition(random.nextInt(10, 100), random.nextInt(10, 100));
|
||||
canv._drawingPlane = _drawingPlane;
|
||||
Draw();
|
||||
}
|
||||
}
|
||||
);
|
||||
buttonCreateHydroplane.addActionListener(
|
||||
new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e){
|
||||
Random random = new Random();
|
||||
_drawingPlane = new DrawingHydroplane(
|
||||
random.nextInt(100, 300),
|
||||
random.nextInt(1000, 3000),
|
||||
new Color(random.nextInt(0, 256), random.nextInt(0, 256), random.nextInt(0, 256)),
|
||||
new Color(random.nextInt(0, 256), random.nextInt(0, 256), random.nextInt(0, 256)),
|
||||
random.nextInt(0, 2) == 1,
|
||||
random.nextInt(0, 2) == 1,
|
||||
random.nextInt(1, 4) * 10,
|
||||
pictureBoxWidth,
|
||||
pictureBoxHeight);
|
||||
_drawingPlane.SetPosition(random.nextInt(10, 100), random.nextInt(10, 100));
|
||||
canv._drawingPlane = _drawingPlane;
|
||||
Draw();
|
||||
}
|
||||
}
|
||||
);
|
||||
buttonStrategysStep.addActionListener(
|
||||
new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e){
|
||||
if (_drawingPlane == 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 DrawningObjectPlane(_drawingPlane), pictureBoxWidth, pictureBoxHeight);
|
||||
comboBoxStrategy.setEnabled(false);
|
||||
}
|
||||
if (abstractStrategy == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
abstractStrategy.MakeStep();
|
||||
Draw();
|
||||
if (abstractStrategy.GetStatus() == Status.Finish)
|
||||
{
|
||||
comboBoxStrategy.setEnabled(true);
|
||||
abstractStrategy = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
ActionListener actioListener = new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e){
|
||||
if (_drawingPlane == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
switch(((JButton)(e.getSource())).getName()){
|
||||
case "up":
|
||||
_drawingPlane.MoveTransport(Direction.Up);
|
||||
break;
|
||||
case "down":
|
||||
_drawingPlane.MoveTransport(Direction.Down);
|
||||
break;
|
||||
case "left":
|
||||
_drawingPlane.MoveTransport(Direction.Left);
|
||||
break;
|
||||
case "right":
|
||||
_drawingPlane.MoveTransport(Direction.Right);
|
||||
break;
|
||||
}
|
||||
Draw();
|
||||
}
|
||||
};
|
||||
|
||||
up.addActionListener(actioListener);
|
||||
down.addActionListener(actioListener);
|
||||
left.addActionListener(actioListener);
|
||||
right.addActionListener(actioListener);
|
||||
|
||||
w.setSize (1000, 600);
|
||||
w.setLayout(null);
|
||||
canv = new Canvas();
|
||||
canv.setBounds(0, 0, pictureBoxWidth, pictureBoxHeight);
|
||||
buttonCreatePlane.setBounds(2, 540, 150, 20);
|
||||
buttonCreateHydroplane.setBounds(160, 540, 200, 20);
|
||||
up.setBounds(900, 480, 40, 40);
|
||||
down.setBounds(900, 520, 40, 40);
|
||||
left.setBounds(860, 520, 40, 40);
|
||||
right.setBounds(940, 520, 40, 40);
|
||||
comboBoxStrategy.setBounds(pictureBoxWidth - 150, 20, 150, 20);
|
||||
buttonStrategysStep.setBounds(pictureBoxWidth - 150, 45, 150, 20);
|
||||
buttonSelectPlane.setBounds(pictureBoxWidth/2, 540, 150, 20);
|
||||
w.add(canv);
|
||||
w.add(buttonCreatePlane);
|
||||
w.add(buttonCreateHydroplane);
|
||||
w.add(up);
|
||||
w.add(down);
|
||||
w.add(left);
|
||||
w.add(right);
|
||||
w.add(comboBoxStrategy);
|
||||
w.add(buttonStrategysStep);
|
||||
w.add(buttonSelectPlane);
|
||||
|
||||
w.setVisible(true);
|
||||
}
|
||||
}
|
||||
class Canvas extends JComponent{
|
||||
public DrawingPlane _drawingPlane;
|
||||
public Canvas(){}
|
||||
public void paintComponent (Graphics g){
|
||||
if (_drawingPlane == null){
|
||||
return;
|
||||
}
|
||||
super.paintComponents (g) ;
|
||||
Graphics2D g2d = (Graphics2D)g;
|
||||
_drawingPlane.DrawTransport(g2d);
|
||||
super.repaint();
|
||||
}
|
||||
}
|
284
Hydroplane/src/main/java/org/example/FormPlaneCollecltion.java
Normal file
284
Hydroplane/src/main/java/org/example/FormPlaneCollecltion.java
Normal file
@ -0,0 +1,284 @@
|
||||
package org.example;
|
||||
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.util.LinkedList;
|
||||
import java.util.Stack;
|
||||
|
||||
import javax.swing.DefaultListModel;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JComboBox;
|
||||
import javax.swing.JComponent;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JList;
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.JTextField;
|
||||
import javax.swing.event.ListSelectionEvent;
|
||||
import javax.swing.event.ListSelectionListener;
|
||||
|
||||
public class FormPlaneCollecltion {
|
||||
|
||||
private class Canvas extends JComponent{
|
||||
public Canvas(){
|
||||
}
|
||||
public void paintComponent (Graphics g){
|
||||
super.paintComponent(g);
|
||||
if (jListStorage.getSelectedIndex() == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var obj = _storage.get(jListStorage.getSelectedValue());
|
||||
if (obj == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (obj.ShowPlanes() != null) {
|
||||
g.drawImage(obj.ShowPlanes(), 0, 0, this);
|
||||
}
|
||||
super.repaint();
|
||||
}
|
||||
}
|
||||
|
||||
Canvas canv;
|
||||
|
||||
static int pictureBoxWidth = 800;
|
||||
static int pictureBoxHeight = 580;
|
||||
|
||||
private PlanesGenericStorage _storage;
|
||||
|
||||
public void Draw(){
|
||||
canv.repaint();
|
||||
}
|
||||
|
||||
private Stack<DrawingPlane> stackRemoved;
|
||||
private JList<String> jListStorage;
|
||||
private DefaultListModel<String> listModel;
|
||||
|
||||
private void ReloadObjects()
|
||||
{
|
||||
int index = jListStorage.getSelectedIndex();
|
||||
listModel.clear();
|
||||
for (String key : _storage.Keys()) {
|
||||
listModel.addElement(key);
|
||||
}
|
||||
if (listModel.size() > 0 && (index == -1 || index >= listModel.size()))
|
||||
{
|
||||
jListStorage.setSelectedIndex(0);
|
||||
}
|
||||
else if (listModel.size() > 0 && index > -1 && index < listModel.size())
|
||||
{
|
||||
jListStorage.setSelectedIndex(index);
|
||||
}
|
||||
}
|
||||
|
||||
FormPlaneCollecltion() {
|
||||
listModel = new DefaultListModel<String>();
|
||||
jListStorage = new JList<String>(listModel);
|
||||
canv = new Canvas();
|
||||
JFrame w = new JFrame("PlaneCollecltion");
|
||||
_storage = new PlanesGenericStorage(pictureBoxWidth, pictureBoxHeight);
|
||||
|
||||
JButton ButtonAddPlane = new JButton("AddPlane");
|
||||
ButtonAddPlane.addActionListener(
|
||||
new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
if (jListStorage.getSelectedIndex() == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var obj = _storage.get(jListStorage.getSelectedValue());
|
||||
if (obj == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
FormHydroplane form = new FormHydroplane();
|
||||
form.buttonSelectPlane.addActionListener(
|
||||
new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
if (obj.Add(form._drawingPlane) != -1)
|
||||
{
|
||||
JOptionPane.showMessageDialog(null, "Объект добавлен", "Информация", JOptionPane.INFORMATION_MESSAGE);
|
||||
System.out.println("Объект добавлен");
|
||||
Draw();
|
||||
}
|
||||
else
|
||||
{
|
||||
JOptionPane.showMessageDialog(null, "Не удалось добавить объект", "Информация", JOptionPane.INFORMATION_MESSAGE);
|
||||
System.out.println("Не удалось добавить объект");
|
||||
}
|
||||
form.w.dispose();
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
stackRemoved = new Stack<DrawingPlane>();
|
||||
JTextField TextBoxNumber = new JTextField();
|
||||
JButton ButtonRemovePlane = new JButton("RemovePlane");
|
||||
ButtonRemovePlane.addActionListener(
|
||||
new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e){
|
||||
if (jListStorage.getSelectedIndex() == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var obj = _storage.get(jListStorage.getSelectedValue());
|
||||
if (obj == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (JOptionPane.showConfirmDialog(null, "Удалить объект?", "Удаление", JOptionPane.YES_NO_OPTION) == JOptionPane.NO_OPTION)
|
||||
{
|
||||
return;
|
||||
}
|
||||
for (char it : TextBoxNumber.getText().toCharArray())
|
||||
if (it < '0' || it > '9')
|
||||
{
|
||||
JOptionPane.showMessageDialog(null, "Не удалось удалить объект", "Информация", JOptionPane.INFORMATION_MESSAGE);
|
||||
System.out.println("Не удалось удалить объект");
|
||||
return;
|
||||
}
|
||||
if (TextBoxNumber.getText().length() == 0)
|
||||
{
|
||||
JOptionPane.showMessageDialog(null, "Не удалось удалить объект", "Информация", JOptionPane.INFORMATION_MESSAGE);
|
||||
System.out.println("Не удалось удалить объект");
|
||||
return;
|
||||
}
|
||||
|
||||
int pos = Integer.parseInt(TextBoxNumber.getText());
|
||||
var removed = obj.remove(pos);
|
||||
if (removed != null)
|
||||
{
|
||||
stackRemoved.add(removed);
|
||||
JOptionPane.showMessageDialog(null, "Объект удален", "Информация", JOptionPane.INFORMATION_MESSAGE);
|
||||
System.out.println("Объект удален");
|
||||
Draw();
|
||||
}
|
||||
else
|
||||
{
|
||||
JOptionPane.showMessageDialog(null, "Не удалось удалить объект", "Информация", JOptionPane.INFORMATION_MESSAGE);
|
||||
System.out.println("Не удалось удалить объект");
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
JButton buttonGetRemoved = new JButton("buttonGetRemoved");
|
||||
buttonGetRemoved.addActionListener(
|
||||
new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e){
|
||||
if (stackRemoved.size()==0){
|
||||
JOptionPane.showMessageDialog(null, "Нет удалённых", "Информация", JOptionPane.INFORMATION_MESSAGE);
|
||||
System.out.println("Нет удалённых");
|
||||
return;
|
||||
}
|
||||
System.out.println("Удалённый объект");
|
||||
FormHydroplane form = new FormHydroplane();
|
||||
form.ChangePlane(stackRemoved.pop());
|
||||
form.Draw();
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
JButton ButtonRefreshCollection = new JButton("Refresh Collection");
|
||||
ButtonRefreshCollection.addActionListener(
|
||||
new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e){
|
||||
Draw();
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
JButton toForm4GenericDopClass = new JButton("ToForm4GenericDopClass");
|
||||
toForm4GenericDopClass.addActionListener(
|
||||
new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e){
|
||||
Form4GenericDopClass form4GenericDopClass = new Form4GenericDopClass();
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
JTextField textBoxSetName = new JTextField();
|
||||
JButton buttonAddSet = new JButton("Add Set");
|
||||
buttonAddSet.addActionListener(
|
||||
new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e){
|
||||
if (textBoxSetName.getText().length() == 0)
|
||||
{
|
||||
JOptionPane.showMessageDialog(null, "Не все данные заполнены", "Информация", JOptionPane.INFORMATION_MESSAGE);
|
||||
System.out.println("Не все данные заполнены");
|
||||
return;
|
||||
}
|
||||
_storage.AddSet(textBoxSetName.getText());
|
||||
ReloadObjects();
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
jListStorage.addListSelectionListener(
|
||||
new ListSelectionListener() {
|
||||
public void valueChanged(ListSelectionEvent e){
|
||||
Draw();
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
JButton buttonRemoveSet = new JButton("Remove Set");
|
||||
buttonRemoveSet.addActionListener(
|
||||
new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e){
|
||||
if (jListStorage.getSelectedIndex() == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (JOptionPane.showConfirmDialog(null, "Удалить объект " + jListStorage.getSelectedValue() + "?", "Удаление", JOptionPane.YES_NO_OPTION) == JOptionPane.NO_OPTION)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_storage.DelSet(jListStorage.getSelectedValue());
|
||||
ReloadObjects();
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
w.setSize (1000, 600);
|
||||
w.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
|
||||
w.setLayout(null);
|
||||
canv.setBounds(0, 0, pictureBoxWidth, pictureBoxHeight);
|
||||
ButtonAddPlane.setBounds(pictureBoxWidth, 0, 160, 20);
|
||||
TextBoxNumber.setBounds(pictureBoxWidth, 30, 160, 20);
|
||||
ButtonRemovePlane.setBounds(pictureBoxWidth, 60, 160, 20);
|
||||
ButtonRefreshCollection.setBounds(pictureBoxWidth, 90, 160, 20);
|
||||
toForm4GenericDopClass.setBounds(pictureBoxWidth, 120, 160, 20);
|
||||
|
||||
buttonAddSet.setBounds(pictureBoxWidth, 150, 160, 20);
|
||||
textBoxSetName.setBounds(pictureBoxWidth, 180, 160, 20);
|
||||
jListStorage.setBounds(pictureBoxWidth, 210, 160, 80);
|
||||
buttonRemoveSet.setBounds(pictureBoxWidth, 300, 160, 20);
|
||||
|
||||
buttonGetRemoved.setBounds(pictureBoxWidth, 330, 160, 20);
|
||||
|
||||
w.add(canv);
|
||||
w.add(ButtonAddPlane);
|
||||
w.add(ButtonRemovePlane);
|
||||
w.add(ButtonRefreshCollection);
|
||||
w.add(TextBoxNumber);
|
||||
w.add(toForm4GenericDopClass);
|
||||
|
||||
w.add(buttonAddSet);
|
||||
w.add(textBoxSetName);
|
||||
w.add(jListStorage);
|
||||
w.add(buttonRemoveSet);
|
||||
|
||||
w.add(buttonGetRemoved);
|
||||
|
||||
w.setVisible(true);
|
||||
}
|
||||
}
|
||||
|
61
Hydroplane/src/main/java/org/example/GenericDopClass.java
Normal file
61
Hydroplane/src/main/java/org/example/GenericDopClass.java
Normal file
@ -0,0 +1,61 @@
|
||||
package org.example;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Random;
|
||||
|
||||
public class GenericDopClass<T extends EntityPlane, U extends IWindowDrawing> {
|
||||
|
||||
private ArrayList<T> Planes;
|
||||
private ArrayList<U> Windows;
|
||||
private int maxCountPlanes;
|
||||
private int countPlanes;
|
||||
private int maxCountWindows;
|
||||
private int countWindows;
|
||||
private Random random;
|
||||
|
||||
private int _pictureWidth;
|
||||
private int _pictureHeight;
|
||||
|
||||
public GenericDopClass(int _maxCountPlanes, int _maxCountWindows, int pictureWidth, int pictureHeight){
|
||||
maxCountPlanes = _maxCountPlanes;
|
||||
maxCountWindows = _maxCountWindows;
|
||||
Planes = new ArrayList<T>(maxCountPlanes);
|
||||
Windows = new ArrayList<U>(maxCountWindows);
|
||||
countPlanes = 0;
|
||||
countWindows = 0;
|
||||
_pictureWidth = pictureWidth;
|
||||
_pictureHeight = pictureHeight;
|
||||
random = new Random();
|
||||
}
|
||||
|
||||
public void Add(T plane){
|
||||
if (plane == null)
|
||||
return;
|
||||
if (countPlanes > maxCountPlanes)
|
||||
return;
|
||||
Planes.add(countPlanes++, plane);
|
||||
}
|
||||
|
||||
public void Add(U window){
|
||||
if (window == null)
|
||||
return;
|
||||
if (countWindows > maxCountWindows)
|
||||
return;
|
||||
Windows.add(countWindows++, window);
|
||||
}
|
||||
|
||||
public DrawingPlane getRDrawingObject(){
|
||||
if (countPlanes == 0 || countWindows == 0)
|
||||
return null;
|
||||
int i = random.nextInt(countPlanes);
|
||||
int j = random.nextInt(countWindows);
|
||||
DrawingPlane drawingPlane;
|
||||
if (Planes.get(i) instanceof EntityHydroplane){
|
||||
drawingPlane = new DrawingHydroplane((EntityHydroplane)Planes.get(i), Windows.get(j), _pictureWidth, _pictureHeight);
|
||||
}
|
||||
else{
|
||||
drawingPlane = new DrawingPlane(Planes.get(i), Windows.get(j), _pictureWidth, _pictureHeight);
|
||||
}
|
||||
return drawingPlane;
|
||||
}
|
||||
}
|
14
Hydroplane/src/main/java/org/example/IMoveableObject.java
Normal file
14
Hydroplane/src/main/java/org/example/IMoveableObject.java
Normal file
@ -0,0 +1,14 @@
|
||||
package org.example;
|
||||
|
||||
public interface IMoveableObject {
|
||||
|
||||
ObjectParameters GetObjectPosition();
|
||||
|
||||
int GetStep();
|
||||
|
||||
boolean CheckCanMove(Direction direction);
|
||||
|
||||
void MoveObject(Direction direction);
|
||||
|
||||
}
|
||||
|
13
Hydroplane/src/main/java/org/example/IWindowDrawing.java
Normal file
13
Hydroplane/src/main/java/org/example/IWindowDrawing.java
Normal file
@ -0,0 +1,13 @@
|
||||
package org.example;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
public interface IWindowDrawing{
|
||||
|
||||
public NumWindow getNumWindow();
|
||||
|
||||
public void setNumWindow(int kWindow);
|
||||
|
||||
public void Draw(int _startPosX, int _startPosY, Color color, Graphics2D g2d);
|
||||
|
||||
}
|
7
Hydroplane/src/main/java/org/example/Main.java
Normal file
7
Hydroplane/src/main/java/org/example/Main.java
Normal file
@ -0,0 +1,7 @@
|
||||
package org.example;
|
||||
|
||||
public class Main{
|
||||
public static void main(String[] args) {
|
||||
FormPlaneCollecltion formPlaneCollecltion = new FormPlaneCollecltion();
|
||||
}
|
||||
}
|
51
Hydroplane/src/main/java/org/example/MoveToBorder.java
Normal file
51
Hydroplane/src/main/java/org/example/MoveToBorder.java
Normal file
@ -0,0 +1,51 @@
|
||||
package org.example;
|
||||
|
||||
public class MoveToBorder extends AbstractStrategy{
|
||||
|
||||
protected boolean IsTargetDestinaion()
|
||||
{
|
||||
var objParams = GetObjectParameters();
|
||||
if (objParams == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return objParams.RightBorder() <= FieldWidth &&
|
||||
objParams.RightBorder() + GetStep() >= FieldWidth &&
|
||||
objParams.DownBorder() <= FieldHeight &&
|
||||
objParams.DownBorder() + GetStep() >= FieldHeight;
|
||||
}
|
||||
|
||||
protected void MoveToTarget()
|
||||
{
|
||||
var objParams = GetObjectParameters();
|
||||
if (objParams == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var diffX = objParams.RightBorder() - FieldWidth;
|
||||
if (Math.abs(diffX) > GetStep())
|
||||
{
|
||||
if (diffX > 0)
|
||||
{
|
||||
MoveLeft();
|
||||
}
|
||||
else
|
||||
{
|
||||
MoveRight();
|
||||
}
|
||||
}
|
||||
var diffY = objParams.DownBorder() - FieldHeight;
|
||||
if (Math.abs(diffY) > GetStep())
|
||||
{
|
||||
if (diffY > 0)
|
||||
{
|
||||
MoveUp();
|
||||
}
|
||||
else
|
||||
{
|
||||
MoveDown();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
51
Hydroplane/src/main/java/org/example/MoveToCenter.java
Normal file
51
Hydroplane/src/main/java/org/example/MoveToCenter.java
Normal file
@ -0,0 +1,51 @@
|
||||
package org.example;
|
||||
|
||||
public class MoveToCenter extends AbstractStrategy {
|
||||
|
||||
protected boolean IsTargetDestinaion()
|
||||
{
|
||||
var objParams = GetObjectParameters();
|
||||
if (objParams == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return
|
||||
Math.abs(objParams.ObjectMiddleHorizontal() - FieldWidth / 2) <= GetStep()
|
||||
&&
|
||||
Math.abs(objParams.ObjectMiddleVertical() - FieldHeight / 2) <= GetStep();
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
8
Hydroplane/src/main/java/org/example/NumWindow.java
Normal file
8
Hydroplane/src/main/java/org/example/NumWindow.java
Normal file
@ -0,0 +1,8 @@
|
||||
package org.example;
|
||||
|
||||
public enum NumWindow
|
||||
{
|
||||
tenWindows,
|
||||
twentyWindows,
|
||||
thirtyWindows
|
||||
}
|
30
Hydroplane/src/main/java/org/example/ObjectParameters.java
Normal file
30
Hydroplane/src/main/java/org/example/ObjectParameters.java
Normal file
@ -0,0 +1,30 @@
|
||||
package org.example;
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,92 @@
|
||||
package org.example;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.image.BufferedImage;
|
||||
|
||||
public class PlanesGenericCollection<T extends DrawingPlane, U extends IMoveableObject> {
|
||||
|
||||
private int _pictureWidth;
|
||||
|
||||
private int _pictureHeight;
|
||||
|
||||
private int _placeSizeWidth = 175;
|
||||
|
||||
private int _placeSizeHeight = 85;
|
||||
|
||||
private SetGeneric<T> _collection;
|
||||
|
||||
public PlanesGenericCollection(int picWidth, int picHeight)
|
||||
{
|
||||
int width = picWidth / _placeSizeWidth;
|
||||
int height = picHeight / _placeSizeHeight;
|
||||
_pictureWidth = picWidth;
|
||||
_pictureHeight = picHeight;
|
||||
_collection = new SetGeneric<T>(width * height);
|
||||
}
|
||||
|
||||
public int Add(T obj)
|
||||
{
|
||||
if (obj == null)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
return _collection.Insert(obj);
|
||||
}
|
||||
|
||||
public T remove(int pos)
|
||||
{
|
||||
T obj = _collection.Get(pos);
|
||||
if (obj != null)
|
||||
{
|
||||
_collection.Remove(pos);
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
|
||||
public U GetU(int pos)
|
||||
{
|
||||
return (U)_collection.Get(pos).GetMoveableObject();
|
||||
}
|
||||
|
||||
public BufferedImage ShowPlanes()
|
||||
{
|
||||
BufferedImage bmp = new BufferedImage(_pictureWidth, _pictureHeight, BufferedImage.TYPE_INT_ARGB);
|
||||
Graphics2D g = bmp.createGraphics();
|
||||
DrawBackground(g);
|
||||
DrawObjects(g);
|
||||
g.dispose();
|
||||
return bmp;
|
||||
}
|
||||
|
||||
private void DrawBackground(Graphics2D g)
|
||||
{
|
||||
g.setColor(Color.BLACK);
|
||||
|
||||
for (int i = 0; i < _pictureWidth / _placeSizeWidth; i++)
|
||||
{
|
||||
for (int j = 0; j < _pictureHeight / _placeSizeHeight + 1; ++j)
|
||||
{//линия рамзетки места
|
||||
g.drawLine( i * _placeSizeWidth, j * _placeSizeHeight, i * _placeSizeWidth + _placeSizeWidth / 2, j * _placeSizeHeight);
|
||||
}
|
||||
g.drawLine( i * _placeSizeWidth, 0, i * _placeSizeWidth, _pictureHeight / _placeSizeHeight * _placeSizeHeight);
|
||||
}
|
||||
}
|
||||
|
||||
private void DrawObjects(Graphics2D g)
|
||||
{
|
||||
int i = 0;
|
||||
for (T plane : _collection.GetPlanes(100))
|
||||
{
|
||||
if (plane != null)
|
||||
{
|
||||
plane.SetPosition((i % (_pictureWidth / _placeSizeWidth)) * _placeSizeWidth, (i / (_pictureWidth / _placeSizeWidth)) * _placeSizeHeight);
|
||||
if (plane instanceof DrawingHydroplane)
|
||||
((DrawingHydroplane)plane).DrawTransport(g);
|
||||
else
|
||||
plane.DrawTransport(g);
|
||||
}
|
||||
i++;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,52 @@
|
||||
package org.example;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class PlanesGenericStorage {
|
||||
|
||||
HashMap<String, PlanesGenericCollection<DrawingPlane, DrawningObjectPlane>> _planeStorages;
|
||||
|
||||
public List<String> Keys(){
|
||||
return _planeStorages.keySet().stream().collect(Collectors.toList());
|
||||
}
|
||||
|
||||
private int _pictureWidth;
|
||||
|
||||
private int _pictureHeight;
|
||||
|
||||
public PlanesGenericStorage(int pictureWidth, int pictureHeight)
|
||||
{
|
||||
_planeStorages = new HashMap<String, PlanesGenericCollection<DrawingPlane, DrawningObjectPlane>>();
|
||||
_pictureWidth = pictureWidth;
|
||||
_pictureHeight = pictureHeight;
|
||||
}
|
||||
|
||||
public void AddSet(String name)
|
||||
{
|
||||
if (_planeStorages.containsKey(name))
|
||||
return;
|
||||
_planeStorages.put(name, new PlanesGenericCollection<DrawingPlane, DrawningObjectPlane>(_pictureWidth, _pictureHeight));
|
||||
}
|
||||
|
||||
public void DelSet(String name)
|
||||
{
|
||||
if (!_planeStorages.containsKey(name))
|
||||
return;
|
||||
_planeStorages.remove(name);
|
||||
}
|
||||
|
||||
public PlanesGenericCollection<DrawingPlane, DrawningObjectPlane> get(String ind)
|
||||
{
|
||||
if (_planeStorages.containsKey(ind))
|
||||
return _planeStorages.get(ind);
|
||||
return null;
|
||||
}
|
||||
|
||||
public DrawningObjectPlane get(String ind1, int ind2){
|
||||
if (!_planeStorages.containsKey(ind1))
|
||||
return null;
|
||||
return _planeStorages.get(ind1).GetU(ind2);
|
||||
}
|
||||
}
|
89
Hydroplane/src/main/java/org/example/SetGeneric.java
Normal file
89
Hydroplane/src/main/java/org/example/SetGeneric.java
Normal file
@ -0,0 +1,89 @@
|
||||
package org.example;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.NoSuchElementException;
|
||||
|
||||
public class SetGeneric<T extends Object> {
|
||||
|
||||
private ArrayList<T>_places;
|
||||
|
||||
public int Count () { return _places.size();};
|
||||
|
||||
private int _maxCount;
|
||||
|
||||
public SetGeneric(int count)
|
||||
{
|
||||
_maxCount = count;
|
||||
_places = new ArrayList<T>(count);
|
||||
}
|
||||
|
||||
public int Insert(T plane)
|
||||
{
|
||||
if (_places.size() >= _maxCount)
|
||||
return -1;
|
||||
_places.add(0, plane);
|
||||
return 0;
|
||||
}
|
||||
|
||||
public boolean Insert(T plane, int position)
|
||||
{
|
||||
if (_places.size() >= _maxCount)
|
||||
return false;
|
||||
|
||||
if (position < 0 || position > _places.size())
|
||||
return false;
|
||||
|
||||
if (position == _places.size())
|
||||
_places.add(plane);
|
||||
else
|
||||
_places.add(position, plane);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean Remove(int position)
|
||||
{
|
||||
if (position < 0 || position >= _places.size())
|
||||
return false;
|
||||
_places.remove(position);
|
||||
return true;
|
||||
}
|
||||
|
||||
public T Get(int position)
|
||||
{
|
||||
if (position < 0 || position >= _places.size())
|
||||
return null;
|
||||
return _places.get(position);
|
||||
}
|
||||
|
||||
public Iterable<T> GetPlanes(final Integer maxPlanes) {
|
||||
return new Iterable<T>() {
|
||||
@Override
|
||||
public Iterator<T> iterator() {
|
||||
return new Iterator<T>() {
|
||||
private int currentIndex = 0;
|
||||
private int count = 0;
|
||||
|
||||
@Override
|
||||
public boolean hasNext() {
|
||||
return currentIndex < _places.size() && (maxPlanes == null || count < maxPlanes);
|
||||
}
|
||||
|
||||
@Override
|
||||
public T next() {
|
||||
if (hasNext()) {
|
||||
count++;
|
||||
return _places.get(currentIndex++);
|
||||
}
|
||||
throw new NoSuchElementException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
};
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
8
Hydroplane/src/main/java/org/example/Status.java
Normal file
8
Hydroplane/src/main/java/org/example/Status.java
Normal file
@ -0,0 +1,8 @@
|
||||
package org.example;
|
||||
|
||||
public enum Status {
|
||||
NotInit,
|
||||
InProgress,
|
||||
Finish
|
||||
}
|
||||
|
61
Hydroplane/src/main/java/org/example/WindowDrawing.java
Normal file
61
Hydroplane/src/main/java/org/example/WindowDrawing.java
Normal file
@ -0,0 +1,61 @@
|
||||
package org.example;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
public class WindowDrawing implements IWindowDrawing{
|
||||
|
||||
private NumWindow numWindow;
|
||||
|
||||
public NumWindow getNumWindow() {
|
||||
return numWindow;
|
||||
}
|
||||
|
||||
public void setNumWindow(int kWindow){
|
||||
switch(kWindow){
|
||||
case 10:
|
||||
numWindow = NumWindow.tenWindows;
|
||||
break;
|
||||
case 20:
|
||||
numWindow = NumWindow.twentyWindows;
|
||||
break;
|
||||
case 30:
|
||||
numWindow = NumWindow.thirtyWindows;
|
||||
break;
|
||||
default:
|
||||
numWindow = NumWindow.tenWindows;
|
||||
System.out.println("Произошел косяк с количеством, но давайте их будет 10, вообще было " + kWindow);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void Draw(int _startPosX, int _startPosY, Color color, Graphics2D g){
|
||||
g.setColor(color);
|
||||
switch (numWindow) {
|
||||
case tenWindows -> {
|
||||
for (int i = 0; i < 10; i++) {
|
||||
g.fillOval(_startPosX + 35 + i * 8, _startPosY + 28, 4, 4);
|
||||
}
|
||||
}
|
||||
case twentyWindows -> {
|
||||
for (int i = 0; i < 10; i++) {
|
||||
g.fillOval(_startPosX + 35 + i * 8, _startPosY + 28, 4, 4);
|
||||
}
|
||||
for (int i = 0; i < 10; i++) {
|
||||
g.fillOval(_startPosX + 35 + i * 8, _startPosY + 28 + 6, 4, 4);
|
||||
}
|
||||
}
|
||||
case thirtyWindows -> {
|
||||
for (int i = 0; i < 10; i++) {
|
||||
g.fillOval(_startPosX + 35 + i * 8, _startPosY + 28, 4, 4);
|
||||
}
|
||||
for (int i = 0; i < 10; i++) {
|
||||
g.fillOval(_startPosX + 35 + i * 8, _startPosY + 28 + 5, 4, 4);
|
||||
}
|
||||
for (int i = 0; i < 10; i++) {
|
||||
g.fillOval(_startPosX + 35 + i * 8, _startPosY + 28 + 10, 4, 4);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
61
Hydroplane/src/main/java/org/example/WindowDrawingRect.java
Normal file
61
Hydroplane/src/main/java/org/example/WindowDrawingRect.java
Normal file
@ -0,0 +1,61 @@
|
||||
package org.example;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
public class WindowDrawingRect implements IWindowDrawing{
|
||||
|
||||
private NumWindow numWindow;
|
||||
|
||||
public NumWindow getNumWindow() {
|
||||
return numWindow;
|
||||
}
|
||||
|
||||
public void setNumWindow(int kWindow){
|
||||
switch(kWindow){
|
||||
case 10:
|
||||
numWindow = NumWindow.tenWindows;
|
||||
break;
|
||||
case 20:
|
||||
numWindow = NumWindow.twentyWindows;
|
||||
break;
|
||||
case 30:
|
||||
numWindow = NumWindow.thirtyWindows;
|
||||
break;
|
||||
default:
|
||||
numWindow = NumWindow.tenWindows;
|
||||
System.out.println("Произошел косяк с количеством, но давайте их будет 10, вообще было " + kWindow);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void Draw(int _startPosX, int _startPosY, Color color, Graphics2D g){
|
||||
g.setColor(color);
|
||||
switch (numWindow) {
|
||||
case tenWindows -> {
|
||||
for (int i = 0; i < 10; i++) {
|
||||
g.fillRect(_startPosX + 35 + i * 8, _startPosY + 28, 4, 4);
|
||||
}
|
||||
}
|
||||
case twentyWindows -> {
|
||||
for (int i = 0; i < 10; i++) {
|
||||
g.fillRect(_startPosX + 35 + i * 8, _startPosY + 28, 4, 4);
|
||||
}
|
||||
for (int i = 0; i < 10; i++) {
|
||||
g.fillRect(_startPosX + 35 + i * 8, _startPosY + 28 + 5, 4, 4);
|
||||
}
|
||||
}
|
||||
case thirtyWindows -> {
|
||||
for (int i = 0; i < 10; i++) {
|
||||
g.fillRect(_startPosX + 35 + i * 8, _startPosY + 28, 4, 4);
|
||||
}
|
||||
for (int i = 0; i < 10; i++) {
|
||||
g.fillRect(_startPosX + 35 + i * 8, _startPosY + 28 + 5, 4, 4);
|
||||
}
|
||||
for (int i = 0; i < 10; i++) {
|
||||
g.fillRect(_startPosX + 35 + i * 8, _startPosY + 28 + 10, 4, 4);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,79 @@
|
||||
package org.example;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
public class WindowDrawingTringle implements IWindowDrawing{
|
||||
|
||||
private NumWindow numWindow;
|
||||
|
||||
public NumWindow getNumWindow() {
|
||||
return numWindow;
|
||||
}
|
||||
|
||||
public void setNumWindow(int kWindow){
|
||||
switch(kWindow){
|
||||
case 10:
|
||||
numWindow = NumWindow.tenWindows;
|
||||
break;
|
||||
case 20:
|
||||
numWindow = NumWindow.twentyWindows;
|
||||
break;
|
||||
case 30:
|
||||
numWindow = NumWindow.thirtyWindows;
|
||||
break;
|
||||
default:
|
||||
numWindow = NumWindow.tenWindows;
|
||||
System.out.println("Произошел косяк с количеством, но давайте их будет 10, вообще было " + kWindow);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void Draw(int _startPosX, int _startPosY, Color color, Graphics2D g){
|
||||
g.setColor(color);
|
||||
switch (numWindow) {
|
||||
case tenWindows -> {
|
||||
for (int i = 0; i < 10; i++) {
|
||||
g.fillPolygon(
|
||||
new int[]{ _startPosX + 35 + i * 8, _startPosX + 35 + i * 8 + 2, _startPosX + 35 + i * 8 + 4 },
|
||||
new int[]{ _startPosY + 30, _startPosY + 30 + 4, _startPosY + 30 },
|
||||
3);
|
||||
}
|
||||
}
|
||||
case twentyWindows -> {
|
||||
for (int i = 0; i < 10; i++) {
|
||||
g.fillPolygon(
|
||||
new int[]{ _startPosX + 35 + i * 8, _startPosX + 35 + i * 8 + 2, _startPosX + 35 + i * 8 + 4 },
|
||||
new int[]{ _startPosY + 30, _startPosY + 30 + 4, _startPosY + 30 },
|
||||
3);
|
||||
}
|
||||
for (int i = 0; i < 10; i++) {
|
||||
g.fillPolygon(
|
||||
new int[]{ _startPosX + 35 + i * 8, _startPosX + 35 + i * 8 + 2, _startPosX + 35 + i * 8 + 4 },
|
||||
new int[]{ _startPosY + 30 + 5, _startPosY + 30 + 4 + 5, _startPosY + 30 + 5 },
|
||||
3);
|
||||
}
|
||||
}
|
||||
case thirtyWindows -> {
|
||||
for (int i = 0; i < 10; i++) {
|
||||
g.fillPolygon(
|
||||
new int[]{ _startPosX + 35 + i * 8, _startPosX + 35 + i * 8 + 2, _startPosX + 35 + i * 8 + 4 },
|
||||
new int[]{ _startPosY + 30, _startPosY + 30 + 4, _startPosY + 30 },
|
||||
3);
|
||||
}
|
||||
for (int i = 0; i < 10; i++) {
|
||||
g.fillPolygon(
|
||||
new int[]{ _startPosX + 35 + i * 8, _startPosX + 35 + i * 8 + 2, _startPosX + 35 + i * 8 + 4 },
|
||||
new int[]{ _startPosY + 30 + 5, _startPosY + 30 + 4 + 5, _startPosY + 30 + 5 },
|
||||
3);
|
||||
}
|
||||
for (int i = 0; i < 10; i++) {
|
||||
g.fillPolygon(
|
||||
new int[]{ _startPosX + 35 + i * 8, _startPosX + 35 + i * 8 + 2, _startPosX + 35 + i * 8 + 4 },
|
||||
new int[]{ _startPosY + 30 + 10, _startPosY + 30 + 4 + 10, _startPosY + 30 + 10 },
|
||||
3);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
BIN
Hydroplane/src/main/java/org/example/images/down.png
Normal file
BIN
Hydroplane/src/main/java/org/example/images/down.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 256 B |
BIN
Hydroplane/src/main/java/org/example/images/left.png
Normal file
BIN
Hydroplane/src/main/java/org/example/images/left.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 269 B |
BIN
Hydroplane/src/main/java/org/example/images/right.png
Normal file
BIN
Hydroplane/src/main/java/org/example/images/right.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 257 B |
BIN
Hydroplane/src/main/java/org/example/images/up.png
Normal file
BIN
Hydroplane/src/main/java/org/example/images/up.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 250 B |
Loading…
x
Reference in New Issue
Block a user