From 078b5ffac54994f43e020ae4b90e6f0b7721545d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=93=D0=B0=D0=BB=D0=B8=D0=BD=D0=B0=20=D0=A4=D0=B5=D0=B4?= =?UTF-8?q?=D0=BE=D1=80=D0=B5=D0=BD=D0=BA=D0=BE?= Date: Sun, 5 Nov 2023 21:56:49 +0400 Subject: [PATCH] lab2 DONE! --- .../java/org/example/DrawingHydroplane.java | 14 +++++--- .../main/java/org/example/DrawingPlane.java | 33 +++++++------------ .../java/org/example/DrawningObjectPlane.java | 5 +++ .../java/org/example/EntityHydroplane.java | 4 --- .../main/java/org/example/EntityPlane.java | 4 --- .../main/java/org/example/FormHydroplane.java | 17 ++++------ .../java/org/example/IMoveableObject.java | 1 + .../main/java/org/example/IWindowDrawing.java | 4 --- .../main/java/org/example/MoveToBorder.java | 2 ++ .../main/java/org/example/MoveToCenter.java | 2 ++ .../java/org/example/ObjectParameters.java | 1 + .../main/java/org/example/WindowDrawing.java | 13 ++++---- .../java/org/example/WindowDrawingRect.java | 13 ++++---- .../org/example/WindowDrawingTringle.java | 13 +++----- 14 files changed, 56 insertions(+), 70 deletions(-) diff --git a/Hydroplane/src/main/java/org/example/DrawingHydroplane.java b/Hydroplane/src/main/java/org/example/DrawingHydroplane.java index 8a20c95..bac953c 100644 --- a/Hydroplane/src/main/java/org/example/DrawingHydroplane.java +++ b/Hydroplane/src/main/java/org/example/DrawingHydroplane.java @@ -1,10 +1,6 @@ package org.example; import java.awt.*; -import java.util.*; -import javax.swing.*; -import javax.swing.Timer; -import java.awt.event.*; public class DrawingHydroplane extends DrawingPlane{ @@ -40,7 +36,15 @@ public class DrawingHydroplane extends DrawingPlane{ 3 ); - //windowDrawing.Draw(_startPosX, _startPosY, _EntityHydroplane.AdditionalColor, g); + g.fillRect(_startPosX + 65, _startPosY + 55, 5, 15); + g.fillRect(_startPosX + 125, _startPosY + 55, 5, 15); + + g.drawLine(_startPosX + 65, _startPosY + 55, _startPosX + 65, _startPosY + 70); + g.drawLine(_startPosX + 70, _startPosY + 55, _startPosX + 70, _startPosY + 70); + g.drawLine(_startPosX + 125, _startPosY + 55, _startPosX + 125, _startPosY + 70); + g.drawLine(_startPosX + 130, _startPosY + 55, _startPosX + 130, _startPosY + 70); + + windowDrawing.Draw(_startPosX, _startPosY, ((EntityHydroplane)_EntityPlane).AdditionalColor, g); if (((EntityHydroplane)_EntityPlane).Bobber) { g.fillPolygon( diff --git a/Hydroplane/src/main/java/org/example/DrawingPlane.java b/Hydroplane/src/main/java/org/example/DrawingPlane.java index 5ef5879..b1d5919 100644 --- a/Hydroplane/src/main/java/org/example/DrawingPlane.java +++ b/Hydroplane/src/main/java/org/example/DrawingPlane.java @@ -2,13 +2,10 @@ package org.example; import java.awt.*; import java.util.*; -import javax.swing.*; -import javax.swing.Timer; -import java.awt.event.*; public class DrawingPlane{ - //protected IWheelDrawing wheelDrawing; + protected IWindowDrawing windowDrawing; public EntityPlane _EntityPlane; @@ -20,9 +17,9 @@ public class DrawingPlane{ protected int _startPosY; - protected int _planeWidth = 190; + protected int _planeWidth = 175; - protected int _planeHeight = 80; + protected int _planeHeight = 90; public DrawingPlane(int speed, double weight, Color bodyColor, int _numWindow, int width, int height) { @@ -31,24 +28,24 @@ public class DrawingPlane{ if (_pictureHeight < _planeHeight || _pictureWidth < _planeWidth) return; _EntityPlane = new EntityPlane(speed, weight, bodyColor, _numWindow); - /* + Random random = new Random(); switch(random.nextInt(0, 3)){ case 0: - wheelDrawing = new WheelDrawingSimple(); + windowDrawing = new WindowDrawing(); break; case 1: - wheelDrawing = new WheelDrawingBalls(); + windowDrawing = new WindowDrawingRect(); break; case 2: - wheelDrawing = new WheelDrawingDavidStar(); + windowDrawing = new WindowDrawingTringle(); break; default: - wheelDrawing = new WheelDrawingSimple(); + windowDrawing = new WindowDrawing(); break; } - wheelDrawing.setNumWheel(_numWheel); - */ + windowDrawing.setNumWindow(_numWindow); + } public void SetPosition(int x, int y) @@ -123,9 +120,6 @@ public class DrawingPlane{ new int[]{ _startPosY, _startPosY + 55, _startPosY + 55, _startPosY + 40, _startPosY + 40, _startPosY + 25, _startPosY + 25 }, 7); - g.fillRect(_startPosX + 65, _startPosY + 55, 5, 15); - g.fillRect(_startPosX + 125, _startPosY + 55, 5, 15); - g.setColor(Color.black); g.drawRect(_startPosX + 5, _startPosY + 25, 125, 30); @@ -136,12 +130,7 @@ public class DrawingPlane{ g.drawOval(_startPosX + 35, _startPosY + 43, 80, 7); - g.drawLine(_startPosX + 65, _startPosY + 55, _startPosX + 65, _startPosY + 70); - g.drawLine(_startPosX + 70, _startPosY + 55, _startPosX + 70, _startPosY + 70); - g.drawLine(_startPosX + 125, _startPosY + 55, _startPosX + 125, _startPosY + 70); - g.drawLine(_startPosX + 130, _startPosY + 55, _startPosX + 130, _startPosY + 70); - - //windowDrawing.Draw(_startPosX, _startPosY, _EntityHydroplane.AdditionalColor, g); + windowDrawing.Draw(_startPosX, _startPosY, Color.white, g); } } \ No newline at end of file diff --git a/Hydroplane/src/main/java/org/example/DrawningObjectPlane.java b/Hydroplane/src/main/java/org/example/DrawningObjectPlane.java index 914d22e..b0b19c7 100644 --- a/Hydroplane/src/main/java/org/example/DrawningObjectPlane.java +++ b/Hydroplane/src/main/java/org/example/DrawningObjectPlane.java @@ -1,11 +1,14 @@ package org.example; public class DrawningObjectPlane implements IMoveableObject { + private DrawingPlane _drawingPlane = null; + public DrawningObjectPlane(DrawingPlane drawingPlane) { _drawingPlane = drawingPlane; } + public ObjectParameters GetObjectPosition(){ if (_drawingPlane == null || _drawingPlane._EntityPlane == null) @@ -16,7 +19,9 @@ public class DrawningObjectPlane implements IMoveableObject { _drawingPlane.GetPosY(), _drawingPlane.GetWidth(), _drawingPlane.GetHeight()); } public int GetStep(){ return (int)_drawingPlane._EntityPlane.Step; } + public boolean CheckCanMove(Direction direction) { return _drawingPlane.CanMove(direction);} + public void MoveObject(Direction direction) { _drawingPlane.MoveTransport(direction); } } diff --git a/Hydroplane/src/main/java/org/example/EntityHydroplane.java b/Hydroplane/src/main/java/org/example/EntityHydroplane.java index 6426857..4a87141 100644 --- a/Hydroplane/src/main/java/org/example/EntityHydroplane.java +++ b/Hydroplane/src/main/java/org/example/EntityHydroplane.java @@ -1,10 +1,6 @@ package org.example; import java.awt.*; -import java.util.*; -import javax.swing.*; -import javax.swing.Timer; -import java.awt.event.*; public class EntityHydroplane extends EntityPlane{ diff --git a/Hydroplane/src/main/java/org/example/EntityPlane.java b/Hydroplane/src/main/java/org/example/EntityPlane.java index 749c8aa..7ad0d23 100644 --- a/Hydroplane/src/main/java/org/example/EntityPlane.java +++ b/Hydroplane/src/main/java/org/example/EntityPlane.java @@ -1,10 +1,6 @@ package org.example; import java.awt.*; -import java.util.*; -import javax.swing.*; -import javax.swing.Timer; -import java.awt.event.*; public class EntityPlane{ diff --git a/Hydroplane/src/main/java/org/example/FormHydroplane.java b/Hydroplane/src/main/java/org/example/FormHydroplane.java index 21039d3..50b1588 100644 --- a/Hydroplane/src/main/java/org/example/FormHydroplane.java +++ b/Hydroplane/src/main/java/org/example/FormHydroplane.java @@ -3,10 +3,10 @@ package org.example; import java.awt.*; import java.util.*; import javax.swing.*; -import javax.swing.Timer; import java.awt.event.*; public class FormHydroplane{ + private DrawingPlane _drawingPlane; private AbstractStrategy abstractStrategy; Canvas canv; @@ -55,13 +55,12 @@ public class FormHydroplane{ buttonCreatePlane.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e){ - System.out.println(e.getActionCommand()); Random random = new Random(); _drawingPlane = new DrawingPlane( random.nextInt(100, 300), random.nextInt(1000, 3000), new Color(random.nextInt(0, 256), random.nextInt(0, 256), random.nextInt(0, 256)), - random.nextInt(2, 5), + random.nextInt(1, 4) * 10, pictureBoxWidth, pictureBoxHeight); _drawingPlane.SetPosition(random.nextInt(10, 100), random.nextInt(10, 100)); @@ -73,7 +72,6 @@ public class FormHydroplane{ buttonCreateHydroplane.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e){ - System.out.println(e.getActionCommand()); Random random = new Random(); _drawingPlane = new DrawingHydroplane( random.nextInt(100, 300), @@ -82,7 +80,7 @@ public class FormHydroplane{ new Color(random.nextInt(0, 256), random.nextInt(0, 256), random.nextInt(0, 256)), random.nextInt(0, 2) == 1, random.nextInt(0, 2) == 1, - random.nextInt(2, 5), + random.nextInt(1, 4) * 10, pictureBoxWidth, pictureBoxHeight); _drawingPlane.SetPosition(random.nextInt(10, 100), random.nextInt(10, 100)); @@ -136,7 +134,6 @@ public class FormHydroplane{ ActionListener actioListener = new ActionListener() { public void actionPerformed(ActionEvent e){ - System.out.println(((JButton)(e.getSource())).getName()); if (_drawingPlane == null) { return; @@ -169,8 +166,8 @@ public class FormHydroplane{ w.setLayout(null); canv = new Canvas(); canv.setBounds(0, 0, pictureBoxWidth, pictureBoxHeight); - buttonCreatePlane.setBounds(2, 540, 100, 20); - buttonCreateHydroplane.setBounds(105, 540, 150, 20); + buttonCreatePlane.setBounds(2, 540, 150, 20); + buttonCreateHydroplane.setBounds(160, 540, 200, 20); up.setBounds(900, 480, 40, 40); down.setBounds(900, 520, 40, 40); left.setBounds(860, 520, 40, 40); @@ -186,13 +183,13 @@ public class FormHydroplane{ w.add(right); w.add(comboBoxStrategy); w.add(buttonStrategysStep); + w.setVisible(true); } } class Canvas extends JComponent{ public DrawingPlane _drawingPlane; - public Canvas(){ - } + public Canvas(){} public void paintComponent (Graphics g){ if (_drawingPlane == null){ return; diff --git a/Hydroplane/src/main/java/org/example/IMoveableObject.java b/Hydroplane/src/main/java/org/example/IMoveableObject.java index 6fab6e4..f8ea5a2 100644 --- a/Hydroplane/src/main/java/org/example/IMoveableObject.java +++ b/Hydroplane/src/main/java/org/example/IMoveableObject.java @@ -9,5 +9,6 @@ public interface IMoveableObject { boolean CheckCanMove(Direction direction); void MoveObject(Direction direction); + } diff --git a/Hydroplane/src/main/java/org/example/IWindowDrawing.java b/Hydroplane/src/main/java/org/example/IWindowDrawing.java index 7b17f9f..512d46f 100644 --- a/Hydroplane/src/main/java/org/example/IWindowDrawing.java +++ b/Hydroplane/src/main/java/org/example/IWindowDrawing.java @@ -1,10 +1,6 @@ package org.example; import java.awt.*; -import java.util.*; -import javax.swing.*; -import javax.swing.Timer; -import java.awt.event.*; public interface IWindowDrawing{ diff --git a/Hydroplane/src/main/java/org/example/MoveToBorder.java b/Hydroplane/src/main/java/org/example/MoveToBorder.java index 74c52bb..e1d1ba7 100644 --- a/Hydroplane/src/main/java/org/example/MoveToBorder.java +++ b/Hydroplane/src/main/java/org/example/MoveToBorder.java @@ -1,6 +1,7 @@ package org.example; public class MoveToBorder extends AbstractStrategy{ + protected boolean IsTargetDestinaion() { var objParams = GetObjectParameters(); @@ -13,6 +14,7 @@ public class MoveToBorder extends AbstractStrategy{ objParams.DownBorder() <= FieldHeight && objParams.DownBorder() + GetStep() >= FieldHeight; } + protected void MoveToTarget() { var objParams = GetObjectParameters(); diff --git a/Hydroplane/src/main/java/org/example/MoveToCenter.java b/Hydroplane/src/main/java/org/example/MoveToCenter.java index 9f874ab..fe90f54 100644 --- a/Hydroplane/src/main/java/org/example/MoveToCenter.java +++ b/Hydroplane/src/main/java/org/example/MoveToCenter.java @@ -1,6 +1,7 @@ package org.example; public class MoveToCenter extends AbstractStrategy { + protected boolean IsTargetDestinaion() { var objParams = GetObjectParameters(); @@ -13,6 +14,7 @@ public class MoveToCenter extends AbstractStrategy { && Math.abs(objParams.ObjectMiddleVertical() - FieldHeight / 2) <= GetStep(); } + protected void MoveToTarget() { var objParams = GetObjectParameters(); diff --git a/Hydroplane/src/main/java/org/example/ObjectParameters.java b/Hydroplane/src/main/java/org/example/ObjectParameters.java index 6b8d434..674babf 100644 --- a/Hydroplane/src/main/java/org/example/ObjectParameters.java +++ b/Hydroplane/src/main/java/org/example/ObjectParameters.java @@ -1,6 +1,7 @@ package org.example; public class ObjectParameters { + private int _x; private int _y; private int _width; diff --git a/Hydroplane/src/main/java/org/example/WindowDrawing.java b/Hydroplane/src/main/java/org/example/WindowDrawing.java index e9eb222..dd6144d 100644 --- a/Hydroplane/src/main/java/org/example/WindowDrawing.java +++ b/Hydroplane/src/main/java/org/example/WindowDrawing.java @@ -3,6 +3,7 @@ package org.example; import java.awt.*; public class WindowDrawing implements IWindowDrawing{ + private NumWindow numWindow; public NumWindow getNumWindow() { @@ -32,26 +33,26 @@ public class WindowDrawing implements IWindowDrawing{ switch (numWindow) { case tenWindows -> { for (int i = 0; i < 10; i++) { - g.fillOval(_startPosX + 35 + i * 8, _startPosY + 30, 4, 4); + g.fillOval(_startPosX + 35 + i * 8, _startPosY + 28, 4, 4); } } case twentyWindows -> { for (int i = 0; i < 10; i++) { - g.fillOval(_startPosX + 35 + i * 8, _startPosY + 30, 4, 4); + g.fillOval(_startPosX + 35 + i * 8, _startPosY + 28, 4, 4); } for (int i = 0; i < 10; i++) { - g.fillOval(_startPosX + 35 + i * 8, _startPosY + 30 + 4, 4, 4); + g.fillOval(_startPosX + 35 + i * 8, _startPosY + 28 + 6, 4, 4); } } case thirtyWindows -> { for (int i = 0; i < 10; i++) { - g.fillOval(_startPosX + 35 + i * 8, _startPosY + 30, 4, 4); + g.fillOval(_startPosX + 35 + i * 8, _startPosY + 28, 4, 4); } for (int i = 0; i < 10; i++) { - g.fillOval(_startPosX + 35 + i * 8, _startPosY + 30 + 4, 4, 4); + g.fillOval(_startPosX + 35 + i * 8, _startPosY + 28 + 5, 4, 4); } for (int i = 0; i < 10; i++) { - g.fillOval(_startPosX + 35 + i * 8, _startPosY + 30 + 8, 4, 4); + g.fillOval(_startPosX + 35 + i * 8, _startPosY + 28 + 10, 4, 4); } } } diff --git a/Hydroplane/src/main/java/org/example/WindowDrawingRect.java b/Hydroplane/src/main/java/org/example/WindowDrawingRect.java index c620975..f69d072 100644 --- a/Hydroplane/src/main/java/org/example/WindowDrawingRect.java +++ b/Hydroplane/src/main/java/org/example/WindowDrawingRect.java @@ -3,6 +3,7 @@ package org.example; import java.awt.*; public class WindowDrawingRect implements IWindowDrawing{ + private NumWindow numWindow; public NumWindow getNumWindow() { @@ -32,26 +33,26 @@ public class WindowDrawingRect implements IWindowDrawing{ switch (numWindow) { case tenWindows -> { for (int i = 0; i < 10; i++) { - g.fillRect(_startPosX + 35 + i * 8, _startPosY + 30, 4, 4); + g.fillRect(_startPosX + 35 + i * 8, _startPosY + 28, 4, 4); } } case twentyWindows -> { for (int i = 0; i < 10; i++) { - g.fillRect(_startPosX + 35 + i * 8, _startPosY + 30, 4, 4); + g.fillRect(_startPosX + 35 + i * 8, _startPosY + 28, 4, 4); } for (int i = 0; i < 10; i++) { - g.fillRect(_startPosX + 35 + i * 8, _startPosY + 30 + 4, 4, 4); + g.fillRect(_startPosX + 35 + i * 8, _startPosY + 28 + 5, 4, 4); } } case thirtyWindows -> { for (int i = 0; i < 10; i++) { - g.fillRect(_startPosX + 35 + i * 8, _startPosY + 30, 4, 4); + g.fillRect(_startPosX + 35 + i * 8, _startPosY + 28, 4, 4); } for (int i = 0; i < 10; i++) { - g.fillRect(_startPosX + 35 + i * 8, _startPosY + 30 + 4, 4, 4); + g.fillRect(_startPosX + 35 + i * 8, _startPosY + 28 + 5, 4, 4); } for (int i = 0; i < 10; i++) { - g.fillRect(_startPosX + 35 + i * 8, _startPosY + 30 + 8, 4, 4); + g.fillRect(_startPosX + 35 + i * 8, _startPosY + 28 + 10, 4, 4); } } } diff --git a/Hydroplane/src/main/java/org/example/WindowDrawingTringle.java b/Hydroplane/src/main/java/org/example/WindowDrawingTringle.java index a280bf6..d830699 100644 --- a/Hydroplane/src/main/java/org/example/WindowDrawingTringle.java +++ b/Hydroplane/src/main/java/org/example/WindowDrawingTringle.java @@ -3,6 +3,7 @@ package org.example; import java.awt.*; public class WindowDrawingTringle implements IWindowDrawing{ + private NumWindow numWindow; public NumWindow getNumWindow() { @@ -32,7 +33,6 @@ public class WindowDrawingTringle implements IWindowDrawing{ switch (numWindow) { case tenWindows -> { for (int i = 0; i < 10; i++) { - //g.fillOval(_startPosX + 35 + i * 8, _startPosY + 30, 4, 4); g.fillPolygon( new int[]{ _startPosX + 35 + i * 8, _startPosX + 35 + i * 8 + 2, _startPosX + 35 + i * 8 + 4 }, new int[]{ _startPosY + 30, _startPosY + 30 + 4, _startPosY + 30 }, @@ -41,40 +41,35 @@ public class WindowDrawingTringle implements IWindowDrawing{ } case twentyWindows -> { for (int i = 0; i < 10; i++) { - //g.fillOval(_startPosX + 35 + i * 8, _startPosY + 30, 4, 4); g.fillPolygon( new int[]{ _startPosX + 35 + i * 8, _startPosX + 35 + i * 8 + 2, _startPosX + 35 + i * 8 + 4 }, new int[]{ _startPosY + 30, _startPosY + 30 + 4, _startPosY + 30 }, 3); } for (int i = 0; i < 10; i++) { - //g.fillOval(_startPosX + 35 + i * 8, _startPosY + 30 + 4, 4, 4); g.fillPolygon( new int[]{ _startPosX + 35 + i * 8, _startPosX + 35 + i * 8 + 2, _startPosX + 35 + i * 8 + 4 }, - new int[]{ _startPosY + 30 + 4, _startPosY + 30 + 4 + 4, _startPosY + 30 + 4 }, + new int[]{ _startPosY + 30 + 5, _startPosY + 30 + 4 + 5, _startPosY + 30 + 5 }, 3); } } case thirtyWindows -> { for (int i = 0; i < 10; i++) { - //g.fillOval(_startPosX + 35 + i * 8, _startPosY + 30, 4, 4); g.fillPolygon( new int[]{ _startPosX + 35 + i * 8, _startPosX + 35 + i * 8 + 2, _startPosX + 35 + i * 8 + 4 }, new int[]{ _startPosY + 30, _startPosY + 30 + 4, _startPosY + 30 }, 3); } for (int i = 0; i < 10; i++) { - //g.fillOval(_startPosX + 35 + i * 8, _startPosY + 30 + 4, 4, 4); g.fillPolygon( new int[]{ _startPosX + 35 + i * 8, _startPosX + 35 + i * 8 + 2, _startPosX + 35 + i * 8 + 4 }, - new int[]{ _startPosY + 30 + 4, _startPosY + 30 + 4 + 4, _startPosY + 30 + 4 }, + new int[]{ _startPosY + 30 + 5, _startPosY + 30 + 4 + 5, _startPosY + 30 + 5 }, 3); } for (int i = 0; i < 10; i++) { - //g.fillOval(_startPosX + 35 + i * 8, _startPosY + 30 + 8, 4, 4); g.fillPolygon( new int[]{ _startPosX + 35 + i * 8, _startPosX + 35 + i * 8 + 2, _startPosX + 35 + i * 8 + 4 }, - new int[]{ _startPosY + 30 + 8, _startPosY + 30 + 4 + 8, _startPosY + 30 + 8 }, + new int[]{ _startPosY + 30 + 10, _startPosY + 30 + 4 + 10, _startPosY + 30 + 10 }, 3); } }