Compare commits
No commits in common. "main" and "LabWork_2" have entirely different histories.
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>
|
@ -1,77 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project version="4">
|
|
||||||
<component name="AutoImportSettings">
|
|
||||||
<option name="autoReloadType" value="SELECTIVE" />
|
|
||||||
</component>
|
|
||||||
<component name="ChangeListManager">
|
|
||||||
<list default="true" id="39e7c520-e505-4e53-a269-c949d7c9f5d1" name="Changes" comment="">
|
|
||||||
<change afterPath="$PROJECT_DIR$/src/Scripts/Wheels/DrawOrnament.java" afterDir="false" />
|
|
||||||
<change afterPath="$PROJECT_DIR$/src/Scripts/Wheels/DrawOrnamentOval.java" afterDir="false" />
|
|
||||||
<change afterPath="$PROJECT_DIR$/src/Scripts/Wheels/DrawOrnamentTriangle.java" afterDir="false" />
|
|
||||||
<change afterPath="$PROJECT_DIR$/src/Scripts/Wheels/IOrnament.java" afterDir="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/Scripts/DrawingModernMonorail.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/Scripts/DrawingModernMonorail.java" afterDir="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/Scripts/DrawingWheels.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/Scripts/Wheels/DrawingWheels.java" afterDir="false" />
|
|
||||||
</list>
|
|
||||||
<option name="SHOW_DIALOG" value="false" />
|
|
||||||
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
|
||||||
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
|
|
||||||
<option name="LAST_RESOLUTION" value="IGNORE" />
|
|
||||||
</component>
|
|
||||||
<component name="FileTemplateManagerImpl">
|
|
||||||
<option name="RECENT_TEMPLATES">
|
|
||||||
<list>
|
|
||||||
<option value="Class" />
|
|
||||||
</list>
|
|
||||||
</option>
|
|
||||||
</component>
|
|
||||||
<component name="Git.Settings">
|
|
||||||
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$/.." />
|
|
||||||
</component>
|
|
||||||
<component name="ProjectColorInfo">{
|
|
||||||
"customColor": "",
|
|
||||||
"associatedIndex": 6
|
|
||||||
}</component>
|
|
||||||
<component name="ProjectId" id="2eoYwJEsRANWvz6w6GN58HZ6e7Y" />
|
|
||||||
<component name="ProjectViewState">
|
|
||||||
<option name="hideEmptyMiddlePackages" value="true" />
|
|
||||||
<option name="showLibraryContents" value="true" />
|
|
||||||
</component>
|
|
||||||
<component name="PropertiesComponent"><![CDATA[{
|
|
||||||
"keyToString": {
|
|
||||||
"Application.Program.executor": "Run",
|
|
||||||
"RunOnceActivity.OpenProjectViewOnStart": "true",
|
|
||||||
"RunOnceActivity.ShowReadmeOnStart": "true",
|
|
||||||
"git-widget-placeholder": "LabWork__2",
|
|
||||||
"kotlin-language-version-configured": "true"
|
|
||||||
}
|
|
||||||
}]]></component>
|
|
||||||
<component name="RunManager">
|
|
||||||
<configuration name="Program" type="Application" factoryName="Application">
|
|
||||||
<option name="MAIN_CLASS_NAME" value="Scripts.Program" />
|
|
||||||
<module name="ProjectMonorail" />
|
|
||||||
<method v="2">
|
|
||||||
<option name="Make" enabled="true" />
|
|
||||||
</method>
|
|
||||||
</configuration>
|
|
||||||
</component>
|
|
||||||
<component name="SharedIndexes">
|
|
||||||
<attachedChunks>
|
|
||||||
<set>
|
|
||||||
<option value="jdk-21.0.2-openjdk-21.0.2-4caba194b151-4f524021" />
|
|
||||||
</set>
|
|
||||||
</attachedChunks>
|
|
||||||
</component>
|
|
||||||
<component name="SpellCheckerSettings" RuntimeDictionaries="0" Folders="0" CustomDictionaries="0" DefaultDictionary="application-level" UseSingleDictionary="true" transferred="true" />
|
|
||||||
<component name="TaskManager">
|
|
||||||
<task active="true" id="Default" summary="Default task">
|
|
||||||
<changelist id="39e7c520-e505-4e53-a269-c949d7c9f5d1" name="Changes" comment="" />
|
|
||||||
<created>1712572637448</created>
|
|
||||||
<option name="number" value="Default" />
|
|
||||||
<option name="presentableId" value="Default" />
|
|
||||||
<updated>1712572637448</updated>
|
|
||||||
</task>
|
|
||||||
<servers />
|
|
||||||
</component>
|
|
||||||
</project>
|
|
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 |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
8
ProjectMonorail/src/Scripts/DirectionType.java
Normal file
8
ProjectMonorail/src/Scripts/DirectionType.java
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
package Scripts;
|
||||||
|
|
||||||
|
public enum DirectionType {
|
||||||
|
Up,
|
||||||
|
Down,
|
||||||
|
Left,
|
||||||
|
Right;
|
||||||
|
}
|
68
ProjectMonorail/src/Scripts/DrawingField.java
Normal file
68
ProjectMonorail/src/Scripts/DrawingField.java
Normal file
@ -0,0 +1,68 @@
|
|||||||
|
package Scripts;
|
||||||
|
|
||||||
|
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;}
|
||||||
|
|
||||||
|
@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,getWidth(),getHeight());
|
||||||
|
}
|
||||||
|
|
||||||
|
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,getWidth(),getHeight());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void ResizeField(){
|
||||||
|
if (_drawingMonorail !=null)
|
||||||
|
_drawingMonorail.SetPictureSize(getWidth(),getHeight());
|
||||||
|
else return;
|
||||||
|
}
|
||||||
|
}
|
126
ProjectMonorail/src/Scripts/DrawingModernMonorail.java
Normal file
126
ProjectMonorail/src/Scripts/DrawingModernMonorail.java
Normal file
@ -0,0 +1,126 @@
|
|||||||
|
package Scripts;
|
||||||
|
|
||||||
|
import Scripts.Wheels.DrawingWheels;
|
||||||
|
|
||||||
|
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 = new DrawingWheels();
|
||||||
|
Random rnd = new Random();
|
||||||
|
_wheels.SetCountWheels(2 + rnd.nextInt(0, 3));
|
||||||
|
_wheelsSeed = rnd.nextInt(0, 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
@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());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
202
ProjectMonorail/src/Scripts/DrawingMonorail.java
Normal file
202
ProjectMonorail/src/Scripts/DrawingMonorail.java
Normal file
@ -0,0 +1,202 @@
|
|||||||
|
package Scripts;
|
||||||
|
|
||||||
|
import Scripts.Wheels.DrawingWheels;
|
||||||
|
|
||||||
|
import java.awt.*;
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
|
public class DrawingMonorail {
|
||||||
|
protected EntityMonorail _entityMonorail;
|
||||||
|
protected DrawingWheels _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 DrawingWheels 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);
|
||||||
|
}
|
||||||
|
|
||||||
|
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, int width, int height)
|
||||||
|
{
|
||||||
|
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());
|
||||||
|
}
|
||||||
|
}
|
28
ProjectMonorail/src/Scripts/EntityModernMonorail.java
Normal file
28
ProjectMonorail/src/Scripts/EntityModernMonorail.java
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
package Scripts;
|
||||||
|
|
||||||
|
import java.awt.*;
|
||||||
|
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 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/ (int)_weight;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
30
ProjectMonorail/src/Scripts/EntityMonorail.java
Normal file
30
ProjectMonorail/src/Scripts/EntityMonorail.java
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
package Scripts;
|
||||||
|
|
||||||
|
import java.awt.*;
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
|
public class EntityMonorail {
|
||||||
|
public float Step;
|
||||||
|
protected int _speed;
|
||||||
|
protected float _weight;
|
||||||
|
protected Color _bodyColor;
|
||||||
|
|
||||||
|
public int getSpeed() {
|
||||||
|
return _speed;
|
||||||
|
}
|
||||||
|
public float getWeight() {
|
||||||
|
return _weight;
|
||||||
|
}
|
||||||
|
public Color getBodyColor() {
|
||||||
|
return _bodyColor;
|
||||||
|
}
|
||||||
|
|
||||||
|
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/ (int)_weight;
|
||||||
|
}
|
||||||
|
}
|
184
ProjectMonorail/src/Scripts/FormModernMonorail.java
Normal file
184
ProjectMonorail/src/Scripts/FormModernMonorail.java
Normal file
@ -0,0 +1,184 @@
|
|||||||
|
package Scripts;
|
||||||
|
|
||||||
|
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 JButton ButtonCreateMonorail = new JButton("Create Monorail");
|
||||||
|
private JButton ButtonCreateModernMonorail = new JButton("Create Modern Monorail");
|
||||||
|
|
||||||
|
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();
|
||||||
|
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||||
|
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));
|
||||||
|
CreatePanel.add(ButtonCreateMonorail);
|
||||||
|
CreatePanel.add(ButtonCreateModernMonorail);
|
||||||
|
|
||||||
|
ButtonCreateModernMonorail.addActionListener(e->{
|
||||||
|
field.CreateButtonAction_ModernMonorail();
|
||||||
|
repaint();
|
||||||
|
});
|
||||||
|
|
||||||
|
ButtonCreateMonorail.addActionListener(e->{
|
||||||
|
field.CreateButtonAction_Monorail();
|
||||||
|
repaint();
|
||||||
|
});
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,93 @@
|
|||||||
|
package Scripts.MovementStratagy;
|
||||||
|
|
||||||
|
import Scripts.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.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.DirectionType;
|
||||||
|
import Scripts.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
|
||||||
|
}
|
7
ProjectMonorail/src/Scripts/Program.java
Normal file
7
ProjectMonorail/src/Scripts/Program.java
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
package Scripts;
|
||||||
|
|
||||||
|
public class Program {
|
||||||
|
public static void main(String[] args){
|
||||||
|
new FormModernMonorail();
|
||||||
|
}
|
||||||
|
}
|
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);
|
||||||
|
}
|
||||||
|
}
|
46
ProjectMonorail/src/Scripts/Wheels/DrawingWheels.java
Normal file
46
ProjectMonorail/src/Scripts/Wheels/DrawingWheels.java
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
package Scripts.Wheels;
|
||||||
|
|
||||||
|
import Scripts.Wheels.CountWheels;
|
||||||
|
|
||||||
|
import java.awt.*;
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
|
public class DrawingWheels {
|
||||||
|
private CountWheels _wheels;
|
||||||
|
private IOrnament _ornament;
|
||||||
|
|
||||||
|
public void SetCountWheels(int Count){
|
||||||
|
for (CountWheels temp: CountWheels.values())
|
||||||
|
if (temp.getCountWheels() == Count){
|
||||||
|
_wheels=temp;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getCountWheels() {
|
||||||
|
return _wheels.getCountWheels();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void DrawWheels(Graphics2D g,int startPosX[], int startPosY, Color color) {
|
||||||
|
Random rnd = new Random();
|
||||||
|
int ranOrnament = rnd.nextInt(0, 3);
|
||||||
|
switch (ranOrnament) {
|
||||||
|
case 0:
|
||||||
|
_ornament = new DrawOrnament();
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
_ornament = new DrawOrnamentTriangle();
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
_ornament = new DrawOrnamentOval();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
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