From b5be809757079187aa749f31e3e0cb8e6da6cc08 Mon Sep 17 00:00:00 2001 From: Senju Date: Fri, 23 Sep 2022 11:35:42 +0400 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5=20=D0=BD=D0=BE=D0=B2=D1=8B=D1=85=20=D0=BA?= =?UTF-8?q?=D0=BB=D0=B0=D1=81=D1=81=D0=BE=D0=B2=20=D0=B8=20=D0=B8=D1=85=20?= =?UTF-8?q?=D0=B7=D0=B0=D0=BF=D0=BE=D0=BB=D0=BD=D0=B5=D0=BD=D0=B8=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Direction.java | 8 ++++ src/DrawingWarship.java | 86 +++++++++++++++++++++++++++++++++++++++++ src/EntityWarship.java | 12 +++--- src/FormWarship.java | 4 +- 4 files changed, 103 insertions(+), 7 deletions(-) create mode 100644 src/Direction.java create mode 100644 src/DrawingWarship.java diff --git a/src/Direction.java b/src/Direction.java new file mode 100644 index 0000000..9c9bce1 --- /dev/null +++ b/src/Direction.java @@ -0,0 +1,8 @@ +package src; + +public enum Direction { + Up, + Down, + Left, + Right; +} diff --git a/src/DrawingWarship.java b/src/DrawingWarship.java new file mode 100644 index 0000000..1cd3f5d --- /dev/null +++ b/src/DrawingWarship.java @@ -0,0 +1,86 @@ +package src; + +import java.awt.*; + +public class DrawingWarship { + private EntityWarship Warship; + public EntityWarship GetWarship(){return Warship;} + + private float _startPosX; + private float _startPosY; + + private Integer _pictureWidth = null; + private Integer _pictureHeight = null; + + private final int _warshipWidth = 94; + private final int _warshipHeight = 40; + + public void Init(int speed, float weight, Color bodyColor) + { + Warship = new EntityWarship(); + Warship.Init(speed, weight, bodyColor); + } + + public void SetPosition(int x, int y, int width, int height) + { + if (width >= x + _warshipWidth && height >= y + _warshipHeight && x >= 0 && y >= 0) + { + _startPosX = x; + _startPosY = y; + _pictureWidth = width; + _pictureHeight = height; + } + } + + public void MoveTransport(Direction direction) + { + if (_pictureWidth == null || _pictureHeight == null) + { + return; + } + switch (direction) + { + // вправо + case Right: + if (_startPosX + _warshipWidth + Warship.Step < _pictureWidth) + { + _startPosX += Warship.Step; + } + break; + //влево + case Left: + if(_startPosX - Warship.Step > 0) + { + _startPosX -= Warship.Step; + } + break; + //вверх + case Up: + if (_startPosY - Warship.Step > 0) + { + _startPosY -= Warship.Step; + } + break; + //вниз + case Down: + if (_startPosY + _warshipHeight + Warship.Step < _pictureHeight) + { + _startPosY += Warship.Step; + } + break; + } + } + + public void DrawTransport(Graphics g){ + if (_startPosX < 0 || _startPosY < 0 || _pictureHeight == null || _pictureWidth == null) + { + return; + } + Graphics2D g2 = (Graphics2D) g; + float[] pointXWarship = {_startPosX + 4, _startPosX + 94, _startPosX + 114, _startPosX + 94, _startPosX + 4}; + float[] pointYWarship = {_startPosY, _startPosY, _startPosY + 20, _startPosY + 40, _startPosY + 40}; + + + + } +} diff --git a/src/EntityWarship.java b/src/EntityWarship.java index c3fc3c4..aa9f85c 100644 --- a/src/EntityWarship.java +++ b/src/EntityWarship.java @@ -5,16 +5,16 @@ import java.util.Random; public class EntityWarship { private int Speed; - private void setSpeed(int speed){this.Speed = speed;} - public int getSpeed(){return Speed;} + private void SetSpeed(int speed){this.Speed = speed;} + public int GetSpeed(){return Speed;} private float Weight; - private void setWeight(float weight){this.Weight = weight;} - public float getWeight(){return Weight;} + private void SetWeight(float weight){this.Weight = weight;} + public float GetWeight(){return Weight;} private Color BodyColor ; - private void setBodyColor (Color bodyColor){this.BodyColor = bodyColor;} - public Color getBodyColor (){return BodyColor;} + private void SetBodyColor (Color bodyColor){this.BodyColor = bodyColor;} + public Color GetBodyColor (){return BodyColor;} public float Step; public void Init(int speed, float weight, Color bodyColor) diff --git a/src/FormWarship.java b/src/FormWarship.java index 64b6a5b..bd6b839 100644 --- a/src/FormWarship.java +++ b/src/FormWarship.java @@ -1,5 +1,7 @@ package src; -public class FormWarship { +import javax.swing.*; + +public class FormWarship extends JFrame{ }