Compare commits
5 Commits
Author | SHA1 | Date | |
---|---|---|---|
298e8ad973 | |||
ef856b41d2 | |||
e3f5feadb2 | |||
78d14ef13e | |||
e34fca8784 |
29
OOP/.gitignore
vendored
Normal file
29
OOP/.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
|
3
OOP/.idea/.gitignore
generated
vendored
Normal file
3
OOP/.idea/.gitignore
generated
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
# Default ignored files
|
||||||
|
/shelf/
|
||||||
|
/workspace.xml
|
6
OOP/.idea/misc.xml
generated
Normal file
6
OOP/.idea/misc.xml
generated
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
|
||||||
|
<output url="file://$PROJECT_DIR$/out" />
|
||||||
|
</component>
|
||||||
|
</project>
|
8
OOP/.idea/modules.xml
generated
Normal file
8
OOP/.idea/modules.xml
generated
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="ProjectModuleManager">
|
||||||
|
<modules>
|
||||||
|
<module fileurl="file://$PROJECT_DIR$/OOP.iml" filepath="$PROJECT_DIR$/OOP.iml" />
|
||||||
|
</modules>
|
||||||
|
</component>
|
||||||
|
</project>
|
124
OOP/.idea/uiDesigner.xml
generated
Normal file
124
OOP/.idea/uiDesigner.xml
generated
Normal file
@ -0,0 +1,124 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="Palette2">
|
||||||
|
<group name="Swing">
|
||||||
|
<item class="com.intellij.uiDesigner.HSpacer" tooltip-text="Horizontal Spacer" icon="/com/intellij/uiDesigner/icons/hspacer.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="1" hsize-policy="6" anchor="0" fill="1" />
|
||||||
|
</item>
|
||||||
|
<item class="com.intellij.uiDesigner.VSpacer" tooltip-text="Vertical Spacer" icon="/com/intellij/uiDesigner/icons/vspacer.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="6" hsize-policy="1" anchor="0" fill="2" />
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JPanel" icon="/com/intellij/uiDesigner/icons/panel.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3" />
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JScrollPane" icon="/com/intellij/uiDesigner/icons/scrollPane.svg" removable="false" auto-create-binding="false" can-attach-label="true">
|
||||||
|
<default-constraints vsize-policy="7" hsize-policy="7" anchor="0" fill="3" />
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JButton" icon="/com/intellij/uiDesigner/icons/button.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="3" anchor="0" fill="1" />
|
||||||
|
<initial-values>
|
||||||
|
<property name="text" value="Button" />
|
||||||
|
</initial-values>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JRadioButton" icon="/com/intellij/uiDesigner/icons/radioButton.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
|
||||||
|
<initial-values>
|
||||||
|
<property name="text" value="RadioButton" />
|
||||||
|
</initial-values>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JCheckBox" icon="/com/intellij/uiDesigner/icons/checkBox.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
|
||||||
|
<initial-values>
|
||||||
|
<property name="text" value="CheckBox" />
|
||||||
|
</initial-values>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JLabel" icon="/com/intellij/uiDesigner/icons/label.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="0" anchor="8" fill="0" />
|
||||||
|
<initial-values>
|
||||||
|
<property name="text" value="Label" />
|
||||||
|
</initial-values>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JTextField" icon="/com/intellij/uiDesigner/icons/textField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
|
||||||
|
<preferred-size width="150" height="-1" />
|
||||||
|
</default-constraints>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JPasswordField" icon="/com/intellij/uiDesigner/icons/passwordField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
|
||||||
|
<preferred-size width="150" height="-1" />
|
||||||
|
</default-constraints>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JFormattedTextField" icon="/com/intellij/uiDesigner/icons/formattedTextField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
|
||||||
|
<preferred-size width="150" height="-1" />
|
||||||
|
</default-constraints>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JTextArea" icon="/com/intellij/uiDesigner/icons/textArea.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||||
|
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||||
|
<preferred-size width="150" height="50" />
|
||||||
|
</default-constraints>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JTextPane" icon="/com/intellij/uiDesigner/icons/textPane.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||||
|
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||||
|
<preferred-size width="150" height="50" />
|
||||||
|
</default-constraints>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JEditorPane" icon="/com/intellij/uiDesigner/icons/editorPane.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||||
|
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||||
|
<preferred-size width="150" height="50" />
|
||||||
|
</default-constraints>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JComboBox" icon="/com/intellij/uiDesigner/icons/comboBox.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="2" anchor="8" fill="1" />
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JTable" icon="/com/intellij/uiDesigner/icons/table.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||||
|
<preferred-size width="150" height="50" />
|
||||||
|
</default-constraints>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JList" icon="/com/intellij/uiDesigner/icons/list.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="6" hsize-policy="2" anchor="0" fill="3">
|
||||||
|
<preferred-size width="150" height="50" />
|
||||||
|
</default-constraints>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JTree" icon="/com/intellij/uiDesigner/icons/tree.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||||
|
<preferred-size width="150" height="50" />
|
||||||
|
</default-constraints>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JTabbedPane" icon="/com/intellij/uiDesigner/icons/tabbedPane.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
|
||||||
|
<preferred-size width="200" height="200" />
|
||||||
|
</default-constraints>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JSplitPane" icon="/com/intellij/uiDesigner/icons/splitPane.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
|
||||||
|
<preferred-size width="200" height="200" />
|
||||||
|
</default-constraints>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JSpinner" icon="/com/intellij/uiDesigner/icons/spinner.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JSlider" icon="/com/intellij/uiDesigner/icons/slider.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JSeparator" icon="/com/intellij/uiDesigner/icons/separator.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3" />
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JProgressBar" icon="/com/intellij/uiDesigner/icons/progressbar.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1" />
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JToolBar" icon="/com/intellij/uiDesigner/icons/toolbar.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1">
|
||||||
|
<preferred-size width="-1" height="20" />
|
||||||
|
</default-constraints>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JToolBar$Separator" icon="/com/intellij/uiDesigner/icons/toolbarSeparator.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="0" anchor="0" fill="1" />
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JScrollBar" icon="/com/intellij/uiDesigner/icons/scrollbar.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="6" hsize-policy="0" anchor="0" fill="2" />
|
||||||
|
</item>
|
||||||
|
</group>
|
||||||
|
</component>
|
||||||
|
</project>
|
6
OOP/.idea/vcs.xml
generated
Normal file
6
OOP/.idea/vcs.xml
generated
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="VcsDirectoryMappings">
|
||||||
|
<mapping directory="$PROJECT_DIR$/.." vcs="Git" />
|
||||||
|
</component>
|
||||||
|
</project>
|
12
OOP/OOP.iml
Normal file
12
OOP/OOP.iml
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
<?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$/Resources" type="java-resource" />
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||||
|
</content>
|
||||||
|
<orderEntry type="inheritedJdk" />
|
||||||
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
|
</component>
|
||||||
|
</module>
|
BIN
OOP/Resources/arrowDown.png
Normal file
BIN
OOP/Resources/arrowDown.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 965 B |
BIN
OOP/Resources/arrowLeft.png
Normal file
BIN
OOP/Resources/arrowLeft.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1005 B |
BIN
OOP/Resources/arrowRight.png
Normal file
BIN
OOP/Resources/arrowRight.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 978 B |
BIN
OOP/Resources/arrowUp.png
Normal file
BIN
OOP/Resources/arrowUp.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1012 B |
85
OOP/src/Drawnings/DrawningElectricLocomotive.java
Normal file
85
OOP/src/Drawnings/DrawningElectricLocomotive.java
Normal file
@ -0,0 +1,85 @@
|
|||||||
|
package Drawnings;
|
||||||
|
|
||||||
|
import Entities.EntityElectricLocomotive;
|
||||||
|
import java.awt.*;
|
||||||
|
|
||||||
|
|
||||||
|
public class DrawningElectricLocomotive extends DrawningLocomotive {
|
||||||
|
private EntityElectricLocomotive entityElectricLocomotive;
|
||||||
|
|
||||||
|
public DrawningElectricLocomotive(int speed, float weight, Color bodyColor,int wheelsType, Color additionalColor, boolean batteryStorage, boolean pantograph){
|
||||||
|
super(speed, weight ,bodyColor,wheelsType, 100,100);
|
||||||
|
entityElectricLocomotive = new EntityElectricLocomotive(speed,weight,bodyColor,additionalColor,batteryStorage,pantograph);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void DrawTransport(Graphics g){
|
||||||
|
if(entityElectricLocomotive == null || _startPosX == null || _startPosY == null){return;}
|
||||||
|
super.DrawTransport(g);
|
||||||
|
Graphics2D g2d = (Graphics2D)g;
|
||||||
|
|
||||||
|
Point[] line = new Point[]{
|
||||||
|
new Point(_startPosX, _startPosY + 25 + 20),
|
||||||
|
new Point(_startPosX, _startPosY + 30 + 20),
|
||||||
|
new Point(_startPosX + 100, _startPosY + 30 + 20),
|
||||||
|
new Point(_startPosX + 100, _startPosY + 25 + 20),
|
||||||
|
};
|
||||||
|
Polygon linePolugon = new Polygon();
|
||||||
|
for(Point point: line){
|
||||||
|
linePolugon.addPoint(point.x, point.y);
|
||||||
|
}
|
||||||
|
g2d.setColor(entityElectricLocomotive.getAdditionalColor());
|
||||||
|
g2d.fillPolygon(linePolugon);
|
||||||
|
|
||||||
|
|
||||||
|
if(entityElectricLocomotive.getBatteryStorage()){
|
||||||
|
int mod = 50;
|
||||||
|
Point[] battery = new Point[]{
|
||||||
|
new Point(_startPosX + 40/2 + mod, _startPosY + 2+ 20),
|
||||||
|
new Point(_startPosX + 40/2 + mod, _startPosY + 4+ 20),
|
||||||
|
new Point(_startPosX + 35/2 + mod , _startPosY + 4+ 20),
|
||||||
|
new Point(_startPosX + 35/2 + mod, _startPosY + 16+ 20),
|
||||||
|
new Point(_startPosX + 60/2 + mod, _startPosY + 16+ 20),
|
||||||
|
new Point(_startPosX + 60/2 + mod, _startPosY + 4+ 20),
|
||||||
|
new Point(_startPosX + 55/2 + mod, _startPosY + 4+ 20),
|
||||||
|
new Point(_startPosX + 55/2 + mod, _startPosY + 2+ 20),
|
||||||
|
};
|
||||||
|
mod += 20;
|
||||||
|
Point[] battery2 = new Point[]{
|
||||||
|
new Point(_startPosX + 40/2 + mod, _startPosY + 2+ 20),
|
||||||
|
new Point(_startPosX + 40/2 + mod, _startPosY + 4+ 20),
|
||||||
|
new Point(_startPosX + 35/2 + mod , _startPosY + 4+ 20),
|
||||||
|
new Point(_startPosX + 35/2 + mod, _startPosY + 16+ 20),
|
||||||
|
new Point(_startPosX + 60/2 + mod, _startPosY + 16+ 20),
|
||||||
|
new Point(_startPosX + 60/2 + mod, _startPosY + 4+ 20),
|
||||||
|
new Point(_startPosX + 55/2 + mod, _startPosY + 4+ 20),
|
||||||
|
new Point(_startPosX + 55/2 + mod, _startPosY + 2+ 20),
|
||||||
|
};
|
||||||
|
|
||||||
|
Polygon batteryPolygon = new Polygon();
|
||||||
|
for(Point points : battery){
|
||||||
|
batteryPolygon.addPoint(points.x, points.y);
|
||||||
|
}
|
||||||
|
Polygon battery2Polygon = new Polygon();
|
||||||
|
for(Point points : battery2){
|
||||||
|
battery2Polygon.addPoint(points.x, points.y);
|
||||||
|
}
|
||||||
|
g2d.setColor(Color.YELLOW);
|
||||||
|
g2d.fillPolygon(batteryPolygon);
|
||||||
|
g2d.fillPolygon(battery2Polygon);
|
||||||
|
}
|
||||||
|
if(entityElectricLocomotive.getPantograph()){
|
||||||
|
g2d.setColor(Color.BLACK);
|
||||||
|
g.drawRect(_startPosX + 40,_startPosY,10,1);
|
||||||
|
g.drawRect(_startPosX + 5 + 40, _startPosY ,1,20);
|
||||||
|
|
||||||
|
g.drawRect(_startPosX + 40 + 30,_startPosY,10,1);
|
||||||
|
g.drawRect(_startPosX + 5 + 40 + 30, _startPosY ,1,20);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
58
OOP/src/Drawnings/DrawningElectricLocomotiveWheels.java
Normal file
58
OOP/src/Drawnings/DrawningElectricLocomotiveWheels.java
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
package Drawnings;
|
||||||
|
|
||||||
|
import java.awt.*;
|
||||||
|
|
||||||
|
public class DrawningElectricLocomotiveWheels implements IDrawWheels{
|
||||||
|
private WheelsCount _wheelCount;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setNumber(int wheelCount) {
|
||||||
|
for (WheelsCount value : WheelsCount.values()) {
|
||||||
|
if (value.getEnumNumber() == wheelCount) {
|
||||||
|
_wheelCount = value;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void drawWheels(Graphics2D g2d, Color color, int startPosX, int startPosY) {
|
||||||
|
g2d.setColor(color);
|
||||||
|
g2d.setStroke(new BasicStroke(4));
|
||||||
|
|
||||||
|
if (_wheelCount.getEnumNumber() >= 2){
|
||||||
|
g2d.drawOval(startPosX, startPosY + 70,10,10);
|
||||||
|
g2d.drawOval(startPosX+ 10, startPosY + 70,10,10);
|
||||||
|
|
||||||
|
g2d.drawOval(startPosX + 50, startPosY + 70,10,10);
|
||||||
|
g2d.drawOval(startPosX+ 10 + 50, startPosY + 70,10,10);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_wheelCount.getEnumNumber() >= 3){
|
||||||
|
g2d.drawOval(startPosX, startPosY + 70,10,10);
|
||||||
|
g2d.drawOval(startPosX+ 10, startPosY + 70,10,10);
|
||||||
|
g2d.drawOval(startPosX+ 10 +10, startPosY + 70,10,10);
|
||||||
|
|
||||||
|
g2d.drawOval(startPosX + 50, startPosY + 70,10,10);
|
||||||
|
g2d.drawOval(startPosX + 10 + 50, startPosY + 70,10,10);
|
||||||
|
g2d.drawOval(startPosX + 10 + 10 + 50, startPosY + 70,10,10);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_wheelCount.getEnumNumber() >= 4){
|
||||||
|
g2d.drawOval(startPosX, startPosY + 70,10,10);
|
||||||
|
g2d.drawOval(startPosX+ 10, startPosY + 70,10,10);
|
||||||
|
g2d.drawOval(startPosX+ 10 +10, startPosY + 70,10,10);
|
||||||
|
g2d.drawOval(startPosX+ 10 +10 + 10, startPosY + 70,10,10);
|
||||||
|
|
||||||
|
g2d.drawOval(startPosX + 50, startPosY + 70,10,10);
|
||||||
|
g2d.drawOval(startPosX + 10 + 50, startPosY + 70,10,10);
|
||||||
|
g2d.drawOval(startPosX + 10 + 10 + 50, startPosY + 70,10,10);
|
||||||
|
g2d.drawOval(startPosX + 10 + 10 + 10 + 50, startPosY + 70,10,10);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
78
OOP/src/Drawnings/DrawningFancyWheels.java
Normal file
78
OOP/src/Drawnings/DrawningFancyWheels.java
Normal file
@ -0,0 +1,78 @@
|
|||||||
|
package Drawnings;
|
||||||
|
|
||||||
|
import java.awt.*;
|
||||||
|
|
||||||
|
public class DrawningFancyWheels implements IDrawWheels{
|
||||||
|
private WheelsCount _wheelCount;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setNumber(int wheelCount) {
|
||||||
|
for (WheelsCount value : WheelsCount.values()) {
|
||||||
|
if (value.getEnumNumber() == wheelCount) {
|
||||||
|
_wheelCount = value;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void drawWheels(Graphics2D g2d, Color color, int startPosX, int startPosY) {
|
||||||
|
g2d.setColor(color);
|
||||||
|
g2d.setStroke(new BasicStroke(4));
|
||||||
|
|
||||||
|
if (_wheelCount.getEnumNumber() >= 2){
|
||||||
|
g2d.drawOval(startPosX, startPosY + 70,10,10);
|
||||||
|
g2d.drawOval(startPosX + 1, startPosY + 70 + 1, 8, 8);
|
||||||
|
g2d.drawOval(startPosX+ 10, startPosY + 70,10,10);
|
||||||
|
g2d.drawOval(startPosX + 1 + 10, startPosY + 70 + 1, 8, 8);
|
||||||
|
|
||||||
|
|
||||||
|
g2d.drawOval(startPosX + 50, startPosY + 70,10,10);
|
||||||
|
g2d.drawOval(startPosX + 1 + 50, startPosY + 70 + 1, 8, 8);
|
||||||
|
g2d.drawOval(startPosX+ 10 + 50, startPosY + 70,10,10);
|
||||||
|
g2d.drawOval(startPosX + 1 + 10 + 50, startPosY + 70 + 1, 8, 8);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_wheelCount.getEnumNumber() >= 3){
|
||||||
|
g2d.drawOval(startPosX, startPosY + 70,10,10);
|
||||||
|
g2d.drawOval(startPosX + 1, startPosY + 70 + 1, 8, 8);
|
||||||
|
g2d.drawOval(startPosX+ 10, startPosY + 70,10,10);
|
||||||
|
g2d.drawOval(startPosX + 1 + 10, startPosY + 70 + 1, 8, 8);
|
||||||
|
g2d.drawOval(startPosX+ 10 +10, startPosY + 70,10,10);
|
||||||
|
g2d.drawOval(startPosX + 1 + 10 + 10, startPosY + 70 + 1, 8, 8);
|
||||||
|
|
||||||
|
g2d.drawOval(startPosX + 50, startPosY + 70,10,10);
|
||||||
|
g2d.drawOval(startPosX + 1 + 50, startPosY + 70 + 1, 8, 8);
|
||||||
|
g2d.drawOval(startPosX+ 10 + 50, startPosY + 70,10,10);
|
||||||
|
g2d.drawOval(startPosX + 1 + 10 + 50, startPosY + 70 + 1, 8, 8);
|
||||||
|
g2d.drawOval(startPosX + 10 + 10 + 50, startPosY + 70,10,10);
|
||||||
|
g2d.drawOval(startPosX + 1 + 10 + 10 + 50, startPosY + 70 + 1, 8, 8);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_wheelCount.getEnumNumber() >= 4){
|
||||||
|
g2d.drawOval(startPosX, startPosY + 70,10,10);
|
||||||
|
g2d.drawOval(startPosX + 1, startPosY + 70 + 1, 8, 8);
|
||||||
|
g2d.drawOval(startPosX+ 10, startPosY + 70,10,10);
|
||||||
|
g2d.drawOval(startPosX + 1 + 10, startPosY + 70 + 1, 8, 8);
|
||||||
|
g2d.drawOval(startPosX+ 10 +10, startPosY + 70,10,10);
|
||||||
|
g2d.drawOval(startPosX + 1 + 10 + 10, startPosY + 70 + 1, 8, 8);
|
||||||
|
g2d.drawOval(startPosX+ 10 +10 + 10, startPosY + 70,10,10);
|
||||||
|
g2d.drawOval(startPosX + 1 + 10 + 10 + 10, startPosY + 70 + 1, 8, 8);
|
||||||
|
|
||||||
|
g2d.drawOval(startPosX + 50, startPosY + 70,10,10);
|
||||||
|
g2d.drawOval(startPosX + 1 + 50, startPosY + 70 + 1, 8, 8);
|
||||||
|
g2d.drawOval(startPosX+ 10 + 50, startPosY + 70,10,10);
|
||||||
|
g2d.drawOval(startPosX + 1 + 10 + 50, startPosY + 70 + 1, 8, 8);
|
||||||
|
g2d.drawOval(startPosX + 10 + 10 + 50, startPosY + 70,10,10);
|
||||||
|
g2d.drawOval(startPosX + 1 + 10 + 10 + 50, startPosY + 70 + 1, 8, 8);
|
||||||
|
g2d.drawOval(startPosX + 10 + 10 + 10 + 50, startPosY + 70,10,10);
|
||||||
|
g2d.drawOval(startPosX + 1 + 10 + 10 + 10 + 50, startPosY + 70 + 1, 8, 8);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
185
OOP/src/Drawnings/DrawningLocomotive.java
Normal file
185
OOP/src/Drawnings/DrawningLocomotive.java
Normal file
@ -0,0 +1,185 @@
|
|||||||
|
package Drawnings;
|
||||||
|
|
||||||
|
|
||||||
|
import Entities.EntityLocomotive;
|
||||||
|
import MovementStrategy.MovementDirection;
|
||||||
|
|
||||||
|
import java.awt.*;
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
|
public class DrawningLocomotive {
|
||||||
|
private final EntityLocomotive entityLocomotive;
|
||||||
|
|
||||||
|
public EntityLocomotive getEntityLocomotive(){
|
||||||
|
return entityLocomotive;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Integer _pictureWidth;
|
||||||
|
private Integer _pictureHeight;
|
||||||
|
protected Integer _startPosX;
|
||||||
|
protected Integer _startPosY;
|
||||||
|
private int _drawingLocomotiveWidth = 100;
|
||||||
|
private int _drawingLocomotiveHight = 100;
|
||||||
|
|
||||||
|
public int GetPosX() {
|
||||||
|
return _startPosX;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int GetPosY() {
|
||||||
|
return _startPosY;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int GetWidth() {
|
||||||
|
return _drawingLocomotiveWidth;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int GetHeight() {
|
||||||
|
return _drawingLocomotiveHight;
|
||||||
|
}
|
||||||
|
|
||||||
|
private IDrawWheels drawWheels;
|
||||||
|
|
||||||
|
|
||||||
|
public DrawningElectricLocomotiveWheels _drawningElectricLocomotiveWheels;
|
||||||
|
|
||||||
|
public DrawningLocomotive(int speed, double weight, Color bodyColor, int wheelsType) {
|
||||||
|
entityLocomotive = new EntityLocomotive(speed, weight, bodyColor);
|
||||||
|
_startPosY = null;
|
||||||
|
_startPosX = null;
|
||||||
|
_pictureWidth = null;
|
||||||
|
_pictureHeight = null;
|
||||||
|
switch (wheelsType){
|
||||||
|
case 0:
|
||||||
|
drawWheels = new DrawningElectricLocomotiveWheels();
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
drawWheels = new DrawningFancyWheels();
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
drawWheels = new DrawningUltraFancyWheels();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
Random random = new Random();
|
||||||
|
int[] countwheels = {2, 3, 4};
|
||||||
|
int wheelCount = countwheels[random.nextInt(countwheels.length)];
|
||||||
|
drawWheels.setNumber(wheelCount);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
protected DrawningLocomotive(int speed, float weight, Color bodyColor,int wheelsType, int locomotiveWidth, int locomotiveHight) {
|
||||||
|
this(speed, weight, bodyColor, wheelsType);
|
||||||
|
_drawingLocomotiveHight = locomotiveHight;
|
||||||
|
_drawingLocomotiveWidth = locomotiveWidth;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPosition(int x, int y) {
|
||||||
|
if (_pictureHeight == null || _pictureWidth == null)
|
||||||
|
return;
|
||||||
|
_startPosX = x;
|
||||||
|
_startPosY = y;
|
||||||
|
|
||||||
|
if (_drawingLocomotiveWidth + x > _pictureWidth || x < 0) {
|
||||||
|
_startPosX = 0;
|
||||||
|
}
|
||||||
|
if (_drawingLocomotiveHight + y > _pictureHeight || y < 0) {
|
||||||
|
_startPosY = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean setPictureSize(int width, int height) {
|
||||||
|
|
||||||
|
if (_drawingLocomotiveHight > height || _drawingLocomotiveWidth > width)
|
||||||
|
return false;
|
||||||
|
_pictureHeight = height;
|
||||||
|
_pictureWidth = width;
|
||||||
|
|
||||||
|
if (_startPosX != null && _startPosY != null) {
|
||||||
|
if (_startPosX + _drawingLocomotiveWidth > width)
|
||||||
|
_startPosX = width - _drawingLocomotiveWidth;
|
||||||
|
if (_startPosY + _drawingLocomotiveHight > height)
|
||||||
|
_startPosY = height - _drawingLocomotiveHight;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean moveTransport(MovementDirection direction) {
|
||||||
|
if (entityLocomotive == null || _pictureWidth == null || _pictureHeight == null)
|
||||||
|
return false;
|
||||||
|
switch (direction) {
|
||||||
|
case Left:
|
||||||
|
if (_startPosX - entityLocomotive.getStep() > 0)
|
||||||
|
_startPosX -= (int) entityLocomotive.getStep();
|
||||||
|
return true;
|
||||||
|
case Up:
|
||||||
|
if (_startPosY - entityLocomotive.getStep() > 0)
|
||||||
|
_startPosY -= (int) entityLocomotive.getStep();
|
||||||
|
return true;
|
||||||
|
case Right:
|
||||||
|
if (_startPosX + entityLocomotive.getStep() < _pictureWidth - _drawingLocomotiveWidth)
|
||||||
|
_startPosX += (int) entityLocomotive.getStep();
|
||||||
|
return true;
|
||||||
|
case Down:
|
||||||
|
if (_startPosY + entityLocomotive.getStep() < _pictureHeight - _drawingLocomotiveHight)
|
||||||
|
_startPosY += (int) entityLocomotive.getStep();
|
||||||
|
return true;
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void DrawTransport(Graphics g){
|
||||||
|
if (entityLocomotive == null || _startPosX == null || _startPosY == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Graphics2D g2d = (Graphics2D)g;
|
||||||
|
drawWheels.drawWheels(g2d, Color.BLACK, _startPosX, _startPosY);
|
||||||
|
Point[] Body = new Point[]{
|
||||||
|
new Point(_startPosX + 20,_startPosY + 20),
|
||||||
|
new Point(_startPosX, _startPosY + 25 + 20),
|
||||||
|
new Point(_startPosX , _startPosY + 50 + 20),
|
||||||
|
new Point(_startPosX + 100 , _startPosY + 50 + 20),
|
||||||
|
new Point(_startPosX + 100, _startPosY + 25 + 20),
|
||||||
|
new Point(_startPosX + 105, _startPosY + 20),
|
||||||
|
};
|
||||||
|
|
||||||
|
Polygon BodyPolygon = new Polygon();
|
||||||
|
for(Point point:Body){
|
||||||
|
BodyPolygon.addPoint(point.x, point.y);
|
||||||
|
}
|
||||||
|
g2d.setColor(entityLocomotive.getBodyColor());
|
||||||
|
g2d.fillPolygon(BodyPolygon);
|
||||||
|
|
||||||
|
|
||||||
|
Point[] line = new Point[]{
|
||||||
|
new Point(_startPosX, _startPosY + 25 + 20),
|
||||||
|
new Point(_startPosX, _startPosY + 30 + 20),
|
||||||
|
new Point(_startPosX + 100, _startPosY + 30 + 20),
|
||||||
|
new Point(_startPosX + 100, _startPosY + 25 + 20),
|
||||||
|
};
|
||||||
|
|
||||||
|
Polygon linePolugon = new Polygon();
|
||||||
|
for(Point point: line){
|
||||||
|
linePolugon.addPoint(point.x, point.y);
|
||||||
|
}
|
||||||
|
g2d.setColor(Color.black);
|
||||||
|
g2d.fillPolygon(linePolugon);
|
||||||
|
|
||||||
|
Point[] glass = new Point[]{
|
||||||
|
new Point(_startPosX + 20, _startPosY + 2 + 20),
|
||||||
|
new Point(_startPosX + 6 , _startPosY + 20 + 20),
|
||||||
|
new Point(_startPosX + 20, _startPosY + 20 + 20),
|
||||||
|
new Point(_startPosX + 20, _startPosY + 2 + 20)
|
||||||
|
};
|
||||||
|
Polygon glassPolygon = new Polygon();
|
||||||
|
for(Point point: glass){
|
||||||
|
glassPolygon.addPoint(point.x, point.y);
|
||||||
|
}
|
||||||
|
g2d.setColor(Color.WHITE);
|
||||||
|
g2d.fillPolygon(glassPolygon);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
63
OOP/src/Drawnings/DrawningUltraFancyWheels.java
Normal file
63
OOP/src/Drawnings/DrawningUltraFancyWheels.java
Normal file
@ -0,0 +1,63 @@
|
|||||||
|
package Drawnings;
|
||||||
|
|
||||||
|
import java.awt.*;
|
||||||
|
|
||||||
|
public class DrawningUltraFancyWheels implements IDrawWheels{
|
||||||
|
private WheelsCount _wheelCount;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setNumber(int wheelCount) {
|
||||||
|
for (WheelsCount value : WheelsCount.values()) {
|
||||||
|
if (value.getEnumNumber() == wheelCount) {
|
||||||
|
_wheelCount = value;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void drawWheels(Graphics2D g2d, Color color, int startPosX, int startPosY) {
|
||||||
|
g2d.setColor(color);
|
||||||
|
g2d.setStroke(new BasicStroke(4));
|
||||||
|
|
||||||
|
if (_wheelCount.getEnumNumber() >= 2){
|
||||||
|
g2d.drawOval(startPosX, startPosY + 70,10,10);
|
||||||
|
g2d.drawLine(startPosX + 1, startPosY + 70 + 1, startPosX + 8, startPosY + 70 + 8);
|
||||||
|
g2d.drawOval(startPosX+ 10, startPosY + 70,10,10);
|
||||||
|
g2d.drawLine(startPosX + 1 + 10, startPosY + 70 + 1, startPosX + 8 + 10, startPosY + 70 + 8);
|
||||||
|
|
||||||
|
g2d.drawOval(startPosX + 50, startPosY + 70,10,10);
|
||||||
|
g2d.drawLine(startPosX + 1 + 50, startPosY + 70 + 1, startPosX + 8 + 50, startPosY + 70 + 8);
|
||||||
|
g2d.drawOval(startPosX+ 10 + 50, startPosY + 70,10,10);
|
||||||
|
g2d.drawLine(startPosX + 1 + 10 + 50, startPosY + 70 + 1, startPosX + 8 + 10 + 50, startPosY + 70 + 8);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_wheelCount.getEnumNumber() >= 3){
|
||||||
|
g2d.drawOval(startPosX, startPosY + 70,10,10);
|
||||||
|
g2d.drawOval(startPosX+ 10, startPosY + 70,10,10);
|
||||||
|
g2d.drawOval(startPosX+ 10 +10, startPosY + 70,10,10);
|
||||||
|
g2d.drawLine(startPosX + 1 + 10 + 10, startPosY + 70 + 1, startPosX + 8 + 10 + 10, startPosY + 70 + 8);
|
||||||
|
|
||||||
|
g2d.drawOval(startPosX + 50, startPosY + 70,10,10);
|
||||||
|
g2d.drawOval(startPosX + 10 + 50, startPosY + 70,10,10);
|
||||||
|
g2d.drawOval(startPosX + 10 + 10 + 50, startPosY + 70,10,10);
|
||||||
|
g2d.drawLine(startPosX + 1 + 10 + 10 + 50, startPosY + 70 + 1, startPosX + 8 + 10 + 10 + 50, startPosY + 70 + 8);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_wheelCount.getEnumNumber() >= 4){
|
||||||
|
g2d.drawOval(startPosX, startPosY + 70,10,10);
|
||||||
|
g2d.drawOval(startPosX+ 10, startPosY + 70,10,10);
|
||||||
|
g2d.drawOval(startPosX+ 10 +10, startPosY + 70,10,10);
|
||||||
|
g2d.drawOval(startPosX+ 10 +10 + 10, startPosY + 70,10,10);
|
||||||
|
g2d.drawLine(startPosX + 1 + 10 + 10 + 10, startPosY + 70 + 1, startPosX + 8 + 10 + 10 + 10, startPosY + 70 + 8);
|
||||||
|
|
||||||
|
g2d.drawOval(startPosX + 50, startPosY + 70,10,10);
|
||||||
|
g2d.drawOval(startPosX + 10 + 50, startPosY + 70,10,10);
|
||||||
|
g2d.drawOval(startPosX + 10 + 10 + 50, startPosY + 70,10,10);
|
||||||
|
g2d.drawOval(startPosX + 10 + 10 + 10 + 50, startPosY + 70,10,10);
|
||||||
|
g2d.drawLine(startPosX + 1 + 10 + 10 + 10 + 50, startPosY + 70 + 1, startPosX + 8 + 10 + 10 + 10 + 50, startPosY + 70 + 8);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
7
OOP/src/Drawnings/IDrawWheels.java
Normal file
7
OOP/src/Drawnings/IDrawWheels.java
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
package Drawnings;
|
||||||
|
|
||||||
|
import java.awt.*;
|
||||||
|
public interface IDrawWheels {
|
||||||
|
void setNumber(int x);
|
||||||
|
void drawWheels(Graphics2D graphics2D, Color color, int _startX, int _startY);
|
||||||
|
}
|
14
OOP/src/Drawnings/WheelsCount.java
Normal file
14
OOP/src/Drawnings/WheelsCount.java
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
package Drawnings;
|
||||||
|
|
||||||
|
public enum WheelsCount {
|
||||||
|
Two(2),
|
||||||
|
Three(3),
|
||||||
|
Four(4);
|
||||||
|
final private int EnumNumber;
|
||||||
|
WheelsCount(int enumNumber) {
|
||||||
|
EnumNumber = enumNumber;
|
||||||
|
}
|
||||||
|
public int getEnumNumber() {
|
||||||
|
return EnumNumber;
|
||||||
|
}
|
||||||
|
}
|
26
OOP/src/Entities/EntityElectricLocomotive.java
Normal file
26
OOP/src/Entities/EntityElectricLocomotive.java
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
package Entities;
|
||||||
|
|
||||||
|
import java.awt.*;
|
||||||
|
|
||||||
|
public class EntityElectricLocomotive extends EntityLocomotive{
|
||||||
|
|
||||||
|
private Color AdditionalColor;
|
||||||
|
public Color getAdditionalColor() {
|
||||||
|
return AdditionalColor;
|
||||||
|
}
|
||||||
|
private boolean BatteryStorage;
|
||||||
|
public boolean getBatteryStorage() {
|
||||||
|
return BatteryStorage;
|
||||||
|
}
|
||||||
|
private boolean Pantograph;
|
||||||
|
public boolean getPantograph() {
|
||||||
|
return Pantograph;
|
||||||
|
}
|
||||||
|
|
||||||
|
public EntityElectricLocomotive(int speed, double weight, Color bodyColor, Color additionalColor, boolean pantograph, boolean batteryStorage) {
|
||||||
|
super(speed, weight, bodyColor);
|
||||||
|
AdditionalColor = additionalColor;
|
||||||
|
Pantograph = pantograph;
|
||||||
|
BatteryStorage = batteryStorage;
|
||||||
|
}
|
||||||
|
}
|
36
OOP/src/Entities/EntityLocomotive.java
Normal file
36
OOP/src/Entities/EntityLocomotive.java
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
package Entities;
|
||||||
|
|
||||||
|
import java.awt.*;
|
||||||
|
|
||||||
|
public class EntityLocomotive {
|
||||||
|
private int Speed;
|
||||||
|
|
||||||
|
public int getSpeed() {
|
||||||
|
return Speed;
|
||||||
|
}
|
||||||
|
|
||||||
|
private double Weight;
|
||||||
|
|
||||||
|
public double getWeight() {
|
||||||
|
return Weight;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Color BodyColor;
|
||||||
|
|
||||||
|
public Color getBodyColor() {
|
||||||
|
return BodyColor;
|
||||||
|
}
|
||||||
|
|
||||||
|
private double Step;
|
||||||
|
|
||||||
|
public double getStep() {
|
||||||
|
return Speed * 100 / Weight;
|
||||||
|
}
|
||||||
|
|
||||||
|
public EntityLocomotive(int speed, double weight, Color bodyColor) {
|
||||||
|
Speed = speed;
|
||||||
|
Weight = weight;
|
||||||
|
BodyColor = bodyColor;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
131
OOP/src/FormElectricLocomotive.form
Normal file
131
OOP/src/FormElectricLocomotive.form
Normal file
@ -0,0 +1,131 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="FormElectricLocomotive">
|
||||||
|
<grid id="27dc6" binding="PanelWrapper" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||||
|
<margin top="0" left="0" bottom="0" right="0"/>
|
||||||
|
<constraints>
|
||||||
|
<xy x="20" y="20" width="599" height="476"/>
|
||||||
|
</constraints>
|
||||||
|
<properties/>
|
||||||
|
<border type="none"/>
|
||||||
|
<children>
|
||||||
|
<grid id="1ff9a" binding="PictureBox" layout-manager="GridLayoutManager" row-count="6" column-count="5" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||||
|
<margin top="0" left="0" bottom="0" right="0"/>
|
||||||
|
<constraints>
|
||||||
|
<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>
|
||||||
|
<toolTipText value=""/>
|
||||||
|
</properties>
|
||||||
|
<border type="none"/>
|
||||||
|
<children>
|
||||||
|
<vspacer id="7b40c">
|
||||||
|
<constraints>
|
||||||
|
<grid row="2" column="0" row-span="2" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false">
|
||||||
|
<preferred-size width="88" height="14"/>
|
||||||
|
</grid>
|
||||||
|
</constraints>
|
||||||
|
</vspacer>
|
||||||
|
<hspacer id="e0b21">
|
||||||
|
<constraints>
|
||||||
|
<grid row="4" column="1" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
</hspacer>
|
||||||
|
<component id="a8c2" class="javax.swing.JButton" binding="buttonCreateElectricLocomotive">
|
||||||
|
<constraints>
|
||||||
|
<grid row="5" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="2" fill="1" indent="0" use-parent-layout="false">
|
||||||
|
<minimum-size width="150" height="30"/>
|
||||||
|
<preferred-size width="150" height="30"/>
|
||||||
|
<maximum-size width="150" height="30"/>
|
||||||
|
</grid>
|
||||||
|
</constraints>
|
||||||
|
<properties>
|
||||||
|
<text value="Создать ЭлектроЛокомотив"/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
<component id="79b3e" class="javax.swing.JButton" binding="buttonCreateLocomotive">
|
||||||
|
<constraints>
|
||||||
|
<grid row="5" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="10" fill="0" indent="0" use-parent-layout="false">
|
||||||
|
<minimum-size width="150" height="30"/>
|
||||||
|
<preferred-size width="150" height="30"/>
|
||||||
|
<maximum-size width="150" height="30"/>
|
||||||
|
</grid>
|
||||||
|
</constraints>
|
||||||
|
<properties>
|
||||||
|
<text value="Создать локомотив"/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
<component id="fe25b" class="javax.swing.JButton" binding="buttonLeft">
|
||||||
|
<constraints>
|
||||||
|
<grid row="5" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="4" fill="0" indent="0" use-parent-layout="false">
|
||||||
|
<minimum-size width="30" height="30"/>
|
||||||
|
<preferred-size width="30" height="30"/>
|
||||||
|
<maximum-size width="30" height="30"/>
|
||||||
|
</grid>
|
||||||
|
</constraints>
|
||||||
|
<properties>
|
||||||
|
<icon value="arrowLeft.png"/>
|
||||||
|
<text value=""/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
<component id="3eabd" class="javax.swing.JButton" binding="buttonStrategyStep">
|
||||||
|
<constraints>
|
||||||
|
<grid row="1" column="3" row-span="1" col-span="2" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
<properties>
|
||||||
|
<text value="Шаг"/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
<component id="86d84" class="javax.swing.JButton" binding="buttonRight">
|
||||||
|
<constraints>
|
||||||
|
<grid row="5" column="4" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="0" indent="0" use-parent-layout="false">
|
||||||
|
<minimum-size width="30" height="30"/>
|
||||||
|
<preferred-size width="30" height="30"/>
|
||||||
|
<maximum-size width="30" height="30"/>
|
||||||
|
</grid>
|
||||||
|
</constraints>
|
||||||
|
<properties>
|
||||||
|
<icon value="arrowRight.png"/>
|
||||||
|
<text value=""/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
<component id="3dc0" class="javax.swing.JButton" binding="buttonDown">
|
||||||
|
<constraints>
|
||||||
|
<grid row="5" column="3" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="0" indent="0" use-parent-layout="false">
|
||||||
|
<minimum-size width="30" height="30"/>
|
||||||
|
<preferred-size width="30" height="30"/>
|
||||||
|
<maximum-size width="30" height="30"/>
|
||||||
|
</grid>
|
||||||
|
</constraints>
|
||||||
|
<properties>
|
||||||
|
<icon value="arrowDown.png"/>
|
||||||
|
<text value=""/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
<component id="ccb2a" class="javax.swing.JButton" binding="buttonUp">
|
||||||
|
<constraints>
|
||||||
|
<grid row="4" column="3" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="0" indent="0" use-parent-layout="false">
|
||||||
|
<minimum-size width="30" height="30"/>
|
||||||
|
<preferred-size width="30" height="30"/>
|
||||||
|
<maximum-size width="30" height="30"/>
|
||||||
|
</grid>
|
||||||
|
</constraints>
|
||||||
|
<properties>
|
||||||
|
<icon value="arrowUp.png"/>
|
||||||
|
<text value=""/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
<component id="988c8" class="javax.swing.JComboBox" binding="comboBoxStrategy">
|
||||||
|
<constraints>
|
||||||
|
<grid row="0" column="2" row-span="1" col-span="3" vsize-policy="0" hsize-policy="2" anchor="9" fill="1" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
<properties>
|
||||||
|
<actionCommand value=""/>
|
||||||
|
<doubleBuffered value="false"/>
|
||||||
|
<toolTipText value=""/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
</children>
|
||||||
|
</grid>
|
||||||
|
</children>
|
||||||
|
</grid>
|
||||||
|
</form>
|
177
OOP/src/FormElectricLocomotive.java
Normal file
177
OOP/src/FormElectricLocomotive.java
Normal file
@ -0,0 +1,177 @@
|
|||||||
|
|
||||||
|
import Drawnings.DrawningElectricLocomotive;
|
||||||
|
import Drawnings.DrawningLocomotive;
|
||||||
|
import MovementStrategy.*;
|
||||||
|
|
||||||
|
import javax.swing.*;
|
||||||
|
import java.awt.*;
|
||||||
|
import java.awt.event.ActionEvent;
|
||||||
|
import java.awt.event.ActionListener;
|
||||||
|
import java.util.LinkedList;
|
||||||
|
import java.util.Random;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class FormElectricLocomotive extends JFrame {
|
||||||
|
protected DrawningLocomotive _drawningLocomotive;
|
||||||
|
JPanel PanelWrapper;
|
||||||
|
private JPanel PictureBox;
|
||||||
|
private JButton buttonCreateElectricLocomotive;
|
||||||
|
private JButton buttonCreateLocomotive;
|
||||||
|
private JButton buttonRight;
|
||||||
|
private JButton buttonDown;
|
||||||
|
private JButton buttonLeft;
|
||||||
|
private JButton buttonUp;
|
||||||
|
private JComboBox comboBoxStrategy;
|
||||||
|
private JButton buttonStrategyStep;
|
||||||
|
private AbstractStrategy _strategy;
|
||||||
|
private List<JComponent> controls;
|
||||||
|
|
||||||
|
private void createObject(String type) {
|
||||||
|
Random random = new Random();
|
||||||
|
switch (type) {
|
||||||
|
case "Drawnings.DrawningLocomotive":
|
||||||
|
_drawningLocomotive = new DrawningLocomotive(50, 100,
|
||||||
|
new Color(random.nextInt(256), random.nextInt(256), random.nextInt(256)), random.nextInt(3));
|
||||||
|
break;
|
||||||
|
case "Drawnings.DrawningElectricLocomotive":
|
||||||
|
_drawningLocomotive = new DrawningElectricLocomotive(50, 100,
|
||||||
|
new Color(random.nextInt(256), random.nextInt(256), random.nextInt(256)),random.nextInt(3),
|
||||||
|
new Color(random.nextInt(256), random.nextInt(256), random.nextInt(256)),
|
||||||
|
random.nextBoolean(), random.nextBoolean());
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_drawningLocomotive.setPictureSize(PictureBox.getWidth(), PictureBox.getHeight());
|
||||||
|
_drawningLocomotive.setPosition(random.nextInt(100),
|
||||||
|
random.nextInt(100));
|
||||||
|
_strategy = null;
|
||||||
|
comboBoxStrategy.setEnabled(true);
|
||||||
|
|
||||||
|
Draw();
|
||||||
|
}
|
||||||
|
|
||||||
|
public FormElectricLocomotive() {
|
||||||
|
buttonUp.setName("buttonUp");
|
||||||
|
buttonDown.setName("buttonDown");
|
||||||
|
buttonLeft.setName("buttonLeft");
|
||||||
|
buttonRight.setName("buttonRight");
|
||||||
|
|
||||||
|
InitializeControlsRepaintList();
|
||||||
|
|
||||||
|
buttonCreateElectricLocomotive.addActionListener(new ActionListener() {
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
createObject("Drawnings.DrawningElectricLocomotive");
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
buttonCreateLocomotive.addActionListener(new ActionListener() {
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
createObject("Drawnings.DrawningLocomotive");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
ActionListener buttonMoveClickedListener = new ActionListener() {
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
String buttonName = ((JButton) e.getSource()).getName();
|
||||||
|
boolean result = false;
|
||||||
|
|
||||||
|
switch (buttonName) {
|
||||||
|
case "buttonUp": {
|
||||||
|
result = _drawningLocomotive.moveTransport(MovementDirection.Up);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case "buttonDown": {
|
||||||
|
result = _drawningLocomotive.moveTransport(MovementDirection.Down);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case "buttonLeft": {
|
||||||
|
result = _drawningLocomotive.moveTransport(MovementDirection.Left);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case "buttonRight": {
|
||||||
|
result = _drawningLocomotive.moveTransport(MovementDirection.Right);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (result)
|
||||||
|
Draw();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
buttonRight.addActionListener(buttonMoveClickedListener);
|
||||||
|
buttonDown.addActionListener(buttonMoveClickedListener);
|
||||||
|
buttonLeft.addActionListener(buttonMoveClickedListener);
|
||||||
|
buttonUp.addActionListener(buttonMoveClickedListener);
|
||||||
|
comboBoxStrategy.addItem("К центру");
|
||||||
|
comboBoxStrategy.addItem("К краю");
|
||||||
|
buttonStrategyStep.addActionListener(new ActionListener() {
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
if (_drawningLocomotive == null)
|
||||||
|
return;
|
||||||
|
if (comboBoxStrategy.isEnabled()) {
|
||||||
|
switch (comboBoxStrategy.getSelectedIndex()) {
|
||||||
|
case 0:
|
||||||
|
_strategy = new MoveToCenter();
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
_strategy = new MoveToBorder();
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
_strategy = null;
|
||||||
|
break;
|
||||||
|
|
||||||
|
}
|
||||||
|
if (_strategy == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_strategy.SetData(new MoveableLocomotive(_drawningLocomotive), PictureBox.getWidth(), PictureBox.getHeight());
|
||||||
|
}
|
||||||
|
if (_strategy == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_strategy.MakeStep();
|
||||||
|
Draw();
|
||||||
|
comboBoxStrategy.setEnabled(false);
|
||||||
|
|
||||||
|
if (_strategy.GetStatus() == StrategyStatus.Finish) {
|
||||||
|
comboBoxStrategy.setEnabled(true);
|
||||||
|
_strategy = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
private void Draw() {
|
||||||
|
if (_drawningLocomotive.getEntityLocomotive() == null)
|
||||||
|
return;
|
||||||
|
if (PictureBox.getWidth() == 0 || PictureBox.getHeight() == 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Graphics g = PictureBox.getGraphics();
|
||||||
|
g.setColor(PictureBox.getBackground());
|
||||||
|
g.fillRect(0,0, PictureBox.getWidth(), PictureBox.getHeight());
|
||||||
|
_drawningLocomotive.DrawTransport(g);
|
||||||
|
|
||||||
|
RepaintControls();
|
||||||
|
}
|
||||||
|
private void RepaintControls() {
|
||||||
|
for (JComponent control : controls) {
|
||||||
|
control.repaint();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void InitializeControlsRepaintList() {
|
||||||
|
controls = new LinkedList<>();
|
||||||
|
controls.add(buttonCreateElectricLocomotive);
|
||||||
|
controls.add(buttonCreateLocomotive);
|
||||||
|
controls.add(buttonUp);
|
||||||
|
controls.add(buttonDown);
|
||||||
|
controls.add(buttonLeft);
|
||||||
|
controls.add(buttonRight);
|
||||||
|
controls.add(comboBoxStrategy);
|
||||||
|
controls.add(buttonStrategyStep);
|
||||||
|
}
|
||||||
|
}
|
16
OOP/src/Main.java
Normal file
16
OOP/src/Main.java
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
import javax.swing.*;
|
||||||
|
|
||||||
|
//TIP To <b>Run</b> code, press <shortcut actionId="Run"/> or
|
||||||
|
// click the <icon src="AllIcons.Actions.Execute"/> icon in the gutter.
|
||||||
|
public class Main {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
JFrame.setDefaultLookAndFeelDecorated(false);
|
||||||
|
JFrame frame = new JFrame("Поезд");
|
||||||
|
frame.setContentPane(new FormElectricLocomotive().PanelWrapper);
|
||||||
|
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||||
|
frame.setLocation(500, 200);
|
||||||
|
frame.pack();
|
||||||
|
frame.setSize(700, 500);
|
||||||
|
frame.setVisible(true);
|
||||||
|
}
|
||||||
|
}
|
66
OOP/src/MovementStrategy/AbstractStrategy.java
Normal file
66
OOP/src/MovementStrategy/AbstractStrategy.java
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
package MovementStrategy;
|
||||||
|
|
||||||
|
public abstract class AbstractStrategy {
|
||||||
|
private IMoveableObject _moveableObject;
|
||||||
|
private StrategyStatus _state = StrategyStatus.NotInit;
|
||||||
|
protected int FieldWidth;
|
||||||
|
protected int 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;
|
||||||
|
_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(MovementDirection.Left); }
|
||||||
|
protected boolean MoveRight() { return MoveTo(MovementDirection.Right); }
|
||||||
|
protected boolean MoveUp() { return MoveTo(MovementDirection.Up); }
|
||||||
|
protected boolean MoveDown() { return MoveTo(MovementDirection.Down); }
|
||||||
|
protected ObjectParameters GetObjectParameters() { return _moveableObject.GetObjectPosition(); }
|
||||||
|
|
||||||
|
protected int GetStep()
|
||||||
|
{
|
||||||
|
if (_state != StrategyStatus.InProgress)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return _moveableObject.GetStep();
|
||||||
|
}
|
||||||
|
protected abstract void MoveToTarget();
|
||||||
|
protected abstract boolean IsTargetDestination();
|
||||||
|
private boolean MoveTo(MovementDirection directionType)
|
||||||
|
{
|
||||||
|
if (_state != StrategyStatus.InProgress)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (_moveableObject.TryMoveObject(directionType))
|
||||||
|
{
|
||||||
|
_moveableObject.MoveObject(directionType);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
8
OOP/src/MovementStrategy/IMoveableObject.java
Normal file
8
OOP/src/MovementStrategy/IMoveableObject.java
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
package MovementStrategy;
|
||||||
|
|
||||||
|
public interface IMoveableObject {
|
||||||
|
ObjectParameters GetObjectPosition();
|
||||||
|
int GetStep();
|
||||||
|
boolean TryMoveObject(MovementDirection direction);
|
||||||
|
void MoveObject(MovementDirection direction);
|
||||||
|
}
|
47
OOP/src/MovementStrategy/MoveToBorder.java
Normal file
47
OOP/src/MovementStrategy/MoveToBorder.java
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
package MovementStrategy;
|
||||||
|
|
||||||
|
public class MoveToBorder extends AbstractStrategy {
|
||||||
|
protected boolean IsTargetDestination()
|
||||||
|
{
|
||||||
|
ObjectParameters objParams = GetObjectParameters();
|
||||||
|
if (objParams == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return objParams.RightBorder() <= FieldWidth &&
|
||||||
|
objParams.RightBorder() + GetStep() >= FieldWidth &&
|
||||||
|
objParams.DownBorder() <= FieldHeight &&
|
||||||
|
objParams.DownBorder() + GetStep() >= FieldHeight;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void MoveToTarget()
|
||||||
|
{
|
||||||
|
ObjectParameters objParams = GetObjectParameters();
|
||||||
|
if (objParams == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
int diffX = objParams.RightBorder() - FieldWidth;
|
||||||
|
if (Math.abs(diffX) > GetStep())
|
||||||
|
{
|
||||||
|
if (diffX > 0)
|
||||||
|
{
|
||||||
|
MoveLeft();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
MoveRight();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
int diffY = objParams.DownBorder() - FieldHeight;
|
||||||
|
if (Math.abs(diffY) > GetStep())
|
||||||
|
{
|
||||||
|
if (diffY > 0)
|
||||||
|
{
|
||||||
|
MoveUp();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
MoveDown();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
47
OOP/src/MovementStrategy/MoveToCenter.java
Normal file
47
OOP/src/MovementStrategy/MoveToCenter.java
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
package MovementStrategy;
|
||||||
|
|
||||||
|
|
||||||
|
public class MoveToCenter extends AbstractStrategy {
|
||||||
|
protected boolean IsTargetDestination()
|
||||||
|
{
|
||||||
|
ObjectParameters objParams = GetObjectParameters();
|
||||||
|
if (objParams == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return (objParams.ObjectMiddleHorizontal() - GetStep() <= FieldWidth / 2 &&
|
||||||
|
objParams.ObjectMiddleHorizontal() + GetStep() >= FieldWidth / 2 &&
|
||||||
|
objParams.ObjectMiddleVertical() - GetStep() <= FieldHeight / 2 &&
|
||||||
|
objParams.ObjectMiddleVertical() + GetStep() >= FieldHeight / 2);
|
||||||
|
}
|
||||||
|
protected void MoveToTarget()
|
||||||
|
{
|
||||||
|
|
||||||
|
ObjectParameters objParams = GetObjectParameters();
|
||||||
|
if (objParams == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
int diffX = objParams.ObjectMiddleHorizontal() - FieldWidth / 2;
|
||||||
|
if (Math.abs(diffX) > GetStep()) {
|
||||||
|
if (diffX > 0)
|
||||||
|
{
|
||||||
|
MoveLeft();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
MoveRight();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
int diffY = objParams.ObjectMiddleVertical() - FieldHeight / 2;
|
||||||
|
if (Math.abs(diffY) > GetStep()) {
|
||||||
|
if (diffY > 0)
|
||||||
|
{
|
||||||
|
MoveUp();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
MoveDown();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
24
OOP/src/MovementStrategy/MoveableLocomotive.java
Normal file
24
OOP/src/MovementStrategy/MoveableLocomotive.java
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
package MovementStrategy;
|
||||||
|
|
||||||
|
import Drawnings.DrawningLocomotive;
|
||||||
|
|
||||||
|
public class MoveableLocomotive implements IMoveableObject {
|
||||||
|
private DrawningLocomotive _locomotive = null;
|
||||||
|
public MoveableLocomotive(DrawningLocomotive drawningLocomotive)
|
||||||
|
{
|
||||||
|
_locomotive = drawningLocomotive;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ObjectParameters GetObjectPosition()
|
||||||
|
{
|
||||||
|
if (_locomotive == null || _locomotive.getEntityLocomotive() == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return new ObjectParameters(_locomotive.GetPosX(), _locomotive.GetPosY(), _locomotive.GetWidth(), _locomotive.GetHeight());
|
||||||
|
}
|
||||||
|
|
||||||
|
public int GetStep() { return (int) _locomotive.getEntityLocomotive().getStep(); }
|
||||||
|
public boolean TryMoveObject(MovementDirection direction) { return _locomotive.moveTransport(direction); }
|
||||||
|
public void MoveObject(MovementDirection direction) { _locomotive.moveTransport(direction); }
|
||||||
|
}
|
9
OOP/src/MovementStrategy/MovementDirection.java
Normal file
9
OOP/src/MovementStrategy/MovementDirection.java
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
|
||||||
|
package MovementStrategy;
|
||||||
|
|
||||||
|
public enum MovementDirection {
|
||||||
|
Up,
|
||||||
|
Down,
|
||||||
|
Left,
|
||||||
|
Right;
|
||||||
|
}
|
25
OOP/src/MovementStrategy/ObjectParameters.java
Normal file
25
OOP/src/MovementStrategy/ObjectParameters.java
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
package MovementStrategy;
|
||||||
|
|
||||||
|
public class ObjectParameters {
|
||||||
|
private int _x;
|
||||||
|
private int _y;
|
||||||
|
private int _width;
|
||||||
|
private int _height;
|
||||||
|
|
||||||
|
public int LeftBorder() { return _x; }
|
||||||
|
public int TopBorder() { return _y; }
|
||||||
|
public int RightBorder() { return _x + _width; }
|
||||||
|
public int DownBorder() { return _y + _height; }
|
||||||
|
|
||||||
|
|
||||||
|
public int ObjectMiddleHorizontal () { return _x + _width / 2; }
|
||||||
|
public int ObjectMiddleVertical () { return _y + _height / 2; }
|
||||||
|
|
||||||
|
public ObjectParameters(int x, int y, int width, int height)
|
||||||
|
{
|
||||||
|
_x = x;
|
||||||
|
_y = y;
|
||||||
|
_width = width;
|
||||||
|
_height = height;
|
||||||
|
}
|
||||||
|
}
|
7
OOP/src/MovementStrategy/StrategyStatus.java
Normal file
7
OOP/src/MovementStrategy/StrategyStatus.java
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
package MovementStrategy;
|
||||||
|
|
||||||
|
public enum StrategyStatus {
|
||||||
|
NotInit,
|
||||||
|
InProgress,
|
||||||
|
Finish
|
||||||
|
}
|
4
OOP_Hard/.idea/shelf/Uncommitted_changes_before_Checkout_at_08_06_2024_6_41__Changes_.xml
generated
Normal file
4
OOP_Hard/.idea/shelf/Uncommitted_changes_before_Checkout_at_08_06_2024_6_41__Changes_.xml
generated
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
<changelist name="Uncommitted_changes_before_Checkout_at_08_06_2024_6_41_[Changes]" date="1717814510674" recycled="true" deleted="true">
|
||||||
|
<option name="PATH" value="$PROJECT_DIR$/.idea/shelf/Uncommitted_changes_before_Checkout_at_08_06_2024_6_41_[Changes]/shelved.patch" />
|
||||||
|
<option name="DESCRIPTION" value="Uncommitted changes before Checkout at 08.06.2024 6:41 [Changes]" />
|
||||||
|
</changelist>
|
147
OOP_Hard/.idea/workspace.xml
generated
Normal file
147
OOP_Hard/.idea/workspace.xml
generated
Normal file
@ -0,0 +1,147 @@
|
|||||||
|
<?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="2c6dc409-0e61-4c24-961c-ffc4b8f66b41" name="Changes" comment="Колеса тоже сделал" />
|
||||||
|
<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_BRANCH_BY_REPOSITORY">
|
||||||
|
<map>
|
||||||
|
<entry key="$PROJECT_DIR$" value="LabWork2" />
|
||||||
|
</map>
|
||||||
|
</option>
|
||||||
|
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
|
||||||
|
</component>
|
||||||
|
<component name="ProjectColorInfo">{
|
||||||
|
"associatedIndex": 3
|
||||||
|
}</component>
|
||||||
|
<component name="ProjectId" id="2hUltEP4wg6CjwGnxkE3ybJGhnn" />
|
||||||
|
<component name="ProjectLevelVcsManager" settingsEditedManually="true" />
|
||||||
|
<component name="ProjectViewState">
|
||||||
|
<option name="hideEmptyMiddlePackages" value="true" />
|
||||||
|
<option name="showLibraryContents" value="true" />
|
||||||
|
</component>
|
||||||
|
<component name="PropertiesComponent"><![CDATA[{
|
||||||
|
"keyToString": {
|
||||||
|
"Application.Main.executor": "Run",
|
||||||
|
"RunOnceActivity.OpenProjectViewOnStart": "true",
|
||||||
|
"RunOnceActivity.ShowReadmeOnStart": "true",
|
||||||
|
"SHARE_PROJECT_CONFIGURATION_FILES": "true",
|
||||||
|
"git-widget-placeholder": "master",
|
||||||
|
"kotlin-language-version-configured": "true",
|
||||||
|
"last_opened_file_path": "C:/Users/1/IdeaProjects/PIBD-11_Basalov_A.D_Hard1/OOP",
|
||||||
|
"onboarding.tips.debug.path": "C:/Users/1/IdeaProjects/OOP_Hard/src/Main.java"
|
||||||
|
}
|
||||||
|
}]]></component>
|
||||||
|
<component name="RecentsManager">
|
||||||
|
<key name="MoveFile.RECENT_KEYS">
|
||||||
|
<recent name="C:\Users\1\IdeaProjects\OOP_Hard\Resources" />
|
||||||
|
<recent name="C:\Users\1\IdeaProjects\OOP_Hard" />
|
||||||
|
</key>
|
||||||
|
</component>
|
||||||
|
<component name="SharedIndexes">
|
||||||
|
<attachedChunks>
|
||||||
|
<set>
|
||||||
|
<option value="jdk-1.8.0_402-corretto-1.8.0_402-4caba194b151-ae57be32" />
|
||||||
|
</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="2c6dc409-0e61-4c24-961c-ffc4b8f66b41" name="Changes" comment="" />
|
||||||
|
<created>1717656751523</created>
|
||||||
|
<option name="number" value="Default" />
|
||||||
|
<option name="presentableId" value="Default" />
|
||||||
|
<updated>1717656751523</updated>
|
||||||
|
</task>
|
||||||
|
<task id="LOCAL-00001" summary="d">
|
||||||
|
<option name="closed" value="true" />
|
||||||
|
<created>1717663084303</created>
|
||||||
|
<option name="number" value="00001" />
|
||||||
|
<option name="presentableId" value="LOCAL-00001" />
|
||||||
|
<option name="project" value="LOCAL" />
|
||||||
|
<updated>1717663084303</updated>
|
||||||
|
</task>
|
||||||
|
<task id="LOCAL-00002" summary="Добавил базовую сущность">
|
||||||
|
<option name="closed" value="true" />
|
||||||
|
<created>1717764105573</created>
|
||||||
|
<option name="number" value="00002" />
|
||||||
|
<option name="presentableId" value="LOCAL-00002" />
|
||||||
|
<option name="project" value="LOCAL" />
|
||||||
|
<updated>1717764105573</updated>
|
||||||
|
</task>
|
||||||
|
<task id="LOCAL-00003" summary="Остается вернуть колеса">
|
||||||
|
<option name="closed" value="true" />
|
||||||
|
<created>1717768092738</created>
|
||||||
|
<option name="number" value="00003" />
|
||||||
|
<option name="presentableId" value="LOCAL-00003" />
|
||||||
|
<option name="project" value="LOCAL" />
|
||||||
|
<updated>1717768092738</updated>
|
||||||
|
</task>
|
||||||
|
<task id="LOCAL-00004" summary="Колеса тоже сделал">
|
||||||
|
<option name="closed" value="true" />
|
||||||
|
<created>1717770679679</created>
|
||||||
|
<option name="number" value="00004" />
|
||||||
|
<option name="presentableId" value="LOCAL-00004" />
|
||||||
|
<option name="project" value="LOCAL" />
|
||||||
|
<updated>1717770679679</updated>
|
||||||
|
</task>
|
||||||
|
<option name="localTasksCounter" value="5" />
|
||||||
|
<servers />
|
||||||
|
</component>
|
||||||
|
<component name="Vcs.Log.Tabs.Properties">
|
||||||
|
<option name="TAB_STATES">
|
||||||
|
<map>
|
||||||
|
<entry key="MAIN">
|
||||||
|
<value>
|
||||||
|
<State>
|
||||||
|
<option name="FILTERS">
|
||||||
|
<map>
|
||||||
|
<entry key="branch">
|
||||||
|
<value>
|
||||||
|
<list>
|
||||||
|
<option value="master" />
|
||||||
|
</list>
|
||||||
|
</value>
|
||||||
|
</entry>
|
||||||
|
</map>
|
||||||
|
</option>
|
||||||
|
</State>
|
||||||
|
</value>
|
||||||
|
</entry>
|
||||||
|
</map>
|
||||||
|
</option>
|
||||||
|
</component>
|
||||||
|
<component name="VcsManagerConfiguration">
|
||||||
|
<MESSAGE value="d" />
|
||||||
|
<MESSAGE value="Добавил базовую сущность" />
|
||||||
|
<MESSAGE value="Остается вернуть колеса" />
|
||||||
|
<MESSAGE value="Колеса тоже сделал" />
|
||||||
|
<option name="LAST_COMMIT_MESSAGE" value="Колеса тоже сделал" />
|
||||||
|
</component>
|
||||||
|
<component name="XDebuggerManager">
|
||||||
|
<breakpoint-manager>
|
||||||
|
<breakpoints>
|
||||||
|
<line-breakpoint enabled="true" type="java-line">
|
||||||
|
<url>file://$PROJECT_DIR$/src/Main.java</url>
|
||||||
|
<line>14</line>
|
||||||
|
<option name="timeStamp" value="1" />
|
||||||
|
</line-breakpoint>
|
||||||
|
</breakpoints>
|
||||||
|
</breakpoint-manager>
|
||||||
|
</component>
|
||||||
|
</project>
|
Loading…
x
Reference in New Issue
Block a user