From 56c85de90927889b1801b3fb8aaebad54d9a5de2 Mon Sep 17 00:00:00 2001 From: ArtemEmelyanov Date: Tue, 29 Nov 2022 00:25:21 +0400 Subject: [PATCH] Add interface --- DrawningObjectPlane.java | 38 ++++++++++++++++++++++++++++++++++++++ DrawningPlane.java | 9 +++++++++ IDrawningObject.java | 13 +++++++++++++ 3 files changed, 60 insertions(+) create mode 100644 DrawningObjectPlane.java create mode 100644 IDrawningObject.java diff --git a/DrawningObjectPlane.java b/DrawningObjectPlane.java new file mode 100644 index 0000000..49f8fbc --- /dev/null +++ b/DrawningObjectPlane.java @@ -0,0 +1,38 @@ +import java.awt.*; + +public class DrawningObjectPlane implements IDrawningObject { + private DrawningPlane _plane = null; + + public DrawningObjectPlane(DrawningPlane plane) + { + _plane = plane; + } + + public float Step() { + if(_plane != null && _plane.Plane != null) + return _plane.Plane.Step; + return 0; + } + + @Override + public void SetObject(int x, int y, int width, int height) { + _plane.SetPosition(x,y,width,height); + } + + @Override + public void MoveObject(Direction direction) { + _plane.MoveTransport(direction); + } + + @Override + public void DrawingObject(Graphics g) { + _plane.DrawTransport(g); + } + + @Override + public float[] GetCurrentPosition() { + if(_plane!=null) + return _plane.GetCurrentPosition(); + return null; + } +} diff --git a/DrawningPlane.java b/DrawningPlane.java index 561078e..964996f 100644 --- a/DrawningPlane.java +++ b/DrawningPlane.java @@ -143,4 +143,13 @@ public class DrawningPlane extends JPanel { _startPosY = _pictureHeight - _PlaneHeight; } } + + public float[] GetCurrentPosition() { + float[] dim = new float[4]; + dim[0] = _startPosX; + dim[1] =_startPosY; + dim[2] = _startPosX + _PlaneWidth; + dim[3] = _startPosY + _PlaneHeight; + return dim; + } } diff --git a/IDrawningObject.java b/IDrawningObject.java new file mode 100644 index 0000000..9b32730 --- /dev/null +++ b/IDrawningObject.java @@ -0,0 +1,13 @@ +import java.awt.*; + +public interface IDrawningObject { + public float Step = 0; + + void SetObject(int x, int y, int width, int height); + + void MoveObject(Direction direction); + + void DrawingObject(Graphics g); + + float[] GetCurrentPosition(); +}