From 0e85f721778f6133d9d255eebb826920fbf84e9c 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 14:55:39 +0400 Subject: [PATCH] Changed some private fields to protected in DrawingArtillery. Added method getCurrentPosition --- DrawingArtillery.java | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/DrawingArtillery.java b/DrawingArtillery.java index 472a1e2..1dd0216 100644 --- a/DrawingArtillery.java +++ b/DrawingArtillery.java @@ -1,14 +1,14 @@ import java.awt.*; public class DrawingArtillery { - private EntityArtillery artillery; - private DrawingRollers drawingRollers; - private float _startPosX; - private float _startPosY; + protected EntityArtillery artillery; + protected DrawingRollers drawingRollers; + protected float _startPosX; + protected float _startPosY; private Integer _pictureWidth = null; private Integer _pictureHeight = null; - private final int _artilleryWidth = 80; - private final int _artilleryHeight = 50; + protected int _artilleryWidth = 80; + protected int _artilleryHeight = 50; public EntityArtillery getArtillery() { return artillery; @@ -19,6 +19,12 @@ public class DrawingArtillery { drawingRollers = new DrawingRollers(rollersCount, bodyColor); } + protected DrawingArtillery(int speed, float weight, Color bodyColor, int rollersCount, int artilleryWidth, int artilleryHeight) { + this(speed, weight, bodyColor, rollersCount); + _artilleryWidth = artilleryWidth; + _artilleryHeight = artilleryHeight; + } + public void SetPosition(int x, int y, int width, int height) { if (x < 0 || x + _artilleryWidth >= width) { @@ -80,7 +86,7 @@ public class DrawingArtillery { return; } g.setColor(artillery.getBodyColor() != null ? artillery.getBodyColor() : Color.BLACK); - g.fillRect((int) (_startPosX + _artilleryWidth / 8 * 2), (int) _startPosY, _artilleryWidth / 8 * 4, _artilleryWidth / 5); + g.fillRect((int) (_startPosX + _artilleryWidth / 8 * 2), (int) _startPosY, _artilleryWidth / 8 * 4, _artilleryHeight / 5); g.fillRect((int) _startPosX, (int) (_startPosY + _artilleryHeight / 5), _artilleryWidth, _artilleryHeight / 3); @@ -108,4 +114,8 @@ public class DrawingArtillery { _startPosY = _pictureHeight - _artilleryHeight; } } + + public float[] getCurrentPosition() { + return new float[] { _startPosX, _startPosX + _artilleryWidth - 1, _startPosY, _startPosY + _artilleryHeight -1 }; + } }