diff --git a/.idea/uiDesigner.xml b/.idea/uiDesigner.xml
new file mode 100644
index 0000000..2b63946
--- /dev/null
+++ b/.idea/uiDesigner.xml
@@ -0,0 +1,124 @@
+
+
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+
+
+
+ -
+
+
+
+
+
+ -
+
+
+
+
+
+ -
+
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+
+
+ -
+
+
+ -
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index d2e0a73..ffec6a2 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -4,7 +4,27 @@
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -13,7 +33,7 @@
@@ -21,9 +41,9 @@
-
+ {
+ "associatedIndex": 8
+}
@@ -33,15 +53,35 @@
"keyToString": {
"RunOnceActivity.OpenProjectViewOnStart": "true",
"RunOnceActivity.ShowReadmeOnStart": "true",
- "git-widget-placeholder": "lab1",
- "last_opened_file_path": "E:/GitLab/PIbd-22_Isaeva_A.I._Airbus_Hard"
+ "SHARE_PROJECT_CONFIGURATION_FILES": "true",
+ "git-widget-placeholder": "lab2",
+ "last_opened_file_path": "E:/GitLab/PIbd-22_Isaeva_A.I._Airbus_Hard/src/MovementStrategy"
}
}]]>
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -64,6 +104,6 @@
-
+
\ No newline at end of file
diff --git a/out/production/PIbd-22_Isaeva_A.I._Airbus_Hard/Entities/CountPortholes.class b/out/production/PIbd-22_Isaeva_A.I._Airbus_Hard/Entities/CountPortholes.class
new file mode 100644
index 0000000..130233d
Binary files /dev/null and b/out/production/PIbd-22_Isaeva_A.I._Airbus_Hard/Entities/CountPortholes.class differ
diff --git a/out/production/PIbd-22_Isaeva_A.I._Airbus_Hard/Entities/EntityAirbus.class b/out/production/PIbd-22_Isaeva_A.I._Airbus_Hard/Entities/EntityAirbus.class
new file mode 100644
index 0000000..cf759af
Binary files /dev/null and b/out/production/PIbd-22_Isaeva_A.I._Airbus_Hard/Entities/EntityAirbus.class differ
diff --git a/out/production/PIbd-22_Isaeva_A.I._Airbus_Hard/FormAirbus$1.class b/out/production/PIbd-22_Isaeva_A.I._Airbus_Hard/FormAirbus$1.class
new file mode 100644
index 0000000..ffe7420
Binary files /dev/null and b/out/production/PIbd-22_Isaeva_A.I._Airbus_Hard/FormAirbus$1.class differ
diff --git a/out/production/PIbd-22_Isaeva_A.I._Airbus_Hard/FormAirbus$2.class b/out/production/PIbd-22_Isaeva_A.I._Airbus_Hard/FormAirbus$2.class
new file mode 100644
index 0000000..ddf77b5
Binary files /dev/null and b/out/production/PIbd-22_Isaeva_A.I._Airbus_Hard/FormAirbus$2.class differ
diff --git a/out/production/PIbd-22_Isaeva_A.I._Airbus_Hard/FormAirbus$Canvas.class b/out/production/PIbd-22_Isaeva_A.I._Airbus_Hard/FormAirbus$Canvas.class
new file mode 100644
index 0000000..d676854
Binary files /dev/null and b/out/production/PIbd-22_Isaeva_A.I._Airbus_Hard/FormAirbus$Canvas.class differ
diff --git a/out/production/PIbd-22_Isaeva_A.I._Airbus_Hard/FormAirbus.class b/out/production/PIbd-22_Isaeva_A.I._Airbus_Hard/FormAirbus.class
new file mode 100644
index 0000000..c5e7b5b
Binary files /dev/null and b/out/production/PIbd-22_Isaeva_A.I._Airbus_Hard/FormAirbus.class differ
diff --git a/out/production/PIbd-22_Isaeva_A.I._Airbus_Hard/Main.class b/out/production/PIbd-22_Isaeva_A.I._Airbus_Hard/Main.class
new file mode 100644
index 0000000..b8e33fd
Binary files /dev/null and b/out/production/PIbd-22_Isaeva_A.I._Airbus_Hard/Main.class differ
diff --git a/out/production/PIbd-22_Isaeva_A.I._Airbus_Hard/MovementStrategy/Direction.class b/out/production/PIbd-22_Isaeva_A.I._Airbus_Hard/MovementStrategy/Direction.class
new file mode 100644
index 0000000..883737e
Binary files /dev/null and b/out/production/PIbd-22_Isaeva_A.I._Airbus_Hard/MovementStrategy/Direction.class differ
diff --git a/src/Drawnings/DrawingAirbus.java b/src/Drawnings/DrawningAirbus.java
similarity index 63%
rename from src/Drawnings/DrawingAirbus.java
rename to src/Drawnings/DrawningAirbus.java
index efd3310..a8fc97e 100644
--- a/src/Drawnings/DrawingAirbus.java
+++ b/src/Drawnings/DrawningAirbus.java
@@ -1,29 +1,48 @@
package Drawnings;
import java.awt.*;
+import java.util.Random;
import Entities.*;
import MovementStrategy.*;
-public class DrawingAirbus {
+public class DrawningAirbus {
public EntityAirbus entityAirbus;
- public DrawingPortholes _portholes;
+ public IDrawningPortholes _portholes;
private int _pictureWidth;
private int _pictureHeight;
- private int _startPosX;
- private int _startPosY;
- private int _airbusWidth = 123;
+ protected int _startPosX;
+ protected int _startPosY;
+ private int _airbusWidth = 124;
private int _airbusHeight = 44;
- public void Init(int speed, float weight, Color bodyColor, Color additionalColor, boolean isCompartment, boolean isadditionalEngine, int countPortholes, int width, int height) {
+ public int GetPosX() { return _startPosX; }
+ public int GetPosY() { return _startPosY; }
+ public int GetWidth() { return _airbusWidth; }
+ public int GetHeight() { return _airbusHeight; }
+
+ public DrawningAirbus(int speed, float weight, Color bodyColor, int countPortholes, int width, int height) {
if (width < _airbusHeight || height < _airbusWidth)
return;
_pictureWidth = width;
_pictureHeight = height;
- entityAirbus = new EntityAirbus();
- entityAirbus.Init(speed, weight, bodyColor, additionalColor, isCompartment, isadditionalEngine);
+ entityAirbus = new EntityAirbus(speed, weight, bodyColor);
- _portholes = new DrawingPortholes();
+ Random random = new Random();
+ switch (random.nextInt(0,3)) {
+ case 0:
+ _portholes = new DrawningPortholesCircle();
+ break;
+ case 1:
+ _portholes = new DrawningPortholesHeart();
+ break;
+ case 2:
+ _portholes = new DrawningPortholesSquare();
+ break;
+ default:
+ _portholes = new DrawningPortholesCircle();
+ break;
+ }
_portholes.SetCount(countPortholes);
}
@@ -39,6 +58,27 @@ public class DrawingAirbus {
}
}
+ public boolean CanMove(Direction direction)
+ {
+ if (entityAirbus == null)
+ {
+ return false;
+ }
+ switch (direction)
+ {
+ case Left:
+ return _startPosX - entityAirbus.Step > 0;
+ case Right:
+ return _startPosX + _airbusWidth + entityAirbus.Step < _pictureWidth;
+ case Up:
+ return _startPosY - entityAirbus.Step > 0;
+ case Down:
+ return _startPosY + _airbusHeight + entityAirbus.Step < _pictureHeight;
+ default:
+ return false;
+ }
+ }
+
public void MoveTransport(Direction direction){
if (entityAirbus == null) {
return;
@@ -46,28 +86,16 @@ public class DrawingAirbus {
switch (direction) {
case Left:
- if (_startPosX - entityAirbus.Step > 0)
- {
- _startPosX -= entityAirbus.Step;
- }
+ _startPosX -= entityAirbus.Step;
break;
case Right:
- if (_startPosX + _airbusWidth + entityAirbus.Step < _pictureWidth)
- {
- _startPosX += entityAirbus.Step;
- }
+ _startPosX += entityAirbus.Step;
break;
case Up:
- if (_startPosY - entityAirbus.Step > 0)
- {
- _startPosY -= entityAirbus.Step;
- }
+ _startPosY -= entityAirbus.Step;
break;
case Down:
- if (_startPosY + _airbusHeight + entityAirbus.Step < _pictureHeight)
- {
- _startPosY += entityAirbus.Step;
- }
+ _startPosY += entityAirbus.Step;
break;
}
}
@@ -122,23 +150,5 @@ public class DrawingAirbus {
g.drawOval(_startPosX+25,_startPosY+38, 6, 6);
g.drawOval(_startPosX+30,_startPosY+38, 6, 6);
g.drawOval(_startPosX+100,_startPosY+38, 6, 6);
-
- // пассажирский отсек
- if (entityAirbus.IsCompartment())
- {
- g.setColor(entityAirbus.getAdditionalColor());
- g.fillOval(_startPosX+57, _startPosY+11, 39, 9);
- g.setColor(Color.BLACK);
- g.drawOval(_startPosX+57, _startPosY+11, 39, 9);
- }
-
- // доп двигатель
- if (entityAirbus.IsAdditionalEngine())
- {
- g.setColor(entityAirbus.getAdditionalColor());
- g.fillOval(_startPosX, _startPosY + 25, 11, 5);
- g.setColor(Color.BLACK);
- g.drawOval(_startPosX, _startPosY + 25, 11, 5);
- }
}
}
diff --git a/src/Drawnings/DrawningPlane.java b/src/Drawnings/DrawningPlane.java
new file mode 100644
index 0000000..ce380f4
--- /dev/null
+++ b/src/Drawnings/DrawningPlane.java
@@ -0,0 +1,43 @@
+package Drawnings;
+
+import Entities.EntityPlane;
+
+import java.awt.*;
+
+public class DrawningPlane extends DrawningAirbus {
+
+ public DrawningPlane(int speed, float weight, Color bodyColor, int countPortholes, Color additionalColor, boolean isCompartment, boolean isAdditionalEngine, int width, int height)
+ {
+ super(speed, weight, bodyColor, countPortholes, width, height);
+ if (entityAirbus != null) {
+ entityAirbus = new EntityPlane(speed, weight, bodyColor, additionalColor, isCompartment, isAdditionalEngine);
+ }
+ }
+ @Override
+ public void DrawTransport(Graphics2D g) {
+
+ if (entityAirbus == null)
+ {
+ return;
+ }
+
+ Color additionalColor = ((EntityPlane)entityAirbus).getAdditionalColor();
+ // пассажирский отсек
+ if (((EntityPlane)entityAirbus).IsCompartment()) {
+ g.setColor(additionalColor);
+ g.fillOval(_startPosX + 57, _startPosY + 11, 39, 9);
+ g.setColor(Color.BLACK);
+ g.drawOval(_startPosX + 57, _startPosY + 11, 39, 9);
+ }
+
+ super.DrawTransport(g);
+
+ // доп двигатель
+ if (((EntityPlane)entityAirbus).IsAdditionalEngine()) {
+ g.setColor(additionalColor);
+ g.fillOval(_startPosX, _startPosY + 25, 11, 5);
+ g.setColor(Color.BLACK);
+ g.drawOval(_startPosX, _startPosY + 25, 11, 5);
+ }
+ }
+}
diff --git a/src/Drawnings/DrawingPortholes.java b/src/Drawnings/DrawningPortholesCircle.java
similarity index 64%
rename from src/Drawnings/DrawingPortholes.java
rename to src/Drawnings/DrawningPortholesCircle.java
index 11faa56..f93c2b8 100644
--- a/src/Drawnings/DrawingPortholes.java
+++ b/src/Drawnings/DrawningPortholesCircle.java
@@ -3,17 +3,15 @@ package Drawnings;
import java.awt.*;
import Entities.*;
-public class DrawingPortholes {
+public class DrawningPortholesCircle implements IDrawningPortholes {
private CountPortholes _porthole;
- public int Count;
public CountPortholes getCount()
{
return _porthole;
}
public void SetCount (int count) {
- Count = count;
- switch (Count) {
+ switch (count) {
case 10:
_porthole = CountPortholes.Ten;
break;
@@ -29,69 +27,69 @@ public class DrawingPortholes {
}
}
- public void Draw (Graphics2D g, int _startPosx, int _startPoxY) {
+ public void Draw (Graphics2D g, int _startPosX, int _startPosY) {
g.setColor(Color.BLACK);
if (_porthole == CountPortholes.Ten) {
// цикл
for (int i = 0; i < 10; ++i)
{
g.setColor(Color.cyan);
- g.fillOval(_startPosx + 19 + i*8, _startPoxY+21, 3, 3);
+ g.fillOval(_startPosX + 19 + i*8, _startPosY+21, 3, 3);
g.setColor(Color.black);
- g.drawOval(_startPosx + 19 + i*8, _startPoxY+21, 3, 3);
+ g.drawOval(_startPosX + 19 + i*8, _startPosY+21, 3, 3);
}
}
if (_porthole == CountPortholes.Twenty) {
for (int i = 0; i < 10; ++i)
{
g.setColor(Color.cyan);
- g.fillOval(_startPosx + 19 + i*8, _startPoxY+21, 3, 3);
+ g.fillOval(_startPosX + 19 + i*8, _startPosY+21, 3, 3);
g.setColor(Color.black);
- g.drawOval(_startPosx + 19 + i*8, _startPoxY+21, 3, 3);
+ g.drawOval(_startPosX + 19 + i*8, _startPosY+21, 3, 3);
}
for (int i=0; i < 5; ++i)
{
g.setColor(Color.cyan);
- g.fillOval(_startPosx + 15 + i*5, _startPoxY+26, 3, 3);
+ g.fillOval(_startPosX + 15 + i*5, _startPosY+26, 3, 3);
g.setColor(Color.black);
- g.drawOval(_startPosx + 15 + i*5, _startPoxY+26, 3, 3);
+ g.drawOval(_startPosX + 15 + i*5, _startPosY+26, 3, 3);
}
for (int i=0; i < 5; ++i)
{
g.setColor(Color.cyan);
- g.fillOval(_startPosx + 70 + i*5, _startPoxY+26, 3, 3);
+ g.fillOval(_startPosX + 70 + i*5, _startPosY+26, 3, 3);
g.setColor(Color.black);
- g.drawOval(_startPosx + 70 + i*5, _startPoxY+26, 3, 3);
+ g.drawOval(_startPosX + 70 + i*5, _startPosY+26, 3, 3);
}
}
if (_porthole == CountPortholes.Thirty){
for (int i = 0; i < 10; ++i)
{
g.setColor(Color.cyan);
- g.fillOval(_startPosx + 19 + i*8, _startPoxY+21, 3, 3);
+ g.fillOval(_startPosX + 19 + i*8, _startPosY+21, 3, 3);
g.setColor(Color.black);
- g.drawOval(_startPosx + 19 + i*8, _startPoxY+21, 3, 3);
+ g.drawOval(_startPosX + 19 + i*8, _startPosY+21, 3, 3);
}
for (int i=0; i < 5; ++i)
{
g.setColor(Color.cyan);
- g.fillOval(_startPosx + 15 + i*5, _startPoxY+26, 3, 3);
+ g.fillOval(_startPosX + 15 + i*5, _startPosY+26, 3, 3);
g.setColor(Color.black);
- g.drawOval(_startPosx + 15 + i*5, _startPoxY+26, 3, 3);
+ g.drawOval(_startPosX + 15 + i*5, _startPosY+26, 3, 3);
}
for (int i=0; i < 5; ++i)
{
g.setColor(Color.cyan);
- g.fillOval(_startPosx + 70 + i*5, _startPoxY+26, 3, 3);
+ g.fillOval(_startPosX + 70 + i*5, _startPosY+26, 3, 3);
g.setColor(Color.black);
- g.drawOval(_startPosx + 70 + i*5, _startPoxY+26, 3, 3);
+ g.drawOval(_startPosX + 70 + i*5, _startPosY+26, 3, 3);
}
for (int i = 0; i < 10; ++i)
{
g.setColor(Color.cyan);
- g.fillOval(_startPosx + 19 + i*8, _startPoxY+31, 3, 3);
+ g.fillOval(_startPosX + 19 + i*8, _startPosY+31, 3, 3);
g.setColor(Color.black);
- g.drawOval(_startPosx + 19 + i*8, _startPoxY+31, 3, 3);
+ g.drawOval(_startPosX + 19 + i*8, _startPosY+31, 3, 3);
}
}
}
diff --git a/src/Drawnings/DrawningPortholesHeart.java b/src/Drawnings/DrawningPortholesHeart.java
new file mode 100644
index 0000000..6b93ee1
--- /dev/null
+++ b/src/Drawnings/DrawningPortholesHeart.java
@@ -0,0 +1,81 @@
+package Drawnings;
+
+import Entities.CountPortholes;
+
+import java.awt.*;
+
+public class DrawningPortholesHeart implements IDrawningPortholes {
+ private CountPortholes _porthole;
+
+ public CountPortholes getCount()
+ {
+ return _porthole;
+ }
+ public void SetCount (int count) {
+ switch (count) {
+ case 10:
+ _porthole = CountPortholes.Ten;
+ break;
+ case 20:
+ _porthole = CountPortholes.Twenty;
+ break;
+ case 30:
+ _porthole = CountPortholes.Thirty;
+ break;
+ default:
+ _porthole = CountPortholes.Ten;
+ break;
+ }
+ }
+
+ public void Draw (Graphics2D g, int _startPosX, int _startPosY) {
+ g.setColor(Color.BLACK);
+ if (_porthole == CountPortholes.Ten) {
+ for (int i = 0; i < 10; ++i)
+ {
+ drawHeart(g, _startPosX + 19 + i*8, _startPosY + 20);
+ }
+ }
+ if (_porthole == CountPortholes.Twenty) {
+ for (int i = 0; i < 10; ++i)
+ {
+ drawHeart(g, _startPosX + 19 + i*8, _startPosY + 20);
+ }
+ for (int i=0; i < 5; ++i)
+ {
+ drawHeart(g, _startPosX + 12 + i*6, _startPosY + 26);
+ }
+ for (int i=0; i < 5; ++i)
+ {
+ drawHeart(g, _startPosX + 70 + i*6, _startPosY + 26);
+ }
+ }
+ if (_porthole == CountPortholes.Thirty){
+ for (int i = 0; i < 10; ++i)
+ {
+ drawHeart(g, _startPosX + 19 + i*8, _startPosY + 20);
+ }
+ for (int i=0; i < 5; ++i)
+ {
+ drawHeart(g, _startPosX + 12 + i*6, _startPosY + 26);
+ }
+ for (int i=0; i < 5; ++i)
+ {
+ drawHeart(g, _startPosX + 70 + i*6, _startPosY + 26);
+ }
+ for (int i = 0; i < 10; ++i)
+ {
+ drawHeart(g, _startPosX + 19 + i*8, _startPosY+32);
+ }
+ }
+ }
+
+ public void drawHeart(Graphics2D g, int _startPosX, int _startPosY){
+ int[] HeartX = {_startPosX+2, _startPosX, _startPosX, _startPosX+1, _startPosX+2, _startPosX+3, _startPosX+5, _startPosX+5};
+ int[] HeartY = {_startPosY+4, _startPosY+2, _startPosY, _startPosY, _startPosY+1, _startPosY, _startPosY, _startPosY+2};
+ g.setColor(Color.cyan);
+ g.fillPolygon(HeartX, HeartY, HeartX.length);
+ g.setColor(Color.black);
+ g.drawPolygon(HeartX, HeartY, HeartX.length);
+ }
+}
\ No newline at end of file
diff --git a/src/Drawnings/DrawningPortholesSquare.java b/src/Drawnings/DrawningPortholesSquare.java
new file mode 100644
index 0000000..23e5563
--- /dev/null
+++ b/src/Drawnings/DrawningPortholesSquare.java
@@ -0,0 +1,97 @@
+package Drawnings;
+
+import Entities.CountPortholes;
+
+import java.awt.*;
+
+public class DrawningPortholesSquare implements IDrawningPortholes {
+ private CountPortholes _porthole;
+
+ public CountPortholes getCount()
+ {
+ return _porthole;
+ }
+ public void SetCount (int count) {
+ switch (count) {
+ case 10:
+ _porthole = CountPortholes.Ten;
+ break;
+ case 20:
+ _porthole = CountPortholes.Twenty;
+ break;
+ case 30:
+ _porthole = CountPortholes.Thirty;
+ break;
+ default:
+ _porthole = CountPortholes.Ten;
+ break;
+ }
+ }
+
+ public void Draw (Graphics2D g, int _startPosX, int _startPosY) {
+ g.setColor(Color.BLACK);
+ if (_porthole == CountPortholes.Ten) {
+ // цикл
+ for (int i = 0; i < 10; ++i)
+ {
+ g.setColor(Color.cyan);
+ g.fillRect(_startPosX + 19 + i*8, _startPosY+21, 3, 3);
+ g.setColor(Color.black);
+ g.drawRect(_startPosX + 19 + i*8, _startPosY+21, 3, 3);
+ }
+ }
+ if (_porthole == CountPortholes.Twenty) {
+ for (int i = 0; i < 10; ++i)
+ {
+ g.setColor(Color.cyan);
+ g.fillRect(_startPosX + 19 + i*8, _startPosY+21, 3, 3);
+ g.setColor(Color.black);
+ g.drawRect(_startPosX + 19 + i*8, _startPosY+21, 3, 3);
+ }
+ for (int i=0; i < 5; ++i)
+ {
+ g.setColor(Color.cyan);
+ g.fillRect(_startPosX + 15 + i*5, _startPosY+26, 3, 3);
+ g.setColor(Color.black);
+ g.drawRect(_startPosX + 15 + i*5, _startPosY+26, 3, 3);
+ }
+ for (int i=0; i < 5; ++i)
+ {
+ g.setColor(Color.cyan);
+ g.fillRect(_startPosX + 70 + i*5, _startPosY+26, 3, 3);
+ g.setColor(Color.black);
+ g.drawRect(_startPosX + 70 + i*5, _startPosY+26, 3, 3);
+ }
+ }
+ if (_porthole == CountPortholes.Thirty){
+ for (int i = 0; i < 10; ++i)
+ {
+ g.setColor(Color.cyan);
+ g.fillRect(_startPosX + 19 + i*8, _startPosY+21, 3, 3);
+ g.setColor(Color.black);
+ g.drawRect(_startPosX + 19 + i*8, _startPosY+21, 3, 3);
+ }
+ for (int i=0; i < 5; ++i)
+ {
+ g.setColor(Color.cyan);
+ g.fillRect(_startPosX + 15 + i*5, _startPosY+26, 3, 3);
+ g.setColor(Color.black);
+ g.drawRect(_startPosX + 15 + i*5, _startPosY+26, 3, 3);
+ }
+ for (int i=0; i < 5; ++i)
+ {
+ g.setColor(Color.cyan);
+ g.fillRect(_startPosX + 70 + i*5, _startPosY+26, 3, 3);
+ g.setColor(Color.black);
+ g.drawRect(_startPosX + 70 + i*5, _startPosY+26, 3, 3);
+ }
+ for (int i = 0; i < 10; ++i)
+ {
+ g.setColor(Color.cyan);
+ g.fillRect(_startPosX + 19 + i*8, _startPosY+31, 3, 3);
+ g.setColor(Color.black);
+ g.drawRect(_startPosX + 19 + i*8, _startPosY+31, 3, 3);
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/Drawnings/IDrawningPortholes.java b/src/Drawnings/IDrawningPortholes.java
new file mode 100644
index 0000000..6ac3162
--- /dev/null
+++ b/src/Drawnings/IDrawningPortholes.java
@@ -0,0 +1,10 @@
+package Drawnings;
+
+import java.awt.*;
+import Entities.CountPortholes;
+
+public interface IDrawningPortholes {
+ public CountPortholes getCount();
+ public void SetCount (int count);
+ public void Draw (Graphics2D g, int _startPosX, int _startPoxY);
+}
\ No newline at end of file
diff --git a/src/Entities/EntityAirbus.java b/src/Entities/EntityAirbus.java
index 1f4b8a7..0c83f72 100644
--- a/src/Entities/EntityAirbus.java
+++ b/src/Entities/EntityAirbus.java
@@ -6,11 +6,7 @@ public class EntityAirbus {
private int Speed;
private float Weight;
private Color BodyColor;
- private Color AdditionalColor;
- private boolean IsCompartment;
- private boolean IsAdditionalEngine;
-
- public int Step;
+ public float Step;
public int getSpeed() {
return Speed;
@@ -21,27 +17,14 @@ public class EntityAirbus {
public Color getBodyColor() {
return BodyColor;
}
- public Color getAdditionalColor() {
- return AdditionalColor;
- }
- public boolean IsCompartment() {
- return IsCompartment;
- }
- public boolean IsAdditionalEngine() {
- return IsAdditionalEngine;
- }
- public void Init(int speed, float weight, Color bodyColor, Color additionalColor, boolean isCompartment, boolean isAdditionalEngine)
+ public EntityAirbus(int speed, float weight, Color bodyColor)
{
+ Weight = weight;
+ Speed = speed;
+ BodyColor = bodyColor;
- Weight = weight;
- Speed = speed;
- BodyColor = bodyColor;
- AdditionalColor = additionalColor;
- IsCompartment = isCompartment;
- IsAdditionalEngine = isAdditionalEngine;
-
- Step = Speed * 100 / (int) Weight;
+ Step = Speed * 100 / (int) Weight;
}
}
diff --git a/src/Entities/EntityPlane.java b/src/Entities/EntityPlane.java
new file mode 100644
index 0000000..90f94f5
--- /dev/null
+++ b/src/Entities/EntityPlane.java
@@ -0,0 +1,21 @@
+package Entities;
+
+import javax.swing.text.AttributeSet;
+import java.awt.*;
+
+public class EntityPlane extends EntityAirbus {
+ private Color AdditionalColor;
+ private boolean IsCompartment;
+ private boolean IsAdditionalEngine;
+
+ public EntityPlane(int speed, float weight, Color bodyColor, Color additionalColor, boolean isCompartment, boolean isAdditionalEngine) {
+ super(speed, weight, bodyColor);
+ AdditionalColor = additionalColor;
+ IsCompartment = isCompartment;
+ IsAdditionalEngine = isAdditionalEngine;
+ }
+
+ public Color getAdditionalColor() { return AdditionalColor; }
+ public boolean IsCompartment() { return IsCompartment; }
+ public boolean IsAdditionalEngine() { return IsAdditionalEngine; }
+}
diff --git a/src/FormAirbus.java b/src/FormAirbus.java
index 05d6c5e..78cf068 100644
--- a/src/FormAirbus.java
+++ b/src/FormAirbus.java
@@ -7,12 +7,23 @@ import MovementStrategy.*;
public class FormAirbus extends JFrame {
- private DrawingAirbus _drawningAirbus;
- private Canvas canvas = new Canvas();
+ private int width;
+ private int height;
+ private DrawningAirbus _drawningAirbus;
+ private AbstractStrategy _abstractStrategy;
+ private Canvas canvas;
- JLabel labelCount = new JLabel("Введите число иллюминаторов:");
- private JTextField fieldCount = new JTextField();
- private JButton buttonCreate;
+ // выбор кол-ва иллюминаторов
+ JLabel labelCount;
+ private JTextField fieldCount;
+
+ // выбор стратегии
+ JLabel labelStrategy;
+ JComboBox comboBoxStrategy;
+ JButton buttonStrategy;
+
+ private JButton buttonCreateAirbus;
+ private JButton buttonCreatePlane;
private JButton buttonUp;
private JButton buttonDown;
private JButton buttonRight;
@@ -26,43 +37,67 @@ public class FormAirbus extends JFrame {
private void InitializeComponent()
{
- buttonCreate = new JButton("Создать самолёт");
+ canvas = new Canvas();
+
+ labelCount = new JLabel("Введите число иллюминаторов:");
+ fieldCount = new JTextField();
+
+ labelStrategy = new JLabel("Шаг стратегии:");
+ comboBoxStrategy = new JComboBox(new Integer[] {0, 1});
+ buttonStrategy = new JButton("Выбрать стратегию");
+ buttonStrategy.setMargin(new Insets(0, 0, 0, 0));
+
+ buttonCreateAirbus = new JButton("Создать аэробус");
+ buttonCreateAirbus.setMargin(new Insets(0, 0, 0, 0));
+
+ buttonCreatePlane = new JButton("Создать самолёт");
+ buttonCreatePlane.setMargin(new Insets(0, 0, 0, 0));
buttonUp = new JButton();
buttonUp.setName("up");
buttonUp.setIcon(new ImageIcon("images\\KeyUp.png"));
- buttonUp.setSize(48, 44);
buttonRight = new JButton();
buttonRight.setName("right");
buttonRight.setIcon(new ImageIcon("images\\KeyRight.png"));
- buttonRight.setSize(48, 44);
buttonLeft = new JButton();
-
buttonLeft.setName("left");
buttonLeft.setIcon(new ImageIcon("images\\KeyLeft.png"));
- buttonLeft.setSize(48, 44);
buttonDown = new JButton();
buttonDown.setName("down");
buttonDown.setIcon(new ImageIcon("images\\KeyDown.png"));
- buttonDown.setSize(48, 44);
setSize(800,500);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLayout(null);
- buttonCreate.setBounds(12, 355, 170, 44);
+ buttonCreateAirbus.setBounds(12, 355, 146, 33);
+ buttonCreatePlane.setBounds(182, 355, 146, 33);
+
+ labelCount.setBounds(42, 405, 240, 20);
+ fieldCount.setBounds(240, 407, 48, 20);
+
+ labelStrategy.setBounds(630, 20, 146, 33);
+ comboBoxStrategy.setBounds(630, 50, 146, 20);
+ buttonStrategy.setBounds(630, 80, 146, 33);
+
buttonUp.setBounds(679, 313, 48, 44);
buttonRight.setBounds( 728, 358, 48, 44);
buttonLeft.setBounds(630, 358, 48, 44);
buttonDown.setBounds( 679, 358, 48, 44);
labelCount.setBounds(12, 405, 240, 20);
fieldCount.setBounds(210, 407, 48, 20);
- canvas.setBounds(0,0,800, 460);
+ canvas.setBounds(0,0,790, 460);
- add(buttonCreate);
+ add(buttonCreateAirbus);
+ add(buttonCreatePlane);
+ add(labelCount);
+ add(fieldCount);
+ add(labelStrategy);
+ add(comboBoxStrategy);
+ add(buttonStrategy);
add(buttonUp);
add(buttonRight);
add(buttonDown);
@@ -71,14 +106,18 @@ public class FormAirbus extends JFrame {
add(fieldCount);
add(canvas);
- buttonCreate.addActionListener(buttonCreateListener);
+ // логика формы
+ buttonCreateAirbus.addActionListener(buttonCreateAirbusListener);
+ buttonCreatePlane.addActionListener(buttonCreatePlaneListener);
+ buttonStrategy.addActionListener(buttonStrategyListener);
buttonUp.addActionListener(buttonsMoveListener);
buttonRight.addActionListener(buttonsMoveListener);
buttonDown.addActionListener(buttonsMoveListener);
buttonLeft.addActionListener(buttonsMoveListener);
}
- ActionListener buttonCreateListener = new ActionListener() {
+ ActionListener buttonCreateAirbusListener = new ActionListener() {
+ @Override
public void actionPerformed(ActionEvent e) {
int countPortholes;
try
@@ -96,15 +135,86 @@ public class FormAirbus extends JFrame {
}
Random rand = new Random();
- _drawningAirbus = new DrawingAirbus();
- _drawningAirbus.Init(rand.nextInt(200) + 100, rand.nextInt(2000) + 1000,
+ _drawningAirbus = new DrawningAirbus(rand.nextInt(200) + 100, rand.nextInt(2000) + 1000,
new Color(rand.nextInt(256),rand.nextInt(256),rand.nextInt(256)),
- new Color(rand.nextInt(256), rand.nextInt(256), rand.nextInt(256)),
- rand.nextBoolean(), rand.nextBoolean(),
countPortholes,
canvas.getWidth(), canvas.getHeight());
_drawningAirbus.SetPosition(rand.nextInt(100) + 10, rand.nextInt(100) + 10);
+ comboBoxStrategy.setEnabled(true);
+ canvas.repaint();
+ }
+ };
+
+ ActionListener buttonCreatePlaneListener = new ActionListener() {
+ @Override
+ public void actionPerformed(ActionEvent e) {
+ int countPortholes;
+ try
+ {
+ countPortholes = Integer.parseInt(fieldCount.getText());
+ }
+ catch (Exception ex)
+ {
+ countPortholes = 0;
+ }
+ if (countPortholes != 10 && countPortholes != 20 && countPortholes != 30)
+ {
+ JOptionPane.showMessageDialog(null, "Число должно быть равно 10, 20 или 30.\nКол-во иллюминаторов приравнено к 10");
+ countPortholes = 10;
+ }
+
+ Random rand = new Random();
+ _drawningAirbus = new DrawningPlane(rand.nextInt(200) + 100, rand.nextInt(2000) + 1000,
+ new Color(rand.nextInt(256),rand.nextInt(256),rand.nextInt(256)),
+ countPortholes,
+ new Color(rand.nextInt(256), rand.nextInt(256), rand.nextInt(256)),
+ rand.nextBoolean(), rand.nextBoolean(),
+ canvas.getWidth(), canvas.getHeight());
+
+ _drawningAirbus.SetPosition(rand.nextInt(100) + 10, rand.nextInt(100) + 10);
+ comboBoxStrategy.setEnabled(true);
+ canvas.repaint();
+ }
+ };
+
+ ActionListener buttonStrategyListener = new ActionListener() {
+ @Override
+ public void actionPerformed(ActionEvent e) {
+ if (_drawningAirbus == null)
+ {
+ return;
+ }
+ if (comboBoxStrategy.isEnabled()) {
+
+ switch (comboBoxStrategy.getSelectedIndex()) {
+ case 0:
+ _abstractStrategy = new MoveToCenter();
+ break;
+ case 1:
+ _abstractStrategy = new MoveToBorder();
+ break;
+ default:
+ _abstractStrategy = null;
+ break;
+ }
+ ;
+ if (_abstractStrategy == null) {
+ return;
+ }
+ _abstractStrategy.SetData(new DrawningObjectAirbus(_drawningAirbus), canvas.getWidth(), canvas.getHeight());
+ comboBoxStrategy.setEnabled(false);
+ }
+ if (_abstractStrategy == null)
+ {
+ return;
+ }
+ _abstractStrategy.MakeStep();
+ if (_abstractStrategy.GetStatus() == Status.Finish)
+ {
+ comboBoxStrategy.setEnabled(true);
+ _abstractStrategy = null;
+ }
canvas.repaint();
}
};
@@ -136,8 +246,7 @@ public class FormAirbus extends JFrame {
};
class Canvas extends JComponent{
- public Canvas(){
- }
+ public Canvas() {}
public void paintComponent (Graphics g){
if (_drawningAirbus == null){
return;
diff --git a/src/Main.java b/src/Main.java
index 03af442..ba66689 100644
--- a/src/Main.java
+++ b/src/Main.java
@@ -1,4 +1,5 @@
public class Main {
+
public static void main(String[] args) {
new FormAirbus();
}
diff --git a/src/MovementStrategy/AbstractStrategy.java b/src/MovementStrategy/AbstractStrategy.java
new file mode 100644
index 0000000..742c4df
--- /dev/null
+++ b/src/MovementStrategy/AbstractStrategy.java
@@ -0,0 +1,76 @@
+package MovementStrategy;
+
+public abstract class AbstractStrategy {
+ private IMoveableObject _moveableObject;
+ private Status _state = Status.NotInit;
+ protected int FieldWidth;
+ protected int FieldHeight;
+ public Status GetStatus() { return _state; }
+
+ // Изменить статус, установить поля
+ public void SetData(IMoveableObject moveableObject, int width, int height)
+ {
+ if (moveableObject == null)
+ {
+ _state = Status.NotInit;
+ return;
+ }
+ _state = Status.InProgress;
+ _moveableObject = moveableObject;
+ FieldWidth = width;
+ FieldHeight = height;
+ }
+
+ // сделать шаг
+ public void MakeStep()
+ {
+ if (_state != Status.InProgress)
+ {
+ return;
+ }
+ if (IsTargetDestination())
+ {
+ _state = Status.Finish;
+ return;
+ }
+ MoveToTarget();
+ }
+
+ // перемещения
+ protected boolean MoveLeft() { return MoveTo(Direction.Left); }
+ protected boolean MoveRight() { return MoveTo(Direction.Right); }
+ protected boolean MoveUp() { return MoveTo(Direction.Up); }
+ protected boolean MoveDown() { return MoveTo(Direction.Down); }
+
+ // параметры
+ protected ObjectParameters GetObjectParameters() { return _moveableObject.GetObjectPosition(); }
+ // шаг
+ protected int GetStep()
+ {
+ if (_state != Status.InProgress)
+ {
+ return 0;
+ }
+ return _moveableObject.GetStep();
+ }
+ // перемещение
+ protected abstract void MoveToTarget();
+
+ // достигнута ли цель
+ protected abstract boolean IsTargetDestination();
+
+ // попытка перемещения по направлению
+ private boolean MoveTo(Direction directionType)
+ {
+ if (_state != Status.InProgress)
+ {
+ return false;
+ }
+ if (_moveableObject.CheckCanMove(directionType))
+ {
+ _moveableObject.MoveObject(directionType);
+ return true;
+ }
+ return false;
+ }
+}
diff --git a/src/MovementStrategy/DrawningObjectAirbus.java b/src/MovementStrategy/DrawningObjectAirbus.java
new file mode 100644
index 0000000..47a9c6f
--- /dev/null
+++ b/src/MovementStrategy/DrawningObjectAirbus.java
@@ -0,0 +1,24 @@
+package MovementStrategy;
+import Drawnings.*;
+
+public class DrawningObjectAirbus implements IMoveableObject {
+ private DrawningAirbus _drawningAirbus = null;
+
+ public DrawningObjectAirbus(DrawningAirbus drawningAirbus)
+ {
+ _drawningAirbus = drawningAirbus;
+ }
+
+ public ObjectParameters GetObjectPosition()
+ {
+ if (_drawningAirbus == null || _drawningAirbus.entityAirbus == null)
+ {
+ return null;
+ }
+ return new ObjectParameters(_drawningAirbus.GetPosX(), _drawningAirbus.GetPosY(), _drawningAirbus.GetWidth(), _drawningAirbus.GetHeight());
+ }
+
+ public int GetStep() { return (int)_drawningAirbus.entityAirbus.Step; }
+ public boolean CheckCanMove(Direction direction) { return _drawningAirbus.CanMove(direction); }
+ public void MoveObject(Direction direction) { _drawningAirbus.MoveTransport(direction); }
+}
diff --git a/src/MovementStrategy/IMoveableObject.java b/src/MovementStrategy/IMoveableObject.java
new file mode 100644
index 0000000..ffd427e
--- /dev/null
+++ b/src/MovementStrategy/IMoveableObject.java
@@ -0,0 +1,8 @@
+package MovementStrategy;
+
+public interface IMoveableObject {
+ ObjectParameters GetObjectPosition();
+ int GetStep();
+ boolean CheckCanMove(Direction direction);
+ void MoveObject(Direction direction);
+}
diff --git a/src/MovementStrategy/MoveToBorder.java b/src/MovementStrategy/MoveToBorder.java
new file mode 100644
index 0000000..08e2b44
--- /dev/null
+++ b/src/MovementStrategy/MoveToBorder.java
@@ -0,0 +1,53 @@
+package MovementStrategy;
+
+public class MoveToBorder extends AbstractStrategy {
+ @Override
+ protected boolean IsTargetDestination()
+ {
+ var objParams = GetObjectParameters();
+ if (objParams == null)
+ {
+ return false;
+ }
+ return objParams.RightBorder() <= FieldWidth &&
+ objParams.RightBorder() + GetStep() >= FieldWidth &&
+ objParams.DownBorder() <= FieldHeight &&
+ objParams.DownBorder() + GetStep() >= FieldHeight;
+ }
+
+ // движение к цели
+ @Override
+ protected void MoveToTarget()
+ {
+ var objParams = GetObjectParameters();
+ if (objParams == null)
+ {
+ return;
+ }
+ var diffX = FieldWidth;
+ if (Math.abs(diffX) > GetStep())
+ {
+ if (diffX < 0)
+ {
+ MoveLeft();
+ }
+ else
+ {
+ MoveRight();
+ }
+ }
+
+ var diffY = FieldHeight;
+ if (Math.abs(diffY) > GetStep())
+ {
+ if (diffY < 0)
+ {
+ MoveUp();
+ }
+ else
+ {
+ MoveDown();
+ }
+ }
+ }
+}
diff --git a/src/MovementStrategy/MoveToCenter.java b/src/MovementStrategy/MoveToCenter.java
new file mode 100644
index 0000000..1b278cb
--- /dev/null
+++ b/src/MovementStrategy/MoveToCenter.java
@@ -0,0 +1,53 @@
+package MovementStrategy;
+
+public class MoveToCenter extends AbstractStrategy {
+ @Override
+ protected boolean IsTargetDestination()
+ {
+ var objParams = GetObjectParameters();
+ if (objParams == null)
+ {
+ return false;
+ }
+ return objParams.ObjectMiddleHorizontal() <= FieldWidth / 2 &&
+ objParams.ObjectMiddleHorizontal() + GetStep() >= FieldWidth / 2 &&
+ objParams.ObjectMiddleVertical() <= FieldHeight / 2 &&
+ objParams.ObjectMiddleVertical() + GetStep() >= FieldHeight / 2;
+ }
+
+ // движение к цели
+ @Override
+ protected void MoveToTarget()
+ {
+ var objParams = GetObjectParameters();
+ if (objParams == null)
+ {
+ return;
+ }
+ var diffX = objParams.ObjectMiddleHorizontal() - FieldWidth / 2;
+ if (Math.abs(diffX) > GetStep())
+ {
+ if (diffX > 0)
+ {
+ MoveLeft();
+ }
+ else
+ {
+ MoveRight();
+ }
+ }
+
+ var diffY = objParams.ObjectMiddleVertical() - FieldHeight / 2;
+ if (Math.abs(diffY) > GetStep())
+ {
+ if (diffY > 0)
+ {
+ MoveUp();
+ }
+ else
+ {
+ MoveDown();
+ }
+ }
+ }
+}
diff --git a/src/MovementStrategy/ObjectParameters.java b/src/MovementStrategy/ObjectParameters.java
new file mode 100644
index 0000000..a741f5a
--- /dev/null
+++ b/src/MovementStrategy/ObjectParameters.java
@@ -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;
+ }
+}
diff --git a/src/MovementStrategy/Status.java b/src/MovementStrategy/Status.java
new file mode 100644
index 0000000..586b538
--- /dev/null
+++ b/src/MovementStrategy/Status.java
@@ -0,0 +1,7 @@
+package MovementStrategy;
+
+public enum Status {
+ NotInit,
+ InProgress,
+ Finish
+}