From 6840f8220ec58ebf2e98b16e781b5166387e1eb6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A1=D0=B5=D1=80=D0=B3=D0=B5=D0=B9=20=D0=9F=D0=BE=D0=BB?= =?UTF-8?q?=D0=B5=D0=B2=D0=BE=D0=B9?= Date: Sat, 8 Oct 2022 15:25:07 +0400 Subject: [PATCH] Added class DrawingObjectArtillery --- DrawingArtillery.java | 2 +- DrawingObjectArtillery.java | 37 +++++++++++++++++++++++++++++++++++++ FormArtillery.java | 2 +- 3 files changed, 39 insertions(+), 2 deletions(-) create mode 100644 DrawingObjectArtillery.java diff --git a/DrawingArtillery.java b/DrawingArtillery.java index 1dd0216..2b64328 100644 --- a/DrawingArtillery.java +++ b/DrawingArtillery.java @@ -25,7 +25,7 @@ public class DrawingArtillery { _artilleryHeight = artilleryHeight; } - public void SetPosition(int x, int y, int width, int height) { + public void setPosition(int x, int y, int width, int height) { if (x < 0 || x + _artilleryWidth >= width) { return; diff --git a/DrawingObjectArtillery.java b/DrawingObjectArtillery.java new file mode 100644 index 0000000..95a71e4 --- /dev/null +++ b/DrawingObjectArtillery.java @@ -0,0 +1,37 @@ +import java.awt.*; + +public class DrawingObjectArtillery implements IDrawingObject { + private DrawingArtillery _artillery = null; + + public DrawingObjectArtillery(DrawingArtillery artillery) { + _artillery = artillery; + } + + public float getStep() { + if (_artillery != null && _artillery.artillery != null) { + return _artillery.artillery.getStep(); + } + return 0; + } + + public float[] getCurrentPosition() { + if (_artillery != null) { + return _artillery.getCurrentPosition(); + } + return new float[] { 0, 0, 0, 0 }; + } + + public void moveObject(Direction direction) { + if (_artillery != null) { + _artillery.moveTransport(direction); + } + } + + public void setObject(int x, int y, int width, int height) { + _artillery.setPosition(x, y, width, height); + } + + public void drawingObject(Graphics2D g) { + _artillery.drawTransport(g); + } +} diff --git a/FormArtillery.java b/FormArtillery.java index 97533a5..6b22958 100644 --- a/FormArtillery.java +++ b/FormArtillery.java @@ -32,7 +32,7 @@ public class FormArtillery extends JFrame { rnd.nextInt(0, 256)), rnd.nextInt(4, 7) ); - _artillery.SetPosition(10 + rnd.nextInt(90), 10 + rnd.nextInt(90), pictureBox.getWidth(), pictureBox.getHeight()); + _artillery.setPosition(10 + rnd.nextInt(90), 10 + rnd.nextInt(90), pictureBox.getWidth(), pictureBox.getHeight()); speedLabel.setText(String.format("Скорость: %s", _artillery.getArtillery().getSpeed())); weightLabel.setText(String.format("Вес: %s", _artillery.getArtillery().getWeight())); colorLabel.setText(String.format("Цвет: %x", _artillery.getArtillery().getBodyColor().getRGB()));