diff --git a/CollectionFrame.java b/CollectionFrame.java index 63bdb2a..6f05f8b 100644 --- a/CollectionFrame.java +++ b/CollectionFrame.java @@ -5,6 +5,7 @@ import java.awt.event.ActionListener; class CollectionFrame extends JComponent { private final CarsGenericCollection _tanks; + protected final int Width; protected final int Height; public CollectionFrame(int width, int height) @@ -123,6 +124,8 @@ class GarageFrame extends JFrame { } }); + + Collection = new CollectionFrame(Width-200, Height); Collection.setLayout(null); Collection.setBounds(0, 0, Width-200, Height); diff --git a/ComboFrame.java b/ComboFrame.java index 9194ae1..3d056a4 100644 --- a/ComboFrame.java +++ b/ComboFrame.java @@ -10,14 +10,12 @@ class DrawRandomTanker extends JComponent { public DrawRandomTanker() { GeneratorTanker = new ComboGenericCollection<>(25, 1000, 600); - GeneratorTanker.Add(GeneratorTanker.GenerateTanker()); - GeneratorTanker.Add(GeneratorTanker.GenerateTanker()); - GeneratorTanker.Add(GeneratorTanker.GenerateTanker()); - GeneratorTanker.Add(GeneratorTanker.GenerateTanker()); - GeneratorTanker.Add(GeneratorTanker.GenerateWheel()); - GeneratorTanker.Add(GeneratorTanker.GenerateWheel()); - GeneratorTanker.Add(GeneratorTanker.GenerateWheel()); - GeneratorTanker.Add(GeneratorTanker.GenerateWheel()); + GeneratorTanker.Add(GenerateTanker()); + GeneratorTanker.Add(GenerateWheel()); + GeneratorTanker.Add(GenerateTanker()); + GeneratorTanker.Add(GenerateWheel()); + GeneratorTanker.Add(GenerateTanker()); + GeneratorTanker.Add(GenerateWheel()); } public void paintComponent(Graphics g) { @@ -27,7 +25,40 @@ class DrawRandomTanker extends JComponent { _drawTanker.DrawTransport(g); super.repaint(); } + private boolean IntToBool(int n) {return n % 2 == 0;} + public BaseTanker GenerateTanker() + { + Random random = new Random(); + int mode = random.nextInt(0, 100) % 2; + if (mode == 0) + { + return new BaseTanker(random.nextInt(100, 200), random.nextInt(2000, 4000), + new Color(random.nextInt(0, 256), random.nextInt(0, 256), random.nextInt(0, 256))); + } + else + { + return new GasolineTanker(random.nextInt(100, 200), random.nextInt(2000, 4000), + new Color(random.nextInt(0, 256), random.nextInt(0, 256), random.nextInt(0, 256)), + new Color(random.nextInt(0, 256), random.nextInt(0, 256), random.nextInt(0, 256)), + IntToBool(random.nextInt(0, 100)),IntToBool(random.nextInt(0, 100)), IntToBool(random.nextInt(0, 100))); + } + } + public IWheelDraw GenerateWheel() + { + Random random = new Random(); + int mode = random.nextInt(0, 100) % 3; + IWheelDraw Wheels = new DrawWheelSquare(); + switch (mode) + { + case 0 -> {Wheels = new DrawWheelCircle();} + case 1 -> {Wheels = new DrawWheelClassic();} + case 2 -> {Wheels = new DrawWheelSquare();} + } + int count = random.nextInt(0, 100); + Wheels.setWheelCount(count); + return Wheels; + } protected void GenerateTanker_Click() { _drawTanker = GeneratorTanker.CreateDraw(); diff --git a/ComboGenericCollection.java b/ComboGenericCollection.java index 9a35faa..42af0f9 100644 --- a/ComboGenericCollection.java +++ b/ComboGenericCollection.java @@ -22,37 +22,7 @@ public class ComboGenericCollection {Wheels = (U) new DrawWheelCircle();} - case 1 -> {Wheels = (U) new DrawWheelClassic();} - case 2 -> {Wheels = (U) new DrawWheelSquare();} - } - int count = random.nextInt(0, 100); - Wheels.setWheelCount(count); - return Wheels; - } public boolean Add(T tanker) { @@ -83,7 +53,7 @@ public class ComboGenericCollection