Compare commits
6 Commits
Author | SHA1 | Date | |
---|---|---|---|
4de23d08a2 | |||
baee495b53 | |||
78a8bd4fa1 | |||
e7a0a32fd9 | |||
8ee8e93ec6 | |||
2940b7d7da |
29
ProjectMonorail/.gitignore
vendored
Normal file
29
ProjectMonorail/.gitignore
vendored
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
### IntelliJ IDEA ###
|
||||||
|
out/
|
||||||
|
!**/src/main/**/out/
|
||||||
|
!**/src/test/**/out/
|
||||||
|
|
||||||
|
### Eclipse ###
|
||||||
|
.apt_generated
|
||||||
|
.classpath
|
||||||
|
.factorypath
|
||||||
|
.project
|
||||||
|
.settings
|
||||||
|
.springBeans
|
||||||
|
.sts4-cache
|
||||||
|
bin/
|
||||||
|
!**/src/main/**/bin/
|
||||||
|
!**/src/test/**/bin/
|
||||||
|
|
||||||
|
### NetBeans ###
|
||||||
|
/nbproject/private/
|
||||||
|
/nbbuild/
|
||||||
|
/dist/
|
||||||
|
/nbdist/
|
||||||
|
/.nb-gradle/
|
||||||
|
|
||||||
|
### VS Code ###
|
||||||
|
.vscode/
|
||||||
|
|
||||||
|
### Mac OS ###
|
||||||
|
.DS_Store
|
8
ProjectMonorail/.idea/.gitignore
vendored
Normal file
8
ProjectMonorail/.idea/.gitignore
vendored
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
# Default ignored files
|
||||||
|
/shelf/
|
||||||
|
/workspace.xml
|
||||||
|
# Editor-based HTTP Client requests
|
||||||
|
/httpRequests/
|
||||||
|
# Datasource local storage ignored files
|
||||||
|
/dataSources/
|
||||||
|
/dataSources.local.xml
|
6
ProjectMonorail/.idea/misc.xml
Normal file
6
ProjectMonorail/.idea/misc.xml
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="ProjectRootManager" version="2" languageLevel="JDK_21" default="true" project-jdk-name="openjdk-21" project-jdk-type="JavaSDK">
|
||||||
|
<output url="file://$PROJECT_DIR$/out" />
|
||||||
|
</component>
|
||||||
|
</project>
|
8
ProjectMonorail/.idea/modules.xml
Normal file
8
ProjectMonorail/.idea/modules.xml
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$/ProjectMonorail.iml" filepath="$PROJECT_DIR$/ProjectMonorail.iml" />
|
||||||
|
</modules>
|
||||||
|
</component>
|
||||||
|
</project>
|
124
ProjectMonorail/.idea/uiDesigner.xml
Normal file
124
ProjectMonorail/.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>
|
6
ProjectMonorail/.idea/vcs.xml
Normal file
6
ProjectMonorail/.idea/vcs.xml
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>
|
@ -5,14 +5,15 @@
|
|||||||
</component>
|
</component>
|
||||||
<component name="ChangeListManager">
|
<component name="ChangeListManager">
|
||||||
<list default="true" id="39e7c520-e505-4e53-a269-c949d7c9f5d1" name="Changes" comment="">
|
<list default="true" id="39e7c520-e505-4e53-a269-c949d7c9f5d1" name="Changes" comment="">
|
||||||
<change afterPath="$PROJECT_DIR$/src/Scripts/Wheels/DrawOrnament.java" afterDir="false" />
|
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
||||||
<change afterPath="$PROJECT_DIR$/src/Scripts/Wheels/DrawOrnamentOval.java" afterDir="false" />
|
<change beforePath="$PROJECT_DIR$/src/CountWheels.java" beforeDir="false" />
|
||||||
<change afterPath="$PROJECT_DIR$/src/Scripts/Wheels/DrawOrnamentTriangle.java" afterDir="false" />
|
<change beforePath="$PROJECT_DIR$/src/DirectionType.java" beforeDir="false" />
|
||||||
<change afterPath="$PROJECT_DIR$/src/Scripts/Wheels/IOrnament.java" afterDir="false" />
|
<change beforePath="$PROJECT_DIR$/src/DrawingField.java" beforeDir="false" />
|
||||||
<change beforePath="$PROJECT_DIR$/src/Scripts/CountWheels.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/Scripts/Wheels/CountWheels.java" afterDir="false" />
|
<change beforePath="$PROJECT_DIR$/src/DrawingModernMonorail.java" beforeDir="false" />
|
||||||
<change beforePath="$PROJECT_DIR$/src/Scripts/DrawingModernMonorail.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/Scripts/DrawingModernMonorail.java" afterDir="false" />
|
<change beforePath="$PROJECT_DIR$/src/DrawingWheels.java" beforeDir="false" />
|
||||||
<change beforePath="$PROJECT_DIR$/src/Scripts/DrawingMonorail.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/Scripts/DrawingMonorail.java" afterDir="false" />
|
<change beforePath="$PROJECT_DIR$/src/EntityModernMonorail.java" beforeDir="false" />
|
||||||
<change beforePath="$PROJECT_DIR$/src/Scripts/DrawingWheels.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/Scripts/Wheels/DrawingWheels.java" afterDir="false" />
|
<change beforePath="$PROJECT_DIR$/src/FormModernMonorail.java" beforeDir="false" />
|
||||||
|
<change beforePath="$PROJECT_DIR$/src/Program.java" beforeDir="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" />
|
||||||
@ -43,7 +44,7 @@
|
|||||||
"Application.Program.executor": "Run",
|
"Application.Program.executor": "Run",
|
||||||
"RunOnceActivity.OpenProjectViewOnStart": "true",
|
"RunOnceActivity.OpenProjectViewOnStart": "true",
|
||||||
"RunOnceActivity.ShowReadmeOnStart": "true",
|
"RunOnceActivity.ShowReadmeOnStart": "true",
|
||||||
"git-widget-placeholder": "LabWork__2",
|
"git-widget-placeholder": "LabWorking__2",
|
||||||
"kotlin-language-version-configured": "true"
|
"kotlin-language-version-configured": "true"
|
||||||
}
|
}
|
||||||
}]]></component>
|
}]]></component>
|
||||||
@ -60,6 +61,7 @@
|
|||||||
<attachedChunks>
|
<attachedChunks>
|
||||||
<set>
|
<set>
|
||||||
<option value="jdk-21.0.2-openjdk-21.0.2-4caba194b151-4f524021" />
|
<option value="jdk-21.0.2-openjdk-21.0.2-4caba194b151-4f524021" />
|
||||||
|
<option value="jdk-22-openjdk-22-3183f394aec4-bad0321e" />
|
||||||
</set>
|
</set>
|
||||||
</attachedChunks>
|
</attachedChunks>
|
||||||
</component>
|
</component>
|
||||||
|
11
ProjectMonorail/ProjectMonorail.iml
Normal file
11
ProjectMonorail/ProjectMonorail.iml
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
<?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$">
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||||
|
</content>
|
||||||
|
<orderEntry type="inheritedJdk" />
|
||||||
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
|
</component>
|
||||||
|
</module>
|
BIN
ProjectMonorail/Resource/Arrows/ArrowDown.png
Normal file
BIN
ProjectMonorail/Resource/Arrows/ArrowDown.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.0 KiB |
BIN
ProjectMonorail/Resource/Arrows/ArrowLeft.png
Normal file
BIN
ProjectMonorail/Resource/Arrows/ArrowLeft.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.9 KiB |
BIN
ProjectMonorail/Resource/Arrows/ArrowRight.png
Normal file
BIN
ProjectMonorail/Resource/Arrows/ArrowRight.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.9 KiB |
BIN
ProjectMonorail/Resource/Arrows/ArrowUp.png
Normal file
BIN
ProjectMonorail/Resource/Arrows/ArrowUp.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.9 KiB |
@ -0,0 +1,36 @@
|
|||||||
|
package Scripts.CollectionGenericObjects;
|
||||||
|
|
||||||
|
import Scripts.Drawing.DrawingMonorail;
|
||||||
|
|
||||||
|
import java.awt.*;
|
||||||
|
|
||||||
|
public abstract class AbstractCompany {
|
||||||
|
protected int _placeSizeWidth = 220;
|
||||||
|
protected int _placeSizeHeight = 155;
|
||||||
|
protected int _pictureWidth;
|
||||||
|
protected int _pictureHeight;
|
||||||
|
public ICollectionGenericObjects<DrawingMonorail> _collection = null;
|
||||||
|
private int GetMaxCount() {
|
||||||
|
return _pictureWidth * _pictureHeight / (_placeSizeWidth * _placeSizeHeight);
|
||||||
|
|
||||||
|
}
|
||||||
|
public AbstractCompany(int picWidth, int picHeight, ICollectionGenericObjects<DrawingMonorail> collection)
|
||||||
|
{
|
||||||
|
_pictureWidth = picWidth;
|
||||||
|
_pictureHeight = picHeight;
|
||||||
|
_collection = collection;
|
||||||
|
System.out.println(_pictureHeight+" "+_pictureWidth+" "+_placeSizeHeight+" "+_placeSizeWidth);
|
||||||
|
_collection.SetMaxCount(GetMaxCount());
|
||||||
|
}
|
||||||
|
//Перегрузок нет
|
||||||
|
public DrawingMonorail GetRandomObject()
|
||||||
|
{
|
||||||
|
return _collection.Get((int)(Math.random()*GetMaxCount() + 0));
|
||||||
|
}
|
||||||
|
public void SetPosition()
|
||||||
|
{
|
||||||
|
SetObjectsPosition();
|
||||||
|
}
|
||||||
|
public abstract void DrawBackgound(Graphics graphics);
|
||||||
|
protected abstract void SetObjectsPosition();
|
||||||
|
}
|
@ -0,0 +1,61 @@
|
|||||||
|
package Scripts.CollectionGenericObjects;
|
||||||
|
|
||||||
|
import Scripts.Drawing.DrawingModernMonorail;
|
||||||
|
import Scripts.Drawing.DrawingMonorail;
|
||||||
|
import Scripts.Entities.EntityModernMonorail;
|
||||||
|
import Scripts.Entities.EntityMonorail;
|
||||||
|
import Scripts.Wheels.IDrawingWheels;
|
||||||
|
|
||||||
|
import java.lang.reflect.Array;
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
|
public class AdditionalCollection <T extends EntityMonorail, U extends IDrawingWheels>{
|
||||||
|
public T[] CollectionEntity;
|
||||||
|
public U[] CollectionWheels;
|
||||||
|
public AdditionalCollection(int size, Class<T> type1, Class<T> type2) {
|
||||||
|
CollectionEntity = (T[]) Array.newInstance(type1, size);
|
||||||
|
CollectionWheels = (U[]) Array.newInstance(type2, size);
|
||||||
|
CountEntities = size;
|
||||||
|
CountWheels = size;
|
||||||
|
}
|
||||||
|
public int CountEntities;
|
||||||
|
public int CountWheels;
|
||||||
|
public int Insert(T entity) {
|
||||||
|
int index = 0;
|
||||||
|
while (index < CountEntities) {
|
||||||
|
if (CollectionEntity[index] == null)
|
||||||
|
{
|
||||||
|
CollectionEntity[index] = entity;
|
||||||
|
return index;
|
||||||
|
}
|
||||||
|
++index;
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
public int Insert(U decks) {
|
||||||
|
int index = 0;
|
||||||
|
while (index < CountWheels) {
|
||||||
|
if (CollectionWheels[index] == null)
|
||||||
|
{
|
||||||
|
CollectionWheels[index] = decks;
|
||||||
|
return index;
|
||||||
|
}
|
||||||
|
++index;
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
public DrawingMonorail CreateAdditionalCollectionMonorail() {
|
||||||
|
Random random = new Random();
|
||||||
|
if (CollectionEntity == null || CollectionWheels == null) return null;
|
||||||
|
T entity = CollectionEntity[random.nextInt(CountEntities)];
|
||||||
|
U wheels = CollectionWheels[random.nextInt(CountWheels)];
|
||||||
|
DrawingMonorail drawingBaseStormtrooper = null;
|
||||||
|
if (entity instanceof EntityModernMonorail) {
|
||||||
|
drawingBaseStormtrooper = new DrawingModernMonorail((EntityModernMonorail)entity, wheels);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
drawingBaseStormtrooper = new DrawingMonorail(entity, wheels);
|
||||||
|
}
|
||||||
|
return drawingBaseStormtrooper;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,7 @@
|
|||||||
|
package Scripts.CollectionGenericObjects;
|
||||||
|
|
||||||
|
public enum CollectionType {
|
||||||
|
None,
|
||||||
|
Massive,
|
||||||
|
List
|
||||||
|
}
|
@ -0,0 +1,48 @@
|
|||||||
|
package Scripts.CollectionGenericObjects;
|
||||||
|
|
||||||
|
import Scripts.Drawing.DrawingMonorail;
|
||||||
|
|
||||||
|
import java.awt.*;
|
||||||
|
|
||||||
|
public class DepotSharingService extends AbstractCompany {
|
||||||
|
public DepotSharingService (int picWidth, int picHeight, ICollectionGenericObjects<DrawingMonorail> collection) {
|
||||||
|
super(picWidth, picHeight, collection);
|
||||||
|
}
|
||||||
|
|
||||||
|
private int _offsetX = 30;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void DrawBackgound(Graphics graphics) {
|
||||||
|
int width = _pictureWidth / _placeSizeWidth;
|
||||||
|
int height = _pictureHeight / _placeSizeHeight;
|
||||||
|
graphics.setColor(Color.BLACK);
|
||||||
|
for (int i = 0; i < width; i++)
|
||||||
|
{
|
||||||
|
for (int j = 0; j < height; ++j)
|
||||||
|
{
|
||||||
|
graphics.drawLine(i * _offsetX + i * _placeSizeWidth, j * _placeSizeHeight, _placeSizeWidth + i * _offsetX + i * _placeSizeWidth, j * _placeSizeHeight);
|
||||||
|
graphics.drawLine(i * _offsetX + i * _placeSizeWidth, j * _placeSizeHeight, i * _offsetX + i * _placeSizeWidth, _placeSizeHeight + j * _placeSizeHeight);
|
||||||
|
graphics.drawLine(i * _offsetX + i * _placeSizeWidth, _placeSizeHeight + j * _placeSizeHeight, _placeSizeWidth + i * _offsetX + i * _placeSizeWidth, _placeSizeHeight + j * _placeSizeHeight);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
protected void SetObjectsPosition() {
|
||||||
|
int width = _pictureWidth / _placeSizeWidth;
|
||||||
|
int height = _pictureHeight / _placeSizeHeight;
|
||||||
|
|
||||||
|
int boarderOffsetX = 20;
|
||||||
|
int boarderOffsetY = 20;
|
||||||
|
|
||||||
|
int currnetIndex = 0;
|
||||||
|
|
||||||
|
for (int j = height - 1; j >= 0; j--) {
|
||||||
|
for (int i = 0; i < width; i++, currnetIndex++) {
|
||||||
|
if (_collection.Get(currnetIndex) == null) continue;
|
||||||
|
|
||||||
|
_collection.Get(currnetIndex).SetPictureSize(_pictureWidth, _pictureHeight);
|
||||||
|
_collection.Get(currnetIndex).SetPosition(boarderOffsetX + i * _placeSizeWidth + i * _offsetX, boarderOffsetY + j * _placeSizeHeight);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,13 @@
|
|||||||
|
package Scripts.CollectionGenericObjects;
|
||||||
|
|
||||||
|
public interface ICollectionGenericObjects<T>
|
||||||
|
{
|
||||||
|
int getCount();
|
||||||
|
void SetMaxCount(int count);
|
||||||
|
int Insert(T obj);
|
||||||
|
T Remove(int position);
|
||||||
|
T Get(int position);
|
||||||
|
CollectionType GetCollectionType();
|
||||||
|
Iterable<T> GetItems();
|
||||||
|
void ClearCollection();
|
||||||
|
}
|
@ -0,0 +1,88 @@
|
|||||||
|
package Scripts.CollectionGenericObjects;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.NoSuchElementException;
|
||||||
|
|
||||||
|
public class ListGenericObjects<T> implements ICollectionGenericObjects<T> {
|
||||||
|
private List<T> _collection;
|
||||||
|
private CollectionType collectionType = CollectionType.List;
|
||||||
|
private int _maxCount;
|
||||||
|
|
||||||
|
public int getCount() {
|
||||||
|
return _collection.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CollectionType GetCollectionType() {
|
||||||
|
return collectionType;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void SetMaxCount(int size) {
|
||||||
|
if (size > 0) {
|
||||||
|
_maxCount = size;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public ListGenericObjects() {
|
||||||
|
_collection = new ArrayList<T>();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public T Get(int position)
|
||||||
|
{
|
||||||
|
if (position >= getCount() || position < 0) return null;
|
||||||
|
return _collection.get(position);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int Insert(T obj)
|
||||||
|
{
|
||||||
|
if (getCount() == _maxCount) return -1;
|
||||||
|
_collection.add(obj);
|
||||||
|
return getCount();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public T Remove(int position)
|
||||||
|
{
|
||||||
|
if (position >= getCount() || position < 0) return null;
|
||||||
|
T obj = _collection.get(position);
|
||||||
|
_collection.remove(position);
|
||||||
|
return obj;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Iterable<T> GetItems() {
|
||||||
|
return new Iterable<T>() {
|
||||||
|
@Override
|
||||||
|
public Iterator<T> iterator() {
|
||||||
|
return new Iterator<T>() {
|
||||||
|
private int currentIndex = 0;
|
||||||
|
//нужен ли count
|
||||||
|
private int count = 0;
|
||||||
|
@Override
|
||||||
|
public boolean hasNext() {
|
||||||
|
return currentIndex < getCount();
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public T next() {
|
||||||
|
if (hasNext()) {
|
||||||
|
count++;
|
||||||
|
return _collection.get(currentIndex++);
|
||||||
|
}
|
||||||
|
throw new NoSuchElementException();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public void ClearCollection() {
|
||||||
|
for (T ship : _collection) {
|
||||||
|
ship = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,92 @@
|
|||||||
|
package Scripts.CollectionGenericObjects;
|
||||||
|
|
||||||
|
import Scripts.Drawing.DrawingMonorail;
|
||||||
|
|
||||||
|
import java.lang.reflect.Array;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.NoSuchElementException;
|
||||||
|
|
||||||
|
public class MassiveGenericObjects<T> implements ICollectionGenericObjects<T>
|
||||||
|
{
|
||||||
|
private T[] _collection;
|
||||||
|
private CollectionType collectionType = CollectionType.Massive;
|
||||||
|
private int Count;
|
||||||
|
public void SetMaxCount(int size) {
|
||||||
|
if (size > 0) {
|
||||||
|
if (_collection == null) {
|
||||||
|
_collection = (T[]) Array.newInstance((Class) DrawingMonorail.class, size);
|
||||||
|
Count = size;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CollectionType GetCollectionType() {
|
||||||
|
return collectionType;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getCount() {
|
||||||
|
return Count;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int Insert(T obj) {
|
||||||
|
int index = 0;
|
||||||
|
while (index < getCount())
|
||||||
|
{
|
||||||
|
if (_collection[index] == null)
|
||||||
|
{
|
||||||
|
_collection[index] = obj;
|
||||||
|
return index;
|
||||||
|
}
|
||||||
|
++index;
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public T Remove(int position) {
|
||||||
|
if (position >= getCount() || position < 0)
|
||||||
|
return null;
|
||||||
|
T obj = (T) _collection[position];
|
||||||
|
_collection[position] = null;
|
||||||
|
return obj;
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public T Get(int position) {
|
||||||
|
if (position >= getCount() || position < 0) return null;
|
||||||
|
return (T) _collection[position];
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Iterable<T> GetItems() {
|
||||||
|
return new Iterable<T>() {
|
||||||
|
@Override
|
||||||
|
public Iterator<T> iterator() {
|
||||||
|
return new Iterator<T>() {
|
||||||
|
private int currentIndex = 0;
|
||||||
|
//нужен ли count
|
||||||
|
private int count = 0;
|
||||||
|
@Override
|
||||||
|
public boolean hasNext() {
|
||||||
|
return currentIndex < getCount();
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public T next() {
|
||||||
|
if (hasNext()) {
|
||||||
|
count++;
|
||||||
|
return _collection[currentIndex++];
|
||||||
|
}
|
||||||
|
throw new NoSuchElementException();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public void ClearCollection() {
|
||||||
|
for (T ship : _collection) {
|
||||||
|
ship = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,195 @@
|
|||||||
|
package Scripts.CollectionGenericObjects;
|
||||||
|
|
||||||
|
import Scripts.Drawing.DrawingMonorail;
|
||||||
|
import Scripts.Drawing.ExtentionDrawningMonorail;
|
||||||
|
|
||||||
|
import java.io.*;
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
public class StorageCollection<T extends DrawingMonorail> {
|
||||||
|
private Map<String, ICollectionGenericObjects<T>> _storages;
|
||||||
|
public StorageCollection()
|
||||||
|
{
|
||||||
|
_storages = new HashMap<String, ICollectionGenericObjects<T>>();
|
||||||
|
}
|
||||||
|
public Set<String> Keys() {
|
||||||
|
Set<String> keys = _storages.keySet();
|
||||||
|
return keys;
|
||||||
|
}
|
||||||
|
public void SetCollectionObject(String name, CollectionType collectionType)
|
||||||
|
{
|
||||||
|
if (_storages.containsKey(name)) return;
|
||||||
|
if (collectionType == CollectionType.None) return;
|
||||||
|
else if (collectionType == CollectionType.Massive)
|
||||||
|
_storages.put(name, new MassiveGenericObjects<T>());
|
||||||
|
else if (collectionType == CollectionType.List)
|
||||||
|
_storages.put(name, new ListGenericObjects<T>());
|
||||||
|
}
|
||||||
|
public void DelCollection(String name)
|
||||||
|
{
|
||||||
|
if (_storages.containsKey(name))
|
||||||
|
_storages.remove(name);
|
||||||
|
}
|
||||||
|
public ICollectionGenericObjects<T> GetCollectionObject(String name) {
|
||||||
|
if (_storages.containsKey(name))
|
||||||
|
return _storages.get(name);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public T remove(String name, int position){
|
||||||
|
if(_storages.containsKey(name))
|
||||||
|
return _storages.get(name).Remove(position);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String _collectionKey = "CollectionsStorage";
|
||||||
|
private String _collectionName = "StorageCollection";
|
||||||
|
private String _separatorForKeyValueS = "|";
|
||||||
|
private String _separatorForKeyValue = "\\|";
|
||||||
|
private String _separatorItemsS = ";";
|
||||||
|
private String _separatorItems = "\\;";
|
||||||
|
public boolean SaveData(String filename) {
|
||||||
|
if (_storages.isEmpty()) return false;
|
||||||
|
File file = new File(filename);
|
||||||
|
if (file.exists()) file.delete();
|
||||||
|
try {
|
||||||
|
file.createNewFile();
|
||||||
|
FileWriter writer = new FileWriter(file);
|
||||||
|
writer.write(_collectionKey);
|
||||||
|
writer.write("\n");
|
||||||
|
for (Map.Entry<String, ICollectionGenericObjects<T>> value : _storages.entrySet()) {
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
sb.append(value.getKey());
|
||||||
|
sb.append(_separatorForKeyValueS);
|
||||||
|
sb.append(value.getValue().GetCollectionType());
|
||||||
|
sb.append(_separatorForKeyValueS);
|
||||||
|
sb.append(value.getValue().getCount());
|
||||||
|
sb.append(_separatorForKeyValueS);
|
||||||
|
for (T monorail : value.getValue().GetItems()) {
|
||||||
|
String data = ExtentionDrawningMonorail.GetDataForSave((DrawingMonorail) monorail);
|
||||||
|
if (data.isEmpty()) continue;
|
||||||
|
sb.append(data);
|
||||||
|
sb.append(_separatorItemsS);
|
||||||
|
}
|
||||||
|
sb.append("\n");
|
||||||
|
writer.write(String.valueOf(sb));
|
||||||
|
}
|
||||||
|
writer.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
public boolean SaveOneCollection(String filename, String name) {
|
||||||
|
if (_storages.isEmpty()) return false;
|
||||||
|
File file = new File(filename);
|
||||||
|
if (file.exists()) file.delete();
|
||||||
|
try {
|
||||||
|
file.createNewFile();
|
||||||
|
FileWriter writer = new FileWriter(file);
|
||||||
|
writer.write(_collectionName);
|
||||||
|
writer.write("\n");
|
||||||
|
ICollectionGenericObjects<T> value = _storages.get(name);
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
sb.append(name);
|
||||||
|
sb.append(_separatorForKeyValueS);
|
||||||
|
sb.append(value.GetCollectionType());
|
||||||
|
sb.append(_separatorForKeyValueS);
|
||||||
|
sb.append(value.getCount());
|
||||||
|
sb.append(_separatorForKeyValueS);
|
||||||
|
for (T monorail : value.GetItems()) {
|
||||||
|
String data = ExtentionDrawningMonorail.GetDataForSave((DrawingMonorail) monorail);
|
||||||
|
if (data.isEmpty()) continue;
|
||||||
|
sb.append(data);
|
||||||
|
sb.append(_separatorItemsS);
|
||||||
|
}
|
||||||
|
writer.append(sb);
|
||||||
|
writer.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
public boolean LoadData(String filename) {
|
||||||
|
File file = new File(filename);
|
||||||
|
if (!file.exists()) return false;
|
||||||
|
try (BufferedReader fs = new BufferedReader(new FileReader(filename))) {
|
||||||
|
String s = fs.readLine();
|
||||||
|
if (s == null || s.isEmpty() || !s.startsWith(_collectionKey))
|
||||||
|
return false;
|
||||||
|
_storages.clear();
|
||||||
|
s = "";
|
||||||
|
while ((s = fs.readLine()) != null) {
|
||||||
|
String[] record = s.split(_separatorForKeyValue);
|
||||||
|
if (record.length != 4) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
ICollectionGenericObjects<T> collection = CreateCollection(record[1]);
|
||||||
|
if (collection == null)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
collection.SetMaxCount(Integer.parseInt(record[2]));
|
||||||
|
String[] set = record[3].split(_separatorItems);
|
||||||
|
for (String elem : set) {
|
||||||
|
DrawingMonorail ship = ExtentionDrawningMonorail.CreateDrawingShip(elem);
|
||||||
|
if (collection.Insert((T) ship) == -1)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_storages.put(record[0], collection);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
catch (IOException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public boolean LoadOneCollection(String filename) {
|
||||||
|
File file = new File(filename);
|
||||||
|
if (!file.exists()) return false;
|
||||||
|
try (BufferedReader fs = new BufferedReader(new FileReader(filename))) {
|
||||||
|
String s = fs.readLine();
|
||||||
|
if (s == null || s.isEmpty() || !s.startsWith(_collectionName))
|
||||||
|
return false;
|
||||||
|
if (_storages.containsKey(s)) {
|
||||||
|
_storages.get(s).ClearCollection();
|
||||||
|
}
|
||||||
|
s = fs.readLine();
|
||||||
|
String[] record = s.split(_separatorForKeyValue);
|
||||||
|
if (record.length != 4) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
ICollectionGenericObjects<T> collection = CreateCollection(record[1]);
|
||||||
|
if (collection == null)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
collection.SetMaxCount(Integer.parseInt(record[2]));
|
||||||
|
String[] set = record[3].split(_separatorItems);
|
||||||
|
for (String elem : set) {
|
||||||
|
DrawingMonorail monorail = ExtentionDrawningMonorail.CreateDrawingShip(elem);
|
||||||
|
if (collection.Insert((T) monorail) == -1)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_storages.put(record[0], collection);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
catch (IOException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public ICollectionGenericObjects<T> CreateCollection(String s) {
|
||||||
|
switch (s) {
|
||||||
|
case "Massive":
|
||||||
|
return new MassiveGenericObjects<T>();
|
||||||
|
case "List":
|
||||||
|
return new ListGenericObjects<T>();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
8
ProjectMonorail/src/Scripts/Drawing/DirectionType.java
Normal file
8
ProjectMonorail/src/Scripts/Drawing/DirectionType.java
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
package Scripts.Drawing;
|
||||||
|
|
||||||
|
public enum DirectionType {
|
||||||
|
Up,
|
||||||
|
Down,
|
||||||
|
Left,
|
||||||
|
Right;
|
||||||
|
}
|
71
ProjectMonorail/src/Scripts/Drawing/DrawingField.java
Normal file
71
ProjectMonorail/src/Scripts/Drawing/DrawingField.java
Normal file
@ -0,0 +1,71 @@
|
|||||||
|
package Scripts.Drawing;
|
||||||
|
|
||||||
|
import Scripts.Forms.FormModernMonorail;
|
||||||
|
|
||||||
|
import javax.swing.*;
|
||||||
|
import java.awt.*;
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
|
public class DrawingField extends JPanel {
|
||||||
|
private final FormModernMonorail field;
|
||||||
|
private DrawingMonorail _drawingMonorail;
|
||||||
|
public DrawingField(FormModernMonorail field) {
|
||||||
|
this.field = field;
|
||||||
|
}
|
||||||
|
|
||||||
|
public DrawingMonorail getDrawingMonorail() {return _drawingMonorail;}
|
||||||
|
public void setDrawingMonorail(DrawingMonorail drawingMonorail) {_drawingMonorail = drawingMonorail;}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void paintComponent(Graphics g) {
|
||||||
|
super.paintComponent(g);
|
||||||
|
Graphics2D g2 =(Graphics2D)g;
|
||||||
|
if (_drawingMonorail !=null)
|
||||||
|
_drawingMonorail.DrawTransport(g2);
|
||||||
|
else return;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void UpButtonAction(){
|
||||||
|
if (_drawingMonorail !=null)
|
||||||
|
_drawingMonorail.MoveTransport(DirectionType.Up);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void DownButtonAction(){
|
||||||
|
if (_drawingMonorail !=null)
|
||||||
|
_drawingMonorail.MoveTransport(DirectionType.Down);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void RightButtonAction(){
|
||||||
|
if (_drawingMonorail !=null)
|
||||||
|
_drawingMonorail.MoveTransport(DirectionType.Right);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void LeftButtonAction(){
|
||||||
|
if (_drawingMonorail !=null)
|
||||||
|
_drawingMonorail.MoveTransport(DirectionType.Left);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void CreateButtonAction_Monorail(){
|
||||||
|
Random rnd=new Random();
|
||||||
|
_drawingMonorail = new DrawingMonorail(rnd.nextInt(50)+10,rnd.nextInt(100)+500,new Color(rnd.nextInt(256),rnd.nextInt(256),rnd.nextInt(256)), null, null);
|
||||||
|
_drawingMonorail.SetPictureSize(getWidth(),getHeight());
|
||||||
|
_drawingMonorail.SetPosition(rnd.nextInt(100)+10,rnd.nextInt(100)+10);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void CreateButtonAction_ModernMonorail(){
|
||||||
|
Random rnd=new Random();
|
||||||
|
_drawingMonorail = new DrawingModernMonorail(rnd.nextInt(50)+10,rnd.nextInt(100)+500,new Color(rnd.nextInt(256),rnd.nextInt(256),rnd.nextInt(256)), new Color(rnd.nextInt(256),rnd.nextInt(256),rnd.nextInt(256)), rnd.nextBoolean(), true);
|
||||||
|
_drawingMonorail.SetPictureSize(getWidth(),getHeight());
|
||||||
|
_drawingMonorail.SetPosition(rnd.nextInt(100)+10,rnd.nextInt(100)+10);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void ResizeField(){
|
||||||
|
if (_drawingMonorail !=null)
|
||||||
|
_drawingMonorail.SetPictureSize(getWidth(),getHeight());
|
||||||
|
else return;
|
||||||
|
}
|
||||||
|
}
|
135
ProjectMonorail/src/Scripts/Drawing/DrawingModernMonorail.java
Normal file
135
ProjectMonorail/src/Scripts/Drawing/DrawingModernMonorail.java
Normal file
@ -0,0 +1,135 @@
|
|||||||
|
package Scripts.Drawing;
|
||||||
|
|
||||||
|
import Scripts.Entities.EntityModernMonorail;
|
||||||
|
import Scripts.Entities.EntityMonorail;
|
||||||
|
import Scripts.Wheels.DrawOrnament;
|
||||||
|
import Scripts.Wheels.DrawingWheels;
|
||||||
|
import Scripts.Wheels.IDrawingWheels;
|
||||||
|
|
||||||
|
import java.awt.*;
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
|
public class DrawingModernMonorail extends DrawingMonorail {
|
||||||
|
public DrawingModernMonorail(int speed, float weight, Color bodyColor, Color additionalColor, boolean monorailTrack, boolean cabin)
|
||||||
|
{
|
||||||
|
super(speed, weight, bodyColor, 190, 80);
|
||||||
|
|
||||||
|
_entityMonorail = new EntityModernMonorail(speed, weight, bodyColor, additionalColor, monorailTrack, cabin);
|
||||||
|
_wheels.SetOrnament(new DrawOrnament());
|
||||||
|
}
|
||||||
|
|
||||||
|
public DrawingModernMonorail(EntityModernMonorail entityModernMonorail, IDrawingWheels wheels)
|
||||||
|
{
|
||||||
|
super((EntityMonorail)entityModernMonorail, 190, 80, wheels);
|
||||||
|
|
||||||
|
_entityMonorail = new EntityModernMonorail(entityModernMonorail.getSpeed(), entityModernMonorail.getWeight(), entityModernMonorail.getBodyColor(), entityModernMonorail.getAdditionalColor(), entityModernMonorail.getMonorailTrack(), entityModernMonorail.getMonorailTrack());
|
||||||
|
_wheels.SetOrnament(new DrawOrnament());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void DrawTransport(Graphics g)
|
||||||
|
{
|
||||||
|
if (! (_entityMonorail instanceof EntityModernMonorail)) return;
|
||||||
|
|
||||||
|
super.DrawTransport(g);
|
||||||
|
|
||||||
|
EntityModernMonorail modernMonorail = (EntityModernMonorail)_entityMonorail;
|
||||||
|
Graphics2D g2 = (Graphics2D) g;
|
||||||
|
|
||||||
|
g.setColor(modernMonorail.getAdditionalColor());
|
||||||
|
//Окна
|
||||||
|
g.drawRect(_startPositionX + 14, _startPositionY + 2, 5, 6);
|
||||||
|
g.drawRect(_startPositionX + 21, _startPositionY + 2, 5, 6);
|
||||||
|
g.drawRect(_startPositionX + 70, _startPositionY + 2, 5, 6);
|
||||||
|
|
||||||
|
g.setColor(modernMonorail.getBodyColor());
|
||||||
|
|
||||||
|
if (modernMonorail.getMonorailTrack()) {
|
||||||
|
if (modernMonorail.getCabin()) {
|
||||||
|
g.fillRect(_startPositionX, _startPositionY + 35, 170, 5);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
g.fillRect(_startPositionX, _startPositionY + 35, 86, 5);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//Колеса
|
||||||
|
int[] coordinatesX = new int[_wheels.getCountWheels()];
|
||||||
|
coordinatesX[0] = _startPositionX + 10;
|
||||||
|
coordinatesX[1] = _startPositionX + 65;
|
||||||
|
|
||||||
|
if (coordinatesX.length == 4) {
|
||||||
|
coordinatesX[2] = _startPositionX + 25;
|
||||||
|
coordinatesX[3] = _startPositionX + 50;
|
||||||
|
}
|
||||||
|
else if (coordinatesX.length == 3) {
|
||||||
|
Random rnd = new Random();
|
||||||
|
if (_wheelsSeed == 1) {
|
||||||
|
coordinatesX[2] = _startPositionX + 25;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
coordinatesX[2] = _startPositionX + 50;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
_wheels.DrawWheels(g2, coordinatesX, _startPositionY + 30, modernMonorail.getAdditionalColor());
|
||||||
|
|
||||||
|
if (modernMonorail.getCabin()) {
|
||||||
|
int offset = 170;
|
||||||
|
|
||||||
|
g.setColor(modernMonorail.getBodyColor());
|
||||||
|
//Кузов монорельса
|
||||||
|
g.drawLine(_startPositionX - 8 + offset, _startPositionY + 10, _startPositionX - 13 + offset, _startPositionY);
|
||||||
|
g.drawLine(_startPositionX - 13 + offset, _startPositionY, _startPositionX - 80 + offset, _startPositionY);
|
||||||
|
g.drawLine(_startPositionX - 80 + offset, _startPositionY, _startPositionX - 80 + offset, _startPositionY + 25);
|
||||||
|
g.drawLine(_startPositionX - 80 + offset, _startPositionY + 25, _startPositionX - 8 + offset, _startPositionY + 25);
|
||||||
|
g.drawLine(_startPositionX - 8 + offset, _startPositionY + 25, _startPositionX - 8 + offset, _startPositionY + 10);
|
||||||
|
g.drawLine(_startPositionX - 8 + offset, _startPositionY + 10, _startPositionX - 30 + offset, _startPositionY + 10);
|
||||||
|
g.drawLine(_startPositionX - 39 + offset, _startPositionY + 10, _startPositionX - 80 + offset, _startPositionY + 10);
|
||||||
|
|
||||||
|
//Дверь
|
||||||
|
g.drawRect(_startPositionX - 39 + offset, _startPositionY + 5, 9, 15);
|
||||||
|
|
||||||
|
//Окна
|
||||||
|
g.setColor(modernMonorail.getAdditionalColor());
|
||||||
|
g.drawRect(_startPositionX - 20 + offset, _startPositionY + 2, 5, 6);
|
||||||
|
g.drawRect(_startPositionX - 27 + offset, _startPositionY + 2, 5, 6);
|
||||||
|
g.drawRect(_startPositionX - 76 + offset, _startPositionY + 2, 5, 6);
|
||||||
|
|
||||||
|
//Связка монорельса
|
||||||
|
g.setColor(_entityMonorail.getBodyColor());
|
||||||
|
g.fillRect(_startPositionX - 87 + offset, _startPositionY + 2, 7, 22);
|
||||||
|
|
||||||
|
//Нижняя часть монорельса
|
||||||
|
int[] xPoly_LeftSide = new int[]{_startPositionX + offset, _startPositionX - 8 + offset, _startPositionX - 72 + offset, _startPositionX - 36 + offset, _startPositionX - 36 + offset, _startPositionX - 15 + offset, _startPositionX - 15 + offset, _startPositionX + offset};
|
||||||
|
int[] yPoly_LeftSide = new int[] {_startPositionY + 30, _startPositionY + 25, _startPositionY + 25, _startPositionY + 25, _startPositionY + 32, _startPositionY + 32, _startPositionY + 35, _startPositionY + 32};
|
||||||
|
g.fillPolygon(xPoly_LeftSide, yPoly_LeftSide, xPoly_LeftSide.length);
|
||||||
|
|
||||||
|
int[] xPoly_RightSide = new int[]{_startPositionX - 86 + offset, _startPositionX - 80 + offset, _startPositionX - 50 + offset, _startPositionX - 50 + offset, _startPositionX - 69 + offset, _startPositionX - 79 + offset, _startPositionX - 86 + offset};
|
||||||
|
int[] yPoly_RightSide = new int[] {_startPositionY + 30, _startPositionY + 25, _startPositionY+ 25, _startPositionY + 32, _startPositionY + 32 , _startPositionY + 35, _startPositionY + 32};
|
||||||
|
g.fillPolygon(xPoly_RightSide, yPoly_RightSide, xPoly_RightSide.length);
|
||||||
|
g.fillRect(_startPositionX - 80 + offset, _startPositionY + 25, 70, 3);
|
||||||
|
|
||||||
|
//Колеса
|
||||||
|
coordinatesX = new int[_wheels.getCountWheels()];
|
||||||
|
coordinatesX[0] = _startPositionX - 20 + offset;
|
||||||
|
coordinatesX[1] = _startPositionX - 75 + offset;
|
||||||
|
|
||||||
|
if (coordinatesX.length == 4) {
|
||||||
|
coordinatesX[2] = _startPositionX - 35 + offset;
|
||||||
|
coordinatesX[3] = _startPositionX - 60 + offset;
|
||||||
|
}
|
||||||
|
else if (coordinatesX.length == 3) {
|
||||||
|
Random rnd = new Random();
|
||||||
|
if (_wheelsSeed == 1) {
|
||||||
|
coordinatesX[2] = _startPositionX - 35 + offset;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
coordinatesX[2] = _startPositionX - 60 + offset;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
_wheels.DrawWheels(g2, coordinatesX , _startPositionY + 30, modernMonorail.getAdditionalColor());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
237
ProjectMonorail/src/Scripts/Drawing/DrawingMonorail.java
Normal file
237
ProjectMonorail/src/Scripts/Drawing/DrawingMonorail.java
Normal file
@ -0,0 +1,237 @@
|
|||||||
|
package Scripts.Drawing;
|
||||||
|
|
||||||
|
import Scripts.Entities.EntityMonorail;
|
||||||
|
import Scripts.Wheels.DrawingWheels;
|
||||||
|
import Scripts.Wheels.IDrawingWheels;
|
||||||
|
|
||||||
|
import java.awt.*;
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
|
public class DrawingMonorail {
|
||||||
|
public EntityMonorail _entityMonorail;
|
||||||
|
public IDrawingWheels _wheels;
|
||||||
|
|
||||||
|
private Integer _pictureWidth = null;
|
||||||
|
private Integer _pictureHeight = null;
|
||||||
|
|
||||||
|
protected int _startPositionX;
|
||||||
|
protected int _startPositionY;
|
||||||
|
|
||||||
|
private int _drawningMonorailWidth = 100;
|
||||||
|
private int _drawningMonorailHeight = 80;
|
||||||
|
|
||||||
|
public EntityMonorail getMonorail() {return _entityMonorail;}
|
||||||
|
public IDrawingWheels getWheels() {return _wheels;}
|
||||||
|
protected int _wheelsSeed;
|
||||||
|
|
||||||
|
public int GetPositionX() { return _startPositionX;}
|
||||||
|
|
||||||
|
public int GetPositionY() {return _startPositionY;}
|
||||||
|
|
||||||
|
public int GetWidth() { return _drawningMonorailWidth;}
|
||||||
|
|
||||||
|
public int GetHeight() { return _drawningMonorailHeight;}
|
||||||
|
|
||||||
|
public DrawingMonorail(int speed, float weight, Color bodyColor, Integer drawningMonorailWidth, Integer drawningMonorailHeight)
|
||||||
|
{
|
||||||
|
this(drawningMonorailWidth, drawningMonorailHeight);
|
||||||
|
|
||||||
|
_entityMonorail = new EntityMonorail(speed, weight, bodyColor);
|
||||||
|
_wheels = new DrawingWheels();
|
||||||
|
Random rnd = new Random();
|
||||||
|
_wheels.SetCountWheels(2 + rnd.nextInt(0, 3));
|
||||||
|
_wheelsSeed = rnd.nextInt(0, 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
public DrawingMonorail(int speed, float weight, Color bodyColor)
|
||||||
|
{
|
||||||
|
this(100, 40);
|
||||||
|
|
||||||
|
_entityMonorail = new EntityMonorail(speed, weight, bodyColor);
|
||||||
|
_wheels = new DrawingWheels();
|
||||||
|
Random rnd = new Random();
|
||||||
|
_wheels.SetCountWheels(2 + rnd.nextInt(0, 3));
|
||||||
|
_wheelsSeed = rnd.nextInt(0, 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
public DrawingMonorail(EntityMonorail entityMonorail, Integer drawningMonorailWidth, Integer drawningMonorailHeight, IDrawingWheels wheels)
|
||||||
|
{
|
||||||
|
this(drawningMonorailWidth, drawningMonorailHeight);
|
||||||
|
|
||||||
|
_entityMonorail = new EntityMonorail(entityMonorail.getSpeed(), entityMonorail.getWeight(), entityMonorail.getBodyColor());
|
||||||
|
_wheels = new DrawingWheels();
|
||||||
|
Random rnd = new Random();
|
||||||
|
_wheels.SetCountWheels(2 + rnd.nextInt(0, 3));
|
||||||
|
_wheelsSeed = rnd.nextInt(0, 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
public DrawingMonorail(EntityMonorail entityMonorail, IDrawingWheels wheels)
|
||||||
|
{
|
||||||
|
this(100, 40);
|
||||||
|
|
||||||
|
_entityMonorail = new EntityMonorail(entityMonorail.getSpeed(), entityMonorail.getWeight(), entityMonorail.getBodyColor());
|
||||||
|
_wheels = new DrawingWheels();
|
||||||
|
Random rnd = new Random();
|
||||||
|
_wheels.SetCountWheels(2 + rnd.nextInt(0, 3));
|
||||||
|
_wheelsSeed = rnd.nextInt(0, 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected DrawingMonorail(Integer drawningMonorailWidth, Integer drawningMonorailHeight) {
|
||||||
|
if(drawningMonorailWidth == null || drawningMonorailHeight == null) return;
|
||||||
|
|
||||||
|
_drawningMonorailWidth = drawningMonorailWidth;
|
||||||
|
_drawningMonorailHeight = drawningMonorailHeight;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean SetPictureSize(int width, int height)
|
||||||
|
{
|
||||||
|
if (_drawningMonorailWidth > width || _drawningMonorailHeight > height) return false;
|
||||||
|
|
||||||
|
if (_startPositionX >= 0 && _startPositionY >= 0)
|
||||||
|
{
|
||||||
|
if (_startPositionX + _drawningMonorailWidth > width)
|
||||||
|
{
|
||||||
|
_startPositionX = width - _drawningMonorailWidth;
|
||||||
|
}
|
||||||
|
if (_startPositionY + _drawningMonorailHeight > height)
|
||||||
|
{
|
||||||
|
_startPositionY = height - _drawningMonorailHeight;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
_pictureWidth = width;
|
||||||
|
_pictureHeight = height;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SetPosition(int x, int y)
|
||||||
|
{
|
||||||
|
if (_pictureHeight == null || _pictureWidth == null) return;
|
||||||
|
|
||||||
|
if (x + _drawningMonorailWidth > _pictureWidth || x < 0)
|
||||||
|
{
|
||||||
|
_startPositionX = (int)Math.random() * (_pictureWidth - _drawningMonorailWidth);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_startPositionX = x;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (y + _drawningMonorailHeight > _pictureHeight || y < 0)
|
||||||
|
{
|
||||||
|
_startPositionY = (int)Math.random() * (_pictureHeight - _drawningMonorailHeight);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_startPositionY = y;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean MoveTransport(DirectionType direction)
|
||||||
|
{
|
||||||
|
if (_pictureWidth == null || _pictureHeight == null) return false;
|
||||||
|
|
||||||
|
switch (direction)
|
||||||
|
{
|
||||||
|
case Right:
|
||||||
|
if (_startPositionX + _drawningMonorailWidth + _entityMonorail.Step < _pictureWidth)
|
||||||
|
{
|
||||||
|
_startPositionX += _entityMonorail.Step;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
case Left:
|
||||||
|
if (_startPositionX - _entityMonorail.Step >= 0)
|
||||||
|
{
|
||||||
|
_startPositionX -= _entityMonorail.Step;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
case Up:
|
||||||
|
if (_startPositionY - _entityMonorail.Step >= 0)
|
||||||
|
{
|
||||||
|
_startPositionY -= _entityMonorail.Step;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
case Down:
|
||||||
|
if (_startPositionY + _drawningMonorailHeight + _entityMonorail.Step < _pictureHeight)
|
||||||
|
{
|
||||||
|
_startPositionY += _entityMonorail.Step;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean CanMove(DirectionType direction) {
|
||||||
|
if (_entityMonorail == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return switch (direction) {
|
||||||
|
case Left -> _startPositionX - _entityMonorail.Step > 0;
|
||||||
|
case Up -> _startPositionY - _entityMonorail.Step > 0;
|
||||||
|
case Right -> _startPositionX + _drawningMonorailWidth + _entityMonorail.Step < _pictureWidth;
|
||||||
|
case Down -> _startPositionY + _drawningMonorailHeight + _entityMonorail.Step < _pictureHeight;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public void DrawTransport(Graphics g)
|
||||||
|
{
|
||||||
|
if (_startPositionX < 0 || _startPositionY < 0 || _pictureHeight== null || _pictureWidth== null) return;
|
||||||
|
|
||||||
|
Graphics2D g2 = (Graphics2D) g;
|
||||||
|
g.setColor(_entityMonorail.getBodyColor());
|
||||||
|
|
||||||
|
//Кузов монорельса
|
||||||
|
g.drawLine(_startPositionX + 8, _startPositionY + 10, _startPositionX + 13, _startPositionY);
|
||||||
|
g.drawLine(_startPositionX + 13, _startPositionY, _startPositionX + 80, _startPositionY);
|
||||||
|
g.drawLine(_startPositionX + 80, _startPositionY, _startPositionX + 80, _startPositionY + 25);
|
||||||
|
g.drawLine(_startPositionX + 80, _startPositionY + 25, _startPositionX + 8, _startPositionY + 25);
|
||||||
|
g.drawLine(_startPositionX + 8, _startPositionY + 25, _startPositionX + 8, _startPositionY + 10);
|
||||||
|
g.drawLine(_startPositionX + 8, _startPositionY + 10, _startPositionX + 30, _startPositionY + 10);
|
||||||
|
g.drawLine(_startPositionX + 39, _startPositionY + 10, _startPositionX + 80, _startPositionY + 10);
|
||||||
|
|
||||||
|
//Дверь
|
||||||
|
g.drawRect(_startPositionX + 30, _startPositionY + 5, 9, 15);
|
||||||
|
|
||||||
|
//Окна
|
||||||
|
g.drawRect(_startPositionX + 14, _startPositionY + 2, 5, 6);
|
||||||
|
g.drawRect(_startPositionX + 21, _startPositionY + 2, 5, 6);
|
||||||
|
g.drawRect(_startPositionX + 70, _startPositionY + 2, 5, 6);
|
||||||
|
|
||||||
|
//Связка монорельса
|
||||||
|
g.setColor(_entityMonorail.getBodyColor());
|
||||||
|
g.fillRect(_startPositionX + 80, _startPositionY + 2, 7, 22);
|
||||||
|
|
||||||
|
//Нижняя часть монорельса
|
||||||
|
int xPoly_LeftSide[] = {_startPositionX, _startPositionX + 8, _startPositionX + 72, _startPositionX + 36, _startPositionX + 36, _startPositionX + 15, _startPositionX + 15, _startPositionX};
|
||||||
|
int yPoly_LeftSide[] = {_startPositionY + 30, _startPositionY + 25, _startPositionY + 25, _startPositionY + 25, _startPositionY + 32, _startPositionY + 32, _startPositionY + 35, _startPositionY + 32};
|
||||||
|
g.fillPolygon(xPoly_LeftSide, yPoly_LeftSide, xPoly_LeftSide.length);
|
||||||
|
|
||||||
|
int xPoly_RightSide[] = {_startPositionX + 86, _startPositionX + 80, _startPositionX + 50, _startPositionX + 50, _startPositionX + 69, _startPositionX + 79, _startPositionX + 86};
|
||||||
|
int yPoly_RightSide[] = {_startPositionY + 30, _startPositionY + 25, _startPositionY + 25, _startPositionY + 32, _startPositionY + 32, _startPositionY + 35, _startPositionY + 32};
|
||||||
|
g.fillPolygon(xPoly_RightSide, yPoly_RightSide, xPoly_RightSide.length);
|
||||||
|
|
||||||
|
g.fillRect(_startPositionX + 8, _startPositionY + 25, 70, 3);
|
||||||
|
|
||||||
|
//Колеса
|
||||||
|
int[] coordinatesX = new int[_wheels.getCountWheels()];
|
||||||
|
coordinatesX[0] = _startPositionX + 10;
|
||||||
|
coordinatesX[1] = _startPositionX + 65;
|
||||||
|
|
||||||
|
if (coordinatesX.length == 4) {
|
||||||
|
coordinatesX[2] = _startPositionX + 25;
|
||||||
|
coordinatesX[3] = _startPositionX + 50;
|
||||||
|
}
|
||||||
|
else if (coordinatesX.length == 3) {
|
||||||
|
Random rnd = new Random();
|
||||||
|
if (_wheelsSeed == 1) {
|
||||||
|
coordinatesX[2] = _startPositionX + 25;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
coordinatesX[2] = _startPositionX + 50;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
_wheels.DrawWheels(g2, coordinatesX, _startPositionY + 30, _entityMonorail.getBodyColor());
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,71 @@
|
|||||||
|
package Scripts.Drawing;
|
||||||
|
|
||||||
|
import Scripts.Entities.EntityModernMonorail;
|
||||||
|
import Scripts.Entities.EntityMonorail;
|
||||||
|
import Scripts.Wheels.IDrawingWheels;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
|
|
||||||
|
public class ExtentionDrawningMonorail {
|
||||||
|
private static String _separatorForObjectS = ":";
|
||||||
|
private static String _separatorForObject = "\\:";
|
||||||
|
public static DrawingMonorail CreateDrawingShip(String info) {
|
||||||
|
String[] strs = info.split(_separatorForObject);
|
||||||
|
EntityMonorail entityMonorail;
|
||||||
|
IDrawingWheels wheels = null;
|
||||||
|
if (strs.length == 8)
|
||||||
|
{
|
||||||
|
String s = strs[8];
|
||||||
|
switch (s) {
|
||||||
|
case "DrawingDecksType1":
|
||||||
|
wheels = new DrawingDecksType1();
|
||||||
|
case "DrawingDecksType2":
|
||||||
|
wheels = new DrawingDecksType2();
|
||||||
|
case "DrawingDecksType3":
|
||||||
|
wheels = new DrawingDecksType3();
|
||||||
|
}
|
||||||
|
if (wheels != null) wheels.SetCountWheels(Integer.parseInt(strs[7]));
|
||||||
|
}
|
||||||
|
else if (strs.length == 6) {
|
||||||
|
String s = strs[5];
|
||||||
|
switch (s) {
|
||||||
|
case "DrawingDecksType1":
|
||||||
|
wheels = new DrawingDecksType1();
|
||||||
|
case "DrawingDecksType2":
|
||||||
|
wheels = new DrawingDecksType2();
|
||||||
|
case "DrawingDecksType3":
|
||||||
|
wheels = new DrawingDecksType3();
|
||||||
|
}
|
||||||
|
if (wheels != null) wheels.SetCountWheels(Integer.parseInt(strs[4]));
|
||||||
|
}
|
||||||
|
entityMonorail = EntityModernMonorail.CreateEntityModernMonorail(strs);
|
||||||
|
if (entityMonorail != null)
|
||||||
|
{
|
||||||
|
return new DrawingModernMonorail((EntityModernMonorail) entityMonorail, wheels);
|
||||||
|
}
|
||||||
|
entityMonorail = EntityMonorail.CreateEntityMonorail(strs);
|
||||||
|
if (entityMonorail != null)
|
||||||
|
{
|
||||||
|
return new DrawingMonorail(entityMonorail, wheels);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
public static String GetDataForSave(DrawingMonorail drawningMonorail)
|
||||||
|
{
|
||||||
|
if (drawningMonorail == null) return "";
|
||||||
|
String[] array1 = drawningMonorail.getMonorail().GetStringRepresentation();
|
||||||
|
String[] array2 = drawningMonorail.GetStringRepresentationDecks();
|
||||||
|
if (array1 == null)
|
||||||
|
{
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
ArrayList<String> list = new ArrayList<>();
|
||||||
|
Collections.addAll(list, array1);
|
||||||
|
if (array2 == null) {
|
||||||
|
Collections.addAll(list, "0", " ");
|
||||||
|
}
|
||||||
|
else Collections.addAll(list, array2);
|
||||||
|
return String.join(_separatorForObjectS, list);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,51 @@
|
|||||||
|
package Scripts.Entities;
|
||||||
|
|
||||||
|
import java.awt.*;
|
||||||
|
import java.util.Objects;
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
|
public class EntityModernMonorail extends EntityMonorail {
|
||||||
|
private Color _additionalColor;
|
||||||
|
private boolean _monorailTrack;
|
||||||
|
private boolean _cabin;
|
||||||
|
|
||||||
|
public Color getAdditionalColor() {return _additionalColor;}
|
||||||
|
public boolean getMonorailTrack() {return _monorailTrack;}
|
||||||
|
public boolean getCabin() {return _cabin;}
|
||||||
|
|
||||||
|
public void setAdditionalColor(Color value) {_additionalColor = _additionalColor;}
|
||||||
|
public void setMonorailTrack(Boolean value) { _monorailTrack = value;}
|
||||||
|
public void setCabin(Boolean value) { _cabin = value;}
|
||||||
|
|
||||||
|
public EntityModernMonorail(int speed, float weight, Color bodyColor, Color additionalColor, boolean monorailTrack, boolean cabin){
|
||||||
|
super(speed, weight, bodyColor);
|
||||||
|
Random rnd = new Random();
|
||||||
|
_speed = speed <= 0 ? rnd.nextInt(50)+10 : speed;
|
||||||
|
_weight = weight <= 0 ? rnd.nextInt(100)+500 : weight;
|
||||||
|
_bodyColor = bodyColor;
|
||||||
|
_additionalColor = additionalColor;
|
||||||
|
_monorailTrack = monorailTrack;
|
||||||
|
_cabin = cabin;
|
||||||
|
|
||||||
|
Step = _speed * 100/ (float)_weight;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String[] GetStringRepresentation()
|
||||||
|
{
|
||||||
|
return new String[]{"EntityModernMonorail", _speed.toString(), _weight.toString(),
|
||||||
|
colorToHexString(getBodyColor()), colorToHexString(getAdditionalColor()),
|
||||||
|
String.valueOf(_monorailTrack), String.valueOf(_cabin)};
|
||||||
|
}
|
||||||
|
|
||||||
|
public static EntityModernMonorail CreateEntityModernMonorail(String[] strs)
|
||||||
|
{
|
||||||
|
if (strs.length != 10 || !Objects.equals(strs[0], "EntityModernMonorail"))
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return new EntityModernMonorail(Integer.parseInt(strs[1]), Float.parseFloat(strs[2]), hexStringToColor(strs[3]),
|
||||||
|
hexStringToColor(strs[4]), Boolean.parseBoolean(strs[5]), Boolean.parseBoolean(strs[6]));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
57
ProjectMonorail/src/Scripts/Entities/EntityMonorail.java
Normal file
57
ProjectMonorail/src/Scripts/Entities/EntityMonorail.java
Normal file
@ -0,0 +1,57 @@
|
|||||||
|
package Scripts.Entities;
|
||||||
|
|
||||||
|
import java.awt.*;
|
||||||
|
import java.util.Objects;
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
|
public class EntityMonorail {
|
||||||
|
public float Step;
|
||||||
|
protected Integer _speed;
|
||||||
|
protected Float _weight;
|
||||||
|
protected Color _bodyColor;
|
||||||
|
|
||||||
|
public int getSpeed() {
|
||||||
|
return _speed;
|
||||||
|
}
|
||||||
|
public float getWeight() {
|
||||||
|
return _weight;
|
||||||
|
}
|
||||||
|
public Color getBodyColor() {
|
||||||
|
return _bodyColor;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSpeed(int value) {_speed = value; }
|
||||||
|
public void setWeight(float value) {_weight = value;}
|
||||||
|
public void setBodyColor(Color value) {_bodyColor = value;}
|
||||||
|
|
||||||
|
public EntityMonorail(int speed, float weight, Color bodyColor){
|
||||||
|
Random rnd = new Random();
|
||||||
|
_speed = speed <= 0 ? rnd.nextInt(50)+10 : speed;
|
||||||
|
_weight = weight <= 0 ? rnd.nextInt(100)+500 : weight;
|
||||||
|
_bodyColor = bodyColor;
|
||||||
|
|
||||||
|
Step = _speed * 100/ (float)_weight;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String[] GetStringRepresentation()
|
||||||
|
{
|
||||||
|
return new String[]{"EntityMonorail", _speed.toString(), _weight.toString(), colorToHexString(_bodyColor)};
|
||||||
|
}
|
||||||
|
|
||||||
|
public static EntityMonorail CreateEntityMonorail(String[] strs)
|
||||||
|
{
|
||||||
|
if (strs.length != 6 || !Objects.equals(strs[0], "EntityMonorail"))
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return new EntityMonorail(Integer.parseInt(strs[1]), Float.parseFloat(strs[2]), hexStringToColor(strs[3]));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String colorToHexString(Color color) {
|
||||||
|
return String.format("#%02x%02x%02x", color.getRed(), color.getGreen(), color.getBlue());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Color hexStringToColor(String hexString) {
|
||||||
|
return Color.decode(hexString);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,32 @@
|
|||||||
|
package Scripts.Forms;
|
||||||
|
|
||||||
|
import Scripts.CollectionGenericObjects.AbstractCompany;
|
||||||
|
import Scripts.Drawing.DrawingMonorail;
|
||||||
|
|
||||||
|
import javax.swing.*;
|
||||||
|
|
||||||
|
import java.awt.*;
|
||||||
|
|
||||||
|
public class CanvasFormMonorailCollection<T> extends JComponent {
|
||||||
|
public AbstractCompany company = null;
|
||||||
|
public void SetCollectionToCanvas(AbstractCompany company) {
|
||||||
|
this.company = company;
|
||||||
|
}
|
||||||
|
public CanvasFormMonorailCollection() {};
|
||||||
|
public void paintComponent(Graphics g) {
|
||||||
|
super.paintComponents(g);
|
||||||
|
if (company == null || company._collection == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
company.DrawBackgound(g);
|
||||||
|
for (int i = 0; i < company._collection.getCount(); i++) {
|
||||||
|
|
||||||
|
Graphics2D g2d = (Graphics2D) g;
|
||||||
|
T obj = (T) company._collection.Get(i);
|
||||||
|
if (obj instanceof DrawingMonorail) {
|
||||||
|
((DrawingMonorail) obj).DrawTransport(g2d);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
super.repaint();
|
||||||
|
}
|
||||||
|
}
|
20
ProjectMonorail/src/Scripts/Forms/CanvasMonorail.java
Normal file
20
ProjectMonorail/src/Scripts/Forms/CanvasMonorail.java
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
package Scripts.Forms;
|
||||||
|
|
||||||
|
import Scripts.Drawing.DrawingMonorail;
|
||||||
|
|
||||||
|
import javax.swing.*;
|
||||||
|
import java.awt.*;
|
||||||
|
|
||||||
|
public class CanvasMonorail extends JComponent {
|
||||||
|
public DrawingMonorail _drawingMonorail;
|
||||||
|
public CanvasMonorail(){}
|
||||||
|
public void paintComponent(Graphics g) {
|
||||||
|
if (_drawingMonorail == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
super.paintComponents(g);
|
||||||
|
Graphics2D g2d = (Graphics2D) g;
|
||||||
|
_drawingMonorail.DrawTransport(g2d);
|
||||||
|
super.repaint();
|
||||||
|
}
|
||||||
|
}
|
133
ProjectMonorail/src/Scripts/Forms/FormAdditionalCollection.java
Normal file
133
ProjectMonorail/src/Scripts/Forms/FormAdditionalCollection.java
Normal file
@ -0,0 +1,133 @@
|
|||||||
|
package Scripts.Forms;
|
||||||
|
|
||||||
|
import Scripts.CollectionGenericObjects.AbstractCompany;
|
||||||
|
import Scripts.CollectionGenericObjects.AdditionalCollection;
|
||||||
|
import Scripts.Drawing.DrawingModernMonorail;
|
||||||
|
import Scripts.Drawing.DrawingMonorail;
|
||||||
|
import Scripts.Entities.EntityModernMonorail;
|
||||||
|
import Scripts.Entities.EntityMonorail;
|
||||||
|
import Scripts.Wheels.DrawingWheels;
|
||||||
|
|
||||||
|
import javax.swing.*;
|
||||||
|
import java.awt.*;
|
||||||
|
import java.awt.event.ActionEvent;
|
||||||
|
import java.awt.event.ActionListener;
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
|
public class FormAdditionalCollection extends JFrame {
|
||||||
|
public DrawingMonorail _drawingMonorail = null;
|
||||||
|
private DrawingMonorail _copyMonorail = null;
|
||||||
|
private AbstractCompany _company = null;
|
||||||
|
private CanvasMonorail _canvasMonorail = new CanvasMonorail();
|
||||||
|
private AdditionalCollection<EntityMonorail, DrawingWheels> _additionalCollection = null;
|
||||||
|
private Random random = new Random();
|
||||||
|
private JButton buttonGenerate = new JButton("Создать");
|
||||||
|
private JButton buttonGoToCollection = new JButton("В коллекцию");
|
||||||
|
private JList<String> listEntity = new JList<String>();
|
||||||
|
private JList<String> listWheels = new JList<String>();
|
||||||
|
public FormAdditionalCollection() {
|
||||||
|
setTitle("Случайные монорельсы");
|
||||||
|
setMinimumSize(new Dimension(970,310));
|
||||||
|
_additionalCollection = new AdditionalCollection<EntityMonorail, DrawingWheels>(3,(Class)EntityMonorail.class,(Class)DrawingWheels.class);
|
||||||
|
AddEntities();
|
||||||
|
AddWheels();
|
||||||
|
buttonGoToCollection.addActionListener(new ActionListener() {
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
if(_drawingMonorail !=null){
|
||||||
|
_company._collection.Insert(_copyMonorail);
|
||||||
|
FormMonorailCollection.canvasShow();
|
||||||
|
dispose();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
buttonGenerate.addActionListener(new ActionListener() {
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
_drawingMonorail = _additionalCollection.CreateAdditionalCollectionMonorail();
|
||||||
|
_drawingMonorail.SetPictureSize(getWidth(), getHeight());
|
||||||
|
_drawingMonorail.SetPosition(360,30);
|
||||||
|
_canvasMonorail._drawingMonorail = _drawingMonorail;
|
||||||
|
_canvasMonorail.repaint();
|
||||||
|
if (_drawingMonorail instanceof DrawingModernMonorail)
|
||||||
|
_copyMonorail = new DrawingModernMonorail((EntityModernMonorail) _drawingMonorail.getMonorail(), _drawingMonorail.getWheels());
|
||||||
|
else
|
||||||
|
_copyMonorail = new DrawingMonorail(_drawingMonorail.getMonorail(), _drawingMonorail.getWheels());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
buttonGoToCollection.setBounds(830,200,120,60);
|
||||||
|
buttonGenerate.setBounds(830, 130, 120, 60);
|
||||||
|
listEntity.setBounds(10,200,400,60);
|
||||||
|
listWheels.setBounds(420,200,400,60);
|
||||||
|
add(buttonGenerate);
|
||||||
|
add(buttonGoToCollection);
|
||||||
|
add(listEntity);
|
||||||
|
add(listWheels);
|
||||||
|
add(_canvasMonorail);
|
||||||
|
setVisible(true);
|
||||||
|
}
|
||||||
|
private String ToString(EntityMonorail entity) {
|
||||||
|
String str = "";
|
||||||
|
if (entity instanceof EntityModernMonorail) str += "EntityModernMonorail ";
|
||||||
|
else str += "EntityMonorail ";
|
||||||
|
str += entity.getBodyColor().toString();
|
||||||
|
return str;
|
||||||
|
}
|
||||||
|
private String ToString(DrawingWheels wheels) {
|
||||||
|
if (wheels == null || wheels.getCountWheels() == 0)
|
||||||
|
return "Не имеет колес";
|
||||||
|
String str = ""+wheels.getCountWheels();
|
||||||
|
str+=" колес";
|
||||||
|
|
||||||
|
return str;
|
||||||
|
}
|
||||||
|
public void AddEntities() {
|
||||||
|
for (int i = 0; i < _additionalCollection.CountEntities; i++) {
|
||||||
|
random = new Random();
|
||||||
|
int speed = random.nextInt(100, 300);
|
||||||
|
float weight = random.nextInt(1000, 3000);
|
||||||
|
Color bodycolor = new Color(random.nextInt(256), random.nextInt(256), random.nextInt(256));
|
||||||
|
EntityMonorail entityMonorail;
|
||||||
|
if (random.nextBoolean()) {
|
||||||
|
entityMonorail = new EntityMonorail(speed, weight, bodycolor);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
Color additionalcolor = new Color(random.nextInt(256), random.nextInt(256), random.nextInt(256));
|
||||||
|
boolean monorailTrack = random.nextBoolean();
|
||||||
|
boolean cabin = random.nextBoolean();
|
||||||
|
entityMonorail = new EntityModernMonorail(speed, weight, bodycolor, additionalcolor, monorailTrack, cabin);
|
||||||
|
}
|
||||||
|
_additionalCollection.Insert(entityMonorail);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public void AddWheels() {
|
||||||
|
for (int i = 0; i < _additionalCollection.CountWheels; i++) {
|
||||||
|
random = new Random();
|
||||||
|
EntityMonorail entity = _additionalCollection.CollectionEntity[i];
|
||||||
|
DrawingWheels drawingWheels = null;
|
||||||
|
drawingWheels = new DrawingWheels();
|
||||||
|
drawingWheels.SetCountWheels((int) ((Math.random() * 3) + 1) * 2);
|
||||||
|
|
||||||
|
if(drawingWheels!=null){
|
||||||
|
_additionalCollection.Insert(drawingWheels);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
void setCompany(AbstractCompany company) {
|
||||||
|
this._company = company;
|
||||||
|
String[] data1 = new String[_additionalCollection.CountEntities];
|
||||||
|
for (int i = 0; i < _additionalCollection.CountEntities; i++) {
|
||||||
|
EntityMonorail entity = _additionalCollection.CollectionEntity[i];
|
||||||
|
data1[i] = ToString(entity);
|
||||||
|
}
|
||||||
|
String[] data2 = new String[_additionalCollection.CountWheels];
|
||||||
|
for (int i = 0; i < _additionalCollection.CountWheels; i++) {
|
||||||
|
DrawingWheels wheels = _additionalCollection.CollectionWheels[i];
|
||||||
|
data2[i] = ToString(wheels);
|
||||||
|
}
|
||||||
|
listEntity.setListData(data1);
|
||||||
|
listWheels.setListData(data2);
|
||||||
|
}
|
||||||
|
}
|
174
ProjectMonorail/src/Scripts/Forms/FormModernMonorail.java
Normal file
174
ProjectMonorail/src/Scripts/Forms/FormModernMonorail.java
Normal file
@ -0,0 +1,174 @@
|
|||||||
|
package Scripts.Forms;
|
||||||
|
|
||||||
|
import Scripts.Drawing.DrawingField;
|
||||||
|
import Scripts.Drawing.DrawingMonorail;
|
||||||
|
import Scripts.MovementStratagy.*;
|
||||||
|
|
||||||
|
import javax.swing.*;
|
||||||
|
import java.awt.*;
|
||||||
|
import java.awt.event.ComponentAdapter;
|
||||||
|
import java.awt.event.ComponentEvent;
|
||||||
|
public class FormModernMonorail extends JFrame{
|
||||||
|
private int Width;
|
||||||
|
private int Height;
|
||||||
|
|
||||||
|
private JPanel BottomPanel = new JPanel();
|
||||||
|
private JPanel CreatePanel = new JPanel();
|
||||||
|
private JPanel BottomAndCreatePanel = new JPanel();
|
||||||
|
private JPanel DimentionPanel = new JPanel();
|
||||||
|
private JPanel UPanel = new JPanel();
|
||||||
|
private JPanel DPanel = new JPanel();
|
||||||
|
private JPanel LRPanel = new JPanel();
|
||||||
|
|
||||||
|
private DrawingField field = new DrawingField(this);
|
||||||
|
|
||||||
|
private Icon _iconUp = new ImageIcon("Resource\\Arrows\\ArrowUp.png");
|
||||||
|
private Icon _iconDown = new ImageIcon("Resource\\Arrows\\ArrowDown.png");
|
||||||
|
private Icon _iconRight = new ImageIcon("Resource\\Arrows\\ArrowRight.png");
|
||||||
|
private Icon _iconLeft = new ImageIcon("Resource\\Arrows\\ArrowLeft.png");
|
||||||
|
|
||||||
|
private JButton ButtonUp=new JButton(_iconUp);
|
||||||
|
private JButton ButtonDown=new JButton(_iconDown);
|
||||||
|
private JButton ButtonRight=new JButton(_iconRight);
|
||||||
|
private JButton ButtonLeft=new JButton(_iconLeft);
|
||||||
|
|
||||||
|
private JPanel StrategyPanel = new JPanel();
|
||||||
|
private AbstractStrategy _abstractStrategy;
|
||||||
|
private String[] _strategyItems = {
|
||||||
|
"ToCenter",
|
||||||
|
"ToBorder"
|
||||||
|
};
|
||||||
|
private JComboBox ComboBoxStrategy = new JComboBox(_strategyItems);
|
||||||
|
private JButton ButtonStep = new JButton("Step");
|
||||||
|
|
||||||
|
public FormModernMonorail(){
|
||||||
|
super("Modern Monorail");
|
||||||
|
setSize(600,480);
|
||||||
|
Width=getWidth();
|
||||||
|
Height=getHeight();
|
||||||
|
ShowWindow();
|
||||||
|
RefreshWindow();
|
||||||
|
setVisible(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void ShowWindow(){
|
||||||
|
|
||||||
|
Dimension dimen=new Dimension(30,30);
|
||||||
|
|
||||||
|
ButtonUp.setPreferredSize(dimen);
|
||||||
|
ButtonUp.addActionListener(e->{
|
||||||
|
field.UpButtonAction();
|
||||||
|
repaint();
|
||||||
|
});
|
||||||
|
|
||||||
|
ButtonDown.setPreferredSize(dimen);
|
||||||
|
ButtonDown.addActionListener(e->{
|
||||||
|
field.DownButtonAction();
|
||||||
|
repaint();
|
||||||
|
});
|
||||||
|
|
||||||
|
ButtonRight.setPreferredSize(dimen);
|
||||||
|
ButtonRight.addActionListener(e->{
|
||||||
|
field.RightButtonAction();
|
||||||
|
repaint();
|
||||||
|
});
|
||||||
|
|
||||||
|
ButtonLeft.setPreferredSize(dimen);
|
||||||
|
ButtonLeft.addActionListener(e->{
|
||||||
|
field.LeftButtonAction();
|
||||||
|
repaint();
|
||||||
|
});
|
||||||
|
|
||||||
|
LRPanel.setLayout(new FlowLayout(FlowLayout.CENTER,50,0));
|
||||||
|
LRPanel.setBackground(new Color(0,0,0,0));
|
||||||
|
LRPanel.add(ButtonLeft);
|
||||||
|
LRPanel.add(ButtonRight);
|
||||||
|
|
||||||
|
UPanel.setLayout(new FlowLayout());
|
||||||
|
UPanel.setBackground(new Color(0,0,0,0));
|
||||||
|
UPanel.add(ButtonUp);
|
||||||
|
|
||||||
|
DPanel.setLayout(new FlowLayout());
|
||||||
|
DPanel.setBackground(new Color(0,0,0,0));
|
||||||
|
DPanel.add(ButtonDown);
|
||||||
|
|
||||||
|
DimentionPanel.setLayout(new BoxLayout(DimentionPanel,BoxLayout.Y_AXIS));
|
||||||
|
DimentionPanel.setBackground(new Color(0,0,0,0));
|
||||||
|
DimentionPanel.add(UPanel);
|
||||||
|
DimentionPanel.add(LRPanel);
|
||||||
|
DimentionPanel.add(DPanel);
|
||||||
|
add(DimentionPanel);
|
||||||
|
|
||||||
|
CreatePanel.setLayout(new FlowLayout(FlowLayout.RIGHT,0,0));
|
||||||
|
CreatePanel.setBackground(new Color(0,0,0,0));
|
||||||
|
|
||||||
|
StrategyPanel.setLayout(new FlowLayout(FlowLayout.RIGHT,0,0));
|
||||||
|
StrategyPanel.setBackground(new Color(0,0,0,0));
|
||||||
|
StrategyPanel.add(ButtonStep);
|
||||||
|
StrategyPanel.add(ComboBoxStrategy);
|
||||||
|
|
||||||
|
ButtonStep.addActionListener(e -> {
|
||||||
|
if (field.getDrawingMonorail() == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (ComboBoxStrategy.isEnabled()) {
|
||||||
|
_abstractStrategy = switch (ComboBoxStrategy.getSelectedIndex()) {
|
||||||
|
case 0 -> new MoveToCenter();
|
||||||
|
case 1 -> new MoveToBorder();
|
||||||
|
default -> null;
|
||||||
|
};
|
||||||
|
if (_abstractStrategy == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_abstractStrategy.SetData(new MoveableMonorail(field.getDrawingMonorail()), Width, Height);
|
||||||
|
}
|
||||||
|
if (_abstractStrategy == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
ComboBoxStrategy.setEnabled(false);
|
||||||
|
_abstractStrategy.MakeStep();
|
||||||
|
repaint();
|
||||||
|
if (_abstractStrategy.GetStatus() == StrategyStatus.Finish)
|
||||||
|
{
|
||||||
|
ComboBoxStrategy.setEnabled(true);
|
||||||
|
_abstractStrategy = null;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
BottomPanel.setLayout(new FlowLayout());
|
||||||
|
BottomPanel.setBackground(new Color(0,0,0,0));
|
||||||
|
|
||||||
|
BottomAndCreatePanel.setLayout(new BoxLayout(BottomAndCreatePanel,BoxLayout.Y_AXIS));
|
||||||
|
BottomAndCreatePanel.setBackground(new Color(0,0,0,0));
|
||||||
|
BottomAndCreatePanel.add(CreatePanel);
|
||||||
|
BottomAndCreatePanel.add(StrategyPanel);
|
||||||
|
BottomAndCreatePanel.add(BottomPanel);
|
||||||
|
|
||||||
|
add(BottomAndCreatePanel);
|
||||||
|
add(field);
|
||||||
|
|
||||||
|
addComponentListener(new ComponentAdapter() {
|
||||||
|
@Override
|
||||||
|
public void componentResized(ComponentEvent e) {
|
||||||
|
super.componentResized(e);
|
||||||
|
Width=getWidth();
|
||||||
|
Height=getHeight();
|
||||||
|
|
||||||
|
field.ResizeField();
|
||||||
|
repaint();
|
||||||
|
RefreshWindow();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
public void RefreshWindow(){
|
||||||
|
field.setBounds(0,0,Width,Height);
|
||||||
|
BottomAndCreatePanel.setBounds(-220,Height-110,Width,80);
|
||||||
|
DimentionPanel.setBounds(Width-170,Height-170,190,140);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Init(DrawingMonorail drawingMonorail) {
|
||||||
|
field.setDrawingMonorail(drawingMonorail);
|
||||||
|
}
|
||||||
|
}
|
315
ProjectMonorail/src/Scripts/Forms/FormMonorailCollection.java
Normal file
315
ProjectMonorail/src/Scripts/Forms/FormMonorailCollection.java
Normal file
@ -0,0 +1,315 @@
|
|||||||
|
package Scripts.Forms;
|
||||||
|
|
||||||
|
import Scripts.CollectionGenericObjects.*;
|
||||||
|
import Scripts.Drawing.DrawingModernMonorail;
|
||||||
|
import Scripts.Drawing.DrawingMonorail;
|
||||||
|
|
||||||
|
import java.util.LinkedList;
|
||||||
|
import java.util.Queue;
|
||||||
|
import javax.swing.*;
|
||||||
|
import java.awt.*;
|
||||||
|
import java.awt.event.*;
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
|
import static java.lang.Integer.parseInt;
|
||||||
|
|
||||||
|
public class FormMonorailCollection extends JFrame{
|
||||||
|
private String title;
|
||||||
|
private Dimension dimension;
|
||||||
|
public static CanvasFormMonorailCollection<DrawingMonorail> _canvasMonorail = new CanvasFormMonorailCollection<DrawingMonorail>();
|
||||||
|
private static AbstractCompany _company = null;
|
||||||
|
|
||||||
|
private Queue<DrawingMonorail> _collectionRemovedObjects = new LinkedList<DrawingMonorail>();
|
||||||
|
private StorageCollection<DrawingMonorail> _storageCollection = new StorageCollection<DrawingMonorail>();
|
||||||
|
private JTextField textBoxCollection = new JTextField();
|
||||||
|
private JRadioButton radioButtonMassive = new JRadioButton("Массив");
|
||||||
|
private JRadioButton radioButtonList = new JRadioButton("Список");
|
||||||
|
private JButton buttonAddCollection = new JButton("Добавить");
|
||||||
|
private JList listBoxCollection = new JList();
|
||||||
|
private JButton buttonRemoveCollection = new JButton("Удалить");
|
||||||
|
private JButton buttonCreateCompany = new JButton("Создать компанию");
|
||||||
|
private JButton createMonorailButton = new JButton("Создать монорельс");
|
||||||
|
private JButton removeButton = new JButton("Удалить");
|
||||||
|
private JButton removeObjectsButton = new JButton("Удаленные объекты");
|
||||||
|
|
||||||
|
private JButton GoToCheckButton = new JButton("На проверку");
|
||||||
|
private JButton RandomButton = new JButton("Случайные");
|
||||||
|
private JButton RefreshButton = new JButton("Обновить");
|
||||||
|
private JComboBox ComboBoxCollections = new JComboBox(new String[]{"", "Хранилище"});
|
||||||
|
private JFormattedTextField TextField;
|
||||||
|
public FormMonorailCollection(String title, Dimension dimension) {
|
||||||
|
this.title = title;
|
||||||
|
this.dimension = dimension;
|
||||||
|
}
|
||||||
|
public static void canvasShow() {
|
||||||
|
_company.SetPosition();
|
||||||
|
_canvasMonorail.SetCollectionToCanvas(_company);
|
||||||
|
_canvasMonorail.repaint();
|
||||||
|
}
|
||||||
|
private void CreateObject(String typeOfClass){
|
||||||
|
if (_company == null) return;
|
||||||
|
int speed = (int)(Math.random() * 300 + 100);
|
||||||
|
float weight = (float)(Math.random() * 3000 + 1000);
|
||||||
|
Color bodyColor = getColor();
|
||||||
|
DrawingMonorail drawingMonorail;
|
||||||
|
switch (typeOfClass) {
|
||||||
|
case "DrawingMonorail":
|
||||||
|
drawingMonorail = new DrawingMonorail(speed, weight, bodyColor);
|
||||||
|
break;
|
||||||
|
case "DrawingModernMonorail":
|
||||||
|
Color additionalColor = getColor();
|
||||||
|
boolean monorailTrack = new Random().nextBoolean();
|
||||||
|
boolean cabin = true;
|
||||||
|
drawingMonorail = new DrawingModernMonorail(speed, weight, bodyColor, additionalColor, monorailTrack, cabin);
|
||||||
|
break;
|
||||||
|
default: return;
|
||||||
|
}
|
||||||
|
if (_company._collection.Insert(drawingMonorail) != -1) {
|
||||||
|
JOptionPane.showMessageDialog(null, "Объект добавлен");
|
||||||
|
canvasShow();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
JOptionPane.showMessageDialog(null, "Объект не удалось добавить");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public Color getColor() {
|
||||||
|
Color initializator = new Color((int)(Math.random() * 255 + 0),(int)(Math.random() * 255 + 0),(int)(Math.random() * 255 + 0));
|
||||||
|
Color color = JColorChooser.showDialog(this, "Цвет", initializator);
|
||||||
|
return color;
|
||||||
|
}
|
||||||
|
public void Init() {
|
||||||
|
setTitle(title);
|
||||||
|
setMinimumSize(dimension);
|
||||||
|
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||||
|
|
||||||
|
TextField = new JFormattedTextField();
|
||||||
|
|
||||||
|
ComboBoxCollections.addActionListener(new ActionListener() {
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
switch (ComboBoxCollections.getSelectedItem().toString()) {
|
||||||
|
case "Хранилище":
|
||||||
|
_company = new DepotSharingService(getWidth()-200, getHeight()-110, new MassiveGenericObjects<DrawingMonorail>());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
createMonorailButton.addActionListener(new ActionListener() {
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
if (_company == null) return;
|
||||||
|
FormMonorailConfig form = new FormMonorailConfig("", new Dimension(800, 300));
|
||||||
|
form.setCompany(_company);
|
||||||
|
form.Init();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
removeButton.addActionListener(new ActionListener() {
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
if (_company == null || TextField.getText() == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
int pos = parseInt(TextField.getText());
|
||||||
|
int resultConfirmDialog = JOptionPane.showConfirmDialog(null, "Удалить", "Удаление", JOptionPane.YES_NO_OPTION);
|
||||||
|
if (resultConfirmDialog == JOptionPane.NO_OPTION) return;
|
||||||
|
|
||||||
|
DrawingMonorail obj = _storageCollection.remove(listBoxCollection.getSelectedValue().toString(), pos);
|
||||||
|
System.out.println(obj);
|
||||||
|
if (obj != null) {
|
||||||
|
JOptionPane.showMessageDialog(null, "Объект удален");
|
||||||
|
_collectionRemovedObjects.add(obj);
|
||||||
|
canvasShow();
|
||||||
|
} else {
|
||||||
|
JOptionPane.showMessageDialog(null, "Не удалось удалить объект");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
GoToCheckButton.addActionListener(new ActionListener() {
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
if (_company == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
DrawingMonorail drawingMonorail = null;
|
||||||
|
int counter = 100;
|
||||||
|
while (drawingMonorail == null)
|
||||||
|
{
|
||||||
|
drawingMonorail = _company.GetRandomObject();
|
||||||
|
counter--;
|
||||||
|
if (counter <= 0)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (drawingMonorail == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
FormModernMonorail form = new FormModernMonorail();
|
||||||
|
form.addWindowListener(new WindowAdapter() {
|
||||||
|
@Override
|
||||||
|
public void windowClosing(WindowEvent e) {
|
||||||
|
canvasShow();
|
||||||
|
super.windowClosing(e);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
form.Init(drawingMonorail);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
RefreshButton.addActionListener(new ActionListener() {
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
if (_company == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
canvasShow();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
RandomButton.addActionListener(new ActionListener() {
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
if(_company==null){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
FormAdditionalCollection form = new FormAdditionalCollection();
|
||||||
|
form.setCompany(_company);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
buttonAddCollection.addActionListener(new ActionListener() {
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
if (textBoxCollection.getText().isEmpty() || (!radioButtonMassive.isSelected()
|
||||||
|
&& !radioButtonList.isSelected())) {
|
||||||
|
JOptionPane.showMessageDialog(null, "Не все данные заполнены");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
CollectionType collectionType = CollectionType.None;
|
||||||
|
if (radioButtonMassive.isSelected()) {
|
||||||
|
collectionType = CollectionType.Massive;
|
||||||
|
} else if (radioButtonList.isSelected()) {
|
||||||
|
collectionType = CollectionType.List;
|
||||||
|
}
|
||||||
|
_storageCollection.SetCollectionObject(textBoxCollection.getText(), collectionType);
|
||||||
|
RerfreshListBoxItems();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
buttonRemoveCollection.addActionListener(new ActionListener() {
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
if (listBoxCollection.getSelectedIndex() < 0 || listBoxCollection.getSelectedValue() == null) {
|
||||||
|
JOptionPane.showMessageDialog(null, "Коллекция не выбрана");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
int resultConfirmDialog = JOptionPane.showConfirmDialog(null,
|
||||||
|
"Удалить", "Удаление",
|
||||||
|
JOptionPane.YES_NO_OPTION);
|
||||||
|
if (resultConfirmDialog == JOptionPane.NO_OPTION) return;
|
||||||
|
_storageCollection.DelCollection(listBoxCollection.getSelectedValue().toString());
|
||||||
|
RerfreshListBoxItems();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
buttonCreateCompany.addActionListener(new ActionListener() {
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
if (listBoxCollection.getSelectedIndex() < 0 || listBoxCollection.getSelectedValue() == null) {
|
||||||
|
JOptionPane.showMessageDialog(null, "Коллекция не выбрана");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
ICollectionGenericObjects<DrawingMonorail> collection =
|
||||||
|
_storageCollection.GetCollectionObject(listBoxCollection.getSelectedValue().toString());
|
||||||
|
if (collection == null) {
|
||||||
|
JOptionPane.showMessageDialog(null, "Коллекция не проинициализирована");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
switch (ComboBoxCollections.getSelectedItem().toString()) {
|
||||||
|
case "Хранилище":
|
||||||
|
_company = new DepotSharingService(getWidth() - 200, getHeight() - 110,
|
||||||
|
collection);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
RerfreshListBoxItems();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
removeObjectsButton.addActionListener(new ActionListener() {
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
if (_collectionRemovedObjects.isEmpty()) {
|
||||||
|
JOptionPane.showMessageDialog(null, "Коллекция пуста");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
DrawingMonorail drawingMonorail = null;
|
||||||
|
drawingMonorail = _collectionRemovedObjects.remove();
|
||||||
|
if (drawingMonorail == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
FormModernMonorail form = new FormModernMonorail();
|
||||||
|
form.Init(drawingMonorail);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
ButtonGroup radioButtonsGroup = new ButtonGroup();
|
||||||
|
JLabel labelCollectionName = new JLabel("Название коллекции");
|
||||||
|
radioButtonsGroup.add(radioButtonMassive);
|
||||||
|
radioButtonsGroup.add(radioButtonList);
|
||||||
|
_canvasMonorail.setBounds(0, 0, getWidth() - 200, getHeight());
|
||||||
|
labelCollectionName.setBounds(getWidth()-190, 10, 150, 20);
|
||||||
|
textBoxCollection.setBounds(getWidth()-190,35,150,25);
|
||||||
|
radioButtonMassive.setBounds(getWidth()-190, 60, 75, 20);
|
||||||
|
radioButtonList.setBounds(getWidth()-105, 60, 75, 20);
|
||||||
|
buttonAddCollection.setBounds(getWidth()-190, 85, 150, 20);
|
||||||
|
listBoxCollection.setBounds(getWidth()-190, 115, 150, 70);
|
||||||
|
buttonRemoveCollection.setBounds(getWidth()-190, 195, 150, 20);
|
||||||
|
ComboBoxCollections.setBounds(getWidth() - 190, 225, 150, 20);
|
||||||
|
buttonCreateCompany.setBounds(getWidth()-190, 255, 150, 20);
|
||||||
|
createMonorailButton.setBounds(getWidth() - 190, 285, 150, 30);
|
||||||
|
RandomButton.setBounds(getWidth() - 190, 365, 150, 30);
|
||||||
|
removeObjectsButton.setBounds(getWidth()-190, 505, 150, 30);
|
||||||
|
TextField.setBounds(getWidth() - 190, 545, 150, 30);
|
||||||
|
removeButton.setBounds(getWidth() - 190, 585, 150, 30);
|
||||||
|
GoToCheckButton.setBounds(getWidth() - 190, 625, 150, 30);
|
||||||
|
RefreshButton.setBounds(getWidth() - 190, 665, 150, 30);
|
||||||
|
setSize(dimension.width, dimension.height);
|
||||||
|
setLayout(null);
|
||||||
|
|
||||||
|
add(textBoxCollection);
|
||||||
|
add(radioButtonMassive);
|
||||||
|
add(radioButtonList);
|
||||||
|
add(buttonAddCollection);
|
||||||
|
add(listBoxCollection);
|
||||||
|
add(buttonRemoveCollection);
|
||||||
|
add(buttonCreateCompany);
|
||||||
|
add(labelCollectionName);
|
||||||
|
add(removeObjectsButton);
|
||||||
|
|
||||||
|
add(_canvasMonorail);
|
||||||
|
add(ComboBoxCollections);
|
||||||
|
add(createMonorailButton);
|
||||||
|
add(TextField);
|
||||||
|
add(GoToCheckButton);
|
||||||
|
add(RandomButton);
|
||||||
|
add(removeButton);
|
||||||
|
add(RefreshButton);
|
||||||
|
setVisible(true);
|
||||||
|
}
|
||||||
|
private void RerfreshListBoxItems() {
|
||||||
|
DefaultListModel<String> list = new DefaultListModel<String>();
|
||||||
|
for (String name : _storageCollection.Keys()) {
|
||||||
|
if (name != "") {
|
||||||
|
list.addElement(name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
listBoxCollection.setModel(list);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
457
ProjectMonorail/src/Scripts/Forms/FormMonorailConfig.java
Normal file
457
ProjectMonorail/src/Scripts/Forms/FormMonorailConfig.java
Normal file
@ -0,0 +1,457 @@
|
|||||||
|
package Scripts.Forms;
|
||||||
|
|
||||||
|
import Scripts.CollectionGenericObjects.AbstractCompany;
|
||||||
|
import Scripts.Drawing.DrawingModernMonorail;
|
||||||
|
import Scripts.Drawing.DrawingMonorail;
|
||||||
|
import Scripts.Entities.EntityModernMonorail;
|
||||||
|
import Scripts.Wheels.*;
|
||||||
|
|
||||||
|
import javax.swing.*;
|
||||||
|
import javax.swing.event.ChangeEvent;
|
||||||
|
import javax.swing.event.ChangeListener;
|
||||||
|
import java.awt.*;
|
||||||
|
import java.awt.datatransfer.DataFlavor;
|
||||||
|
import java.awt.datatransfer.StringSelection;
|
||||||
|
import java.awt.datatransfer.Transferable;
|
||||||
|
import java.awt.datatransfer.UnsupportedFlavorException;
|
||||||
|
import java.awt.event.ActionEvent;
|
||||||
|
import java.awt.event.ActionListener;
|
||||||
|
import java.awt.event.MouseAdapter;
|
||||||
|
import java.awt.event.MouseEvent;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
public class FormMonorailConfig extends JFrame {
|
||||||
|
private String title;
|
||||||
|
private Dimension dimension;
|
||||||
|
private DrawingMonorail _drawingMonorail;
|
||||||
|
private AbstractCompany company = null;
|
||||||
|
private JLabel labelSpeed = new JLabel("Скорость");
|
||||||
|
private JLabel labelWeight = new JLabel("Вес");
|
||||||
|
private JLabel labelNumberOfWheels = new JLabel("Колеса");
|
||||||
|
|
||||||
|
private JLabel labelMonorail = new JLabel("Monorail", SwingConstants.CENTER);
|
||||||
|
private JLabel labelModernMonorail = new JLabel("ModernMonorail", SwingConstants.CENTER);
|
||||||
|
private JLabel labelColor = new JLabel("Цвета");
|
||||||
|
private JLabel labelBodyColor = new JLabel("Основной цвет", SwingConstants.CENTER);
|
||||||
|
private JLabel labelAdditionalColor = new JLabel("Дополнительный цвет", SwingConstants.CENTER);
|
||||||
|
private JLabel labelWheels = new JLabel("Тип двигателей",SwingConstants.CENTER);
|
||||||
|
private JLabel labelDefaultEngines = new JLabel("Классические",SwingConstants.CENTER);
|
||||||
|
private JLabel labelOvalEngines = new JLabel("Овальные", SwingConstants.CENTER);
|
||||||
|
private JLabel labelTriangleEngines = new JLabel("Треугольные", SwingConstants.CENTER);
|
||||||
|
|
||||||
|
private JSpinner spinnerSpeed = new JSpinner();
|
||||||
|
private JSpinner spinnerWeight = new JSpinner();
|
||||||
|
private JSpinner spinnerNumberOfWheels = new JSpinner();
|
||||||
|
private JCheckBox checkBoxMonorailTrack = new JCheckBox("Имеет путь");
|
||||||
|
private JCheckBox checkBoxCabin = new JCheckBox("Имеет кабину");
|
||||||
|
private JComponent panelObject = new JPanel();
|
||||||
|
private JPanel panelColorRed = new JPanel();
|
||||||
|
private JPanel panelColorGreen = new JPanel();
|
||||||
|
private JPanel panelColorBlue = new JPanel();
|
||||||
|
private JPanel panelColorYellow = new JPanel();
|
||||||
|
private JPanel panelColorBlack = new JPanel();
|
||||||
|
private JPanel panelColorWhite = new JPanel();
|
||||||
|
private JPanel panelColorGray = new JPanel();
|
||||||
|
private JPanel panelColorCyan = new JPanel();
|
||||||
|
private JButton buttonAdd = new JButton("Добавить");
|
||||||
|
private JButton buttonCancel = new JButton("Отмена");
|
||||||
|
|
||||||
|
public FormMonorailConfig(String title, Dimension dimension) {
|
||||||
|
this.title = title;
|
||||||
|
this.dimension = dimension;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Init() {
|
||||||
|
SpinnerModel numSpeed = new SpinnerNumberModel(100, 100, 1000, 1);
|
||||||
|
SpinnerModel numWeight = new SpinnerNumberModel(100, 100, 1000, 1);
|
||||||
|
spinnerSpeed.setModel(numSpeed);
|
||||||
|
spinnerWeight.setModel(numWeight);
|
||||||
|
SpinnerModel numWheels = new SpinnerNumberModel(2, 2, 4, 1);
|
||||||
|
spinnerNumberOfWheels.setModel(numWheels);
|
||||||
|
panelObject = new Canvas();
|
||||||
|
panelObject.setBorder(BorderFactory.createLineBorder(Color.BLACK, 2));
|
||||||
|
|
||||||
|
spinnerSpeed.addChangeListener(new ChangeListener() {
|
||||||
|
@Override
|
||||||
|
public void stateChanged(ChangeEvent e) {
|
||||||
|
if (_drawingMonorail == null) return;
|
||||||
|
_drawingMonorail.getMonorail().setSpeed((int)spinnerSpeed.getValue());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
spinnerWeight.addChangeListener(new ChangeListener() {
|
||||||
|
@Override
|
||||||
|
public void stateChanged(ChangeEvent e) {
|
||||||
|
if (_drawingMonorail == null) return;
|
||||||
|
_drawingMonorail.getMonorail().setWeight((int)spinnerWeight.getValue());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
spinnerNumberOfWheels.addChangeListener(new ChangeListener() {
|
||||||
|
@Override
|
||||||
|
public void stateChanged(ChangeEvent e) {
|
||||||
|
if(_drawingMonorail ==null)return;
|
||||||
|
_drawingMonorail._wheels.SetCountWheels((int) spinnerNumberOfWheels.getValue());
|
||||||
|
panelObject.repaint();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
checkBoxMonorailTrack.addActionListener(new ActionListener() {
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
if (_drawingMonorail == null) return;
|
||||||
|
if (_drawingMonorail.getMonorail() instanceof EntityModernMonorail entityModernMonorail) {
|
||||||
|
entityModernMonorail.setMonorailTrack(checkBoxMonorailTrack.isSelected());
|
||||||
|
panelObject.repaint();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
checkBoxCabin.addActionListener(new ActionListener() {
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
if (_drawingMonorail == null) return;
|
||||||
|
if (_drawingMonorail.getMonorail() instanceof EntityModernMonorail entityModernMonorail) {
|
||||||
|
entityModernMonorail.setCabin(checkBoxCabin.isSelected());
|
||||||
|
panelObject.repaint();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
labelMonorail.setBackground(Color.WHITE);
|
||||||
|
labelModernMonorail.setBackground(Color.WHITE);
|
||||||
|
labelMonorail.setBorder(BorderFactory.createLineBorder(Color.BLACK, 2));
|
||||||
|
labelModernMonorail.setBorder(BorderFactory.createLineBorder(Color.BLACK, 2));
|
||||||
|
labelBodyColor.setBorder(BorderFactory.createLineBorder(Color.BLACK, 2));
|
||||||
|
labelAdditionalColor.setBorder(BorderFactory.createLineBorder(Color.BLACK, 2));
|
||||||
|
labelDefaultEngines.setBorder(BorderFactory.createLineBorder(Color.BLACK, 2));
|
||||||
|
labelOvalEngines.setBorder(BorderFactory.createLineBorder(Color.BLACK, 2));
|
||||||
|
labelTriangleEngines.setBorder(BorderFactory.createLineBorder(Color.BLACK, 2));
|
||||||
|
MouseAdapter labelObjectsMouseDown = new MouseAdapter() {
|
||||||
|
@Override
|
||||||
|
public void mousePressed(MouseEvent e) {
|
||||||
|
((JLabel) e.getComponent()).getTransferHandler().exportAsDrag(((JLabel) e.getComponent()), e, TransferHandler.COPY);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
TransferHandler labelObjectsTransferHandler = new TransferHandler() {
|
||||||
|
@Override
|
||||||
|
public int getSourceActions(JComponent c) {
|
||||||
|
return TransferHandler.COPY;
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
protected Transferable createTransferable(JComponent c) {
|
||||||
|
return new StringSelection(((JLabel) c).getText());
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
labelMonorail.addMouseListener(labelObjectsMouseDown);
|
||||||
|
labelMonorail.setTransferHandler(labelObjectsTransferHandler);
|
||||||
|
labelModernMonorail.addMouseListener(labelObjectsMouseDown);
|
||||||
|
labelModernMonorail.setTransferHandler(labelObjectsTransferHandler);
|
||||||
|
|
||||||
|
MouseAdapter labelEnginesMouseDown = new MouseAdapter() {
|
||||||
|
@Override
|
||||||
|
public void mousePressed(MouseEvent e) {
|
||||||
|
((JLabel) e.getComponent()).getTransferHandler().exportAsDrag(((JLabel) e.getComponent()), e, TransferHandler.COPY);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
labelDefaultEngines.addMouseListener(labelEnginesMouseDown);
|
||||||
|
labelOvalEngines.addMouseListener(labelEnginesMouseDown);
|
||||||
|
labelTriangleEngines.addMouseListener(labelEnginesMouseDown);
|
||||||
|
labelDefaultEngines.setTransferHandler(new TransferHandler() {
|
||||||
|
@Override
|
||||||
|
public int getSourceActions(JComponent c) {return TransferHandler.COPY;}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Transferable createTransferable(JComponent c) {
|
||||||
|
return new WheelsTransferable(new DrawingWheels());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
labelOvalEngines.setTransferHandler(new TransferHandler() {
|
||||||
|
@Override
|
||||||
|
public int getSourceActions(JComponent c) {return TransferHandler.COPY;}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Transferable createTransferable(JComponent c) {
|
||||||
|
return new WheelsTransferable(new DrawOrnamentOval());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
labelTriangleEngines.setTransferHandler(new TransferHandler() {
|
||||||
|
@Override
|
||||||
|
public int getSourceActions(JComponent c) {return TransferHandler.COPY;}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Transferable createTransferable(JComponent c) {
|
||||||
|
return new WheelsTransferable(new DrawOrnamentTriangle());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
panelObject.setTransferHandler(new TransferHandler() {
|
||||||
|
@Override
|
||||||
|
public boolean canImport(TransferHandler.TransferSupport support) {
|
||||||
|
return support.isDataFlavorSupported(DataFlavor.stringFlavor)
|
||||||
|
|| support.isDataFlavorSupported(WheelsTransferable.wheelsDataFlavor);
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public boolean importData(TransferHandler.TransferSupport support) {
|
||||||
|
if (canImport(support)) {
|
||||||
|
try {
|
||||||
|
String data = (String) support.getTransferable().getTransferData(DataFlavor.stringFlavor);
|
||||||
|
|
||||||
|
switch (data) {
|
||||||
|
case "Monorail":
|
||||||
|
_drawingMonorail = new DrawingMonorail((int) spinnerSpeed.getValue(), (int) spinnerWeight.getValue(), Color.WHITE);
|
||||||
|
break;
|
||||||
|
case "ModernMonorail":
|
||||||
|
_drawingMonorail = new DrawingModernMonorail((int) spinnerSpeed.getValue(), (int) spinnerWeight.getValue(),
|
||||||
|
Color.DARK_GRAY, Color.BLACK, checkBoxMonorailTrack.isSelected(), checkBoxCabin.isSelected());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (_drawingMonorail != null) {
|
||||||
|
_drawingMonorail._wheels = new DrawingWheels();
|
||||||
|
_drawingMonorail._wheels.SetCountWheels((int) spinnerNumberOfWheels.getValue());
|
||||||
|
_drawingMonorail.SetPictureSize(400,150);
|
||||||
|
_drawingMonorail.SetPosition(10,40);
|
||||||
|
}
|
||||||
|
else return false;
|
||||||
|
}
|
||||||
|
catch (UnsupportedFlavorException | IOException e) {}
|
||||||
|
try {
|
||||||
|
IDrawingWheels wheels =
|
||||||
|
(IDrawingWheels) support.getTransferable().getTransferData(WheelsTransferable.wheelsDataFlavor);
|
||||||
|
_drawingMonorail._wheels = wheels;
|
||||||
|
_drawingMonorail._wheels.SetCountWheels((int) spinnerNumberOfWheels.getValue());
|
||||||
|
|
||||||
|
}catch (UnsupportedFlavorException | IOException e) {}
|
||||||
|
panelObject.repaint();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
JPanel[] colorPanels = {
|
||||||
|
panelColorRed,
|
||||||
|
panelColorGreen,
|
||||||
|
panelColorBlue,
|
||||||
|
panelColorYellow,
|
||||||
|
panelColorWhite,
|
||||||
|
panelColorBlack,
|
||||||
|
panelColorGray,
|
||||||
|
panelColorCyan,
|
||||||
|
};
|
||||||
|
panelColorRed.setBackground(Color.RED);
|
||||||
|
panelColorGreen.setBackground(Color.GREEN);
|
||||||
|
panelColorBlue.setBackground(Color.BLUE);
|
||||||
|
panelColorYellow.setBackground(Color.YELLOW);
|
||||||
|
panelColorWhite.setBackground(Color.WHITE);
|
||||||
|
panelColorBlack.setBackground(Color.BLACK);
|
||||||
|
panelColorGray.setBackground(Color.GRAY);
|
||||||
|
panelColorCyan.setBackground(Color.CYAN);
|
||||||
|
MouseAdapter colorMouseDown = new MouseAdapter() {
|
||||||
|
@Override
|
||||||
|
public void mousePressed(MouseEvent e) {
|
||||||
|
((JPanel) e.getComponent()).getTransferHandler().exportAsDrag(((JPanel) e.getComponent()), e, TransferHandler.COPY);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
for (var panelColor : colorPanels) {
|
||||||
|
panelColor.addMouseListener(colorMouseDown);
|
||||||
|
panelColor.setTransferHandler(new ColorTransferHandler());
|
||||||
|
}
|
||||||
|
labelBodyColor.setTransferHandler(new TransferHandler() {
|
||||||
|
@Override
|
||||||
|
public boolean canImport(TransferHandler.TransferSupport support) {
|
||||||
|
return support.isDataFlavorSupported(ColorTransferable.colorDataFlavor);
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public boolean importData(TransferSupport support) {
|
||||||
|
try {
|
||||||
|
Color color = (Color) support.getTransferable().getTransferData(ColorTransferable.colorDataFlavor);
|
||||||
|
if (_drawingMonorail == null) return false;
|
||||||
|
_drawingMonorail.getMonorail().setBodyColor(color);
|
||||||
|
return true;
|
||||||
|
} catch (UnsupportedFlavorException | IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
labelAdditionalColor.setTransferHandler(new TransferHandler() {
|
||||||
|
@Override
|
||||||
|
public boolean canImport(TransferHandler.TransferSupport support) {
|
||||||
|
if (!(_drawingMonorail instanceof DrawingModernMonorail)) return false;
|
||||||
|
return support.isDataFlavorSupported(ColorTransferable.colorDataFlavor);
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public boolean importData(TransferSupport support) {
|
||||||
|
try {
|
||||||
|
Color color = (Color) support.getTransferable().getTransferData(ColorTransferable.colorDataFlavor);
|
||||||
|
if (_drawingMonorail == null) return false;
|
||||||
|
if (_drawingMonorail.getMonorail() instanceof EntityModernMonorail) {
|
||||||
|
((EntityModernMonorail)_drawingMonorail.getMonorail()).setAdditionalColor(color);
|
||||||
|
labelColor.setBackground(color);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
} catch (UnsupportedFlavorException | IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
buttonAdd.addActionListener(new ActionListener() {
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
if (_drawingMonorail == null) return;
|
||||||
|
DrawingMonorail copyDrawingMonorail;
|
||||||
|
if (_drawingMonorail instanceof DrawingModernMonorail)
|
||||||
|
copyDrawingMonorail = new DrawingModernMonorail((EntityModernMonorail) _drawingMonorail.getMonorail(), _drawingMonorail.getWheels());
|
||||||
|
else
|
||||||
|
copyDrawingMonorail = new DrawingMonorail(_drawingMonorail.getMonorail(), _drawingMonorail.getWheels());
|
||||||
|
company._collection.Insert(copyDrawingMonorail);
|
||||||
|
FormMonorailCollection.canvasShow();
|
||||||
|
dispose();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
buttonCancel.addActionListener(new ActionListener() {
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
dispose();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
labelSpeed.setBounds(8, 17, 75, 15);
|
||||||
|
labelWeight.setBounds(8,43, 75, 15);
|
||||||
|
labelNumberOfWheels.setBounds(8, 68, 75, 15);
|
||||||
|
labelMonorail.setBounds(8,150,105,30);
|
||||||
|
labelModernMonorail.setBounds(8,190,110,30);
|
||||||
|
checkBoxMonorailTrack.setBounds(8,85,150,20);
|
||||||
|
checkBoxCabin.setBounds(8,105,150,20);
|
||||||
|
spinnerSpeed.setBounds(80,15, 60,20);
|
||||||
|
spinnerWeight.setBounds(80,40, 60,20);
|
||||||
|
spinnerNumberOfWheels.setBounds(80, 65,60,20);
|
||||||
|
panelObject.setBounds(555,50,400,150);
|
||||||
|
labelBodyColor.setBounds(500,5,100, 40);
|
||||||
|
labelAdditionalColor.setBounds(605,5,170,40);
|
||||||
|
labelWheels.setBounds(225,190,150,15);
|
||||||
|
labelDefaultEngines.setBounds(140, 210, 100, 40);
|
||||||
|
labelOvalEngines.setBounds(250, 210, 100,40);
|
||||||
|
labelTriangleEngines.setBounds(360,210,100,40);
|
||||||
|
labelColor.setBounds(200,10,50,15);
|
||||||
|
panelColorRed.setBounds(200, 30, 40, 40);
|
||||||
|
panelColorGreen.setBounds(250, 30, 40,40);
|
||||||
|
panelColorBlue.setBounds(300,30,40,40);
|
||||||
|
panelColorYellow.setBounds(350,30,40,40);
|
||||||
|
panelColorWhite.setBounds(200, 80,40,40);
|
||||||
|
panelColorBlack.setBounds(250,80,40,40);
|
||||||
|
panelColorGray.setBounds(300,80,40,40);
|
||||||
|
panelColorCyan.setBounds(350,80,40,40);
|
||||||
|
buttonAdd.setBounds(515, 210, 110, 40);
|
||||||
|
buttonCancel.setBounds(640, 210, 110, 40);
|
||||||
|
setSize(dimension.width, dimension.height);
|
||||||
|
setLayout(null);
|
||||||
|
add(labelSpeed);
|
||||||
|
add(labelWeight);
|
||||||
|
add(labelNumberOfWheels);
|
||||||
|
add(labelMonorail);
|
||||||
|
add(labelModernMonorail);
|
||||||
|
add(labelColor);
|
||||||
|
add(labelBodyColor);
|
||||||
|
add(labelAdditionalColor);
|
||||||
|
add(labelDefaultEngines);
|
||||||
|
add(labelDefaultEngines);
|
||||||
|
add(labelOvalEngines);
|
||||||
|
add(labelTriangleEngines);
|
||||||
|
add(spinnerSpeed);
|
||||||
|
add(spinnerWeight);
|
||||||
|
add(spinnerNumberOfWheels);
|
||||||
|
add(checkBoxMonorailTrack);
|
||||||
|
add(checkBoxCabin);
|
||||||
|
add(panelObject);
|
||||||
|
add(panelColorRed);
|
||||||
|
add(panelColorGreen);
|
||||||
|
add(panelColorBlue);
|
||||||
|
add(panelColorYellow);
|
||||||
|
add(panelColorWhite);
|
||||||
|
add(labelWheels);
|
||||||
|
add(panelColorBlack);
|
||||||
|
add(panelColorGray);
|
||||||
|
add(panelColorCyan);
|
||||||
|
add(buttonAdd);
|
||||||
|
add(buttonCancel);
|
||||||
|
setVisible(true);
|
||||||
|
}
|
||||||
|
public void setCompany(AbstractCompany company) {
|
||||||
|
this.company = company;
|
||||||
|
}
|
||||||
|
private class Canvas extends JComponent {
|
||||||
|
public Canvas() {
|
||||||
|
}
|
||||||
|
public void paintComponent(Graphics g) {
|
||||||
|
if (_drawingMonorail == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
super.paintComponents(g);
|
||||||
|
Graphics2D g2d = (Graphics2D) g;
|
||||||
|
_drawingMonorail.DrawTransport(g2d);
|
||||||
|
super.repaint();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private class ColorTransferable implements Transferable {
|
||||||
|
private Color color;
|
||||||
|
private static final DataFlavor colorDataFlavor = new DataFlavor(Color.class, "Color");
|
||||||
|
public ColorTransferable(Color color) {
|
||||||
|
this.color = color;
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public DataFlavor[] getTransferDataFlavors() {
|
||||||
|
return new DataFlavor[]{colorDataFlavor};
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public boolean isDataFlavorSupported(DataFlavor flavor) {
|
||||||
|
return colorDataFlavor.equals(flavor);
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException {
|
||||||
|
if (isDataFlavorSupported(flavor)) {
|
||||||
|
return color;
|
||||||
|
} else {
|
||||||
|
throw new UnsupportedFlavorException(flavor);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private class ColorTransferHandler extends TransferHandler {
|
||||||
|
@Override
|
||||||
|
public int getSourceActions(JComponent c) {
|
||||||
|
return TransferHandler.COPY;
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
protected Transferable createTransferable(JComponent c) {
|
||||||
|
return new ColorTransferable(c.getBackground());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private class WheelsTransferable implements Transferable {
|
||||||
|
private IDrawingWheels wheels;
|
||||||
|
private static final DataFlavor wheelsDataFlavor = new DataFlavor(IDrawingWheels.class, "Wheels");
|
||||||
|
public WheelsTransferable(IDrawingWheels iDrawingWheels) {
|
||||||
|
this.wheels = iDrawingWheels;
|
||||||
|
}
|
||||||
|
public WheelsTransferable(IOrnament ornament) {
|
||||||
|
this.wheels = new DrawingWheels();
|
||||||
|
wheels.SetOrnament(ornament);
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public DataFlavor[] getTransferDataFlavors() {
|
||||||
|
return new DataFlavor[]{wheelsDataFlavor};
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public boolean isDataFlavorSupported(DataFlavor flavor) {
|
||||||
|
return flavor.equals(wheelsDataFlavor);
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException {
|
||||||
|
if (isDataFlavorSupported(flavor)) {
|
||||||
|
return wheels;
|
||||||
|
} else {
|
||||||
|
throw new UnsupportedFlavorException(flavor);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
13
ProjectMonorail/src/Scripts/Forms/FormShipConfig.form
Normal file
13
ProjectMonorail/src/Scripts/Forms/FormShipConfig.form
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="Scripts.Forms.FormMonorailConfig">
|
||||||
|
<grid id="27dc6" row-count="1" column-count="1" layout-manager="GridLayoutManager">
|
||||||
|
<margin top="0" left="0" bottom="0" right="0"/>
|
||||||
|
<constraints>
|
||||||
|
<xy x="20" y="20" width="500" height="400"/>
|
||||||
|
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
<properties/>
|
||||||
|
<border type="none"/>
|
||||||
|
<children/>
|
||||||
|
</grid>
|
||||||
|
</form>
|
@ -0,0 +1,93 @@
|
|||||||
|
package Scripts.MovementStratagy;
|
||||||
|
|
||||||
|
import Scripts.Drawing.DirectionType;
|
||||||
|
|
||||||
|
public abstract class AbstractStrategy {
|
||||||
|
private IMoveableObject moveableObject;
|
||||||
|
|
||||||
|
private StrategyStatus state = StrategyStatus.NotInit;
|
||||||
|
|
||||||
|
private int fieldWidth;
|
||||||
|
|
||||||
|
protected int GetFieldWidth() {
|
||||||
|
return fieldWidth;
|
||||||
|
}
|
||||||
|
|
||||||
|
private int fieldHeight;
|
||||||
|
|
||||||
|
protected int GetFieldHeight() {
|
||||||
|
return fieldHeight;
|
||||||
|
}
|
||||||
|
|
||||||
|
public StrategyStatus GetStatus() {
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SetData(IMoveableObject moveableObject, int width, int height) {
|
||||||
|
if (moveableObject == null) {
|
||||||
|
state = StrategyStatus.NotInit;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
state = StrategyStatus.InProgress;
|
||||||
|
this.moveableObject = moveableObject;
|
||||||
|
fieldWidth = width;
|
||||||
|
fieldHeight = height;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void MakeStep() {
|
||||||
|
if (state != StrategyStatus.InProgress) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (isTargetDestination()) {
|
||||||
|
state = StrategyStatus.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 null;
|
||||||
|
}
|
||||||
|
return moveableObject.GetObjectPosition();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected Integer GetStep() {
|
||||||
|
if (state != StrategyStatus.InProgress) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return moveableObject.GetStep();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected abstract void MoveToTarget();
|
||||||
|
|
||||||
|
protected abstract boolean isTargetDestination();
|
||||||
|
|
||||||
|
private boolean MoveTo(DirectionType direction) {
|
||||||
|
if (state != StrategyStatus.InProgress) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (moveableObject == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (moveableObject.CanMoveObject(direction)) {
|
||||||
|
moveableObject.MoveObject(direction);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,13 @@
|
|||||||
|
package Scripts.MovementStratagy;
|
||||||
|
|
||||||
|
import Scripts.Drawing.DirectionType;
|
||||||
|
|
||||||
|
public interface IMoveableObject{
|
||||||
|
ObjectParameters GetObjectPosition();
|
||||||
|
|
||||||
|
int GetStep();
|
||||||
|
|
||||||
|
boolean CanMoveObject(DirectionType direction);
|
||||||
|
|
||||||
|
void MoveObject(DirectionType direction);
|
||||||
|
}
|
@ -0,0 +1,35 @@
|
|||||||
|
package Scripts.MovementStratagy;
|
||||||
|
|
||||||
|
public class MoveToBorder extends AbstractStrategy {
|
||||||
|
@Override
|
||||||
|
protected boolean isTargetDestination() {
|
||||||
|
var objParams = GetObjectParameters();
|
||||||
|
if (objParams == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return objParams.RightBorder() <= GetFieldWidth() &&
|
||||||
|
objParams.RightBorder() + GetStep() >= GetFieldWidth() &&
|
||||||
|
objParams.DownBorder() <= GetFieldHeight() &&
|
||||||
|
objParams.DownBorder() + GetStep() >= GetFieldHeight();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void MoveToTarget() {
|
||||||
|
var objParams = GetObjectParameters();
|
||||||
|
if (objParams == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var diffX = objParams.ObjectMiddleHorizontal() - GetFieldWidth();
|
||||||
|
if (Math.abs(diffX) > GetStep()) {
|
||||||
|
if (diffX < 0) {
|
||||||
|
MoveRight();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
var diffY = objParams.ObjectMiddleVertical() - GetFieldHeight();
|
||||||
|
if (Math.abs(diffY) > GetStep()) {
|
||||||
|
if (diffY < 0) {
|
||||||
|
MoveDown();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,39 @@
|
|||||||
|
package Scripts.MovementStratagy;
|
||||||
|
|
||||||
|
public class MoveToCenter extends AbstractStrategy {
|
||||||
|
@Override
|
||||||
|
protected boolean isTargetDestination() {
|
||||||
|
var objParams = GetObjectParameters();
|
||||||
|
if (objParams == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return objParams.ObjectMiddleHorizontal() <= GetFieldWidth() / 2 &&
|
||||||
|
objParams.ObjectMiddleHorizontal() + GetStep() >= GetFieldWidth() / 2 &&
|
||||||
|
objParams.ObjectMiddleVertical() <= GetFieldHeight() / 2 &&
|
||||||
|
objParams.ObjectMiddleVertical() + GetStep() >= GetFieldHeight() / 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void MoveToTarget() {
|
||||||
|
var objParams = GetObjectParameters();
|
||||||
|
if (objParams == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var diffX = objParams.ObjectMiddleHorizontal() - GetFieldWidth() / 2;
|
||||||
|
if (Math.abs(diffX) > GetStep()) {
|
||||||
|
if (diffX > 0) {
|
||||||
|
MoveLeft();
|
||||||
|
} else {
|
||||||
|
MoveRight();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
var diffY = objParams.ObjectMiddleVertical() - GetFieldHeight() / 2;
|
||||||
|
if (Math.abs(diffY) > GetStep()) {
|
||||||
|
if (diffY > 0) {
|
||||||
|
MoveUp();
|
||||||
|
} else {
|
||||||
|
MoveDown();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,41 @@
|
|||||||
|
package Scripts.MovementStratagy;
|
||||||
|
|
||||||
|
import Scripts.Drawing.DirectionType;
|
||||||
|
import Scripts.Drawing.DrawingMonorail;
|
||||||
|
|
||||||
|
public class MoveableMonorail implements IMoveableObject {
|
||||||
|
private DrawingMonorail _drawingMonorail = null;
|
||||||
|
public MoveableMonorail(DrawingMonorail drawingMonorail)
|
||||||
|
{
|
||||||
|
_drawingMonorail = drawingMonorail;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ObjectParameters GetObjectPosition() {
|
||||||
|
if (_drawingMonorail == null || _drawingMonorail.getMonorail() == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return new ObjectParameters(_drawingMonorail.GetPositionX(), _drawingMonorail.GetPositionY(),
|
||||||
|
_drawingMonorail.GetWidth(), _drawingMonorail.GetHeight());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int GetStep() {
|
||||||
|
if (_drawingMonorail != null && _drawingMonorail.getMonorail()!=null)
|
||||||
|
return (int)(_drawingMonorail.getMonorail().Step);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean CanMoveObject(DirectionType direction) {
|
||||||
|
if (_drawingMonorail != null)
|
||||||
|
return _drawingMonorail.CanMove(direction);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void MoveObject(DirectionType direction) {
|
||||||
|
if (_drawingMonorail != null)
|
||||||
|
_drawingMonorail.MoveTransport(direction);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,34 @@
|
|||||||
|
package Scripts.MovementStratagy;
|
||||||
|
|
||||||
|
public class ObjectParameters {
|
||||||
|
private final int _x;
|
||||||
|
|
||||||
|
private final int _y;
|
||||||
|
|
||||||
|
private final int _width;
|
||||||
|
|
||||||
|
private final int _height;
|
||||||
|
|
||||||
|
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,7 @@
|
|||||||
|
package Scripts.MovementStratagy;
|
||||||
|
|
||||||
|
public enum StrategyStatus {
|
||||||
|
NotInit,
|
||||||
|
InProgress,
|
||||||
|
Finish
|
||||||
|
}
|
12
ProjectMonorail/src/Scripts/Program.java
Normal file
12
ProjectMonorail/src/Scripts/Program.java
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
package Scripts;
|
||||||
|
|
||||||
|
import Scripts.Forms.FormMonorailCollection;
|
||||||
|
|
||||||
|
import java.awt.*;
|
||||||
|
|
||||||
|
public class Program {
|
||||||
|
public static void main(String[] args){
|
||||||
|
FormMonorailCollection form = new FormMonorailCollection("Монорельс", new Dimension(800, 800));
|
||||||
|
form.Init();
|
||||||
|
}
|
||||||
|
}
|
14
ProjectMonorail/src/Scripts/Wheels/CountWheels.java
Normal file
14
ProjectMonorail/src/Scripts/Wheels/CountWheels.java
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
package Scripts.Wheels;
|
||||||
|
|
||||||
|
public enum CountWheels {
|
||||||
|
Two(2),
|
||||||
|
Three(3),
|
||||||
|
Four(4);
|
||||||
|
private final int Value;
|
||||||
|
CountWheels(int Count){
|
||||||
|
Value=Count;
|
||||||
|
}
|
||||||
|
public int getCountWheels(){
|
||||||
|
return Value;
|
||||||
|
}
|
||||||
|
}
|
13
ProjectMonorail/src/Scripts/Wheels/DrawOrnament.java
Normal file
13
ProjectMonorail/src/Scripts/Wheels/DrawOrnament.java
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
package Scripts.Wheels;
|
||||||
|
|
||||||
|
import java.awt.*;
|
||||||
|
|
||||||
|
public class DrawOrnament implements IOrnament {
|
||||||
|
private int _offsetDraw = 6;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void DrawOrnament(int x, int y, int sizeX, int sizeY, Graphics2D g) {
|
||||||
|
g.setColor(Color.CYAN);
|
||||||
|
g.fillRect(x + _offsetDraw, y + _offsetDraw, sizeX - _offsetDraw, sizeY - _offsetDraw);
|
||||||
|
}
|
||||||
|
}
|
16
ProjectMonorail/src/Scripts/Wheels/DrawOrnamentOval.java
Normal file
16
ProjectMonorail/src/Scripts/Wheels/DrawOrnamentOval.java
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
package Scripts.Wheels;
|
||||||
|
|
||||||
|
import java.awt.*;
|
||||||
|
|
||||||
|
public class DrawOrnamentOval implements IOrnament {
|
||||||
|
|
||||||
|
private int _offsetDraw = 4;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void DrawOrnament(int x, int y, int sizeX, int sizeY, Graphics2D g) {
|
||||||
|
g.setColor(Color.DARK_GRAY);
|
||||||
|
g.drawRect(x + _offsetDraw, y + _offsetDraw, sizeX - _offsetDraw, sizeY - _offsetDraw);
|
||||||
|
g.setColor(Color.PINK);
|
||||||
|
g.drawOval(x + _offsetDraw, y + _offsetDraw, sizeX - _offsetDraw, sizeY - _offsetDraw);
|
||||||
|
}
|
||||||
|
}
|
18
ProjectMonorail/src/Scripts/Wheels/DrawOrnamentTriangle.java
Normal file
18
ProjectMonorail/src/Scripts/Wheels/DrawOrnamentTriangle.java
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
package Scripts.Wheels;
|
||||||
|
|
||||||
|
import java.awt.*;
|
||||||
|
|
||||||
|
public class DrawOrnamentTriangle implements IOrnament {
|
||||||
|
|
||||||
|
private int _offsetDraw = 4;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void DrawOrnament(int x, int y, int sizeX, int sizeY, Graphics2D g) {
|
||||||
|
g.setColor(Color.RED);
|
||||||
|
Polygon elements = new Polygon();
|
||||||
|
elements.addPoint(x + _offsetDraw, y + _offsetDraw * 2);
|
||||||
|
elements.addPoint(x + _offsetDraw * 2, y + _offsetDraw);
|
||||||
|
elements.addPoint(x+ _offsetDraw, y+ _offsetDraw);
|
||||||
|
g.fillPolygon(elements);
|
||||||
|
}
|
||||||
|
}
|
42
ProjectMonorail/src/Scripts/Wheels/DrawingWheels.java
Normal file
42
ProjectMonorail/src/Scripts/Wheels/DrawingWheels.java
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
package Scripts.Wheels;
|
||||||
|
|
||||||
|
import Scripts.Wheels.CountWheels;
|
||||||
|
|
||||||
|
import java.awt.*;
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
|
public class DrawingWheels implements IDrawingWheels{
|
||||||
|
private CountWheels _wheels;
|
||||||
|
private IOrnament _ornament;
|
||||||
|
|
||||||
|
public void SetOrnament(IOrnament ornament) {
|
||||||
|
_ornament = ornament;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SetCountWheels(int Count){
|
||||||
|
for (CountWheels temp: CountWheels.values())
|
||||||
|
if (temp.getCountWheels() == Count){
|
||||||
|
Random rnd = new Random();
|
||||||
|
_wheels=temp;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getCountWheels() {
|
||||||
|
if (_wheels != null) return _wheels.getCountWheels();
|
||||||
|
else {
|
||||||
|
SetCountWheels(2);
|
||||||
|
return _wheels.getCountWheels();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void DrawWheels(Graphics2D g,int startPosX[], int startPosY, Color color) {
|
||||||
|
if (_ornament == null) _ornament = new DrawOrnament();
|
||||||
|
for (int i = 0; i < startPosX.length; i++) {
|
||||||
|
g.setColor(color);
|
||||||
|
g.drawOval(startPosX[i], startPosY, 10, 10);
|
||||||
|
g.fillOval(startPosX[i], startPosY, 10, 10);
|
||||||
|
_ornament.DrawOrnament(startPosX[i], startPosY, 10, 10, g);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
10
ProjectMonorail/src/Scripts/Wheels/IDrawingWheels.java
Normal file
10
ProjectMonorail/src/Scripts/Wheels/IDrawingWheels.java
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
package Scripts.Wheels;
|
||||||
|
|
||||||
|
import java.awt.*;
|
||||||
|
|
||||||
|
public interface IDrawingWheels {
|
||||||
|
public void SetOrnament(IOrnament ornament);
|
||||||
|
public void SetCountWheels(int Count);
|
||||||
|
public int getCountWheels();
|
||||||
|
public void DrawWheels(Graphics2D g, int startPosX[], int startPosY, Color color);
|
||||||
|
}
|
7
ProjectMonorail/src/Scripts/Wheels/IOrnament.java
Normal file
7
ProjectMonorail/src/Scripts/Wheels/IOrnament.java
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
package Scripts.Wheels;
|
||||||
|
|
||||||
|
import java.awt.*;
|
||||||
|
|
||||||
|
public interface IOrnament {
|
||||||
|
void DrawOrnament(int x, int y, int sizeX, int sizeY, Graphics2D g);
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user