diff --git a/Classes/DrawingAircraft.java b/Classes/DrawingAircraft.java index af50b67..4df1c41 100644 --- a/Classes/DrawingAircraft.java +++ b/Classes/DrawingAircraft.java @@ -1,14 +1,14 @@ package Classes; import java.awt.*; -import java.util.ArrayList; import java.util.Random; public class DrawingAircraft { public EntityAircraft Plane; - private DrawingEngines _engines; + private IDrawingEngines _engines; + protected int _startPosX; protected int _startPosY; @@ -22,7 +22,20 @@ public class DrawingAircraft public DrawingAircraft(int speed,float weight, Color bodyColor) { Random rnd = new Random(); - _engines = new DrawingEngines(); + int enginesType = rnd.nextInt(1,4); + if(enginesType == 1) + { + _engines = new DrawingArcEngines(); + } + else if(enginesType == 2) + { + _engines = new DrawingRectangleEngines(); + } + else if(enginesType == 3) + { + _engines = new DrawingOvalEngines(); + } + _engines.setEngines(rnd.nextInt(2,7)); Plane = new EntityAircraft(speed,weight,bodyColor); } diff --git a/Classes/DrawingArcEngines.java b/Classes/DrawingArcEngines.java new file mode 100644 index 0000000..9a0c01a --- /dev/null +++ b/Classes/DrawingArcEngines.java @@ -0,0 +1,70 @@ +package Classes; + + +import java.awt.*; + +public class DrawingArcEngines implements IDrawingEngines +{ + + private int enginesCount; + @Override + public void drawEngines(Graphics g, int startPosX, int startPosY,Color bodyColor) + { + switch(enginesCount) + { + case 2 -> { + g.setColor((Color.BLACK)); + g.drawArc(startPosX + 40,startPosY + 5,30,10,80,200); + g.drawArc(startPosX + 40,startPosY + 90,30,10,80,200); + g.setColor((bodyColor)); + g.fillArc(startPosX + 40,startPosY + 5,30,10,80,200); + g.fillArc(startPosX + 40,startPosY + 90,30,10,80,200); + } + + case 4 -> { + + g.setColor((Color.BLACK)); + g.drawArc(startPosX + 40,startPosY + 5,30,10,80,200); + g.drawArc(startPosX + 40,startPosY + 90,30,10,80,200); + g.drawArc(startPosX + 40,startPosY + 20,30,10,80,200); + g.drawArc(startPosX + 40,startPosY + 75,30,10,80,200); + g.setColor(bodyColor); + g.fillArc(startPosX + 40,startPosY + 5,30,10,80,200); + g.fillArc(startPosX + 40,startPosY + 90,30,10,80,200); + g.fillArc(startPosX + 40,startPosY + 20,30,10,80,200); + g.fillArc(startPosX + 40,startPosY + 75,30,10,80,200); + } + + case 6 -> { + + g.setColor((Color.BLACK)); + g.drawArc(startPosX + 40,startPosY + 5,30,10,80,200); + g.drawArc(startPosX + 40,startPosY + 90,30,10,80,200); + g.drawArc(startPosX + 40,startPosY + 20,30,10,80,200); + g.drawArc(startPosX + 40,startPosY + 75,30,10,80,200); + g.drawArc(startPosX + 40,startPosY + 35,30,10,80,200); + g.drawArc(startPosX + 40,startPosY + 60,30,10,80,200); + g.setColor(bodyColor); + g.fillArc(startPosX + 40,startPosY + 5,30,10,80,200); + g.fillArc(startPosX + 40,startPosY + 90,30,10,80,200); + g.fillArc(startPosX + 40,startPosY + 20,30,10,80,200); + g.fillArc(startPosX + 40,startPosY + 75,30,10,80,200); + g.fillArc(startPosX + 40,startPosY + 35,30,10,80,200); + g.fillArc(startPosX + 40,startPosY + 60,30,10,80,200); + } + } + } + + @Override + public void setEngines(int count) + { + enginesCount = count; + } + + @Override + public int getCount() { + return enginesCount; + } + + +} diff --git a/Classes/DrawingEngines.java b/Classes/DrawingEngines.java deleted file mode 100644 index 30d0314..0000000 --- a/Classes/DrawingEngines.java +++ /dev/null @@ -1,69 +0,0 @@ -package Classes; - - -import java.awt.*; - -public class DrawingEngines -{ - private Engines enginesCount; - - - public void setEngines(int count) - { - enginesCount = Engines.getEnginesEnum(count); - } - - public void drawEngines(Graphics g,int startPosX,int startPosY,Color bodyColor) - { - if(enginesCount != null) - { - switch(enginesCount) - { - case TwoEngines -> { - g.setColor((Color.BLACK)); - g.drawOval(startPosX + 40,startPosY + 5,30,10); - g.drawOval(startPosX + 40,startPosY + 90,30,10); - g.setColor((bodyColor)); - g.fillOval(startPosX + 40,startPosY + 5,30,10); - g.fillOval(startPosX + 40,startPosY + 90,30,10); - } - - case FourEngines -> { - - g.setColor((Color.BLACK)); - g.drawOval(startPosX + 40,startPosY + 5,30,10); - g.drawOval(startPosX + 40,startPosY + 90,30,10); - g.drawOval(startPosX + 40,startPosY + 20,30,10); - g.drawOval(startPosX + 40,startPosY + 75,30,10); - g.setColor(bodyColor); - g.fillOval(startPosX + 40,startPosY + 5,30,10); - g.fillOval(startPosX + 40,startPosY + 90,30,10); - g.fillOval(startPosX + 40,startPosY + 20,30,10); - g.fillOval(startPosX + 40,startPosY + 75,30,10); - } - - case SixEngines -> { - - g.setColor((Color.BLACK)); - g.drawOval(startPosX + 40,startPosY + 5,30,10); - g.drawOval(startPosX + 40,startPosY + 90,30,10); - g.drawOval(startPosX + 40,startPosY + 20,30,10); - g.drawOval(startPosX + 40,startPosY + 75,30,10); - g.drawOval(startPosX + 40,startPosY + 35,30,10); - g.drawOval(startPosX + 40,startPosY + 60,30,10); - g.setColor(bodyColor); - g.fillOval(startPosX + 40,startPosY + 5,30,10); - g.fillOval(startPosX + 40,startPosY + 90,30,10); - g.fillOval(startPosX + 40,startPosY + 20,30,10); - g.fillOval(startPosX + 40,startPosY + 75,30,10); - g.fillOval(startPosX + 40,startPosY + 35,30,10); - g.fillOval(startPosX + 40,startPosY + 60,30,10); - } - } - } - - - - } - -} diff --git a/Classes/DrawingMilitaryAircraft.java b/Classes/DrawingMilitaryAircraft.java index 8f6e69c..71d3a73 100644 --- a/Classes/DrawingMilitaryAircraft.java +++ b/Classes/DrawingMilitaryAircraft.java @@ -47,9 +47,9 @@ public class DrawingMilitaryAircraft extends DrawingAircraft Point point2W2 = new Point(point1W2.x , point1W2.y + 40); Point point3W2 = new Point(point2W2.x + 10,point1W2.y); - pathExtraWing1.addPoint(point1W2.x,point1W2.y); - pathExtraWing1.addPoint(point2W2.x,point2W2.y); - pathExtraWing1.addPoint(point3W2.x,point3W2.y); + pathExtraWing2.addPoint(point1W2.x,point1W2.y); + pathExtraWing2.addPoint(point2W2.x,point2W2.y); + pathExtraWing2.addPoint(point3W2.x,point3W2.y); g.setColor(Color.black); g.drawPolygon(pathExtraWing2); diff --git a/Classes/DrawingOvalEngines.java b/Classes/DrawingOvalEngines.java new file mode 100644 index 0000000..6018d27 --- /dev/null +++ b/Classes/DrawingOvalEngines.java @@ -0,0 +1,69 @@ +package Classes; + + +import java.awt.*; + +public class DrawingOvalEngines implements IDrawingEngines +{ + + private int enginesCount; + @Override + public void drawEngines(Graphics g, int startPosX, int startPosY,Color bodyColor) + { + switch(enginesCount) + { + case 2 -> { + g.setColor((Color.BLACK)); + g.drawOval(startPosX + 40,startPosY + 5,30,10); + g.drawOval(startPosX + 40,startPosY + 90,30,10); + g.setColor((bodyColor)); + g.fillOval(startPosX + 40,startPosY + 5,30,10); + g.fillOval(startPosX + 40,startPosY + 90,30,10); + } + + case 4 -> { + + g.setColor((Color.BLACK)); + g.drawOval(startPosX + 40,startPosY + 5,30,10); + g.drawOval(startPosX + 40,startPosY + 90,30,10); + g.drawOval(startPosX + 40,startPosY + 20,30,10); + g.drawOval(startPosX + 40,startPosY + 75,30,10); + g.setColor(bodyColor); + g.fillOval(startPosX + 40,startPosY + 5,30,10); + g.fillOval(startPosX + 40,startPosY + 90,30,10); + g.fillOval(startPosX + 40,startPosY + 20,30,10); + g.fillOval(startPosX + 40,startPosY + 75,30,10); + } + + case 6 -> { + + g.setColor((Color.BLACK)); + g.drawOval(startPosX + 40,startPosY + 5,30,10); + g.drawOval(startPosX + 40,startPosY + 90,30,10); + g.drawOval(startPosX + 40,startPosY + 20,30,10); + g.drawOval(startPosX + 40,startPosY + 75,30,10); + g.drawOval(startPosX + 40,startPosY + 35,30,10); + g.drawOval(startPosX + 40,startPosY + 60,30,10); + g.setColor(bodyColor); + g.fillOval(startPosX + 40,startPosY + 5,30,10); + g.fillOval(startPosX + 40,startPosY + 90,30,10); + g.fillOval(startPosX + 40,startPosY + 20,30,10); + g.fillOval(startPosX + 40,startPosY + 75,30,10); + g.fillOval(startPosX + 40,startPosY + 35,30,10); + g.fillOval(startPosX + 40,startPosY + 60,30,10); + } + } + } + + @Override + public void setEngines(int count) + { + enginesCount = count; + } + + @Override + public int getCount() { + return enginesCount; + } + +} diff --git a/Classes/DrawingRectangleEngines.java b/Classes/DrawingRectangleEngines.java new file mode 100644 index 0000000..d593a13 --- /dev/null +++ b/Classes/DrawingRectangleEngines.java @@ -0,0 +1,70 @@ +package Classes; + + +import java.awt.*; + +public class DrawingRectangleEngines implements IDrawingEngines +{ + + private int enginesCount; + @Override + public void drawEngines(Graphics g, int startPosX, int startPosY,Color bodyColor) + { + switch(enginesCount) + { + case 2 -> { + g.setColor((Color.BLACK)); + g.drawRect(startPosX + 40,startPosY + 5,30,10); + g.drawRect(startPosX + 40,startPosY + 90,30,10); + g.setColor((bodyColor)); + g.fillRect(startPosX + 40,startPosY + 5,30,10); + g.fillRect(startPosX + 40,startPosY + 90,30,10); + } + + case 4 -> { + + g.setColor((Color.BLACK)); + g.drawRect(startPosX + 40,startPosY + 5,30,10); + g.drawRect(startPosX + 40,startPosY + 90,30,10); + g.drawRect(startPosX + 40,startPosY + 20,30,10); + g.drawRect(startPosX + 40,startPosY + 75,30,10); + g.setColor(bodyColor); + g.fillRect(startPosX + 40,startPosY + 5,30,10); + g.fillRect(startPosX + 40,startPosY + 90,30,10); + g.fillRect(startPosX + 40,startPosY + 20,30,10); + g.fillRect(startPosX + 40,startPosY + 75,30,10); + } + + case 6 -> { + + g.setColor((Color.BLACK)); + g.drawRect(startPosX + 40,startPosY + 5,30,10); + g.drawRect(startPosX + 40,startPosY + 90,30,10); + g.drawRect(startPosX + 40,startPosY + 20,30,10); + g.drawRect(startPosX + 40,startPosY + 75,30,10); + g.drawRect(startPosX + 40,startPosY + 35,30,10); + g.drawRect(startPosX + 40,startPosY + 60,30,10); + g.setColor(bodyColor); + g.fillRect(startPosX + 40,startPosY + 5,30,10); + g.fillRect(startPosX + 40,startPosY + 90,30,10); + g.fillRect(startPosX + 40,startPosY + 20,30,10); + g.fillRect(startPosX + 40,startPosY + 75,30,10); + g.fillRect(startPosX + 40,startPosY + 35,30,10); + g.fillRect(startPosX + 40,startPosY + 60,30,10); + } + } + } + + @Override + public void setEngines(int count) + { + enginesCount = count; + } + + @Override + public int getCount() { + return enginesCount; + } + + +} diff --git a/Classes/IDrawingEngines.java b/Classes/IDrawingEngines.java new file mode 100644 index 0000000..c05b3b7 --- /dev/null +++ b/Classes/IDrawingEngines.java @@ -0,0 +1,10 @@ +package Classes; + +import java.awt.*; + +public interface IDrawingEngines +{ + void drawEngines(Graphics g, int startX, int startY,Color bodyColor); + void setEngines(int count); + int getCount(); +} diff --git a/Form/FormAirFighter.form b/Form/FormAirFighter.form index cac5761..880008e 100644 --- a/Form/FormAirFighter.form +++ b/Form/FormAirFighter.form @@ -38,7 +38,7 @@ - + @@ -46,7 +46,7 @@ - + @@ -61,17 +61,17 @@ - + - + - + @@ -86,7 +86,7 @@ - + @@ -101,7 +101,7 @@ - + @@ -122,6 +122,14 @@ + + + + + + + + diff --git a/Form/FormAirFighter.java b/Form/FormAirFighter.java index 5e87a6c..ba07d06 100644 --- a/Form/FormAirFighter.java +++ b/Form/FormAirFighter.java @@ -1,6 +1,7 @@ package Form; import Classes.Direction; import Classes.DrawingAircraft; +import Classes.DrawingMilitaryAircraft; import javax.swing.*; import java.awt.*; @@ -25,6 +26,7 @@ public class FormAirFighter extends JFrame private JButton moveLeft; private JButton moveUp; private JButton btnCreate; + private JButton btnModification; private void moveButtonClick(ActionEvent event) { if (_aircraft == null) return; @@ -46,6 +48,21 @@ public class FormAirFighter extends JFrame Draw(); } + private void SetData() + { + Random rnd = new Random(); + + _aircraft.SetPosition( + rnd.nextInt(0, 100), + rnd.nextInt(0, 100), + Form.getWidth(), + Form.getHeight() + ); + speedLabel.setText("Speed: " + _aircraft.Plane.getSpeed()); + weightLabel.setText("Weight: " + _aircraft.Plane.getWeight()); + colorLabel.setText("Color: " + _aircraft.Plane.getBodyColor()); + } + private void CreateEntity() { Random random = new Random(); _aircraft = new DrawingAircraft(random.nextInt(10, 300), @@ -55,19 +72,21 @@ public class FormAirFighter extends JFrame random.nextInt(0,256) )); - _aircraft.SetPosition( - random.nextInt(0, 100), - random.nextInt(0, 100), - Form.getWidth(), - Form.getHeight() - ); - speedLabel.setText("Speed: " + _aircraft.Plane.getSpeed()); - weightLabel.setText("Weight: " + _aircraft.Plane.getWeight()); - colorLabel.setText("Color: " + _aircraft.Plane.getBodyColor()); + SetData(); Draw(); } + private void CreateModifiedEntity() + { + Random rnd = new Random(); + _aircraft = new DrawingMilitaryAircraft(rnd.nextInt(100, 300), rnd.nextInt(1000, 2000), + new Color(rnd.nextInt(0,256),rnd.nextInt(0,256),rnd.nextInt(0,256)), new Color(rnd.nextInt(0,256),rnd.nextInt(0,256),rnd.nextInt(0,256)), + rnd.nextBoolean(), rnd.nextBoolean()); + SetData(); + Draw(); + } + private void resizeWindow() { _aircraft.ChangeBorders(pictureBox.getWidth(), pictureBox.getHeight()); Draw(); @@ -95,6 +114,7 @@ public class FormAirFighter extends JFrame setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setVisible(true); btnCreate.addActionListener(e -> CreateEntity()); + btnModification.addActionListener(e -> CreateModifiedEntity()); Form.addComponentListener(new ComponentAdapter() { @Override public void componentResized(ComponentEvent e) { diff --git a/LisovJava.iml b/LisovJava.iml new file mode 100644 index 0000000..b107a2d --- /dev/null +++ b/LisovJava.iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file