From fb4c5f341692fc103e40cdeb09631e6e3ad145b4 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 23:03:27 +0400 Subject: [PATCH] Work is done 02 --- DrawingArtillery.java | 2 +- DrawingCrossRollers.java | 1 - RollersType.java | 17 +++++++++++++++++ 3 files changed, 18 insertions(+), 2 deletions(-) create mode 100644 RollersType.java diff --git a/DrawingArtillery.java b/DrawingArtillery.java index 2ea1b66..2d8c095 100644 --- a/DrawingArtillery.java +++ b/DrawingArtillery.java @@ -16,7 +16,7 @@ public class DrawingArtillery { public DrawingArtillery(int speed, float weight, Color bodyColor, int rollersCount) { artillery = new EntityArtillery(speed, weight, bodyColor); - drawingRollers = new DrawingRollers(rollersCount, bodyColor); + drawingRollers = RollersType.random(rollersCount, bodyColor); } protected DrawingArtillery(int speed, float weight, Color bodyColor, int rollersCount, int artilleryWidth, int artilleryHeight) { diff --git a/DrawingCrossRollers.java b/DrawingCrossRollers.java index 05ffd33..c8ce547 100644 --- a/DrawingCrossRollers.java +++ b/DrawingCrossRollers.java @@ -1,5 +1,4 @@ import java.awt.*; -import java.awt.geom.Line2D; public class DrawingCrossRollers implements IDrawingRollers { private RollersCount rollersCount; diff --git a/RollersType.java b/RollersType.java new file mode 100644 index 0000000..efa60c6 --- /dev/null +++ b/RollersType.java @@ -0,0 +1,17 @@ +import java.awt.*; +import java.util.Random; + +public enum RollersType { + Standard, + Squared, + Cross; + + public static IDrawingRollers random(int rollersCount, Color bodyColor) { + return switch (new Random().nextInt(RollersType.values().length)) { + case 0 -> new DrawingRollers(rollersCount, bodyColor); + case 1 -> new DrawingSquaredRollers(rollersCount, bodyColor); + case 2 -> new DrawingCrossRollers(rollersCount, bodyColor); + default -> null; + }; + } +}