Лабораторная работа 2
This commit is contained in:
parent
b637ff72fc
commit
28e315e889
124
.idea/uiDesigner.xml
Normal file
124
.idea/uiDesigner.xml
Normal file
@ -0,0 +1,124 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="Palette2">
|
||||||
|
<group name="Swing">
|
||||||
|
<item class="com.intellij.uiDesigner.HSpacer" tooltip-text="Horizontal Spacer" icon="/com/intellij/uiDesigner/icons/hspacer.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="1" hsize-policy="6" anchor="0" fill="1" />
|
||||||
|
</item>
|
||||||
|
<item class="com.intellij.uiDesigner.VSpacer" tooltip-text="Vertical Spacer" icon="/com/intellij/uiDesigner/icons/vspacer.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="6" hsize-policy="1" anchor="0" fill="2" />
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JPanel" icon="/com/intellij/uiDesigner/icons/panel.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3" />
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JScrollPane" icon="/com/intellij/uiDesigner/icons/scrollPane.svg" removable="false" auto-create-binding="false" can-attach-label="true">
|
||||||
|
<default-constraints vsize-policy="7" hsize-policy="7" anchor="0" fill="3" />
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JButton" icon="/com/intellij/uiDesigner/icons/button.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="3" anchor="0" fill="1" />
|
||||||
|
<initial-values>
|
||||||
|
<property name="text" value="Button" />
|
||||||
|
</initial-values>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JRadioButton" icon="/com/intellij/uiDesigner/icons/radioButton.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
|
||||||
|
<initial-values>
|
||||||
|
<property name="text" value="RadioButton" />
|
||||||
|
</initial-values>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JCheckBox" icon="/com/intellij/uiDesigner/icons/checkBox.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
|
||||||
|
<initial-values>
|
||||||
|
<property name="text" value="CheckBox" />
|
||||||
|
</initial-values>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JLabel" icon="/com/intellij/uiDesigner/icons/label.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="0" anchor="8" fill="0" />
|
||||||
|
<initial-values>
|
||||||
|
<property name="text" value="Label" />
|
||||||
|
</initial-values>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JTextField" icon="/com/intellij/uiDesigner/icons/textField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
|
||||||
|
<preferred-size width="150" height="-1" />
|
||||||
|
</default-constraints>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JPasswordField" icon="/com/intellij/uiDesigner/icons/passwordField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
|
||||||
|
<preferred-size width="150" height="-1" />
|
||||||
|
</default-constraints>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JFormattedTextField" icon="/com/intellij/uiDesigner/icons/formattedTextField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
|
||||||
|
<preferred-size width="150" height="-1" />
|
||||||
|
</default-constraints>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JTextArea" icon="/com/intellij/uiDesigner/icons/textArea.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||||
|
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||||
|
<preferred-size width="150" height="50" />
|
||||||
|
</default-constraints>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JTextPane" icon="/com/intellij/uiDesigner/icons/textPane.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||||
|
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||||
|
<preferred-size width="150" height="50" />
|
||||||
|
</default-constraints>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JEditorPane" icon="/com/intellij/uiDesigner/icons/editorPane.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||||
|
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||||
|
<preferred-size width="150" height="50" />
|
||||||
|
</default-constraints>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JComboBox" icon="/com/intellij/uiDesigner/icons/comboBox.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="2" anchor="8" fill="1" />
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JTable" icon="/com/intellij/uiDesigner/icons/table.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||||
|
<preferred-size width="150" height="50" />
|
||||||
|
</default-constraints>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JList" icon="/com/intellij/uiDesigner/icons/list.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="6" hsize-policy="2" anchor="0" fill="3">
|
||||||
|
<preferred-size width="150" height="50" />
|
||||||
|
</default-constraints>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JTree" icon="/com/intellij/uiDesigner/icons/tree.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||||
|
<preferred-size width="150" height="50" />
|
||||||
|
</default-constraints>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JTabbedPane" icon="/com/intellij/uiDesigner/icons/tabbedPane.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
|
||||||
|
<preferred-size width="200" height="200" />
|
||||||
|
</default-constraints>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JSplitPane" icon="/com/intellij/uiDesigner/icons/splitPane.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
|
||||||
|
<preferred-size width="200" height="200" />
|
||||||
|
</default-constraints>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JSpinner" icon="/com/intellij/uiDesigner/icons/spinner.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JSlider" icon="/com/intellij/uiDesigner/icons/slider.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JSeparator" icon="/com/intellij/uiDesigner/icons/separator.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3" />
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JProgressBar" icon="/com/intellij/uiDesigner/icons/progressbar.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1" />
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JToolBar" icon="/com/intellij/uiDesigner/icons/toolbar.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1">
|
||||||
|
<preferred-size width="-1" height="20" />
|
||||||
|
</default-constraints>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JToolBar$Separator" icon="/com/intellij/uiDesigner/icons/toolbarSeparator.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="0" anchor="0" fill="1" />
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JScrollBar" icon="/com/intellij/uiDesigner/icons/scrollbar.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="6" hsize-policy="0" anchor="0" fill="2" />
|
||||||
|
</item>
|
||||||
|
</group>
|
||||||
|
</component>
|
||||||
|
</project>
|
12
src/src/ChoiseAndDrawingPortholes/CountPortholes.java
Normal file
12
src/src/ChoiseAndDrawingPortholes/CountPortholes.java
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
package ChoiseAndDrawingPortholes;
|
||||||
|
|
||||||
|
public enum CountPortholes {
|
||||||
|
TenPortholes(10),
|
||||||
|
TwentyPortholes(20),
|
||||||
|
ThirtyPortholes(30);
|
||||||
|
private int numberofportholes;
|
||||||
|
CountPortholes(int numberofportholes) {
|
||||||
|
this.numberofportholes = numberofportholes;
|
||||||
|
}
|
||||||
|
public int getNumportholes() {return numberofportholes;}
|
||||||
|
}
|
@ -1,3 +1,5 @@
|
|||||||
|
package ChoiseAndDrawingPortholes;
|
||||||
|
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
|
|
||||||
public class DrawingPortholes {
|
public class DrawingPortholes {
|
||||||
@ -10,16 +12,16 @@ public class DrawingPortholes {
|
|||||||
public void SetCount(int count) {
|
public void SetCount(int count) {
|
||||||
switch (count) {
|
switch (count) {
|
||||||
case 1: // 10
|
case 1: // 10
|
||||||
_porthole = CountPortholes.Ten;
|
_porthole = CountPortholes.TenPortholes;
|
||||||
break;
|
break;
|
||||||
case 2: // 20
|
case 2: // 20
|
||||||
_porthole = CountPortholes.Twenty;
|
_porthole = CountPortholes.TwentyPortholes;
|
||||||
break;
|
break;
|
||||||
case 3: // 30
|
case 3: // 30
|
||||||
_porthole = CountPortholes.Thirty;
|
_porthole = CountPortholes.ThirtyPortholes;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
_porthole = CountPortholes.Ten;
|
_porthole = CountPortholes.TenPortholes;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -37,7 +39,7 @@ public class DrawingPortholes {
|
|||||||
g.drawOval(_startPosx + 19 + i * 8, _startPoxY + 21, 3, 3);
|
g.drawOval(_startPosx + 19 + i * 8, _startPoxY + 21, 3, 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_porthole != CountPortholes.Ten) {
|
if (_porthole != CountPortholes.TenPortholes) {
|
||||||
for (int i = 0; i < 5; ++i) {
|
for (int i = 0; i < 5; ++i) {
|
||||||
g.setColor(Color.cyan);
|
g.setColor(Color.cyan);
|
||||||
g.fillOval(_startPosx - 15 + i * 5, _startPoxY + 28, 3, 3);
|
g.fillOval(_startPosx - 15 + i * 5, _startPoxY + 28, 3, 3);
|
||||||
@ -51,7 +53,7 @@ public class DrawingPortholes {
|
|||||||
g.drawOval(_startPosx + 115 + i * 5, _startPoxY + 28, 3, 3);
|
g.drawOval(_startPosx + 115 + i * 5, _startPoxY + 28, 3, 3);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (_porthole == CountPortholes.Thirty) {
|
if (_porthole == CountPortholes.ThirtyPortholes) {
|
||||||
for (int i = 0; i < 10; ++i) {
|
for (int i = 0; i < 10; ++i) {
|
||||||
g.setColor(Color.cyan);
|
g.setColor(Color.cyan);
|
||||||
g.fillOval(_startPosx + 19 + i * 8, _startPoxY + 37, 3, 3);
|
g.fillOval(_startPosx + 19 + i * 8, _startPoxY + 37, 3, 3);
|
@ -0,0 +1,31 @@
|
|||||||
|
package ChoiseAndDrawingPortholes;
|
||||||
|
|
||||||
|
import java.awt.*;
|
||||||
|
import Entities.*;
|
||||||
|
|
||||||
|
public class DrawingPortholesCircle implements IDifferentPortholes {
|
||||||
|
private CountPortholes _porthole;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setNumberPortholes(int numberofportholes) {
|
||||||
|
for (CountPortholes numofenum : CountPortholes.values()) {
|
||||||
|
if (numofenum.getNumportholes() == numberofportholes) {
|
||||||
|
_porthole = numofenum;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CountPortholes getNumberOfPortholes() {
|
||||||
|
return _porthole;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void DrawPorthole(Graphics2D g, int x, int y, int width, int height, Color bodyColor) {
|
||||||
|
g.setColor(Color.cyan);
|
||||||
|
g.fillOval(x, y, 3, 3);
|
||||||
|
g.setColor(Color.black);
|
||||||
|
g.drawOval(x, y, 3, 3);
|
||||||
|
}
|
||||||
|
}
|
33
src/src/ChoiseAndDrawingPortholes/DrawingPortholesHeart.java
Normal file
33
src/src/ChoiseAndDrawingPortholes/DrawingPortholesHeart.java
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
package ChoiseAndDrawingPortholes;
|
||||||
|
|
||||||
|
import java.awt.*;
|
||||||
|
|
||||||
|
public class DrawingPortholesHeart implements IDifferentPortholes {
|
||||||
|
private CountPortholes _porthole;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setNumberPortholes(int numberofportholes) {
|
||||||
|
for (CountPortholes numofenum : CountPortholes.values()) {
|
||||||
|
if (numofenum.getNumportholes() == numberofportholes) {
|
||||||
|
_porthole = numofenum;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CountPortholes getNumberOfPortholes() {
|
||||||
|
return _porthole;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void DrawPorthole(Graphics2D g, int x, int y, int width, int height, Color bodyColor) {
|
||||||
|
int[] HeartX = {x + 2, x, x, x + 1, x + 2, x + 3, x + 5, x + 5};
|
||||||
|
int[] HeartY = {y + 4, y + 2, y, y, y + 1, y, y, y + 2};
|
||||||
|
g.setColor(Color.cyan);
|
||||||
|
g.fillPolygon(HeartX, HeartY, HeartX.length);
|
||||||
|
g.setColor(Color.black);
|
||||||
|
g.drawPolygon(HeartX, HeartY, HeartX.length);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,30 @@
|
|||||||
|
package ChoiseAndDrawingPortholes;
|
||||||
|
|
||||||
|
import java.awt.*;
|
||||||
|
|
||||||
|
public class DrawingPortholesSquare implements IDifferentPortholes {
|
||||||
|
private CountPortholes _porthole;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setNumberPortholes(int numberofportholes) {
|
||||||
|
for (CountPortholes numofenum : CountPortholes.values()) {
|
||||||
|
if (numofenum.getNumportholes() == numberofportholes) {
|
||||||
|
_porthole = numofenum;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CountPortholes getNumberOfPortholes() {
|
||||||
|
return _porthole;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void DrawPorthole(Graphics2D g, int x, int y, int width, int height, Color bodyColor) {
|
||||||
|
g.setColor(Color.cyan);
|
||||||
|
g.fillRect(x, y, 3, 3);
|
||||||
|
g.setColor(Color.black);
|
||||||
|
g.drawRect(x, y, 3, 3);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,9 @@
|
|||||||
|
package ChoiseAndDrawingPortholes;
|
||||||
|
|
||||||
|
import java.awt.*;
|
||||||
|
|
||||||
|
public interface IDifferentPortholes {
|
||||||
|
void setNumberPortholes(int numberofportholes);
|
||||||
|
CountPortholes getNumberOfPortholes();
|
||||||
|
void DrawPorthole(Graphics2D g, int x, int y, int width, int height, Color bodyColor);
|
||||||
|
}
|
@ -1,5 +0,0 @@
|
|||||||
public enum CountPortholes {
|
|
||||||
Ten,
|
|
||||||
Twenty,
|
|
||||||
Thirty;
|
|
||||||
}
|
|
@ -1,144 +0,0 @@
|
|||||||
import javax.swing.*;
|
|
||||||
import java.awt.*;
|
|
||||||
import java.util.Random;
|
|
||||||
|
|
||||||
public class DrawingAirbus extends JPanel {
|
|
||||||
public EntityAirbus EntityAirbus;
|
|
||||||
public DrawingPortholes _portholes = null;
|
|
||||||
private Integer picture_width;
|
|
||||||
private Integer picture_height;
|
|
||||||
private Integer _StartPosX;
|
|
||||||
private Integer _StartPosY;
|
|
||||||
private int drawingAirbusWidth = 185;
|
|
||||||
private int drawingAirbusHeight = 100;
|
|
||||||
public void Init(int speed, double weight, Color bodycolor, Color additionalcolor, boolean sheeppipes, boolean fueltank) {
|
|
||||||
EntityAirbus = new EntityAirbus();
|
|
||||||
EntityAirbus.Init(speed, weight, bodycolor, additionalcolor, sheeppipes, fueltank);
|
|
||||||
picture_width = null;
|
|
||||||
picture_height = null;
|
|
||||||
_StartPosX = null;
|
|
||||||
_StartPosY = null;
|
|
||||||
_portholes = new DrawingPortholes();
|
|
||||||
Random rand = new Random();
|
|
||||||
int randomNum = rand.nextInt(4);
|
|
||||||
_portholes.SetCount(randomNum);
|
|
||||||
}
|
|
||||||
public boolean SetPictureSize(int width, int height) {
|
|
||||||
if (width < drawingAirbusWidth || height < drawingAirbusHeight) return false;
|
|
||||||
picture_width = width;
|
|
||||||
picture_height = height;
|
|
||||||
if (_StartPosX != null || _StartPosY != null) {
|
|
||||||
if (_StartPosX + drawingAirbusWidth > picture_width)
|
|
||||||
{
|
|
||||||
_StartPosX = _StartPosX - (_StartPosX + drawingAirbusWidth - picture_width);
|
|
||||||
}
|
|
||||||
else if (_StartPosX < 0) _StartPosX = 0;
|
|
||||||
if (_StartPosY + drawingAirbusHeight > picture_height)
|
|
||||||
{
|
|
||||||
_StartPosY = _StartPosY - (_StartPosY + drawingAirbusHeight - picture_height);
|
|
||||||
}
|
|
||||||
else if (_StartPosY < 0) _StartPosY = 0;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
public void SetPosition(int x, int y) {
|
|
||||||
if (!(picture_width != null && picture_height != null)) return;
|
|
||||||
if (x + drawingAirbusWidth > picture_width)
|
|
||||||
{
|
|
||||||
_StartPosX = x - (x + drawingAirbusWidth - picture_width);
|
|
||||||
}
|
|
||||||
else if (x < 0) _StartPosX = 0;
|
|
||||||
else _StartPosX = x;
|
|
||||||
if (y + drawingAirbusHeight > picture_height)
|
|
||||||
{
|
|
||||||
_StartPosY = y - (y + drawingAirbusHeight - picture_height);
|
|
||||||
}
|
|
||||||
else if (y < 0) _StartPosY = 0;
|
|
||||||
else _StartPosY = y;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean MoveTransport(DirectionType direction) {
|
|
||||||
if (EntityAirbus == null || _StartPosX == null || _StartPosY == null) return false;
|
|
||||||
switch (direction) {
|
|
||||||
case Left:
|
|
||||||
if (_StartPosX - EntityAirbus.Step > 0) {
|
|
||||||
_StartPosX -= (int)EntityAirbus.Step;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
case Up:
|
|
||||||
if (_StartPosY - EntityAirbus.Step > 0)
|
|
||||||
{
|
|
||||||
_StartPosY -= (int)EntityAirbus.Step;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
case Right:
|
|
||||||
if (_StartPosX + drawingAirbusWidth + (int)EntityAirbus.Step < picture_width - EntityAirbus.Step)
|
|
||||||
{
|
|
||||||
_StartPosX += (int)EntityAirbus.Step;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
case Down:
|
|
||||||
if (_StartPosY + drawingAirbusHeight + (int)EntityAirbus.Step < picture_height - EntityAirbus.Step)
|
|
||||||
{
|
|
||||||
_StartPosY += (int)EntityAirbus.Step;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
default:
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void DrawTransport(Graphics2D g) {
|
|
||||||
|
|
||||||
if (EntityAirbus == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
// иллюминаторы
|
|
||||||
_portholes.Draw(g, _StartPosX+30, _StartPosY+34);
|
|
||||||
|
|
||||||
g.setColor(Color.BLACK);
|
|
||||||
//Тело
|
|
||||||
g.drawRect(_StartPosX + 5, _StartPosY + 50, 170, 30);
|
|
||||||
g.drawArc(_StartPosX - 5, _StartPosY + 50, 20, 30, 90, 180);
|
|
||||||
//Заднее крыло
|
|
||||||
g.drawLine( _StartPosX, _StartPosY, _StartPosX + 50, _StartPosY + 50);
|
|
||||||
g.drawLine( _StartPosX, _StartPosY, _StartPosX, _StartPosY + 52);
|
|
||||||
//Заднее боковые крылья
|
|
||||||
g.drawOval(_StartPosX - 7, _StartPosY + 45, 30, 8);
|
|
||||||
g.fillOval(_StartPosX - 7, _StartPosY + 45, 30, 8);
|
|
||||||
//Нос
|
|
||||||
g.drawLine( _StartPosX + 175, _StartPosY + 50, _StartPosX + 200, _StartPosY + 65);
|
|
||||||
g.drawLine( _StartPosX + 200, _StartPosY + 65, _StartPosX + 175, _StartPosY + 80);
|
|
||||||
g.drawLine( _StartPosX + 175, _StartPosY + 50, _StartPosX + 175, _StartPosY + 80);
|
|
||||||
g.drawLine( _StartPosX + 175, _StartPosY + 65, _StartPosX + 200, _StartPosY + 65);
|
|
||||||
//Крылья
|
|
||||||
g.drawArc(_StartPosX + 49, _StartPosY + 62, 5, 5, 90, 180);
|
|
||||||
g.drawLine( _StartPosX + 51, _StartPosY + 62, _StartPosX + 140, _StartPosY + 62);
|
|
||||||
g.drawArc( _StartPosX + 137, _StartPosY + 62, 5, 5, 2790, 180);
|
|
||||||
g.drawLine( _StartPosX + 51, _StartPosY + 67, _StartPosX + 140, _StartPosY + 67);
|
|
||||||
//Задние шасси
|
|
||||||
g.drawLine(_StartPosX + 55, _StartPosY + 80, _StartPosX + 55, _StartPosY + 90);
|
|
||||||
g.drawOval(_StartPosX + 47, _StartPosY + 90, 5, 5);
|
|
||||||
g.drawOval( _StartPosX + 57, _StartPosY + 90, 5, 5);
|
|
||||||
//Передние шасси
|
|
||||||
g.drawLine( _StartPosX + 165, _StartPosY + 80, _StartPosX + 165, _StartPosY + 90);
|
|
||||||
g.drawOval( _StartPosX + 163, _StartPosY + 91, 5, 5);
|
|
||||||
//Пассажирсакий доп. отсек
|
|
||||||
if (EntityAirbus.getIsCompartmen())
|
|
||||||
{
|
|
||||||
g.setColor(EntityAirbus.getAdditionalColor());
|
|
||||||
g.drawArc(_StartPosX + 60, _StartPosY + 28, 115, 45, 0, 180);
|
|
||||||
g.fillArc(_StartPosX + 60, _StartPosY + 28, 115, 45, 0, 180);
|
|
||||||
}
|
|
||||||
// Доп. двигатели
|
|
||||||
if (EntityAirbus.getIsAdditionalEngine())
|
|
||||||
{
|
|
||||||
g.drawLine(_StartPosX + 95, _StartPosY + 68, _StartPosX + 95, _StartPosY + 75);
|
|
||||||
g.setColor(EntityAirbus.getAdditionalColor());
|
|
||||||
int[] xPolygon = { _StartPosX + 83, _StartPosX + 103, _StartPosX + 103, _StartPosX + 83, _StartPosX + 83};
|
|
||||||
int[] yPolygon = {_StartPosY + 78, _StartPosY + 73, _StartPosY + 93, _StartPosY + 88, _StartPosY + 78};
|
|
||||||
g.drawPolygon(xPolygon, yPolygon, xPolygon.length);
|
|
||||||
g.fillPolygon(xPolygon, yPolygon, xPolygon.length);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,16 +1,20 @@
|
|||||||
|
package Drawings;
|
||||||
|
|
||||||
|
import Drawings.DrawingAirbus;
|
||||||
|
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
|
|
||||||
public class CanvasAirbus extends JComponent {
|
public class CanvasAirbus extends JComponent {
|
||||||
public DrawingAirbus _drawingAirbus;
|
public DrawingAirplan _drawingAirplan;
|
||||||
public CanvasAirbus(){}
|
public CanvasAirbus(){}
|
||||||
public void paintComponent(Graphics g) {
|
public void paintComponent(Graphics g) {
|
||||||
if (_drawingAirbus == null) {
|
if (_drawingAirplan == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
super.paintComponents(g);
|
super.paintComponents(g);
|
||||||
Graphics2D g2d = (Graphics2D) g;
|
Graphics2D g2d = (Graphics2D) g;
|
||||||
_drawingAirbus.DrawTransport(g2d);
|
_drawingAirplan.DrawTransport(g2d);
|
||||||
super.repaint();
|
super.repaint();
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,6 +1,9 @@
|
|||||||
|
package Drawings;
|
||||||
|
|
||||||
public enum DirectionType {
|
public enum DirectionType {
|
||||||
Up,
|
Up,
|
||||||
Down,
|
Down,
|
||||||
Left,
|
Left,
|
||||||
Right
|
Right,
|
||||||
|
Unknown
|
||||||
}
|
}
|
40
src/src/Drawings/DrawingAirbus.java
Normal file
40
src/src/Drawings/DrawingAirbus.java
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
package Drawings;
|
||||||
|
|
||||||
|
import Entities.*;
|
||||||
|
import java.awt.*;
|
||||||
|
|
||||||
|
public class DrawingAirbus extends DrawingAirplan {
|
||||||
|
|
||||||
|
public DrawingAirbus(int speed, double weight, Color bodycolor, Color additionalcolor, boolean isCompartment, boolean isAdditionalEngine) {
|
||||||
|
EntityAirplan = new EntityAirbus(speed, weight, bodycolor, additionalcolor, isCompartment, isAdditionalEngine);
|
||||||
|
SetAmountAndTypePortholes();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void DrawTransport(Graphics2D g) {
|
||||||
|
|
||||||
|
if (EntityAirplan == null || !(EntityAirplan instanceof EntityAirbus airbus)
|
||||||
|
|| _StartPosX == null || _StartPosY == null)
|
||||||
|
return;
|
||||||
|
g.setColor(Color.BLACK);
|
||||||
|
super.DrawTransport(g);
|
||||||
|
|
||||||
|
//Пассажирсакий доп. отсек
|
||||||
|
if (EntityAirbus.getIsCompartment())
|
||||||
|
{
|
||||||
|
g.setColor(EntityAirbus.getAdditionalColor());
|
||||||
|
g.drawArc(_StartPosX + 60, _StartPosY + 28, 115, 45, 0, 180);
|
||||||
|
g.fillArc(_StartPosX + 60, _StartPosY + 28, 115, 45, 0, 180);
|
||||||
|
}
|
||||||
|
// Доп. двигатели
|
||||||
|
if (EntityAirbus.getIsAdditionalEngine())
|
||||||
|
{
|
||||||
|
g.drawLine(_StartPosX + 95, _StartPosY + 68, _StartPosX + 95, _StartPosY + 75);
|
||||||
|
g.setColor(EntityAirbus.getAdditionalColor());
|
||||||
|
int[] xPolygon = { _StartPosX + 83, _StartPosX + 103, _StartPosX + 103, _StartPosX + 83, _StartPosX + 83};
|
||||||
|
int[] yPolygon = {_StartPosY + 78, _StartPosY + 73, _StartPosY + 93, _StartPosY + 88, _StartPosY + 78};
|
||||||
|
g.drawPolygon(xPolygon, yPolygon, xPolygon.length);
|
||||||
|
g.fillPolygon(xPolygon, yPolygon, xPolygon.length);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
156
src/src/Drawings/DrawingAirplan.java
Normal file
156
src/src/Drawings/DrawingAirplan.java
Normal file
@ -0,0 +1,156 @@
|
|||||||
|
package Drawings;
|
||||||
|
|
||||||
|
import Entities.*;
|
||||||
|
import ChoiseAndDrawingPortholes.*;
|
||||||
|
import javax.swing.*;
|
||||||
|
import java.awt.*;
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
|
public class DrawingAirplan extends JPanel {
|
||||||
|
public Entities.EntityAirplan EntityAirplan;
|
||||||
|
public IDifferentPortholes drawingPortholes;
|
||||||
|
private Integer picture_width;
|
||||||
|
private Integer picture_height;
|
||||||
|
protected Integer _StartPosX;
|
||||||
|
public Integer GetPosX() {return _StartPosX;}
|
||||||
|
protected Integer _StartPosY;
|
||||||
|
public Integer GetPosY() {return _StartPosY;}
|
||||||
|
protected int drawingAirplanWidth = 185;
|
||||||
|
public Integer GetWidth() {return drawingAirplanWidth;}
|
||||||
|
protected int drawingAirplanHeight = 100;
|
||||||
|
public Integer GetHeight() {return drawingAirplanHeight;}
|
||||||
|
|
||||||
|
protected DrawingAirplan() {
|
||||||
|
picture_width = null;
|
||||||
|
picture_height = null;
|
||||||
|
_StartPosX = null;
|
||||||
|
_StartPosY = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void SetAmountAndTypePortholes() {
|
||||||
|
Random random = new Random();
|
||||||
|
int numberofportholes = random.nextInt(0,3);
|
||||||
|
switch (numberofportholes) {
|
||||||
|
case 1:
|
||||||
|
drawingPortholes = new DrawingPortholesCircle();
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
drawingPortholes = new DrawingPortholesSquare();
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
drawingPortholes = new DrawingPortholesHeart();
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
numberofportholes = 0;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
drawingPortholes.setNumberPortholes(numberofportholes);
|
||||||
|
}
|
||||||
|
|
||||||
|
public DrawingAirplan(int speed, double weight, Color bodycolor) {
|
||||||
|
super();
|
||||||
|
EntityAirplan = new EntityAirplan(speed, weight, bodycolor);
|
||||||
|
SetAmountAndTypePortholes();
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean SetPictureSize(int width, int height) {
|
||||||
|
if (width < drawingAirplanWidth || height < drawingAirplanHeight) return false;
|
||||||
|
picture_width = width;
|
||||||
|
picture_height = height;
|
||||||
|
if (_StartPosX != null || _StartPosY != null) {
|
||||||
|
if (_StartPosX + drawingAirplanWidth > picture_width)
|
||||||
|
{
|
||||||
|
_StartPosX = _StartPosX - (_StartPosX + drawingAirplanWidth - picture_width);
|
||||||
|
}
|
||||||
|
else if (_StartPosX < 0) _StartPosX = 0;
|
||||||
|
if (_StartPosY + drawingAirplanHeight > picture_height)
|
||||||
|
{
|
||||||
|
_StartPosY = _StartPosY - (_StartPosY + drawingAirplanHeight - picture_height);
|
||||||
|
}
|
||||||
|
else if (_StartPosY < 0) _StartPosY = 0;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
public void SetPosition(int x, int y) {
|
||||||
|
if (!(picture_width != null && picture_height != null)) return;
|
||||||
|
if (x + drawingAirplanWidth > picture_width)
|
||||||
|
{
|
||||||
|
_StartPosX = x - (x + drawingAirplanWidth - picture_width);
|
||||||
|
}
|
||||||
|
else if (x < 0) _StartPosX = 0;
|
||||||
|
else _StartPosX = x;
|
||||||
|
if (y + drawingAirplanHeight > picture_height)
|
||||||
|
{
|
||||||
|
_StartPosY = y - (y + drawingAirplanHeight - picture_height);
|
||||||
|
}
|
||||||
|
else if (y < 0) _StartPosY = 0;
|
||||||
|
else _StartPosY = y;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean MoveTransport(DirectionType direction) {
|
||||||
|
if (EntityAirplan == null || _StartPosX == null || _StartPosY == null) return false;
|
||||||
|
switch (direction) {
|
||||||
|
case DirectionType.Left:
|
||||||
|
if (_StartPosX - EntityAirplan.Step > 0) {
|
||||||
|
_StartPosX -= (int)EntityAirplan.Step;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
case DirectionType.Up:
|
||||||
|
if (_StartPosY - EntityAirplan.Step > 0)
|
||||||
|
{
|
||||||
|
_StartPosY -= (int)EntityAirplan.Step;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
case DirectionType.Right:
|
||||||
|
if (_StartPosX + drawingAirplanWidth + (int)EntityAirplan.Step < picture_width - EntityAirplan.Step)
|
||||||
|
{
|
||||||
|
_StartPosX += (int)EntityAirplan.Step;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
case DirectionType.Down:
|
||||||
|
if (_StartPosY + drawingAirplanHeight + (int)EntityAirplan.Step < picture_height - EntityAirplan.Step)
|
||||||
|
{
|
||||||
|
_StartPosY += (int)EntityAirplan.Step;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void DrawTransport(Graphics2D g) {
|
||||||
|
|
||||||
|
if (EntityAirplan == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
g.setColor(Color.BLACK);
|
||||||
|
//Тело
|
||||||
|
g.drawRect(_StartPosX + 5, _StartPosY + 50, 170, 30);
|
||||||
|
g.drawArc(_StartPosX - 5, _StartPosY + 50, 20, 30, 90, 180);
|
||||||
|
//Заднее крыло
|
||||||
|
g.drawLine(_StartPosX, _StartPosY, _StartPosX + 50, _StartPosY + 50);
|
||||||
|
g.drawLine(_StartPosX, _StartPosY, _StartPosX, _StartPosY + 52);
|
||||||
|
//Заднее боковые крылья
|
||||||
|
g.drawOval(_StartPosX - 7, _StartPosY + 45, 30, 8);
|
||||||
|
g.fillOval(_StartPosX - 7, _StartPosY + 45, 30, 8);
|
||||||
|
//Нос
|
||||||
|
g.drawLine(_StartPosX + 175, _StartPosY + 50, _StartPosX + 200, _StartPosY + 65);
|
||||||
|
g.drawLine(_StartPosX + 200, _StartPosY + 65, _StartPosX + 175, _StartPosY + 80);
|
||||||
|
g.drawLine(_StartPosX + 175, _StartPosY + 50, _StartPosX + 175, _StartPosY + 80);
|
||||||
|
g.drawLine(_StartPosX + 175, _StartPosY + 65, _StartPosX + 200, _StartPosY + 65);
|
||||||
|
//Крылья
|
||||||
|
g.drawArc(_StartPosX + 49, _StartPosY + 62, 5, 5, 90, 180);
|
||||||
|
g.drawLine(_StartPosX + 51, _StartPosY + 62, _StartPosX + 140, _StartPosY + 62);
|
||||||
|
g.drawArc(_StartPosX + 137, _StartPosY + 62, 5, 5, 2790, 180);
|
||||||
|
g.drawLine(_StartPosX + 51, _StartPosY + 67, _StartPosX + 140, _StartPosY + 67);
|
||||||
|
//Задние шасси
|
||||||
|
g.drawLine(_StartPosX + 55, _StartPosY + 80, _StartPosX + 55, _StartPosY + 90);
|
||||||
|
g.drawOval(_StartPosX + 47, _StartPosY + 90, 5, 5);
|
||||||
|
g.drawOval(_StartPosX + 57, _StartPosY + 90, 5, 5);
|
||||||
|
//Передние шасси
|
||||||
|
g.drawLine(_StartPosX + 165, _StartPosY + 80, _StartPosX + 165, _StartPosY + 90);
|
||||||
|
g.drawOval(_StartPosX + 163, _StartPosY + 91, 5, 5);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
20
src/src/Entities/EntityAirbus.java
Normal file
20
src/src/Entities/EntityAirbus.java
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
package Entities;
|
||||||
|
|
||||||
|
import java.awt.*;
|
||||||
|
public class EntityAirbus extends EntityAirplan {
|
||||||
|
|
||||||
|
private static Color AdditionalColor;
|
||||||
|
public static Color getAdditionalColor() {return AdditionalColor;}
|
||||||
|
private static boolean IsCompartment;
|
||||||
|
public static boolean getIsCompartment() {return IsCompartment;}
|
||||||
|
private static boolean IsAdditionalEngine;
|
||||||
|
public static boolean getIsAdditionalEngine() {return IsAdditionalEngine;}
|
||||||
|
|
||||||
|
public EntityAirbus(int speed, double weight, Color bodycolor, Color additionalcolor, boolean isCompartment, boolean isAdditionalEngine)
|
||||||
|
{
|
||||||
|
super(speed,weight,bodycolor);
|
||||||
|
AdditionalColor = additionalcolor;
|
||||||
|
IsCompartment = isCompartment;
|
||||||
|
IsAdditionalEngine = isAdditionalEngine;
|
||||||
|
}
|
||||||
|
}
|
18
src/src/Entities/EntityAirplan.java
Normal file
18
src/src/Entities/EntityAirplan.java
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
package Entities;
|
||||||
|
|
||||||
|
import java.awt.*;
|
||||||
|
public class EntityAirplan {
|
||||||
|
private int Speed;
|
||||||
|
private double Weight;
|
||||||
|
private Color BodyColor;
|
||||||
|
public Color getBodyColor() {return BodyColor;}
|
||||||
|
public double Step;
|
||||||
|
public EntityAirplan(int speed, double weight, Color bodycolor)
|
||||||
|
{
|
||||||
|
Speed = speed;
|
||||||
|
Weight = weight;
|
||||||
|
BodyColor = bodycolor;
|
||||||
|
Step = Speed * 100 / Weight;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,24 +0,0 @@
|
|||||||
import java.awt.*;
|
|
||||||
public class EntityAirbus {
|
|
||||||
private int Speed;
|
|
||||||
private double Weight;
|
|
||||||
private Color BodyColor;
|
|
||||||
public Color getBodyColor() {return BodyColor;}
|
|
||||||
private Color AdditionalColor;
|
|
||||||
public Color getAdditionalColor() {return AdditionalColor;}
|
|
||||||
private boolean IsCompartment;
|
|
||||||
public boolean getIsCompartmen() {return IsCompartment;}
|
|
||||||
private boolean IsAdditionalEngine;
|
|
||||||
public boolean getIsAdditionalEngine() {return IsAdditionalEngine;}
|
|
||||||
public double Step;
|
|
||||||
public void Init(int speed, double weight, Color bodycolor, Color additionalcolor, boolean isCompartment, boolean isAdditionalEngine)
|
|
||||||
{
|
|
||||||
Speed = speed;
|
|
||||||
Weight = weight;
|
|
||||||
BodyColor = bodycolor;
|
|
||||||
AdditionalColor = additionalcolor;
|
|
||||||
IsCompartment = isCompartment;
|
|
||||||
IsAdditionalEngine = isAdditionalEngine;
|
|
||||||
Step = Speed * 100 / Weight;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,3 +1,9 @@
|
|||||||
|
import Drawings.CanvasAirbus;
|
||||||
|
import Drawings.DirectionType;
|
||||||
|
import Drawings.DrawingAirbus;
|
||||||
|
import Drawings.DrawingAirplan;
|
||||||
|
import MovementStrategy.*;
|
||||||
|
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import java.awt.event.ActionEvent;
|
import java.awt.event.ActionEvent;
|
||||||
@ -10,24 +16,58 @@ public class FormAirbus extends JFrame {
|
|||||||
private String title;
|
private String title;
|
||||||
private Dimension dimension;
|
private Dimension dimension;
|
||||||
private int Width, Height;
|
private int Width, Height;
|
||||||
private CanvasAirbus canvasAirbus = new CanvasAirbus();
|
public CanvasAirbus canvasAirbus = new CanvasAirbus();
|
||||||
private JButton CreateButton = new JButton("Create");;
|
private JButton CreateButton = new JButton("Create airbus");;
|
||||||
|
private JButton CreateAirplanButton = new JButton("Create airplan");
|
||||||
private JButton UpButton = new JButton();
|
private JButton UpButton = new JButton();
|
||||||
private JButton DownButton = new JButton();;
|
private JButton DownButton = new JButton();;
|
||||||
private JButton LeftButton = new JButton();;
|
private JButton LeftButton = new JButton();;
|
||||||
private JButton RightButton = new JButton();
|
private JButton RightButton = new JButton();
|
||||||
|
private AbstractStrategy _strategy;
|
||||||
|
private JComboBox ComboBoxStrategy = new JComboBox(new String[]{"К центру", "К краю"});
|
||||||
|
private JButton ButtonStrategy = new JButton("Шаг");
|
||||||
public FormAirbus(String title, Dimension dimension) {
|
public FormAirbus(String title, Dimension dimension) {
|
||||||
this.title = title;
|
this.title = title;
|
||||||
this.dimension = dimension;
|
this.dimension = dimension;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void CreateObject(String typeOfClass) {
|
||||||
|
int StartPositionX = (int)(Math.random() * 90 + 10);
|
||||||
|
int StartPositionY = (int)(Math.random() * 90 + 10);
|
||||||
|
int speed = (int)(Math.random() * 300 + 100);
|
||||||
|
double weight = (double)(Math.random() * 3000 + 1000);
|
||||||
|
Color bodyColor = new Color((int)(Math.random() * 255 + 0),(int)(Math.random() * 255 + 0),(int)(Math.random() * 255 + 0));
|
||||||
|
switch (typeOfClass) {
|
||||||
|
case "DrawingAirplan":
|
||||||
|
canvasAirbus._drawingAirplan = new DrawingAirplan(speed, weight, bodyColor);
|
||||||
|
canvasAirbus._drawingAirplan.SetPictureSize(Width, Height);
|
||||||
|
canvasAirbus._drawingAirplan.SetPosition(StartPositionX, StartPositionY);
|
||||||
|
canvasAirbus.repaint();
|
||||||
|
break;
|
||||||
|
case "DrawingAirbus":
|
||||||
|
Color additionalColor = new Color((int)(Math.random() * 255 + 0),(int)(Math.random() * 255 + 0),(int)(Math.random() * 255 + 0));;
|
||||||
|
boolean IsCompartment = new Random().nextBoolean();
|
||||||
|
boolean isAdditionalEngine = new Random().nextBoolean();;
|
||||||
|
canvasAirbus._drawingAirplan = new DrawingAirbus(speed, weight, bodyColor, additionalColor, IsCompartment , isAdditionalEngine);
|
||||||
|
canvasAirbus._drawingAirplan.SetPictureSize(Width, Height);
|
||||||
|
canvasAirbus._drawingAirplan.SetPosition(StartPositionX, StartPositionY);
|
||||||
|
canvasAirbus.repaint();
|
||||||
|
break;
|
||||||
|
default: return;
|
||||||
|
}
|
||||||
|
_strategy = null;
|
||||||
|
ComboBoxStrategy.setEnabled(true);
|
||||||
|
}
|
||||||
|
|
||||||
public void Init() {
|
public void Init() {
|
||||||
setTitle(title);
|
setTitle(title);
|
||||||
setMinimumSize(dimension);
|
setMinimumSize(dimension);
|
||||||
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||||
Width = getWidth() - 15;
|
Width = getWidth() - 15;
|
||||||
Height = getHeight() - 35;
|
Height = getHeight() - 35;
|
||||||
|
_strategy = null;
|
||||||
CreateButton.setName("CREATE");
|
CreateButton.setName("CREATE");
|
||||||
|
CreateAirplanButton.setName("CREATESAIRPLANBUTTON");
|
||||||
Icon iconUp = new ImageIcon("src\\image\\up.jpg");
|
Icon iconUp = new ImageIcon("src\\image\\up.jpg");
|
||||||
UpButton.setIcon(iconUp);
|
UpButton.setIcon(iconUp);
|
||||||
UpButton.setName("UP");
|
UpButton.setName("UP");
|
||||||
@ -44,39 +84,73 @@ public class FormAirbus extends JFrame {
|
|||||||
CreateButton.addActionListener(new ActionListener() {
|
CreateButton.addActionListener(new ActionListener() {
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
int StartPositionX = (int)(Math.random() * 90 + 10);
|
CreateObject("DrawingAirbus");
|
||||||
int StartPositionY = (int)(Math.random() * 90 + 10);
|
}
|
||||||
int speed = (int)(Math.random() * 300 + 100);
|
});
|
||||||
double weight = (double)(Math.random() * 3000 + 1000);
|
|
||||||
Color bodyColor = new Color((int)(Math.random() * 255 + 0),(int)(Math.random() * 255 + 0),(int)(Math.random() * 255 + 0));
|
CreateAirplanButton.addActionListener(new ActionListener() {
|
||||||
Color additionalColor = new Color((int)(Math.random() * 255 + 0),(int)(Math.random() * 255 + 0),(int)(Math.random() * 255 + 0));;
|
@Override
|
||||||
boolean sheepPipes = new Random().nextBoolean();
|
public void actionPerformed(ActionEvent e) {
|
||||||
boolean fuelTank = new Random().nextBoolean();;
|
CreateObject("DrawingAirplan");
|
||||||
canvasAirbus._drawingAirbus = new DrawingAirbus();
|
}
|
||||||
canvasAirbus._drawingAirbus.Init(speed, weight, bodyColor, additionalColor, sheepPipes, fuelTank);
|
});
|
||||||
canvasAirbus._drawingAirbus.SetPictureSize(Width, Height);
|
|
||||||
canvasAirbus._drawingAirbus.SetPosition( StartPositionX, StartPositionY);
|
ButtonStrategy.addActionListener(new ActionListener() {
|
||||||
canvasAirbus.repaint();
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
if (canvasAirbus._drawingAirplan == null) return;
|
||||||
|
if (ComboBoxStrategy.isEnabled())
|
||||||
|
{
|
||||||
|
int index = ComboBoxStrategy.getSelectedIndex();
|
||||||
|
switch(index)
|
||||||
|
{
|
||||||
|
case 0:
|
||||||
|
_strategy = new MoveToCenter();
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
_strategy = new MoveToBorder();
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
_strategy = null;
|
||||||
|
break;
|
||||||
|
};
|
||||||
|
if (_strategy == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_strategy.SetData(new MoveableAirplan(canvasAirbus._drawingAirplan), Width, Height);
|
||||||
|
}
|
||||||
|
if (_strategy == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
ComboBoxStrategy.setEnabled(false);
|
||||||
|
_strategy.MakeStep();
|
||||||
|
if (_strategy.GetStatus() == StrategyStatus.Finish)
|
||||||
|
{
|
||||||
|
ComboBoxStrategy.setEnabled(true);
|
||||||
|
_strategy = null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
ActionListener actionListener = new ActionListener() {
|
ActionListener actionListener = new ActionListener() {
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent event) {
|
public void actionPerformed(ActionEvent event) {
|
||||||
if (canvasAirbus._drawingAirbus == null) return;
|
if (canvasAirbus._drawingAirplan == null) return;
|
||||||
boolean result = false;
|
boolean result = false;
|
||||||
switch ((((JButton)(event.getSource())).getName())) {
|
switch ((((JButton)(event.getSource())).getName())) {
|
||||||
case "UP":
|
case "UP":
|
||||||
result = canvasAirbus._drawingAirbus.MoveTransport(DirectionType.Up);
|
result = canvasAirbus._drawingAirplan.MoveTransport(DirectionType.Up);
|
||||||
break;
|
break;
|
||||||
case "DOWN":
|
case "DOWN":
|
||||||
result = canvasAirbus._drawingAirbus.MoveTransport(DirectionType.Down);
|
result = canvasAirbus._drawingAirplan.MoveTransport(DirectionType.Down);
|
||||||
break;
|
break;
|
||||||
case "LEFT":
|
case "LEFT":
|
||||||
result = canvasAirbus._drawingAirbus.MoveTransport(DirectionType.Left);
|
result = canvasAirbus._drawingAirplan.MoveTransport(DirectionType.Left);
|
||||||
break;
|
break;
|
||||||
case "RIGHT":
|
case "RIGHT":
|
||||||
result = canvasAirbus._drawingAirbus.MoveTransport(DirectionType.Right);
|
result = canvasAirbus._drawingAirplan.MoveTransport(DirectionType.Right);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (result) {
|
if (result) {
|
||||||
@ -92,16 +166,22 @@ public class FormAirbus extends JFrame {
|
|||||||
setSize(dimension.width,dimension.height);
|
setSize(dimension.width,dimension.height);
|
||||||
setLayout(null);
|
setLayout(null);
|
||||||
canvasAirbus.setBounds(0,0, getWidth(), getHeight());
|
canvasAirbus.setBounds(0,0, getWidth(), getHeight());
|
||||||
CreateButton.setBounds(10, getHeight() - 90, 100, 40);
|
CreateButton.setBounds(10, getHeight() - 90, 125, 40);
|
||||||
|
CreateAirplanButton.setBounds(160, getHeight() - 90, 125, 40);
|
||||||
UpButton.setBounds(getWidth() - 140, getHeight() - 160, 50, 50);
|
UpButton.setBounds(getWidth() - 140, getHeight() - 160, 50, 50);
|
||||||
DownButton.setBounds(getWidth() - 140, getHeight() - 100, 50, 50);
|
DownButton.setBounds(getWidth() - 140, getHeight() - 100, 50, 50);
|
||||||
RightButton.setBounds(getWidth() - 80, getHeight() - 100, 50, 50);
|
RightButton.setBounds(getWidth() - 80, getHeight() - 100, 50, 50);
|
||||||
LeftButton.setBounds(getWidth() - 200, getHeight() - 100, 50, 50);
|
LeftButton.setBounds(getWidth() - 200, getHeight() - 100, 50, 50);
|
||||||
|
ComboBoxStrategy.setBounds(getWidth() - 170, 10, 140, 35);
|
||||||
|
ButtonStrategy.setBounds(getWidth() - 130, 55, 100, 25);
|
||||||
add(CreateButton);
|
add(CreateButton);
|
||||||
|
add(CreateAirplanButton);
|
||||||
add(UpButton);
|
add(UpButton);
|
||||||
add(DownButton);
|
add(DownButton);
|
||||||
add(RightButton);
|
add(RightButton);
|
||||||
add(LeftButton);
|
add(LeftButton);
|
||||||
|
add(ComboBoxStrategy);
|
||||||
|
add(ButtonStrategy);
|
||||||
add(canvasAirbus);
|
add(canvasAirbus);
|
||||||
setVisible(true);
|
setVisible(true);
|
||||||
//обработка события изменения размеров окна
|
//обработка события изменения размеров окна
|
||||||
@ -109,14 +189,17 @@ public class FormAirbus extends JFrame {
|
|||||||
public void componentResized(ComponentEvent e) {
|
public void componentResized(ComponentEvent e) {
|
||||||
Width = getWidth() - 15;
|
Width = getWidth() - 15;
|
||||||
Height = getHeight() - 35;
|
Height = getHeight() - 35;
|
||||||
if (canvasAirbus._drawingAirbus != null)
|
if (canvasAirbus._drawingAirplan != null)
|
||||||
canvasAirbus._drawingAirbus.SetPictureSize(Width, Height);
|
canvasAirbus._drawingAirplan.SetPictureSize(Width, Height);
|
||||||
canvasAirbus.setBounds(0,0, getWidth(), getHeight());
|
canvasAirbus.setBounds(0,0, getWidth(), getHeight());
|
||||||
CreateButton.setBounds(10, getHeight() - 90, 100, 40);
|
CreateButton.setBounds(10, getHeight() - 90, 125, 40);
|
||||||
|
CreateAirplanButton.setBounds(160, getHeight() - 90, 125, 40);
|
||||||
UpButton.setBounds(getWidth() - 140, getHeight() - 160, 50, 50);
|
UpButton.setBounds(getWidth() - 140, getHeight() - 160, 50, 50);
|
||||||
DownButton.setBounds(getWidth() - 140, getHeight() - 100, 50, 50);
|
DownButton.setBounds(getWidth() - 140, getHeight() - 100, 50, 50);
|
||||||
RightButton.setBounds(getWidth() - 80, getHeight() - 100, 50, 50);
|
RightButton.setBounds(getWidth() - 80, getHeight() - 100, 50, 50);
|
||||||
LeftButton.setBounds(getWidth() - 200, getHeight() - 100, 50, 50);
|
LeftButton.setBounds(getWidth() - 200, getHeight() - 100, 50, 50);
|
||||||
|
ComboBoxStrategy.setBounds(getWidth() - 170, 10, 140, 35);
|
||||||
|
ButtonStrategy.setBounds(getWidth() - 130, 55, 100, 25);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
56
src/src/MovementStrategy/AbstractStrategy.java
Normal file
56
src/src/MovementStrategy/AbstractStrategy.java
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
package MovementStrategy;
|
||||||
|
|
||||||
|
public abstract class AbstractStrategy {
|
||||||
|
private IMoveableObject _moveableObject;
|
||||||
|
private StrategyStatus _state = StrategyStatus.NotInit;
|
||||||
|
public int FieldWidth;
|
||||||
|
public int FieldHeight;
|
||||||
|
public StrategyStatus GetStatus() {return _state;}
|
||||||
|
public void SetData(IMoveableObject moveableObjects, int width, int height)
|
||||||
|
{
|
||||||
|
if (moveableObjects == null)
|
||||||
|
{
|
||||||
|
_state = StrategyStatus.NotInit;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_state = StrategyStatus.InProgress;
|
||||||
|
_moveableObject = moveableObjects;
|
||||||
|
FieldWidth = width;
|
||||||
|
FieldHeight = height;
|
||||||
|
}
|
||||||
|
public void MakeStep()
|
||||||
|
{
|
||||||
|
if (_state != StrategyStatus.InProgress) return;
|
||||||
|
if (IsTargetDestinaion())
|
||||||
|
{
|
||||||
|
_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 Integer GetStep()
|
||||||
|
{
|
||||||
|
if (_state != StrategyStatus.InProgress)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return _moveableObject.GetStep();
|
||||||
|
}
|
||||||
|
protected abstract void MoveToTarget();
|
||||||
|
protected abstract boolean IsTargetDestinaion();
|
||||||
|
private boolean MoveTo(MovementDirection movementDirection)
|
||||||
|
{
|
||||||
|
if (_state != StrategyStatus.InProgress)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
boolean stateTryMoveObject = _moveableObject.TryMoveObject(movementDirection);
|
||||||
|
if (stateTryMoveObject) return stateTryMoveObject;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
7
src/src/MovementStrategy/IMoveableObject.java
Normal file
7
src/src/MovementStrategy/IMoveableObject.java
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
package MovementStrategy;
|
||||||
|
|
||||||
|
public interface IMoveableObject {
|
||||||
|
ObjectParameters GetObjectPosition();
|
||||||
|
int GetStep();
|
||||||
|
boolean TryMoveObject(MovementDirection direction);
|
||||||
|
}
|
27
src/src/MovementStrategy/MoveToBorder.java
Normal file
27
src/src/MovementStrategy/MoveToBorder.java
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
package MovementStrategy;
|
||||||
|
|
||||||
|
public class MoveToBorder extends AbstractStrategy{
|
||||||
|
@Override
|
||||||
|
protected boolean IsTargetDestinaion() {
|
||||||
|
ObjectParameters objParams = GetObjectParameters();
|
||||||
|
if (objParams == null)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return objParams.RightBorder + GetStep() >= FieldWidth-GetStep() &&
|
||||||
|
objParams.DownBorder + GetStep() >= FieldHeight-GetStep();
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
protected void MoveToTarget() {
|
||||||
|
ObjectParameters objParams = GetObjectParameters();
|
||||||
|
if (objParams == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
//реализация в правый нижний угол
|
||||||
|
int x = objParams.RightBorder;
|
||||||
|
if (x + GetStep() < FieldWidth) MoveRight();
|
||||||
|
int y = objParams.DownBorder;
|
||||||
|
if (y + GetStep() < FieldHeight) MoveDown();
|
||||||
|
}
|
||||||
|
}
|
48
src/src/MovementStrategy/MoveToCenter.java
Normal file
48
src/src/MovementStrategy/MoveToCenter.java
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
package MovementStrategy;
|
||||||
|
|
||||||
|
public class MoveToCenter extends AbstractStrategy{
|
||||||
|
@Override
|
||||||
|
protected boolean IsTargetDestinaion() {
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
47
src/src/MovementStrategy/MoveableAirplan.java
Normal file
47
src/src/MovementStrategy/MoveableAirplan.java
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
package MovementStrategy;
|
||||||
|
|
||||||
|
|
||||||
|
import Drawings.CanvasAirbus;
|
||||||
|
import Drawings.DirectionType;
|
||||||
|
import Drawings.DrawingAirbus;
|
||||||
|
import Drawings.DrawingAirplan;
|
||||||
|
|
||||||
|
public class MoveableAirplan implements IMoveableObject{
|
||||||
|
private CanvasAirbus canvas = new CanvasAirbus();
|
||||||
|
public MoveableAirplan(DrawingAirplan drawningairplan)
|
||||||
|
{
|
||||||
|
canvas._drawingAirplan = drawningairplan;
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public ObjectParameters GetObjectPosition() {
|
||||||
|
if (canvas._drawingAirplan == null || canvas._drawingAirplan.EntityAirplan == null ||
|
||||||
|
canvas._drawingAirplan.GetPosX() == null || canvas._drawingAirplan.GetPosY() == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return new ObjectParameters(canvas._drawingAirplan.GetPosX(), canvas._drawingAirplan.GetPosY(),
|
||||||
|
canvas._drawingAirplan.GetWidth(), canvas._drawingAirplan.GetHeight());
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public int GetStep() {
|
||||||
|
return (int)(canvas._drawingAirplan.EntityAirplan.Step);
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public boolean TryMoveObject(MovementDirection direction) {
|
||||||
|
if (canvas._drawingAirplan == null || canvas._drawingAirplan.EntityAirplan == null)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return canvas._drawingAirplan.MoveTransport(GetDirectionType(direction));
|
||||||
|
}
|
||||||
|
private static DirectionType GetDirectionType(MovementDirection direction)
|
||||||
|
{
|
||||||
|
switch (direction) {
|
||||||
|
case MovementDirection.Left: return DirectionType.Left;
|
||||||
|
case MovementDirection.Right: return DirectionType.Right;
|
||||||
|
case MovementDirection.Up: return DirectionType.Up;
|
||||||
|
case MovementDirection.Down: return DirectionType.Down;
|
||||||
|
default: return DirectionType.Unknown;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
8
src/src/MovementStrategy/MovementDirection.java
Normal file
8
src/src/MovementStrategy/MovementDirection.java
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
package MovementStrategy;
|
||||||
|
|
||||||
|
public enum MovementDirection {
|
||||||
|
Up,
|
||||||
|
Down,
|
||||||
|
Left,
|
||||||
|
Right,
|
||||||
|
}
|
27
src/src/MovementStrategy/ObjectParameters.java
Normal file
27
src/src/MovementStrategy/ObjectParameters.java
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
package MovementStrategy;
|
||||||
|
|
||||||
|
public class ObjectParameters {
|
||||||
|
private int _x;
|
||||||
|
private int _y;
|
||||||
|
private int _width;
|
||||||
|
private int _height;
|
||||||
|
public int LeftBorder = _x;
|
||||||
|
public int TopBorder = _y;
|
||||||
|
public int RightBorder = _x + _width;
|
||||||
|
public int DownBorder = _y + _height;
|
||||||
|
public int ObjectMiddleHorizontal = _x + _width / 2;
|
||||||
|
public int ObjectMiddleVertical = _y + _height / 2;
|
||||||
|
public ObjectParameters(int x, int y, int width, int height)
|
||||||
|
{
|
||||||
|
_x = x;
|
||||||
|
_y = y;
|
||||||
|
_width = width;
|
||||||
|
_height = height;
|
||||||
|
LeftBorder = _x;
|
||||||
|
TopBorder = _y;
|
||||||
|
RightBorder = _x + _width;
|
||||||
|
DownBorder = _y + _height;
|
||||||
|
ObjectMiddleHorizontal = _x + _width / 2;
|
||||||
|
ObjectMiddleVertical = _y + _height / 2;
|
||||||
|
}
|
||||||
|
}
|
7
src/src/MovementStrategy/StrategyStatus.java
Normal file
7
src/src/MovementStrategy/StrategyStatus.java
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
package MovementStrategy;
|
||||||
|
|
||||||
|
public enum StrategyStatus {
|
||||||
|
NotInit,
|
||||||
|
InProgress,
|
||||||
|
Finish
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user