From b2081267727b55286e26d9126fa6c8f2a8e4b704 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=94=D0=B0=D0=BD=D0=B8=D0=B8=D0=BB=20=D0=9F=D1=83=D1=82?= =?UTF-8?q?=D0=B8=D0=BD=D1=86=D0=B5=D0=B2?= Date: Fri, 24 Nov 2023 23:29:20 +0400 Subject: [PATCH 1/2] =?UTF-8?q?=D0=93=D0=BE=D1=82=D0=BE=D0=B2=D0=B0=D1=8F?= =?UTF-8?q?=203=20=D1=83=D1=81=D0=BB=D0=BE=D0=B6=D0=BD=D0=B5=D0=BD=D0=BD?= =?UTF-8?q?=D0=B0=D1=8F=20=D0=BB=D0=B0=D0=B1=D0=BE=D1=80=D0=B0=D1=82=D0=BE?= =?UTF-8?q?=D1=80=D0=BD=D0=B0=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/RoadTrain/DirectionType.java | 1 + .../DrawingObjects/DrawingRoadTrain.java | 6 + .../DrawingObjects/DrawingTruck.java | 15 ++- src/RoadTrain/Extra/GenericDopClass.java | 71 ++++++++++ src/RoadTrain/FormGenericDopClass.java | 65 +++++++++ src/RoadTrain/FormTruckCollection.java | 125 ++++++++++++++++++ src/RoadTrain/Generics/SetGeneric.java | 63 +++++++++ .../Generics/TrucksGenericCollection.java | 85 ++++++++++++ src/RoadTrain/Main.java | 3 +- src/RoadTrain/RoadTrainForm.java | 47 +++++-- 10 files changed, 467 insertions(+), 14 deletions(-) create mode 100644 src/RoadTrain/Extra/GenericDopClass.java create mode 100644 src/RoadTrain/FormGenericDopClass.java create mode 100644 src/RoadTrain/FormTruckCollection.java create mode 100644 src/RoadTrain/Generics/SetGeneric.java create mode 100644 src/RoadTrain/Generics/TrucksGenericCollection.java diff --git a/src/RoadTrain/DirectionType.java b/src/RoadTrain/DirectionType.java index 722f88a..bad0777 100644 --- a/src/RoadTrain/DirectionType.java +++ b/src/RoadTrain/DirectionType.java @@ -1,4 +1,5 @@ package RoadTrain; + public enum DirectionType { Up, Down, diff --git a/src/RoadTrain/DrawingObjects/DrawingRoadTrain.java b/src/RoadTrain/DrawingObjects/DrawingRoadTrain.java index 8fc05a0..d9f4cf6 100644 --- a/src/RoadTrain/DrawingObjects/DrawingRoadTrain.java +++ b/src/RoadTrain/DrawingObjects/DrawingRoadTrain.java @@ -1,6 +1,7 @@ package RoadTrain.DrawingObjects; import java.awt.*; import RoadTrain.Entities.*; +import RoadTrain.Extra.IDrawingWheels; public class DrawingRoadTrain extends DrawingTruck{ @@ -14,6 +15,11 @@ public class DrawingRoadTrain extends DrawingTruck{ additionalColor, waterContainer, sweepingBrush); } } + public DrawingRoadTrain(EntityRoadTrain truck, IDrawingWheels _wheelDrawing, int width, int height, int wheelNumber ){ + super(truck, _wheelDrawing, width, height, wheelNumber); + if (height < _truckHeight || width < _truckWidth) + return; + } @Override public void DrawTransport(Graphics g) { if (!(entityTruck instanceof EntityRoadTrain RoadTrain)) { diff --git a/src/RoadTrain/DrawingObjects/DrawingTruck.java b/src/RoadTrain/DrawingObjects/DrawingTruck.java index 00f4c35..19bf6a4 100644 --- a/src/RoadTrain/DrawingObjects/DrawingTruck.java +++ b/src/RoadTrain/DrawingObjects/DrawingTruck.java @@ -2,6 +2,7 @@ package RoadTrain.DrawingObjects; import RoadTrain.DirectionType; import RoadTrain.Entities.*; import RoadTrain.Extra.*; +import RoadTrain.MovementStraregy.*; import java.util.Random; import java.awt.*; @@ -13,6 +14,7 @@ public class DrawingTruck { private int _pictureHeight; protected int _startPosX; protected int _startPosY; + public IMoveableObject GetMoveableObject() { return new DrawingObjectTruck(this);} public int GetPosX() { return _startPosX; } @@ -28,8 +30,17 @@ public class DrawingTruck { public int GetHeight() { return _truckHeight; } - private int _truckWidth = 80; - private int _truckHeight = 70; + protected int _truckWidth = 80; + protected int _truckHeight = 70; + public DrawingTruck(EntityTruck truck, IDrawingWheels _wheelDrawing, int width, int height, int wheelNumber ){ + if (height < _truckHeight || width < _truckWidth) + return; + _pictureWidth = width; + _pictureHeight = height; + entityTruck = truck; + drawingWheels = _wheelDrawing; + drawingWheels.SetWheelNumber(wheelNumber); + } public DrawingTruck(int speed, double weight, Color mainColor, int width, int height, int wheelNumber) { if (width < _truckWidth || height < _truckHeight) { return; diff --git a/src/RoadTrain/Extra/GenericDopClass.java b/src/RoadTrain/Extra/GenericDopClass.java new file mode 100644 index 0000000..024429f --- /dev/null +++ b/src/RoadTrain/Extra/GenericDopClass.java @@ -0,0 +1,71 @@ +package RoadTrain.Extra; + +import java.util.ArrayList; +import java.util.Random; +import RoadTrain.Entities.*; +import RoadTrain.DrawingObjects.*; + +public class GenericDopClass { + + private ArrayList Trucks; + private ArrayList Wheels; + private int maxCountTrucks; + private int countTrucks; + private int maxCountWheels; + private int countWheels; + private Random random; + private int _pictureWidth; + private int _pictureHeight; + public GenericDopClass(int _maxCountTrucks, int _maxCountWheels, int pictureWidth, int pictureHeight){ + maxCountTrucks = _maxCountTrucks; + maxCountWheels = _maxCountWheels; + Trucks = new ArrayList(maxCountTrucks); + Wheels = new ArrayList(maxCountWheels); + countTrucks = 0; + countWheels = 0; + _pictureWidth = pictureWidth; + _pictureHeight = pictureHeight; + random = new Random(); + } + + public boolean add(T train){ + if (train == null) + return false; + if (countTrucks > maxCountTrucks) + return false; + Trucks.add(countTrucks++, train); + return true; + } + + public boolean add(U wheel){ + if (wheel == null) + return false; + if (countWheels > maxCountWheels) + return false; + Wheels.add(countWheels++, wheel); + return true; + } + + public DrawingTruck getDrawingObject(){ + if (countTrucks == 0 || countWheels == 0) + return null; + if(Trucks.isEmpty()) { + return null; + } + + T truck = Trucks.get(random.nextInt(Trucks.size())); + U wheel = null; + + if(!Wheels.isEmpty()){ + wheel = Wheels.get(random.nextInt(Wheels.size())); + } + DrawingTruck drawingTruck; + if (truck instanceof EntityRoadTrain){ + drawingTruck = new DrawingRoadTrain((EntityRoadTrain)truck, wheel, _pictureWidth, _pictureHeight, random.nextInt(3)); + } + else{ + drawingTruck = new DrawingTruck(truck, wheel, _pictureWidth, _pictureHeight, random.nextInt(3)); + } + return drawingTruck; + } +} diff --git a/src/RoadTrain/FormGenericDopClass.java b/src/RoadTrain/FormGenericDopClass.java new file mode 100644 index 0000000..f5a7f3c --- /dev/null +++ b/src/RoadTrain/FormGenericDopClass.java @@ -0,0 +1,65 @@ +package RoadTrain; +import RoadTrain.DrawingObjects.*; +import RoadTrain.Entities.*; +import RoadTrain.Extra.*; + +import java.awt.Color; +import java.awt.Graphics; +import java.awt.Graphics2D; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +import javax.swing.JButton; +import javax.swing.JComponent; +import javax.swing.JFrame; + +public class FormGenericDopClass extends JFrame { + static int pictureBoxWidth = 980; + static int pictureBoxHeight = 560; + public DrawingTruck _drawingTruck; + private class Canvas extends JComponent{ + public Canvas(){ + } + public void paintComponent (Graphics g){ + if (_drawingTruck == null){ + return; + } + super.paintComponents (g) ; + Graphics2D g2d = (Graphics2D)g; + _drawingTruck.SetPosition(50, 50); + _drawingTruck.DrawTransport(g2d); + super.repaint(); + } + } + GenericDopClass genericDopClass; + public FormGenericDopClass(){ + _drawingTruck = null; + Canvas canv = new Canvas(); + setSize (1000, 600); + setLayout(null); + canv.setBounds(0,0,pictureBoxWidth, pictureBoxHeight); + + genericDopClass = new GenericDopClass<>(100, 100, pictureBoxWidth, pictureBoxHeight); + genericDopClass.add(new EntityTruck(100, 100, Color.BLUE)); + genericDopClass.add(new EntityTruck(100, 100, Color.RED)); + genericDopClass.add(new EntityTruck(100, 100, Color.GRAY)); + genericDopClass.add(new EntityRoadTrain(100, 100, Color.BLUE, Color.ORANGE, true, true)); + genericDopClass.add(new DrawingOneLineWheels()); + genericDopClass.add(new DrawingTwoLineWheels()); + + JButton createButton = new JButton("Создать"); + createButton.addActionListener( + new ActionListener() { + public void actionPerformed(ActionEvent e){ + _drawingTruck = genericDopClass.getDrawingObject(); + canv.repaint(); + } + } + ); + createButton.setBounds(pictureBoxWidth/2, pictureBoxHeight-20, 120, 20); + + add(canv); + add(createButton); + setVisible(true); + } +} \ No newline at end of file diff --git a/src/RoadTrain/FormTruckCollection.java b/src/RoadTrain/FormTruckCollection.java new file mode 100644 index 0000000..b6b520b --- /dev/null +++ b/src/RoadTrain/FormTruckCollection.java @@ -0,0 +1,125 @@ +package RoadTrain; + +import RoadTrain.MovementStraregy.*; +import RoadTrain.Generics.*; +import RoadTrain.DrawingObjects.*; + +import javax.swing.*; +import java.awt.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +public class FormTruckCollection { + private class Canvas extends JComponent { + public TrucksGenericCollection _truck; + public Canvas() { + } + public void paintComponent (Graphics g) { + super.paintComponent(g); + if (_truck.ShowTrucks() != null) { + g.drawImage(_truck.ShowTrucks(), 0, 10, this); + } + super.repaint(); + } + } + Canvas canv; + static int pictureBoxWidth = 700; + static int pictureBoxHeight = 480; + private TrucksGenericCollection _truck; + public void Draw(){ + canv.repaint(); + } + FormTruckCollection() { + canv = new Canvas(); + JFrame Frame = new JFrame ("TrucksCollecltion"); + _truck = new TrucksGenericCollection(pictureBoxWidth, pictureBoxHeight); + canv._truck = _truck; + + JButton ButtonAddTruck = new JButton("Добавить технику"); + + ButtonAddTruck.addActionListener( + new ActionListener() { + public void actionPerformed(ActionEvent e) { + RoadTrainForm form = new RoadTrainForm(); + form.buttonSelectTruck.addActionListener( + new ActionListener() { + public void actionPerformed(ActionEvent e) { + if (_truck.Add(form._drawingTruck) != -1) { + JOptionPane.showMessageDialog(null, "Объект добавлен", "Информация", JOptionPane.INFORMATION_MESSAGE); + Draw(); + } else { + JOptionPane.showMessageDialog(null, "Не удалось добавить объект", "Информация", JOptionPane.INFORMATION_MESSAGE); + } + form.frame.dispose(); + } + } + ); + } + } + ); + + JTextField TextBoxNumber = new JTextField(); + JButton ButtonRemoveTruck = new JButton("Удалить технику"); + ButtonRemoveTruck.addActionListener( + new ActionListener() { + public void actionPerformed(ActionEvent e) { + if (JOptionPane.showConfirmDialog(null, "Удалить объект?", "Удаление", JOptionPane.YES_NO_OPTION) == JOptionPane.NO_OPTION) { + return; + } + for (char it : TextBoxNumber.getText().toCharArray()) + if (it < '0' || it > '9') { + JOptionPane.showMessageDialog(null, "Не удалось удалить объект", "Информация", JOptionPane.INFORMATION_MESSAGE); + return; + } + if (TextBoxNumber.getText().length() == 0) { + JOptionPane.showMessageDialog(null, "Не удалось удалить объект", "Информация", JOptionPane.INFORMATION_MESSAGE); + return; + } + + int pos = Integer.parseInt(TextBoxNumber.getText()); + if (_truck.remove(pos) != null) { + JOptionPane.showMessageDialog(null, "Объект удален", "Информация", JOptionPane.INFORMATION_MESSAGE); + Draw(); + } else { + JOptionPane.showMessageDialog(null, "Не удалось удалить объект", "Информация", JOptionPane.INFORMATION_MESSAGE); + } + } + } + ); + + JButton ButtonRefreshCollection = new JButton("Обновить коллекцию"); + ButtonRefreshCollection.addActionListener( + new ActionListener() { + public void actionPerformed(ActionEvent e){ + Draw(); + } + } + ); + + JButton FormTruckGenerate = new JButton("Генерировать"); + FormTruckGenerate.addActionListener( + new ActionListener() { + public void actionPerformed(ActionEvent e) { + FormGenericDopClass formGenericDopClass = new FormGenericDopClass(); + } + } + ); + + Frame.setSize (880, 520); + Frame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE); + Frame.setLayout(null); + canv.setBounds(0, 0, pictureBoxWidth, pictureBoxHeight); + ButtonAddTruck.setBounds(pictureBoxWidth - 50, 10, 170, 30); + TextBoxNumber.setBounds(pictureBoxWidth - 50, 50, 170, 20); + ButtonRemoveTruck.setBounds(pictureBoxWidth - 50, 80, 170, 30); + ButtonRefreshCollection.setBounds(pictureBoxWidth - 50, 120, 170, 30); + FormTruckGenerate.setBounds(pictureBoxWidth - 50, 160, 170, 30); + Frame.add(canv); + Frame.add(ButtonAddTruck); + Frame.add(ButtonRemoveTruck); + Frame.add(ButtonRefreshCollection); + Frame.add(TextBoxNumber); + Frame.add(FormTruckGenerate); + Frame.setVisible(true); + } +} diff --git a/src/RoadTrain/Generics/SetGeneric.java b/src/RoadTrain/Generics/SetGeneric.java new file mode 100644 index 0000000..0e18662 --- /dev/null +++ b/src/RoadTrain/Generics/SetGeneric.java @@ -0,0 +1,63 @@ +package RoadTrain.Generics; + +public class SetGeneric { + // Массив объектов, которые храним + private Object[] _places; + + // Количество объектов в массиве + public int Count; + + // Конструктор + public SetGeneric(int count) { + _places = new Object[count]; + Count = _places.length; + } + + // Добавление объекта в набор + public int Insert(T truck) { + int i = 0; + for (; i < _places.length; i++) { + if (_places[i] == null) + break; + } + if (i == _places.length) + return -1; + for (; i > 0; i--) { + _places[i] = _places[i - 1]; + } + _places[i] = truck; + return i; + } + + // Добавление объекта в набор на конкретную позицию + public boolean Insert(T truck, int position) { + if (position < 0 || position >= _places.length) + return false; + for (; position < _places.length; position++) { + if (_places[position] == null) + break; + } + if (position == _places.length) + return false; + for (; position > 0; position--) { + _places[position] = _places[position - 1]; + } + _places[position] = truck; + return true; + } + + // Удаление объекта из набора с конкретной позиции + public boolean Remove(int position) { + if (position < 0 || position >= _places.length) + return false; + _places[position] = null; + return true; + } + + // Получение объекта из набора по позиции + public T Get(int position) { + if (position < 0 || position >= _places.length) + return null; + return (T) _places[position]; + } +} diff --git a/src/RoadTrain/Generics/TrucksGenericCollection.java b/src/RoadTrain/Generics/TrucksGenericCollection.java new file mode 100644 index 0000000..86776fd --- /dev/null +++ b/src/RoadTrain/Generics/TrucksGenericCollection.java @@ -0,0 +1,85 @@ +package RoadTrain.Generics; +import RoadTrain.DrawingObjects.*; +import RoadTrain.MovementStraregy.*; + +import java.awt.*; +import java.awt.image.BufferedImage; + +public class TrucksGenericCollection { + // Высота и Ширина окна прорисовки + private int _pictureWidth; + private int _pictureHeight; + + // Размер занимаемого объектом места (ширина и высота) + private int _placeSizeWidth = 180; + private int _placeSizeHeight = 90; + + // Набор объектов + private SetGeneric _collection; + + // Конструктор + public TrucksGenericCollection(int pictureWidth, int pictureHeight) { + int width = pictureWidth / _placeSizeWidth; + int height = pictureHeight / _placeSizeHeight; + _pictureWidth = pictureWidth; + _pictureHeight = pictureHeight; + _collection = new SetGeneric(width * height); + } + + // Перегрузка оператора сложения + public int Add(T obj) { + if (obj == null) { + return -1; + } + return _collection.Insert(obj); + } + + // Перегрузка оператора вычитания + public T remove(int pos) { + T obj = _collection.Get(pos); + if (obj != null) { + _collection.Remove(pos); + } + return obj; + } + + // Получение объекта IMoveableObject + public U GetU(int pos) { + return (U) _collection.Get(pos).GetMoveableObject(); + } + + // Вывод всего набора объектов + public BufferedImage ShowTrucks() { + BufferedImage bitmap = new BufferedImage(_pictureWidth, _pictureHeight, BufferedImage.TYPE_INT_ARGB); + Graphics2D g = bitmap.createGraphics(); + DrawBackground(g); + DrawObjects(g); + g.dispose(); + return bitmap; + } + + // Метод отрисовки фона + private void DrawBackground(Graphics g) { + g.setColor(Color.BLACK); + for (int i = 0; i < _pictureWidth / _placeSizeWidth; i++) { + for (int j = 0; j < _pictureHeight / _placeSizeHeight + 1; ++j) { + // Линия разметки места + g.drawLine(i * _placeSizeWidth, j * _placeSizeHeight, i * _placeSizeWidth + _placeSizeWidth / 2, j * _placeSizeHeight); + } + g.drawLine(i * _placeSizeWidth, 0, i * _placeSizeWidth, _pictureHeight / _placeSizeHeight * _placeSizeHeight); + } + } + + private void DrawObjects(Graphics g) { + for (int i = 0; i < _collection.Count; i++) { + T t = _collection.Get(i); + if (t != null) { + t.SetPosition((i % (_pictureWidth / _placeSizeWidth)) * _placeSizeWidth, (i / (_pictureWidth / _placeSizeWidth)) * _placeSizeHeight); + if (t instanceof DrawingRoadTrain) + ((DrawingRoadTrain) t).DrawTransport((Graphics2D) g); + else + t.DrawTransport((Graphics2D) g); + } + } + } +} diff --git a/src/RoadTrain/Main.java b/src/RoadTrain/Main.java index 2882f49..30c5529 100644 --- a/src/RoadTrain/Main.java +++ b/src/RoadTrain/Main.java @@ -1,6 +1,7 @@ package RoadTrain; + public class Main { public static void main(String[] args){ - RoadTrainForm RoadTrainForm = new RoadTrainForm(); + FormTruckCollection formTruckCollection = new FormTruckCollection(); } } diff --git a/src/RoadTrain/RoadTrainForm.java b/src/RoadTrain/RoadTrainForm.java index c518169..270830c 100644 --- a/src/RoadTrain/RoadTrainForm.java +++ b/src/RoadTrain/RoadTrainForm.java @@ -1,25 +1,31 @@ package RoadTrain; -import javax.swing.*; -import java.awt.*; -import java.awt.Graphics; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.util.*; + import RoadTrain.DrawingObjects.*; import RoadTrain.MovementStraregy.*; +import javax.swing.*; +import java.awt.*; +import java.awt.Graphics; +import java.awt.event.ActionListener; +import java.util.*; + public class RoadTrainForm{ - private DrawingTruck _drawingTruck; + public DrawingTruck _drawingTruck; private AbstractStrategy _abstractStrategy; + public JButton buttonSelectTruck; Canvas canv; + public JFrame frame; public void Draw(){ canv.repaint(); } public RoadTrainForm(){ - JFrame frame = new JFrame("RoadTrain"); + frame = new JFrame("RoadTrain"); JButton buttonCreateTruck = new JButton("Создать грузовик"); buttonCreateTruck.setFocusPainted(false); buttonCreateTruck.setContentAreaFilled(false); + buttonSelectTruck = new JButton("Добавить грузовик"); + buttonSelectTruck.setFocusPainted(false); + buttonSelectTruck.setContentAreaFilled(false); JButton buttonCreateRoadTrain = new JButton("Создать очистительную машину"); buttonCreateRoadTrain.setFocusPainted(false); buttonCreateRoadTrain.setContentAreaFilled(false); @@ -54,10 +60,15 @@ public class RoadTrainForm{ buttonCreateTruck.addActionListener( e -> { Random random = new Random(); + Color color = new Color(random.nextInt(0, 256), random.nextInt(0, 256), random.nextInt(0, 256)); + Color selectedColor = JColorChooser.showDialog(frame, "Выберите цвет", Color.WHITE); + if (selectedColor != null) + { + color = selectedColor; + } _drawingTruck = new DrawingTruck(random.nextInt(200) + 100, random.nextInt(2000) + 1000, - new Color(random.nextInt(256), random.nextInt(256), random.nextInt(256)), - this.canv.getWidth(), this.canv.getHeight(), random.nextInt(3)); + color, this.canv.getWidth(), this.canv.getHeight(), random.nextInt(3)); _drawingTruck.SetPosition(random.nextInt(100), random.nextInt(90)); canv._drawingTruck = _drawingTruck; Draw(); @@ -66,9 +77,21 @@ public class RoadTrainForm{ buttonCreateRoadTrain.addActionListener( e -> { Random random = new Random(); + Color color = new Color(random.nextInt(0, 256), random.nextInt(0, 256), random.nextInt(0, 256)); + Color selectedColor = JColorChooser.showDialog(frame, "Выберите цвет", Color.WHITE); + if (selectedColor != null) + { + color = selectedColor; + } + Color color2 = new Color(random.nextInt(0, 256), random.nextInt(0, 256), random.nextInt(0, 256)); + selectedColor = JColorChooser.showDialog(frame, "Выберите цвет", Color.WHITE); + if (selectedColor != null) + { + color2 = selectedColor; + } _drawingTruck = new DrawingRoadTrain(random.nextInt(200) + 100, random.nextInt(2000) + 1000, - new Color(random.nextInt(256)), new Color(random.nextInt(256)), random.nextBoolean(), random.nextBoolean(), + color, color2, random.nextBoolean(), random.nextBoolean(), this.canv.getWidth(), this.canv.getHeight(), random.nextInt(3)); _drawingTruck.SetPosition(random.nextInt(100), random.nextInt(90)); canv._drawingTruck = _drawingTruck; @@ -141,6 +164,7 @@ public class RoadTrainForm{ buttonRight.setBounds(840, 420, 40, 40); comboBoxStrategy.setBounds(800,10,100,50); buttonStep.setBounds(800,80,100,40); + buttonSelectTruck.setBounds(740, 140, 150, 20); frame.add(canv); frame.add(buttonCreateTruck); frame.add(buttonCreateRoadTrain); @@ -150,6 +174,7 @@ public class RoadTrainForm{ frame.add(buttonRight); frame.add(comboBoxStrategy); frame.add(buttonStep); + frame.add(buttonSelectTruck); frame.setVisible(true); } class Canvas extends JComponent{ -- 2.25.1 From 6f7f3302c1312f940cc618f23c4c505262c573f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=94=D0=B0=D0=BD=D0=B8=D0=B8=D0=BB=20=D0=9F=D1=83=D1=82?= =?UTF-8?q?=D0=B8=D0=BD=D1=86=D0=B5=D0=B2?= Date: Sat, 25 Nov 2023 00:19:05 +0400 Subject: [PATCH 2/2] =?UTF-8?q?=D0=9F=D0=BE=D0=BF=D1=80=D0=B0=D0=B2=D0=BA?= =?UTF-8?q?=D0=B8=20=D0=B2=20=D0=B3=D0=B5=D0=BD=D0=B5=D1=80=D0=B0=D1=86?= =?UTF-8?q?=D0=B8=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/RoadTrain/DrawingObjects/DrawingRoadTrain.java | 6 +++--- src/RoadTrain/DrawingObjects/DrawingTruck.java | 8 ++++---- src/RoadTrain/Entities/EntityRoadTrain.java | 4 ++-- src/RoadTrain/Entities/EntityTruck.java | 4 +++- src/RoadTrain/Extra/GenericDopClass.java | 4 ++-- src/RoadTrain/FormGenericDopClass.java | 8 ++++---- 6 files changed, 18 insertions(+), 16 deletions(-) diff --git a/src/RoadTrain/DrawingObjects/DrawingRoadTrain.java b/src/RoadTrain/DrawingObjects/DrawingRoadTrain.java index d9f4cf6..90df8f9 100644 --- a/src/RoadTrain/DrawingObjects/DrawingRoadTrain.java +++ b/src/RoadTrain/DrawingObjects/DrawingRoadTrain.java @@ -11,12 +11,12 @@ public class DrawingRoadTrain extends DrawingTruck{ super(speed, weight, bodyColor, width, height, wheelNumber); if (entityTruck != null) { - entityTruck = new EntityRoadTrain(speed, weight, bodyColor, + entityTruck = new EntityRoadTrain(speed, weight, bodyColor, wheelNumber, additionalColor, waterContainer, sweepingBrush); } } - public DrawingRoadTrain(EntityRoadTrain truck, IDrawingWheels _wheelDrawing, int width, int height, int wheelNumber ){ - super(truck, _wheelDrawing, width, height, wheelNumber); + public DrawingRoadTrain(EntityRoadTrain truck, IDrawingWheels _wheelDrawing, int width, int height ){ + super(truck, _wheelDrawing, width, height); if (height < _truckHeight || width < _truckWidth) return; } diff --git a/src/RoadTrain/DrawingObjects/DrawingTruck.java b/src/RoadTrain/DrawingObjects/DrawingTruck.java index 19bf6a4..b37d819 100644 --- a/src/RoadTrain/DrawingObjects/DrawingTruck.java +++ b/src/RoadTrain/DrawingObjects/DrawingTruck.java @@ -32,14 +32,14 @@ public class DrawingTruck { } protected int _truckWidth = 80; protected int _truckHeight = 70; - public DrawingTruck(EntityTruck truck, IDrawingWheels _wheelDrawing, int width, int height, int wheelNumber ){ + public DrawingTruck(EntityTruck truck, IDrawingWheels _wheelDrawing, int width, int height){ if (height < _truckHeight || width < _truckWidth) return; _pictureWidth = width; _pictureHeight = height; entityTruck = truck; drawingWheels = _wheelDrawing; - drawingWheels.SetWheelNumber(wheelNumber); + drawingWheels.SetWheelNumber(entityTruck.Numwheel); } public DrawingTruck(int speed, double weight, Color mainColor, int width, int height, int wheelNumber) { if (width < _truckWidth || height < _truckHeight) { @@ -47,7 +47,7 @@ public class DrawingTruck { } _pictureWidth = width; _pictureHeight = height; - entityTruck = new EntityTruck(speed, weight, mainColor); + entityTruck = new EntityTruck(speed, weight, mainColor, wheelNumber); Random rand = new Random(); drawingWheels = switch (rand.nextInt(0, 3)) { case 0 -> new DrawingWheels(); @@ -67,7 +67,7 @@ public class DrawingTruck { _pictureHeight = height; _truckWidth = truckWidth; _truckHeight = truckHeight; - entityTruck = new EntityTruck(speed, weight, mainColor); + entityTruck = new EntityTruck(speed, weight, mainColor, wheelNumber); Random rand = new Random(); drawingWheels = switch (rand.nextInt(0, 3)) { case 0 -> new DrawingWheels(); diff --git a/src/RoadTrain/Entities/EntityRoadTrain.java b/src/RoadTrain/Entities/EntityRoadTrain.java index 4272a88..4afa0e7 100644 --- a/src/RoadTrain/Entities/EntityRoadTrain.java +++ b/src/RoadTrain/Entities/EntityRoadTrain.java @@ -12,9 +12,9 @@ public class EntityRoadTrain extends EntityTruck { return SweepingBrush; } - public EntityRoadTrain(int speed, double weight, Color bodyColor, Color + public EntityRoadTrain(int speed, double weight, Color bodyColor, int numwheel, Color additionalColor, boolean waterContainer, boolean sweepingBrush) { - super(speed, weight, bodyColor); + super(speed, weight, bodyColor, numwheel); AdditionalColor = additionalColor; WaterContainer = waterContainer; SweepingBrush = sweepingBrush; diff --git a/src/RoadTrain/Entities/EntityTruck.java b/src/RoadTrain/Entities/EntityTruck.java index 5caad17..11dab35 100644 --- a/src/RoadTrain/Entities/EntityTruck.java +++ b/src/RoadTrain/Entities/EntityTruck.java @@ -18,14 +18,16 @@ public class EntityTruck { public Color GetBodyColor() { return BodyColor; } + public int Numwheel; public double GetStep() { return (double) Speed * 100 / Weight; } - public EntityTruck(int speed, double weight, Color bodyColor) { + public EntityTruck(int speed, double weight, Color bodyColor, int numwheel) { Speed = speed; Weight = weight; BodyColor = bodyColor; + Numwheel = numwheel; } } diff --git a/src/RoadTrain/Extra/GenericDopClass.java b/src/RoadTrain/Extra/GenericDopClass.java index 024429f..4b1c1e3 100644 --- a/src/RoadTrain/Extra/GenericDopClass.java +++ b/src/RoadTrain/Extra/GenericDopClass.java @@ -61,10 +61,10 @@ public class GenericDopClass { } DrawingTruck drawingTruck; if (truck instanceof EntityRoadTrain){ - drawingTruck = new DrawingRoadTrain((EntityRoadTrain)truck, wheel, _pictureWidth, _pictureHeight, random.nextInt(3)); + drawingTruck = new DrawingRoadTrain((EntityRoadTrain)truck, wheel, _pictureWidth, _pictureHeight); } else{ - drawingTruck = new DrawingTruck(truck, wheel, _pictureWidth, _pictureHeight, random.nextInt(3)); + drawingTruck = new DrawingTruck(truck, wheel, _pictureWidth, _pictureHeight); } return drawingTruck; } diff --git a/src/RoadTrain/FormGenericDopClass.java b/src/RoadTrain/FormGenericDopClass.java index f5a7f3c..7c34338 100644 --- a/src/RoadTrain/FormGenericDopClass.java +++ b/src/RoadTrain/FormGenericDopClass.java @@ -40,10 +40,10 @@ public class FormGenericDopClass extends JFrame { canv.setBounds(0,0,pictureBoxWidth, pictureBoxHeight); genericDopClass = new GenericDopClass<>(100, 100, pictureBoxWidth, pictureBoxHeight); - genericDopClass.add(new EntityTruck(100, 100, Color.BLUE)); - genericDopClass.add(new EntityTruck(100, 100, Color.RED)); - genericDopClass.add(new EntityTruck(100, 100, Color.GRAY)); - genericDopClass.add(new EntityRoadTrain(100, 100, Color.BLUE, Color.ORANGE, true, true)); + genericDopClass.add(new EntityTruck(100, 100, Color.BLUE, 1)); + genericDopClass.add(new EntityTruck(100, 100, Color.RED, 2)); + genericDopClass.add(new EntityTruck(100, 100, Color.GRAY, 1)); + genericDopClass.add(new EntityRoadTrain(100, 100, Color.BLUE, 3, Color.ORANGE, true, true)); genericDopClass.add(new DrawingOneLineWheels()); genericDopClass.add(new DrawingTwoLineWheels()); -- 2.25.1