Added class DrawingObjectArtillery

This commit is contained in:
Сергей Полевой 2022-10-08 15:25:07 +04:00
parent f990882127
commit 6840f8220e
3 changed files with 39 additions and 2 deletions

View File

@ -25,7 +25,7 @@ public class DrawingArtillery {
_artilleryHeight = artilleryHeight; _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) if (x < 0 || x + _artilleryWidth >= width)
{ {
return; return;

View File

@ -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);
}
}

View File

@ -32,7 +32,7 @@ public class FormArtillery extends JFrame {
rnd.nextInt(0, 256)), rnd.nextInt(0, 256)),
rnd.nextInt(4, 7) 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())); speedLabel.setText(String.format("Скорость: %s", _artillery.getArtillery().getSpeed()));
weightLabel.setText(String.format("Вес: %s", _artillery.getArtillery().getWeight())); weightLabel.setText(String.format("Вес: %s", _artillery.getArtillery().getWeight()));
colorLabel.setText(String.format("Цвет: %x", _artillery.getArtillery().getBodyColor().getRGB())); colorLabel.setText(String.format("Цвет: %x", _artillery.getArtillery().getBodyColor().getRGB()));