From ab1835aec79d0bbf5033b84df4cd208967196f51 Mon Sep 17 00:00:00 2001 From: Timourka Date: Mon, 9 Oct 2023 21:18:09 +0400 Subject: [PATCH] difficult --- laba1Loco/DrawingTrain.java | 20 ++++- laba1Loco/FormTrain.java | 6 +- laba1Loco/IWheelDrawing.java | 15 ++++ laba1Loco/WheelDrawingBalls.java | 80 +++++++++++++++++ laba1Loco/WheelDrawingDavidStar.java | 87 +++++++++++++++++++ ...elDrawing.java => WheelDrawingSimple.java} | 6 +- 6 files changed, 205 insertions(+), 9 deletions(-) create mode 100644 laba1Loco/IWheelDrawing.java create mode 100644 laba1Loco/WheelDrawingBalls.java create mode 100644 laba1Loco/WheelDrawingDavidStar.java rename laba1Loco/{WheelDrawing.java => WheelDrawingSimple.java} (95%) diff --git a/laba1Loco/DrawingTrain.java b/laba1Loco/DrawingTrain.java index abfbf12..6fbf441 100644 --- a/laba1Loco/DrawingTrain.java +++ b/laba1Loco/DrawingTrain.java @@ -7,7 +7,7 @@ import javax.swing.Timer; import java.awt.event.*; public class DrawingTrain { - protected WheelDrawing wheelDrawing; + protected IWheelDrawing wheelDrawing; /// /// Класс-сущность /// @@ -51,7 +51,21 @@ public class DrawingTrain { if (_pictureHeight < _locoHeight || _pictureWidth < _locoWidth) return; EntityTrain = new EntityTrain(speed, weight, bodyColor, _numWheel); - wheelDrawing = new WheelDrawing(); + Random random = new Random(); + switch(random.nextInt(0, 3)){ + case 0: + wheelDrawing = new WheelDrawingSimple(); + break; + case 1: + wheelDrawing = new WheelDrawingBalls(); + break; + case 2: + wheelDrawing = new WheelDrawingDavidStar(); + break; + default: + wheelDrawing = new WheelDrawingSimple(); + break; + } wheelDrawing.setNumWheel(_numWheel); } /// @@ -188,6 +202,6 @@ _startPosY+12,_startPosY+12,_startPosY+30,_startPosY+30 g2d.drawRect(_startPosX + 72, _startPosY + 12, 6, 7); //wheels - wheelDrawing.Draw(_startPosX, _startPosY, false, null, g2d); + wheelDrawing.Draw(_startPosX, _startPosY, false, EntityTrain.BodyColor, g2d); } } diff --git a/laba1Loco/FormTrain.java b/laba1Loco/FormTrain.java index ec696a4..4612bbb 100644 --- a/laba1Loco/FormTrain.java +++ b/laba1Loco/FormTrain.java @@ -11,7 +11,7 @@ public class FormTrain{ private AbstractStrategy abstractStrategy; Canvas canv; static int pictureBoxWidth = 980; - static int pictureBoxHeight = 560; + static int pictureBoxHeight = 580; public void Draw(){ canv.repaint(); @@ -127,8 +127,8 @@ public class FormTrain{ random.nextInt(1000, 3000), new Color(random.nextInt(0, 256), random.nextInt(0, 256), random.nextInt(0, 256)), random.nextInt(2, 5), - 1000, - 560); + pictureBoxWidth, + pictureBoxHeight); _drawingTrain.SetPosition(random.nextInt(10, 100), random.nextInt(10, 100)); canv._drawingTrain = _drawingTrain; Draw(); diff --git a/laba1Loco/IWheelDrawing.java b/laba1Loco/IWheelDrawing.java new file mode 100644 index 0000000..fe986f1 --- /dev/null +++ b/laba1Loco/IWheelDrawing.java @@ -0,0 +1,15 @@ +package laba1Loco; + +import java.awt.*; +import java.util.*; +import javax.swing.*; +import javax.swing.Timer; +import java.awt.event.*; + +public interface IWheelDrawing{ + public NumWheel getNumWheel(); + + public void setNumWheel(int kwheel); + + public void Draw(int _startPosX, int _startPosY, boolean fuelTank, Color color, Graphics2D g2d); +} \ No newline at end of file diff --git a/laba1Loco/WheelDrawingBalls.java b/laba1Loco/WheelDrawingBalls.java new file mode 100644 index 0000000..c61a78a --- /dev/null +++ b/laba1Loco/WheelDrawingBalls.java @@ -0,0 +1,80 @@ +package laba1Loco; + +import java.awt.*; +import java.util.*; +import javax.swing.*; +import javax.swing.Timer; +import java.awt.event.*; + +public class WheelDrawingBalls implements IWheelDrawing{ + private NumWheel numWheel; + + public NumWheel getNumWheel() { + return numWheel; + } + + public void setNumWheel(int kwheel){ + switch(kwheel){ + case 2: + numWheel = NumWheel.TwoWheel; + break; + case 3: + numWheel = NumWheel.ThreeWheel; + break; + case 4: + numWheel = NumWheel.FourWheel; + break; + default: + numWheel = NumWheel.TwoWheel; + System.out.println("ВСё плохо, колво колёс почему то не соответтвовало критериям, количество колёс:" + Integer.toString(kwheel) + "но вывели мы как будто их было 2"); + break; + } + } + + private void DrawWheel(int _startPosX, int _startPosY, Color color, Graphics2D g2d){ + g2d.setColor(color); + g2d.fillOval(_startPosX, _startPosY, 8, 8); + + g2d.setColor(Color.PINK); + g2d.fillOval( _startPosX+3, _startPosY+1, 2, 3); + g2d.fillOval( _startPosX+1, _startPosY+4, 2, 2); + g2d.fillOval( _startPosX+6, _startPosY+4, 2, 2); + } + + public void Draw(int _startPosX, int _startPosY, boolean fuelTank, Color color, Graphics2D g2d){ + + DrawWheel(_startPosX + 3, _startPosY + 34, color, g2d); + DrawWheel(_startPosX + 26, _startPosY + 34, color, g2d); + DrawWheel(_startPosX + 46, _startPosY + 34, color, g2d); + DrawWheel(_startPosX + 72, _startPosY + 34, color, g2d); + + if (numWheel == NumWheel.TwoWheel){ + DrawWheel(_startPosX + 14, _startPosY + 34, color, g2d); + DrawWheel(_startPosX + 59, _startPosY + 34, color, g2d); + } + if (numWheel == NumWheel.FourWheel){ + DrawWheel(_startPosX + 11, _startPosY + 34, color, g2d); + DrawWheel(_startPosX + 18, _startPosY + 34, color, g2d); + DrawWheel(_startPosX + 55, _startPosY + 34, color, g2d); + DrawWheel(_startPosX + 63, _startPosY + 34, color, g2d); + } + + if (fuelTank){ + DrawWheel(_startPosX + 3+85, _startPosY + 34, color, g2d); + DrawWheel(_startPosX + 26+85, _startPosY + 34, color, g2d); + DrawWheel(_startPosX + 46+85, _startPosY + 34, color, g2d); + DrawWheel(_startPosX + 72+85, _startPosY + 34, color, g2d); + + if (numWheel == NumWheel.TwoWheel){ + DrawWheel(_startPosX + 14+85, _startPosY + 34, color, g2d); + DrawWheel(_startPosX + 59+85, _startPosY + 34, color, g2d); + } + if (numWheel == NumWheel.FourWheel){ + DrawWheel(_startPosX + 11+85, _startPosY + 34, color, g2d); + DrawWheel(_startPosX + 18+85, _startPosY + 34, color, g2d); + DrawWheel(_startPosX + 55+85, _startPosY + 34, color, g2d); + DrawWheel(_startPosX + 63+85, _startPosY + 34, color, g2d); + } + } + } + } diff --git a/laba1Loco/WheelDrawingDavidStar.java b/laba1Loco/WheelDrawingDavidStar.java new file mode 100644 index 0000000..ab43f3b --- /dev/null +++ b/laba1Loco/WheelDrawingDavidStar.java @@ -0,0 +1,87 @@ +package laba1Loco; + +import java.awt.*; +import java.util.*; +import javax.swing.*; +import javax.swing.Timer; +import java.awt.event.*; + +public class WheelDrawingDavidStar implements IWheelDrawing{ + private NumWheel numWheel; + + public NumWheel getNumWheel() { + return numWheel; + } + + public void setNumWheel(int kwheel){ + switch(kwheel){ + case 2: + numWheel = NumWheel.TwoWheel; + break; + case 3: + numWheel = NumWheel.ThreeWheel; + break; + case 4: + numWheel = NumWheel.FourWheel; + break; + default: + numWheel = NumWheel.TwoWheel; + System.out.println("ВСё плохо, колво колёс почему то не соответтвовало критериям, количество колёс:" + Integer.toString(kwheel) + "но вывели мы как будто их было 2"); + break; + } + } + + private void DrawWheel(int _startPosX, int _startPosY, Color color, Graphics2D g2d){ + g2d.setColor(color); + g2d.fillOval(_startPosX, _startPosY, 8, 8); + + g2d.setColor(Color.WHITE); + g2d.drawPolygon(new int[]{ + _startPosX + 1, _startPosX + 7, _startPosX + 3 + }, new int[]{ + _startPosY + 2, _startPosY + 2, _startPosY + 7 + }, 3); + g2d.drawPolygon(new int[]{ + _startPosX + 1, _startPosX + 7, _startPosX + 4 + }, new int[]{ + _startPosY + 6, _startPosY + 6, _startPosY + 1 + }, 3); + } + + public void Draw(int _startPosX, int _startPosY, boolean fuelTank, Color color, Graphics2D g2d){ + + DrawWheel(_startPosX + 3, _startPosY + 34, color, g2d); + DrawWheel(_startPosX + 26, _startPosY + 34, color, g2d); + DrawWheel(_startPosX + 46, _startPosY + 34, color, g2d); + DrawWheel(_startPosX + 72, _startPosY + 34, color, g2d); + + if (numWheel == NumWheel.TwoWheel){ + DrawWheel(_startPosX + 14, _startPosY + 34, color, g2d); + DrawWheel(_startPosX + 59, _startPosY + 34, color, g2d); + } + if (numWheel == NumWheel.FourWheel){ + DrawWheel(_startPosX + 11, _startPosY + 34, color, g2d); + DrawWheel(_startPosX + 18, _startPosY + 34, color, g2d); + DrawWheel(_startPosX + 55, _startPosY + 34, color, g2d); + DrawWheel(_startPosX + 63, _startPosY + 34, color, g2d); + } + + if (fuelTank){ + DrawWheel(_startPosX + 3+85, _startPosY + 34, color, g2d); + DrawWheel(_startPosX + 26+85, _startPosY + 34, color, g2d); + DrawWheel(_startPosX + 46+85, _startPosY + 34, color, g2d); + DrawWheel(_startPosX + 72+85, _startPosY + 34, color, g2d); + + if (numWheel == NumWheel.TwoWheel){ + DrawWheel(_startPosX + 14+85, _startPosY + 34, color, g2d); + DrawWheel(_startPosX + 59+85, _startPosY + 34, color, g2d); + } + if (numWheel == NumWheel.FourWheel){ + DrawWheel(_startPosX + 11+85, _startPosY + 34, color, g2d); + DrawWheel(_startPosX + 18+85, _startPosY + 34, color, g2d); + DrawWheel(_startPosX + 55+85, _startPosY + 34, color, g2d); + DrawWheel(_startPosX + 63+85, _startPosY + 34, color, g2d); + } + } + } + } diff --git a/laba1Loco/WheelDrawing.java b/laba1Loco/WheelDrawingSimple.java similarity index 95% rename from laba1Loco/WheelDrawing.java rename to laba1Loco/WheelDrawingSimple.java index 33935fb..50077e7 100644 --- a/laba1Loco/WheelDrawing.java +++ b/laba1Loco/WheelDrawingSimple.java @@ -6,10 +6,10 @@ import javax.swing.*; import javax.swing.Timer; import java.awt.event.*; -public class WheelDrawing{ +public class WheelDrawingSimple implements IWheelDrawing{ private NumWheel numWheel; - public NumWheel getSomeProperty() { + public NumWheel getNumWheel() { return numWheel; } @@ -31,7 +31,7 @@ public class WheelDrawing{ } } - void Draw(int _startPosX, int _startPosY, boolean fuelTank, Color color, Graphics2D g2d){ + public void Draw(int _startPosX, int _startPosY, boolean fuelTank, Color color, Graphics2D g2d){ g2d.setColor(color);