From 02566d79573fbecc209a7a59b7433214ad7b6cc1 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:43:17 +0400 Subject: [PATCH] Constructors have been added --- DrawingArtillery.java | 8 +++----- DrawingRollers.java | 2 +- EntityArtillery.java | 2 +- FormArtillery.java | 17 ++++++++--------- 4 files changed, 13 insertions(+), 16 deletions(-) diff --git a/DrawingArtillery.java b/DrawingArtillery.java index f765894..472a1e2 100644 --- a/DrawingArtillery.java +++ b/DrawingArtillery.java @@ -14,11 +14,9 @@ public class DrawingArtillery { return artillery; } - public void Init(int speed, float weight, Color bodyColor, int rollersCount) { - artillery = new EntityArtillery(); - artillery.Init(speed, weight, bodyColor); - drawingRollers = new DrawingRollers(); - drawingRollers.Init(rollersCount, bodyColor); + public DrawingArtillery(int speed, float weight, Color bodyColor, int rollersCount) { + artillery = new EntityArtillery(speed, weight, bodyColor); + drawingRollers = new DrawingRollers(rollersCount, bodyColor); } public void SetPosition(int x, int y, int width, int height) { diff --git a/DrawingRollers.java b/DrawingRollers.java index 0b2b1fc..d12eafd 100644 --- a/DrawingRollers.java +++ b/DrawingRollers.java @@ -4,7 +4,7 @@ public class DrawingRollers { private RollersCount rollersCount; private Color color; - public void Init(int rollersCount, Color bodyColor) { + public DrawingRollers(int rollersCount, Color bodyColor) { setRollersCount(rollersCount); color = bodyColor; } diff --git a/EntityArtillery.java b/EntityArtillery.java index 4367dae..ef15317 100644 --- a/EntityArtillery.java +++ b/EntityArtillery.java @@ -6,7 +6,7 @@ public class EntityArtillery { private float weight; private Color bodyColor; - public void Init(int speed, float weight, Color bodyColor) { + public EntityArtillery(int speed, float weight, Color bodyColor) { Random rnd = new Random(); this.speed = speed <= 0 ? rnd.nextInt(50, 150) : speed; this.weight = weight <= 0 ? rnd.nextInt(40, 70) : weight; diff --git a/FormArtillery.java b/FormArtillery.java index 8e75a9a..97533a5 100644 --- a/FormArtillery.java +++ b/FormArtillery.java @@ -23,15 +23,14 @@ public class FormArtillery extends JFrame { this.setContentPane(artilleryPane); createButton.addActionListener(e -> { Random rnd = new Random(); - _artillery = new DrawingArtillery(); - _artillery.Init( - rnd.nextInt(100, 300), - rnd.nextInt(1000, 2000), - new Color( - rnd.nextInt(0, 256), - rnd.nextInt(0, 256), - rnd.nextInt(0, 256)), - rnd.nextInt(4, 7) + _artillery = new DrawingArtillery( + rnd.nextInt(100, 300), + rnd.nextInt(1000, 2000), + new Color( + rnd.nextInt(0, 256), + rnd.nextInt(0, 256), + rnd.nextInt(0, 256)), + rnd.nextInt(4, 7) ); _artillery.SetPosition(10 + rnd.nextInt(90), 10 + rnd.nextInt(90), pictureBox.getWidth(), pictureBox.getHeight()); speedLabel.setText(String.format("Скорость: %s", _artillery.getArtillery().getSpeed()));