diff --git a/src/DoubleDeckerBus/CollectionCanvas.java b/src/DoubleDeckerBus/CollectionCanvas.java index 1a53fb1..afd7948 100644 --- a/src/DoubleDeckerBus/CollectionCanvas.java +++ b/src/DoubleDeckerBus/CollectionCanvas.java @@ -1,14 +1,14 @@ package DoubleDeckerBus; import DoubleDeckerBus.DrawningObjects.DrawningBus; -import DoubleDeckerBus.Generics.BusGenericCollection; +import DoubleDeckerBus.Generics.TheBusesGenericCollection; import DoubleDeckerBus.MovementStrategy.DrawningObjectBus; import javax.swing.*; import java.awt.*; public class CollectionCanvas extends JComponent { - public BusGenericCollection _bus; + public TheBusesGenericCollection _bus; @Override public void paintComponent (Graphics g){ diff --git a/src/DoubleDeckerBus/FormBusCollection.java b/src/DoubleDeckerBus/FormBusCollection.java index 0ce076d..c805d99 100644 --- a/src/DoubleDeckerBus/FormBusCollection.java +++ b/src/DoubleDeckerBus/FormBusCollection.java @@ -1,7 +1,7 @@ package DoubleDeckerBus; import DoubleDeckerBus.DrawningObjects.DrawningBus; -import DoubleDeckerBus.Generics.BusGenericCollection; +import DoubleDeckerBus.Generics.TheBusesGenericCollection; import DoubleDeckerBus.MovementStrategy.DrawningObjectBus; import javax.swing.*; @@ -9,7 +9,7 @@ import java.awt.*; import java.awt.event.*; public class FormBusCollection { - private final BusGenericCollection _bus; + private final TheBusesGenericCollection _bus; private int pictureBoxWidth = 605; private int pictureBoxHeight = 426; @@ -23,7 +23,7 @@ public class FormBusCollection { } public FormBusCollection() { - _bus = new BusGenericCollection<>(pictureBoxWidth, pictureBoxHeight); + _bus = new TheBusesGenericCollection<>(pictureBoxWidth, pictureBoxHeight); canvas = new CollectionCanvas(); JPanel toolBox = new JPanel(); JFrame collectionFrame = new JFrame(); diff --git a/src/DoubleDeckerBus/Generics/HardGeneric.java b/src/DoubleDeckerBus/Generics/HardGeneric.java index f7eac04..6cd2e01 100644 --- a/src/DoubleDeckerBus/Generics/HardGeneric.java +++ b/src/DoubleDeckerBus/Generics/HardGeneric.java @@ -7,57 +7,56 @@ import DoubleDeckerBus.Entities.EntityBus; import java.util.Random; public class HardGeneric { - T[] arrFirst; - U[] arrSecond; + T[] busArray; + U[] doorArray; - private int curSz; - private int CountFirst; - private int CountSecond; + private int currentSize; + private int MaxCountBuses; + private int MaxCountDoors; private int pictureBoxWidth; private int pictureBoxHeight; - public HardGeneric(int countFirst, int countSecond, int width, int height){ - curSz = 0; - CountFirst = countFirst; - CountSecond = countSecond; - arrFirst = (T[]) new EntityBus[CountFirst]; - arrSecond = (U[]) new IDraw[CountSecond]; + public HardGeneric(int maxCountBuses, int countSecond, int width, int height) { + currentSize = 0; + MaxCountBuses = maxCountBuses; + MaxCountDoors = countSecond; + busArray = (T[]) new EntityBus[MaxCountBuses]; + doorArray = (U[]) new IDraw[MaxCountDoors]; pictureBoxHeight = height; pictureBoxWidth = width; } - public int InsertFirst(T entityBus) { - if (arrFirst[CountFirst-1] != null) { + public int insertBus(T entityBus) { + if (busArray[MaxCountBuses - 1] != null) { return -1; } - for (int i = curSz - 1; i >= 0; i--) { - arrFirst[i + 1] = arrFirst[i]; - arrSecond[i + 1] = arrSecond[i]; + for (int i = currentSize - 1; i >= 0; i--) { + busArray[i + 1] = busArray[i]; + doorArray[i + 1] = doorArray[i]; } - curSz++; - arrFirst[0] = entityBus; + currentSize++; + busArray[0] = entityBus; return 0; } - public int InsertSecond(U inter) { - if (arrSecond[CountSecond-1] != null) { + public int insertDoor(U inter) { + if (doorArray[MaxCountBuses - 1] != null) { return -1; } - arrSecond[0] = inter; + doorArray[0] = inter; return 0; } public DrawningBus MakeObject() { Random rand = new Random(); - int indFirst = rand.nextInt(0, curSz); - int indSecond = rand.nextInt(0,curSz); - EntityBus entity = arrFirst[indFirst]; - IDraw inter = arrSecond[indSecond]; - DrawningBus bus = new DrawningBus(entity.Speed(), entity.Weight(), entity.BodyColor(), + int indBus = rand.nextInt(0, currentSize); + int indDoors = rand.nextInt(0,currentSize); + EntityBus entity = busArray[indBus]; + IDraw inter = doorArray[indDoors]; + return new DrawningBus(entity.Speed(), entity.Weight(), entity.BodyColor(), pictureBoxWidth, pictureBoxHeight); - return bus; } } diff --git a/src/DoubleDeckerBus/Generics/BusGenericCollection.java b/src/DoubleDeckerBus/Generics/TheBusesGenericCollection.java similarity index 93% rename from src/DoubleDeckerBus/Generics/BusGenericCollection.java rename to src/DoubleDeckerBus/Generics/TheBusesGenericCollection.java index 623e2db..03da8ee 100644 --- a/src/DoubleDeckerBus/Generics/BusGenericCollection.java +++ b/src/DoubleDeckerBus/Generics/TheBusesGenericCollection.java @@ -6,7 +6,7 @@ import DoubleDeckerBus.MovementStrategy.IMoveableObject; import java.awt.*; import java.awt.image.BufferedImage; -public class BusGenericCollection { +public class TheBusesGenericCollection { private final int _pictureWidth; private final int _pictureHeight; @@ -17,7 +17,7 @@ public class BusGenericCollection _collection; - public BusGenericCollection(int picWidth, int picHeight){ + public TheBusesGenericCollection(int picWidth, int picHeight){ int width = picWidth / _placeSizeWidth; int height = picHeight / _placeSizeHeight; _pictureWidth = picWidth; diff --git a/src/DoubleDeckerBus/HardForm.java b/src/DoubleDeckerBus/HardForm.java index 222ba05..b9c97f4 100644 --- a/src/DoubleDeckerBus/HardForm.java +++ b/src/DoubleDeckerBus/HardForm.java @@ -2,6 +2,7 @@ package DoubleDeckerBus; import DoubleDeckerBus.DrawningObjects.DrawningBus; import DoubleDeckerBus.DrawningObjects.DrawningDoor; +import DoubleDeckerBus.DrawningObjects.DrawningDoorTriangle; import DoubleDeckerBus.DrawningObjects.IDraw; import DoubleDeckerBus.Entities.EntityBus; import DoubleDeckerBus.Generics.HardGeneric; @@ -18,55 +19,61 @@ public class HardForm { private int pictureBoxWidth; private int pictureBoxHeight; - private EntityBus makeEntity(){ + private EntityBus createRandomEntityBus() { Random rand = new Random(); - return new EntityBus(rand.nextInt(100, 300), rand.nextDouble(1000,3000), - Color.getHSBColor(rand.nextInt(0, 301), rand.nextInt(0, 301), rand.nextInt(0, 301))); + return new EntityBus( + rand.nextInt(100, 300), + rand.nextDouble(1000, 3000), + Color.getHSBColor( + rand.nextInt(0, 301), + rand.nextInt(0, 301), + rand.nextInt(0, 301) + ) + ); } - void Draw(){ + void redrawCanvas() { if (canvas == null) { return; } canvas.repaint(); } - private IDraw makeIDraw(){ - Random rand = new Random(); + private IDraw createDrawningDoor(){ return new DrawningDoor(pictureBoxWidth, pictureBoxHeight, 0, 0); } - public HardForm(){ + public HardForm() { Random rand = new Random(); - int sz = rand.nextInt(1, 10); + int size = rand.nextInt(1, 10); JFrame HardFrame = new JFrame(); HardFrame.setSize(700, 400); HardFrame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); canvas = new Canvas(); canvas.setBounds(0,0,pictureBoxWidth,pictureBoxHeight); - JButton makeObject = new JButton("Создать"); - makeObject.setBounds(0, 0, 100, 40); - canvas.add(makeObject); + JButton createObjectButton = new JButton("Создать"); + createObjectButton.setBounds(0, 0, 100, 40); + canvas.add(createObjectButton); HardFrame.setContentPane(canvas); HardFrame.setVisible(true); pictureBoxHeight = canvas.getHeight(); pictureBoxWidth = canvas.getWidth(); - HardGeneric toDraw = new HardGeneric<>(sz, sz, pictureBoxWidth, pictureBoxHeight); - for (int i = 0; i < sz; i++) { - EntityBus ent = makeEntity(); - toDraw.InsertFirst(ent); - toDraw.InsertSecond(makeIDraw()); + HardGeneric objectGenerator = new HardGeneric<>(size, size, pictureBoxWidth, pictureBoxHeight); + for (int i = 0; i < size; i++) { + EntityBus ent = createRandomEntityBus(); + objectGenerator.insertBus(ent); + objectGenerator.insertDoor(createDrawningDoor()); } - makeObject.addActionListener( + createObjectButton.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { - DrawningBus DrawningBus = toDraw.MakeObject(); + DrawningBus DrawningBus = objectGenerator.MakeObject(); DrawningBus.SetPosition(pictureBoxWidth / 2 - DrawningBus.GetWidth()/2, pictureBoxHeight / 2 - DrawningBus.GetHeight()/2); canvas.DrawningBus = DrawningBus; - Draw(); + redrawCanvas(); } } ); diff --git a/src/DoubleDeckerBus/Main.java b/src/DoubleDeckerBus/Main.java index b3fc1b1..6d72209 100644 --- a/src/DoubleDeckerBus/Main.java +++ b/src/DoubleDeckerBus/Main.java @@ -4,7 +4,7 @@ import java.io.IOException; public class Main { public static void main(String[] args) throws IOException { - //FormDoubleDeckerBus form = new FormDoubleDeckerBus(); + //new FormBusCollection(); new HardForm(); } } \ No newline at end of file