From 52f515ce730518433d1aa87d9b8ef74987ee062b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9A=D0=B0=D1=82=D1=8F=20=D0=98=D1=85=D0=BE=D0=BD=D0=BA?= =?UTF-8?q?=D0=B8=D0=BD=D0=B0?= Date: Sat, 10 Dec 2022 00:10:36 +0400 Subject: [PATCH 1/2] =?UTF-8?q?=D0=BB=D1=802=20=D0=BA=D0=BE=D0=BC=D0=BC?= =?UTF-8?q?=D0=B8=D1=82=201?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/AbstractMap.java | 146 ++++++++++++++++++++++ src/Direction.java | 1 + src/DrawingBoat.java | 68 +++++++---- src/DrawingHardPaddle.java | 72 +++++++++++ src/DrawingPaddle.java | 7 +- src/DrawningHard2Paddle.java | 47 ++++++++ src/DrawningMotorBoat.java | 78 ++++++++++++ src/DrawningObjectBoat.java | 38 ++++++ src/EntityBoat.java | 2 +- src/EntityMotorBoat.java | 21 ++++ src/FormBoat.form | 24 +++- src/FormBoat.java | 47 +++++--- src/FormMap.form | 213 +++++++++++++++++++++++++++++++++ src/FormMap.java | 157 ++++++++++++++++++++++++ src/IDrawningObject.java | 13 ++ src/IDrawningObjectPaddle.java | 8 ++ src/SeaMap.java | 44 +++++++ src/SimpleMap.java | 45 +++++++ 18 files changed, 980 insertions(+), 51 deletions(-) create mode 100644 src/AbstractMap.java create mode 100644 src/DrawingHardPaddle.java create mode 100644 src/DrawningHard2Paddle.java create mode 100644 src/DrawningMotorBoat.java create mode 100644 src/DrawningObjectBoat.java create mode 100644 src/EntityMotorBoat.java create mode 100644 src/FormMap.form create mode 100644 src/FormMap.java create mode 100644 src/IDrawningObject.java create mode 100644 src/IDrawningObjectPaddle.java create mode 100644 src/SeaMap.java create mode 100644 src/SimpleMap.java diff --git a/src/AbstractMap.java b/src/AbstractMap.java new file mode 100644 index 0000000..1f8fb11 --- /dev/null +++ b/src/AbstractMap.java @@ -0,0 +1,146 @@ +import java.awt.*; +import java.awt.image.BufferedImage; +import java.util.Random; + +public abstract class AbstractMap { + private IDrawningObject _drawingObject = null; + protected int[][] _map = null; + protected int _width; + protected int _height; + //ширина и высота ячейки + protected float _size_x; + protected float _size_y; + protected final Random _random = new Random(); + protected final int _freeRoad = 0; + protected final int _barrier = 1; + public BufferedImage CreateMap(int width, int height, IDrawningObject drawingObject) + { + _width = width; + _height = height; + _drawingObject = drawingObject; + GenerateMap(); + while (!SetObjectOnMap()) + { + GenerateMap(); + } + return DrawMapWithObject(); + } + public BufferedImage MoveObject(Direction direction) + { + _drawingObject.MoveObject(direction); + float[] tuple = _drawingObject.GetCurrentPosition(); + if (CheckBarrier(tuple[0],tuple[1],tuple[2],tuple[3])) + { + _drawingObject.MoveObject(MoveObjectBack(direction)); + } + return DrawMapWithObject(); + } + + private Direction MoveObjectBack(Direction direction) + { + switch (direction) + { + case Up: + return Direction.Down; + case Down: + return Direction.Up; + case Left: + return Direction.Right; + case Right: + return Direction.Left; + } + return Direction.None; + } + + private boolean CheckBarrier(float Left, float Right, float Top, float Bottom) + { + int startX = (int)(Left / _size_x); + int startY = (int)(Right / _size_y); + int endX = (int)(Top / _size_x); + int endY = (int)(Bottom / _size_y); + + if (startX < 0 || startY < 0 || endX >= _map[0].length || endY >= _map.length) + { + return true; + } + for (int i = startX; i <= endX; i++) + { + for (int j = startY; j <= endY; j++) + { + if (_map[i][j] == _barrier) + { + return true; + } + } + } + return false; + } + private boolean SetObjectOnMap() + { + if (_drawingObject == null || _map == null) + { + return false; + } + int x = _random.nextInt(0, 10); + int y = _random.nextInt(0, 10); + _drawingObject.SetObject(x, y, _width, _height); + + float[] tuple = _drawingObject.GetCurrentPosition(); + + if (!CheckBarrier(tuple[0], tuple[1], tuple[2], tuple[3])) return true; + float startX = tuple[0]; + float startY = tuple[1]; + float lengthX = tuple[2] - tuple[0]; + float lengthY = tuple[3] - tuple[1]; + while (CheckBarrier(startX, startY, startX + lengthX, startY + lengthY)) + { + boolean result; + do + { + result = CheckBarrier(startX, startY, startX + lengthX, startY + lengthY); + if (!result) + { + _drawingObject.SetObject((int)startX, (int)startY, _width, _height); + return true; + } + else + { + startX += _size_x; + } + } while (result); + startX = x; + startY += _size_y; + } + return false; + } + private BufferedImage DrawMapWithObject() + { + BufferedImage bmp = new BufferedImage(_width, _height, BufferedImage.TYPE_INT_RGB); + if (_drawingObject == null || _map == null) + { + return bmp; + } + Graphics gr = bmp.getGraphics(); + for (int i = 0; i < _map.length; ++i) + { + for (int j = 0; j < _map[0].length; ++j) + { + if (_map[i][j] == _freeRoad) + { + DrawRoadPart(gr, i, j); + } + else if (_map[i][j] == _barrier) + { + DrawBarrierPart(gr, i, j); + } + } + } + // _drawingObject.DrawingObject(gr); + return bmp; + } + + protected abstract void GenerateMap(); + protected abstract void DrawRoadPart(Graphics g, int i, int j); + protected abstract void DrawBarrierPart(Graphics g, int i, int j); + +} diff --git a/src/Direction.java b/src/Direction.java index 996463a..5269225 100644 --- a/src/Direction.java +++ b/src/Direction.java @@ -1,4 +1,5 @@ public enum Direction { + None, Up, Down, Left, diff --git a/src/DrawingBoat.java b/src/DrawingBoat.java index d8d8def..99ffbb0 100644 --- a/src/DrawingBoat.java +++ b/src/DrawingBoat.java @@ -1,23 +1,34 @@ import javax.swing.*; import java.awt.*; +import java.util.Random; + public class DrawingBoat extends JComponent { public EntityBoat Boat; - private float _startPosX; - private float _startPosY; + protected float _startPosX; + protected float _startPosY; private Integer _pictureWidth = null; private Integer _pictureHeight = null; - private final int _boatWidth = 90; - private final int _boatHeight = 80; - private DrawingPaddle _paddles; - public DrawingBoat() { - super(); - } - public void Init(int speed, float weight, Color bodyColor, int paddleCount) + private int _boatWidth = 90; + private int _boatHeight = 80; + private IDrawningObjectPaddle _paddles; + public DrawingBoat(int speed, float weight, Color bodyColor, int paddleCount) { - Boat = new EntityBoat(); - Boat.Init(speed, weight, bodyColor); - _paddles = new DrawingPaddle(); - _paddles.SetPaddlesAmount(paddleCount); + Random random = new Random(); + Boat = new EntityBoat(speed, weight, bodyColor); + int randomPattern=random.nextInt(3); + if (randomPattern==0) + _paddles = new DrawingHardPaddle(); + else if(randomPattern==1) + _paddles = new DrawningHard2Paddle(); + else + _paddles = new DrawingPaddle(); + _paddles.SetPaddlesCount(paddleCount); + } + protected DrawingBoat(int speed, float weight, Color bodyColor, int rollersAmount, int bulldozerWidth, int bulldozerHeight) + { + this(speed, weight, bodyColor, rollersAmount); + _boatWidth = bulldozerWidth; + _boatHeight = bulldozerHeight; } public void SetPosition(int x, int y, int width, int height) { @@ -27,8 +38,8 @@ public class DrawingBoat extends JComponent { _pictureHeight = null; return; } - _startPosX = x; - _startPosY = y; + _startPosX = x+20; + _startPosY = y+20; _pictureWidth = width; _pictureHeight = height; } @@ -43,28 +54,29 @@ public class DrawingBoat extends JComponent { case Right: { if (_startPosX + _boatWidth + Boat.Step() < _pictureWidth) { + System.out.println(Boat.Step()); _startPosX += Boat.Step(); } break; } - case Left: - if (_startPosX - Boat.Step() > 0) - { + case Left: { + if (_startPosX - Boat.Step() > 0) { _startPosX -= Boat.Step(); } break; - case Up: - if (_startPosY - Boat.Step() > 0) - { + } + case Up: { + if (_startPosY - Boat.Step() > 0) { _startPosY -= Boat.Step(); } break; - case Down: - if (_startPosY + _boatHeight + Boat.Step() < _pictureHeight) - { + } + case Down: { + if (_startPosY + _boatHeight + Boat.Step() < _pictureHeight) { _startPosY += Boat.Step(); } break; + } } } public void paintComponent(Graphics gr) @@ -116,4 +128,12 @@ public class DrawingBoat extends JComponent { _startPosY = _pictureHeight - _boatHeight; } } + public float[] GetCurrentPosition(){ + float[] tuple = new float[4]; + tuple[0] = _startPosX; + tuple[1] =_startPosY; + tuple[2] = _startPosX + _boatWidth; + tuple[3] = _startPosY + _boatHeight; + return tuple; + } } diff --git a/src/DrawingHardPaddle.java b/src/DrawingHardPaddle.java new file mode 100644 index 0000000..fa85ce2 --- /dev/null +++ b/src/DrawingHardPaddle.java @@ -0,0 +1,72 @@ +import java.awt.*; + +public class DrawingHardPaddle implements IDrawningObjectPaddle { + private AdditionalDirection _paddleEnum; + @Override + public void SetPaddlesCount(int rollersAmount) { + for (AdditionalDirection item: _paddleEnum.values()) { + if (item.getCount() == rollersAmount) { + _paddleEnum = item; + return; + } + } + } + @Override + public void DrawPaddles(Graphics gr, int _startPosPaddlesX, int _startPosPaddlessY, Color mainBrush) { + Graphics2D g=(Graphics2D)gr; + //цвет + Color br = new Color(0,0,0); + try { br = mainBrush; } + catch (Exception e) { + + } + _startPosPaddlesX +=40; + _startPosPaddlessY +=33; + if (_paddleEnum.getCount() >= 1) { + + paintPaddleUgol(g, _startPosPaddlesX-3, _startPosPaddlessY+5, _startPosPaddlessY + 16+5,mainBrush,false); + paintPaddle(g, _startPosPaddlesX, _startPosPaddlessY, _startPosPaddlessY + 16,mainBrush); + } + if (_paddleEnum.getCount() >= 2) { + + paintPaddleUgol(g, _startPosPaddlesX -10-3, _startPosPaddlessY -41+5, _startPosPaddlessY -51+5,mainBrush,true); + paintPaddle(g, _startPosPaddlesX -10, _startPosPaddlessY -41, _startPosPaddlessY -51,mainBrush); + } + if (_paddleEnum.getCount() >= 3) { + paintPaddleUgol(g, _startPosPaddlesX -20-3, _startPosPaddlessY+5, _startPosPaddlessY + 16+5,mainBrush,false); + paintPaddle(g, _startPosPaddlesX -20, _startPosPaddlessY, _startPosPaddlessY + 16,mainBrush); + + } + } + protected void paintPaddleUgol(Graphics2D g, int _startPosX, int _startPosY1,int _startPosY2, Color pen,boolean need){ + try { g.setPaint(pen); } + catch (Exception e) { + g.setPaint(Color.black); + } + if(need){ + g.fillPolygon(new int[]{_startPosX,_startPosX+5,_startPosX+10}, new int[]{_startPosY2,_startPosY2-10,_startPosY2},3); + g.setPaint(Color.black); + g.drawPolygon(new int[]{_startPosX,_startPosX+5,_startPosX+10}, new int[]{_startPosY2,_startPosY2-10,_startPosY2},3);} + else{ + g.fillPolygon(new int[]{_startPosX,_startPosX+5,_startPosX+10}, new int[]{_startPosY2,_startPosY2+10,_startPosY2},3); + g.setPaint(Color.black); + g.drawPolygon(new int[]{_startPosX,_startPosX+5,_startPosX+10}, new int[]{_startPosY2,_startPosY2+10,_startPosY2},3); + } + /* g.fillRect(_startPosX,_startPosY1,4,17); + g.fillOval(_startPosX-1, _startPosY2, 6, 10); + g.setPaint(Color.black); + g.drawRect(_startPosX,_startPosY1,4,17); + g.drawOval(_startPosX-1, _startPosY2, 6, 10);*/ + } + protected void paintPaddle(Graphics2D g, int _startPosX, int _startPosY1,int _startPosY2, Color pen){ + try { g.setPaint(pen); } + catch (Exception e) { + g.setPaint(Color.black); + } + g.fillRect(_startPosX,_startPosY1,4,17); + g.fillOval(_startPosX-1, _startPosY2, 6, 10); + g.setPaint(Color.black); + g.drawRect(_startPosX,_startPosY1,4,17); + g.drawOval(_startPosX-1, _startPosY2, 6, 10); + } +} \ No newline at end of file diff --git a/src/DrawingPaddle.java b/src/DrawingPaddle.java index d4327b3..f00d0cc 100644 --- a/src/DrawingPaddle.java +++ b/src/DrawingPaddle.java @@ -1,8 +1,9 @@ import javax.swing.*; import java.awt.*; -public class DrawingPaddle extends JComponent { +public class DrawingPaddle implements IDrawningObjectPaddle { private AdditionalDirection _paddle; - public void SetPaddlesAmount(int rpaddlesAmount) { + @Override + public void SetPaddlesCount(int rpaddlesAmount) { for (AdditionalDirection item: _paddle.values()) { if (item.getCount() == rpaddlesAmount) { _paddle = item; @@ -10,8 +11,8 @@ public class DrawingPaddle extends JComponent { } } } + @Override public void DrawPaddles(Graphics gr, int _startPosPaddlesX, int _startPosPaddlessY, Color pen) { - super.paintComponent(gr); Graphics2D g=(Graphics2D)gr; _startPosPaddlesX +=40; diff --git a/src/DrawningHard2Paddle.java b/src/DrawningHard2Paddle.java new file mode 100644 index 0000000..789f250 --- /dev/null +++ b/src/DrawningHard2Paddle.java @@ -0,0 +1,47 @@ +import java.awt.*; + +public class DrawningHard2Paddle implements IDrawningObjectPaddle { + private AdditionalDirection _paddleEnum; + @Override + public void SetPaddlesCount(int paddlesCount) { + for (AdditionalDirection item: _paddleEnum.values()) { + if (item.getCount() == paddlesCount) { + _paddleEnum = item; + return; + } + } + } + @Override + public void DrawPaddles(Graphics gr, int _startPosPaddlesX, int _startPosPaddlessY, Color mainBrush) { + Graphics2D g=(Graphics2D)gr; + //цвет + Color br = new Color(0,0,0); + try { br = mainBrush; } + catch (Exception e) { + + } + _startPosPaddlesX +=40; + _startPosPaddlessY +=33; + if (_paddleEnum.getCount() >= 1) { + paintPaddle(g, _startPosPaddlesX, _startPosPaddlessY, _startPosPaddlessY + 16,mainBrush); + } + if (_paddleEnum.getCount() >= 2) { + paintPaddle(g, _startPosPaddlesX -10, _startPosPaddlessY -41, _startPosPaddlessY -51,mainBrush); + } + if (_paddleEnum.getCount() >= 3) { + paintPaddle(g, _startPosPaddlesX -20, _startPosPaddlessY, _startPosPaddlessY + 16,mainBrush); + + } + } + protected void paintPaddle(Graphics2D g, int _startPosX, int _startPosY1,int _startPosY2, Color pen){ + try { g.setPaint(pen); } + catch (Exception e) { + g.setPaint(Color.black); + } + g.fillRect(_startPosX,_startPosY1,4,17); + g.fillRect(_startPosX-5, _startPosY2, 13, 13); + g.setPaint(Color.black); + g.drawRect(_startPosX,_startPosY1,4,17); + g.drawRect(_startPosX-5, _startPosY2, 13, 13); + } +} diff --git a/src/DrawningMotorBoat.java b/src/DrawningMotorBoat.java new file mode 100644 index 0000000..3607b34 --- /dev/null +++ b/src/DrawningMotorBoat.java @@ -0,0 +1,78 @@ +import java.awt.*; + +public class DrawningMotorBoat extends DrawingBoat{ + public DrawningMotorBoat(int speed, float weight, Color bodyColor, int paddleamount, Color dopColor, boolean attachment, boolean ripper) + { + super(speed, weight, bodyColor, paddleamount, 138, 78); + Boat = new EntityMotorBoat(speed, weight, bodyColor, dopColor, attachment, ripper); + } + @Override + public void paintComponent(Graphics gr) + { + boolean check = Boat instanceof EntityMotorBoat; + if (!check) { + return; + } + EntityMotorBoat bulldozer = (EntityMotorBoat) Boat; + //_startPosY+=40; + Graphics2D g=(Graphics2D)gr; + Color dopBrush = bulldozer.DopColor(); + + gr.setColor(dopBrush); + g.fillOval( (int)_startPosX - 17, (int)_startPosY - 24, 14, 5); + gr.setColor(Color.BLACK); + g.drawOval((int) _startPosX - 17, (int)_startPosY - 24, 14, 5); + gr.setColor(dopBrush); + g.fillRect((int) _startPosX - 10, (int)_startPosY - 30, 10, 20); + gr.setColor(Color.BLACK); + g.drawRect( (int)_startPosX - 10, (int)_startPosY - 30, 10, 20); + + int[] pointsx; + int[] pointsy; + + if (bulldozer.Attachment()) + { + pointsx = new int[]{(int)(_startPosX),(int)(_startPosX),(int)(_startPosX+50),(int)(_startPosX+50)}; + pointsy = new int[] + { + (int)(_startPosY-50),(int)(_startPosY+10),(int)(_startPosY),(int)(_startPosY-40) + }; + gr.setColor(dopBrush); + g.fillPolygon(pointsx,pointsy,4); + gr.setColor(Color.BLACK); + g.drawPolygon(pointsx,pointsy,4); + } + + /* _startPosX -= 15; + _startPosY -= 5;*/ + if (bulldozer.Ripper()) + { + pointsx = new int[]{(int)(_startPosX)+50,(int)(_startPosX)+80,(int)(_startPosX+50)}; + pointsy = new int[]{(int)(_startPosY-40),(int)(_startPosY-20),(int)(_startPosY)}; + gr.setColor(dopBrush); + g.fillPolygon(pointsx,pointsy,3); + gr.setColor(Color.BLACK); + g.drawPolygon(pointsx,pointsy,3); + } + _startPosY-=40; + /* _startPosX += 15; + _startPosY += 5;*/ + super.paintComponent(gr); + _startPosY+=40; + + pointsx = new int[] + { + (int)(_startPosX)+50,(int)(_startPosX)+57,(int)(_startPosX+50) }; + pointsy = new int[] + { + (int)(_startPosY-34),(int)(_startPosY-20),(int)(_startPosY-6) + }; + gr.setColor(Color.CYAN); + g.fillPolygon(pointsx,pointsy,3); + gr.setColor(Color.BLACK); + ((Graphics2D) gr).setStroke(new BasicStroke(1)); + g.drawPolygon(pointsx,pointsy,3); + + } +} + diff --git a/src/DrawningObjectBoat.java b/src/DrawningObjectBoat.java new file mode 100644 index 0000000..b9c62c5 --- /dev/null +++ b/src/DrawningObjectBoat.java @@ -0,0 +1,38 @@ +import java.awt.*; + +public class DrawningObjectBoat implements IDrawningObject{ + private DrawingBoat _boat = null; + public DrawningObjectBoat(DrawingBoat boat) { + _boat = boat; + } + @Override + public float Step() { + if (_boat!=null && _boat.Boat != null) { + return _boat.Boat.Step(); + } + return 0; + } + + @Override + public void SetObject(int x, int y, int width, int height) { + _boat.SetPosition(x+20, y+50, width, height); + } + + @Override + public void MoveObject(Direction direction) { + _boat.MoveTransport(direction); + } + + @Override + public void DrawingObject(Graphics g) { + _boat.paintComponent(g); + } + + @Override + public float[] GetCurrentPosition() + { + if(_boat!=null) + return _boat.GetCurrentPosition(); + return null; + } +} diff --git a/src/EntityBoat.java b/src/EntityBoat.java index 1b9d07b..5f02dd9 100644 --- a/src/EntityBoat.java +++ b/src/EntityBoat.java @@ -14,7 +14,7 @@ public class EntityBoat { } public float Step() { return Speed() * 20 / Weight(); } - public void Init(int speed, float weight, Color bodyColor) + public EntityBoat(int speed, float weight, Color bodyColor) { Random random = new Random(); this.speed = speed <= 0 ? random.nextInt(50, 150) : speed; diff --git a/src/EntityMotorBoat.java b/src/EntityMotorBoat.java new file mode 100644 index 0000000..62771ad --- /dev/null +++ b/src/EntityMotorBoat.java @@ -0,0 +1,21 @@ +import java.awt.*; + +public class EntityMotorBoat extends EntityBoat{ + // Дополнительный цвет + private Color dopColor; + public Color DopColor() { return dopColor; } + // Признак наличия отвала + private boolean attachment; + public boolean Attachment() { return attachment; } + // Признак наличия рыхлителя + private boolean ripper; + public boolean Ripper() { return ripper; } + // Инициализация свойств + public EntityMotorBoat(int speed, float weight, Color bodyColor, Color dopColor, boolean attachment, boolean ripper) + { + super(speed*100, weight, bodyColor); + this.dopColor = dopColor; + this.attachment = attachment; + this.ripper = ripper; + } +} diff --git a/src/FormBoat.form b/src/FormBoat.form index 89f3a52..aa8d755 100644 --- a/src/FormBoat.form +++ b/src/FormBoat.form @@ -1,6 +1,6 @@
- + @@ -21,7 +21,7 @@ - + @@ -99,17 +99,17 @@ - + - + - + @@ -122,7 +122,7 @@ - + @@ -185,6 +185,18 @@ + + + + + + + + + + + + diff --git a/src/FormBoat.java b/src/FormBoat.java index 37f65ac..c58e798 100644 --- a/src/FormBoat.java +++ b/src/FormBoat.java @@ -3,14 +3,7 @@ import java.awt.*; import java.awt.event.*; import java.util.Random; public class FormBoat extends JFrame { - public static void main(String[] args) { - FormBoat window = new FormBoat(); - window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); - window.pack(); - window.setLocationRelativeTo(null); - window.setVisible(true); - } private JPanel mainPanel; private JPanel statusStrip; @@ -28,10 +21,13 @@ public class FormBoat extends JFrame { private JRadioButton radioButtonPaddle3; private JPanel radioButtonsBox; private JPanel pictureBoxBoat; + private JButton buttonCreateModif; private DrawingBoat _boat; private int pictureBoxBoatWidth; private int pictureBoxBoatHeight; ButtonGroup buttonGroupPaddlesRadBut; + + /* public FormBoat() { super("Моторная лодка"); buttonGroupPaddlesRadBut = new ButtonGroup(); @@ -49,16 +45,24 @@ public class FormBoat extends JFrame { } catch (Exception c) { } Random random = new Random(); - _boat = new DrawingBoat(); - _boat.Init(random.nextInt(50, 150), random.nextInt(40, 70), new Color(random.nextInt(0, 256), + _boat = new DrawingBoat(random.nextInt(50, 150), random.nextInt(40, 70), new Color(random.nextInt(0, 256), random.nextInt(0, 256), random.nextInt(0, 256)), GetRollersAmount()); - ChangePictureBoxBoatBorders(); - _boat.SetPosition(random.nextInt(20, 100), random.nextInt(50, 100), pictureBoxBoatWidth, pictureBoxBoatHeight); - toolStripStatusLabelSpeed.setText("Скорость: " + _boat.Boat.Speed()); - toolStripStatusLabelWeight.setText("Вес: " + _boat.Boat.Weight()); - - toolStripStatusLabelBodyColor.setText("Цвет: " + Integer.toHexString(_boat.Boat.BodyColor().getRGB())); - pictureBoxBoat.add(_boat, BorderLayout.CENTER); + SetData(); + } + }); + buttonCreateModif.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + try { + pictureBoxBoat.remove(_boat); + } catch (Exception c) { + } + Random random = new Random(); + _boat = new DrawningMotorBoat(random.nextInt(30, 50), random.nextInt(1000, 2000), + new Color(random.nextInt(0, 256), random.nextInt(0, 256), + random.nextInt(0, 256)), GetRollersAmount(), new Color(random.nextInt(0, 256), random.nextInt(0, 256), + random.nextInt(0, 256)), random.nextBoolean(), random.nextBoolean()); + SetData(); } }); addComponentListener(new ComponentAdapter() { @@ -85,6 +89,15 @@ public class FormBoat extends JFrame { buttonLeft.addActionListener(buttonsMove); buttonRight.addActionListener(buttonsMove); buttonDown.addActionListener(buttonsMove); + } + private void SetData() { + Random random = new Random(); + ChangePictureBoxBoatBorders(); + _boat.SetPosition(random.nextInt(20, 100), random.nextInt(50, 100), pictureBoxBoatWidth, pictureBoxBoatHeight); + toolStripStatusLabelSpeed.setText("Скорость: " + _boat.Boat.Speed()); + toolStripStatusLabelWeight.setText("Вес: " + _boat.Boat.Weight()); + toolStripStatusLabelBodyColor.setText("Цвет: " + Integer.toHexString(_boat.Boat.BodyColor().getRGB())); + pictureBoxBoat.add(_boat, BorderLayout.CENTER); } class ButtonsMove implements ActionListener { public void actionPerformed(ActionEvent e) { @@ -121,5 +134,5 @@ public class FormBoat extends JFrame { } else { return 3; } - } + }*/ } diff --git a/src/FormMap.form b/src/FormMap.form new file mode 100644 index 0000000..e5f9191 --- /dev/null +++ b/src/FormMap.form @@ -0,0 +1,213 @@ + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
diff --git a/src/FormMap.java b/src/FormMap.java new file mode 100644 index 0000000..f833c0c --- /dev/null +++ b/src/FormMap.java @@ -0,0 +1,157 @@ +import javax.swing.*; +import java.awt.*; +import java.awt.event.*; +import java.awt.image.BufferedImage; +import java.util.Random; +public class FormMap extends JFrame { + public static void main(String[] args) { + + FormMap window = new FormMap(); + window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + window.pack(); + window.setLocationRelativeTo(null); + window.setVisible(true); + } + + private JPanel mainPanel; + private JPanel statusStrip; + private JLabel toolStripStatusLabelSpeed; + private JLabel toolStripStatusLabelBodyColor; + private JLabel toolStripStatusLabelWeight; + private JPanel buttonsBox; + private JButton buttonLeft; + private JButton buttonRight; + private JButton buttonUp; + private JButton buttonDown; + private JButton buttonCreate; + private JRadioButton radioButtonPaddle1; + private JRadioButton radioButtonPaddle2; + private JRadioButton radioButtonPaddle3; + private JPanel radioButtonsBox; + private JPanel pictureBoxBoat; + private JComboBox comboBoxSelectorMap; + private JButton buttonCreateModif; + private DrawingBoat _boat; + private int pictureBoxBoatWidth; + private int pictureBoxBoatHeight; + private AbstractMap _abstractMap; + private JLabel pictureLabel; + private DrawningObjectBoat drawningObjectBoat; + ButtonGroup buttonGroupPaddlesRadBut; + public FormMap() { + super("Моторная лодка"); + buttonGroupPaddlesRadBut = new ButtonGroup(); + buttonGroupPaddlesRadBut.add(radioButtonPaddle1); + buttonGroupPaddlesRadBut.add(radioButtonPaddle2); + buttonGroupPaddlesRadBut.add(radioButtonPaddle3); + setPreferredSize(new Dimension(1000, 700)); + getContentPane().add(mainPanel); + + buttonCreate.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + Random random = new Random(); + var _boat = new DrawingBoat(random.nextInt(50, 150), random.nextInt(40, 70), new Color(random.nextInt(0, 256), + random.nextInt(0, 256), random.nextInt(0, 256)), GetRollersAmount()); + SetData(_boat); + } + }); + buttonCreateModif.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + Random random = new Random(); + var _boat = new DrawningMotorBoat(random.nextInt(30, 50), random.nextInt(1000, 2000), + new Color(random.nextInt(0, 256), random.nextInt(0, 256), + random.nextInt(0, 256)), GetRollersAmount(), new Color(random.nextInt(0, 256), random.nextInt(0, 256), + random.nextInt(0, 256)), random.nextBoolean(), random.nextBoolean()); + SetData(_boat); + } + }); + comboBoxSelectorMap.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + comboBoxSelectorMap = (JComboBox)e.getSource(); + String item = String.valueOf(comboBoxSelectorMap.getSelectedItem()); + System.out.println(item); + switch (item) { + case "Простая карта"-> + _abstractMap = new SimpleMap(); + case "Морская карта" -> + _abstractMap = new SeaMap(); + + } + } + }); + + //джижение + ButtonsMove buttonsMove = new ButtonsMove(); + buttonUp.setName("Up"); + buttonLeft.setName("Left"); + buttonRight.setName("Right"); + buttonDown.setName("Down"); + buttonUp.addActionListener(buttonsMove); + buttonLeft.addActionListener(buttonsMove); + buttonRight.addActionListener(buttonsMove); + buttonDown.addActionListener(buttonsMove); + } + private void SetData(DrawingBoat _boat) { + if (_abstractMap == null) return; + try { + pictureBoxBoat.remove(pictureLabel); + } catch (Exception c) { } + ChangePictureBoxBoatBorders(); + // _boat.SetPosition(random.nextInt(20, 100), random.nextInt(50, 100), pictureBoxBoatWidth, pictureBoxBoatHeight); + toolStripStatusLabelSpeed.setText("Скорость: " + _boat.Boat.Speed()); + toolStripStatusLabelWeight.setText("Вес: " + _boat.Boat.Weight()); + toolStripStatusLabelBodyColor.setText("Цвет: " + Integer.toHexString(_boat.Boat.BodyColor().getRGB())); + drawningObjectBoat = new DrawningObjectBoat(_boat); + BufferedImage picture = _abstractMap.CreateMap(pictureBoxBoatWidth, pictureBoxBoatHeight, + drawningObjectBoat); + drawningObjectBoat.DrawingObject(picture.getGraphics()); + pictureLabel = new JLabel(new ImageIcon(picture)); + pictureBoxBoat.add(pictureLabel, BorderLayout.CENTER); + } + class ButtonsMove implements ActionListener { + public void actionPerformed(ActionEvent e) { + if (_abstractMap == null) return; + pictureBoxBoat.remove(pictureLabel); + pictureBoxBoat.revalidate(); + pictureBoxBoat.repaint(); + JButton temp = (JButton) e.getSource(); + String name = temp.getName(); + BufferedImage picture = _abstractMap.MoveObject(Direction.None); + switch (name) { + case "Up" -> picture=_abstractMap.MoveObject(Direction.Up); + case "Right" ->picture= _abstractMap.MoveObject(Direction.Right); + case "Left" -> picture=_abstractMap.MoveObject(Direction.Left); + case "Down" -> picture=_abstractMap.MoveObject(Direction.Down); + } + drawningObjectBoat.DrawingObject(picture.getGraphics()); + pictureLabel = new JLabel(new ImageIcon(picture)); + pictureBoxBoat.add(pictureLabel, BorderLayout.CENTER); + } + } + + private void ChangePictureBoxBoatBorders() { + char[] temp = pictureBoxBoat.getSize().toString().toCharArray(); + for (int i = 0; i < temp.length; i++) { + if (!Character.isDigit(temp[i])) { + temp[i] = ' '; + } + } + String width = new String(temp); + String[] parameters = width.split("\\s*(\\s|,|!|\\.)\\s*", 4); + pictureBoxBoatWidth = Integer.parseInt(parameters[1]); + pictureBoxBoatHeight = Integer.parseInt(parameters[2]); + } + private int GetRollersAmount() { + if (radioButtonPaddle1.isSelected()) { + return 1; + } + else if (radioButtonPaddle2.isSelected()) { + return 2; + } else { + return 3; + } + } +} diff --git a/src/IDrawningObject.java b/src/IDrawningObject.java new file mode 100644 index 0000000..1a5f9ea --- /dev/null +++ b/src/IDrawningObject.java @@ -0,0 +1,13 @@ +import java.awt.*; + +public interface IDrawningObject { + public float Step(); + // Установка позиции объекта + void SetObject(int x, int y, int width, int height); + // Изменение направления пермещения объекта + void MoveObject(Direction direction); + // Отрисовка объекта + void DrawingObject(Graphics g); + // Получение текущей позиции объекта + float[] GetCurrentPosition(); +} \ No newline at end of file diff --git a/src/IDrawningObjectPaddle.java b/src/IDrawningObjectPaddle.java new file mode 100644 index 0000000..dcb207d --- /dev/null +++ b/src/IDrawningObjectPaddle.java @@ -0,0 +1,8 @@ +import java.awt.*; + +public interface IDrawningObjectPaddle { + //свойство для передачи числового значения + void SetPaddlesCount(int rollersAmount); + //метод, принимающий параметры для отрисовки + void DrawPaddles(Graphics gr, int _startPosRollersX, int _startPosRollersY, Color mainBrush); +} diff --git a/src/SeaMap.java b/src/SeaMap.java new file mode 100644 index 0000000..3912141 --- /dev/null +++ b/src/SeaMap.java @@ -0,0 +1,44 @@ +import java.awt.*; + +public class SeaMap extends SimpleMap { + private final Color barrierColor = Color.BLUE; + // Цвет участка открытого + private final Color roadColor = Color.CYAN; + + @Override + protected void GenerateMap() { + _map = new int[100][100]; + _size_x = (float)_width / _map.length; + _size_y = (float)_height / _map[0].length; + int counter = 0; + for (int i = 0; i < _map.length; ++i) + { + for (int j = 0; j < _map[0].length; ++j) + { + _map[i][j] = _freeRoad; + } + } + while (counter < 10) + { + int x = _random.nextInt(0, 100); + int y = _random.nextInt(0, 100); + if (_map[x][y] == _freeRoad) + { + _map[x][y] = _barrier; + counter++; + } + } + } + + @Override + protected void DrawRoadPart(Graphics g, int i, int j) { + g.setColor(roadColor); + g.fillRect((int)(i * _size_x), (int)(j * _size_y), (int)(i * (_size_x + 1)), (int)(j * (_size_y + 1))); + } + + @Override + protected void DrawBarrierPart(Graphics g, int i, int j) { + g.setColor(barrierColor); + g.fillRect((int)(i * _size_x), (int)(j * _size_y),(int) (i * (_size_x + 1)), (int)(j * (_size_y + 1))); + } +} \ No newline at end of file diff --git a/src/SimpleMap.java b/src/SimpleMap.java new file mode 100644 index 0000000..b34bf51 --- /dev/null +++ b/src/SimpleMap.java @@ -0,0 +1,45 @@ +import java.awt.*; + +public class SimpleMap extends AbstractMap { + + private final Color barrierColor = Color.BLACK; + // Цвет участка открытого + private final Color roadColor = Color.GRAY; + + @Override + protected void GenerateMap() { + _map = new int[100][100]; + _size_x = (float)_width / _map.length; + _size_y = (float)_height / _map[0].length; + int counter = 0; + for (int i = 0; i < _map.length; ++i) + { + for (int j = 0; j < _map[0].length; ++j) + { + _map[i][j] = _freeRoad; + } + } + while (counter < 10) + { + int x = _random.nextInt(0, 100); + int y = _random.nextInt(0, 100); + if (_map[x][y] == _freeRoad) + { + _map[x][y] = _barrier; + counter++; + } + } + } + + @Override + protected void DrawRoadPart(Graphics g, int i, int j) { + g.setColor(roadColor); + g.fillRect((int)(i * _size_x), (int)(j * _size_y), (int)(i * (_size_x + 1)), (int)(j * (_size_y + 1))); + } + + @Override + protected void DrawBarrierPart(Graphics g, int i, int j) { + g.setColor(barrierColor); + g.fillRect((int)(i * _size_x), (int)(j * _size_y),(int) (i * (_size_x + 1)), (int)(j * (_size_y + 1))); + } +} \ No newline at end of file -- 2.25.1 From c1e50db073efdca93c1ae9391c2cfed484619ac6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9A=D0=B0=D1=82=D1=8F=20=D0=98=D1=85=D0=BE=D0=BD=D0=BA?= =?UTF-8?q?=D0=B8=D0=BD=D0=B0?= Date: Sat, 10 Dec 2022 00:56:47 +0400 Subject: [PATCH 2/2] =?UTF-8?q?=D0=BB=D1=802=20=D0=BA=D0=BE=D0=BC=D0=BC?= =?UTF-8?q?=D0=B8=D1=82=202?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/AbstractMap.java | 7 ---- src/DrawingBoat.java | 13 +++--- src/DrawingHardPaddle.java | 72 -------------------------------- src/DrawingPaddle.java | 6 +-- src/DrawingPaddleSquare.java | 47 +++++++++++++++++++++ src/DrawingPaddleTriangle.java | 70 +++++++++++++++++++++++++++++++ src/DrawningHard2Paddle.java | 47 --------------------- src/DrawningMotorBoat.java | 75 +++++++++++++--------------------- src/DrawningObjectBoat.java | 4 -- src/EntityBoat.java | 12 +++--- src/EntityMotorBoat.java | 19 ++++----- src/FormBoat.java | 15 ++----- src/FormMap.java | 13 ++---- src/IDrawningObject.java | 4 -- src/IDrawningObjectPaddle.java | 6 +-- src/SeaMap.java | 24 ++++------- src/SimpleMap.java | 25 ++++-------- 17 files changed, 192 insertions(+), 267 deletions(-) delete mode 100644 src/DrawingHardPaddle.java create mode 100644 src/DrawingPaddleSquare.java create mode 100644 src/DrawingPaddleTriangle.java delete mode 100644 src/DrawningHard2Paddle.java diff --git a/src/AbstractMap.java b/src/AbstractMap.java index 1f8fb11..c586f74 100644 --- a/src/AbstractMap.java +++ b/src/AbstractMap.java @@ -1,13 +1,11 @@ import java.awt.*; import java.awt.image.BufferedImage; import java.util.Random; - public abstract class AbstractMap { private IDrawningObject _drawingObject = null; protected int[][] _map = null; protected int _width; protected int _height; - //ширина и высота ячейки protected float _size_x; protected float _size_y; protected final Random _random = new Random(); @@ -35,7 +33,6 @@ public abstract class AbstractMap { } return DrawMapWithObject(); } - private Direction MoveObjectBack(Direction direction) { switch (direction) @@ -51,7 +48,6 @@ public abstract class AbstractMap { } return Direction.None; } - private boolean CheckBarrier(float Left, float Right, float Top, float Bottom) { int startX = (int)(Left / _size_x); @@ -135,12 +131,9 @@ public abstract class AbstractMap { } } } - // _drawingObject.DrawingObject(gr); return bmp; } - protected abstract void GenerateMap(); protected abstract void DrawRoadPart(Graphics g, int i, int j); protected abstract void DrawBarrierPart(Graphics g, int i, int j); - } diff --git a/src/DrawingBoat.java b/src/DrawingBoat.java index 99ffbb0..0726732 100644 --- a/src/DrawingBoat.java +++ b/src/DrawingBoat.java @@ -17,18 +17,18 @@ public class DrawingBoat extends JComponent { Boat = new EntityBoat(speed, weight, bodyColor); int randomPattern=random.nextInt(3); if (randomPattern==0) - _paddles = new DrawingHardPaddle(); + _paddles = new DrawingPaddleTriangle(); else if(randomPattern==1) - _paddles = new DrawningHard2Paddle(); + _paddles = new DrawingPaddleSquare(); else _paddles = new DrawingPaddle(); _paddles.SetPaddlesCount(paddleCount); } - protected DrawingBoat(int speed, float weight, Color bodyColor, int rollersAmount, int bulldozerWidth, int bulldozerHeight) + protected DrawingBoat(int speed, float weight, Color bodyColor, int paddleCount, int boatWidth, int boatHeight) { - this(speed, weight, bodyColor, rollersAmount); - _boatWidth = bulldozerWidth; - _boatHeight = bulldozerHeight; + this(speed, weight, bodyColor, paddleCount); + _boatWidth = boatWidth; + _boatHeight = boatHeight; } public void SetPosition(int x, int y, int width, int height) { @@ -89,7 +89,6 @@ public class DrawingBoat extends JComponent { return; } Color pen = new Color(0,0,0); - //границы лодки int [] pointsX = new int[]{(int)(_startPosX),(int)(_startPosX + 50),(int)(_startPosX + 70),(int)(_startPosX + 50),(int)(_startPosX)}; int [] pointsY = new int[]{(int)(_startPosY),(int)(_startPosY),(int)(_startPosY + 20),(int)(_startPosY + 40),(int)(_startPosY+40)}; diff --git a/src/DrawingHardPaddle.java b/src/DrawingHardPaddle.java deleted file mode 100644 index fa85ce2..0000000 --- a/src/DrawingHardPaddle.java +++ /dev/null @@ -1,72 +0,0 @@ -import java.awt.*; - -public class DrawingHardPaddle implements IDrawningObjectPaddle { - private AdditionalDirection _paddleEnum; - @Override - public void SetPaddlesCount(int rollersAmount) { - for (AdditionalDirection item: _paddleEnum.values()) { - if (item.getCount() == rollersAmount) { - _paddleEnum = item; - return; - } - } - } - @Override - public void DrawPaddles(Graphics gr, int _startPosPaddlesX, int _startPosPaddlessY, Color mainBrush) { - Graphics2D g=(Graphics2D)gr; - //цвет - Color br = new Color(0,0,0); - try { br = mainBrush; } - catch (Exception e) { - - } - _startPosPaddlesX +=40; - _startPosPaddlessY +=33; - if (_paddleEnum.getCount() >= 1) { - - paintPaddleUgol(g, _startPosPaddlesX-3, _startPosPaddlessY+5, _startPosPaddlessY + 16+5,mainBrush,false); - paintPaddle(g, _startPosPaddlesX, _startPosPaddlessY, _startPosPaddlessY + 16,mainBrush); - } - if (_paddleEnum.getCount() >= 2) { - - paintPaddleUgol(g, _startPosPaddlesX -10-3, _startPosPaddlessY -41+5, _startPosPaddlessY -51+5,mainBrush,true); - paintPaddle(g, _startPosPaddlesX -10, _startPosPaddlessY -41, _startPosPaddlessY -51,mainBrush); - } - if (_paddleEnum.getCount() >= 3) { - paintPaddleUgol(g, _startPosPaddlesX -20-3, _startPosPaddlessY+5, _startPosPaddlessY + 16+5,mainBrush,false); - paintPaddle(g, _startPosPaddlesX -20, _startPosPaddlessY, _startPosPaddlessY + 16,mainBrush); - - } - } - protected void paintPaddleUgol(Graphics2D g, int _startPosX, int _startPosY1,int _startPosY2, Color pen,boolean need){ - try { g.setPaint(pen); } - catch (Exception e) { - g.setPaint(Color.black); - } - if(need){ - g.fillPolygon(new int[]{_startPosX,_startPosX+5,_startPosX+10}, new int[]{_startPosY2,_startPosY2-10,_startPosY2},3); - g.setPaint(Color.black); - g.drawPolygon(new int[]{_startPosX,_startPosX+5,_startPosX+10}, new int[]{_startPosY2,_startPosY2-10,_startPosY2},3);} - else{ - g.fillPolygon(new int[]{_startPosX,_startPosX+5,_startPosX+10}, new int[]{_startPosY2,_startPosY2+10,_startPosY2},3); - g.setPaint(Color.black); - g.drawPolygon(new int[]{_startPosX,_startPosX+5,_startPosX+10}, new int[]{_startPosY2,_startPosY2+10,_startPosY2},3); - } - /* g.fillRect(_startPosX,_startPosY1,4,17); - g.fillOval(_startPosX-1, _startPosY2, 6, 10); - g.setPaint(Color.black); - g.drawRect(_startPosX,_startPosY1,4,17); - g.drawOval(_startPosX-1, _startPosY2, 6, 10);*/ - } - protected void paintPaddle(Graphics2D g, int _startPosX, int _startPosY1,int _startPosY2, Color pen){ - try { g.setPaint(pen); } - catch (Exception e) { - g.setPaint(Color.black); - } - g.fillRect(_startPosX,_startPosY1,4,17); - g.fillOval(_startPosX-1, _startPosY2, 6, 10); - g.setPaint(Color.black); - g.drawRect(_startPosX,_startPosY1,4,17); - g.drawOval(_startPosX-1, _startPosY2, 6, 10); - } -} \ No newline at end of file diff --git a/src/DrawingPaddle.java b/src/DrawingPaddle.java index f00d0cc..a47b64b 100644 --- a/src/DrawingPaddle.java +++ b/src/DrawingPaddle.java @@ -1,4 +1,3 @@ -import javax.swing.*; import java.awt.*; public class DrawingPaddle implements IDrawningObjectPaddle { private AdditionalDirection _paddle; @@ -14,7 +13,6 @@ public class DrawingPaddle implements IDrawningObjectPaddle { @Override public void DrawPaddles(Graphics gr, int _startPosPaddlesX, int _startPosPaddlessY, Color pen) { Graphics2D g=(Graphics2D)gr; - _startPosPaddlesX +=40; _startPosPaddlessY +=33; if (_paddle.getCount() >= 1) { @@ -29,9 +27,7 @@ public class DrawingPaddle implements IDrawningObjectPaddle { } protected void paintPaddle(Graphics2D g, int _startPosX, int _startPosY1,int _startPosY2, Color pen){ try { g.setPaint(pen); } - catch (Exception e) { - g.setPaint(Color.black); - } + catch (Exception e) { g.setPaint(Color.black); } g.fillRect(_startPosX,_startPosY1,4,17); g.fillOval(_startPosX-1, _startPosY2, 6, 10); g.setPaint(Color.black); diff --git a/src/DrawingPaddleSquare.java b/src/DrawingPaddleSquare.java new file mode 100644 index 0000000..fccf6f7 --- /dev/null +++ b/src/DrawingPaddleSquare.java @@ -0,0 +1,47 @@ +import java.awt.*; + +public class DrawingPaddleSquare implements IDrawningObjectPaddle { + private AdditionalDirection _paddleDirect; + + @Override + public void SetPaddlesCount(int paddlesCount) { + for (AdditionalDirection item : _paddleDirect.values()) { + if (item.getCount() == paddlesCount) { + _paddleDirect = item; + return; + } + } + } + @Override + public void DrawPaddles(Graphics gr, int _startPosPaddlesX, int _startPosPaddlessY, Color mainBrush) { + Graphics2D g = (Graphics2D) gr; + Color br = new Color(0, 0, 0); + try { + br = mainBrush; + } catch (Exception e) { + } + _startPosPaddlesX += 40; + _startPosPaddlessY += 33; + if (_paddleDirect.getCount() >= 1) { + paintPaddle(g, _startPosPaddlesX, _startPosPaddlessY, _startPosPaddlessY + 16, mainBrush); + } + if (_paddleDirect.getCount() >= 2) { + paintPaddle(g, _startPosPaddlesX - 10, _startPosPaddlessY - 41, _startPosPaddlessY - 51, mainBrush); + } + if (_paddleDirect.getCount() >= 3) { + paintPaddle(g, _startPosPaddlesX - 20, _startPosPaddlessY, _startPosPaddlessY + 16, mainBrush); + } + } + protected void paintPaddle(Graphics2D g, int _startPosX, int _startPosY1, int _startPosY2, Color pen) { + try { + g.setPaint(pen); + } catch (Exception e) { + g.setPaint(Color.black); + } + g.fillRect(_startPosX, _startPosY1, 4, 17); + g.fillRect(_startPosX - 5, _startPosY2, 13, 13); + g.setPaint(Color.black); + g.drawRect(_startPosX, _startPosY1, 4, 17); + g.drawRect(_startPosX - 5, _startPosY2, 13, 13); + } +} diff --git a/src/DrawingPaddleTriangle.java b/src/DrawingPaddleTriangle.java new file mode 100644 index 0000000..2cd084b --- /dev/null +++ b/src/DrawingPaddleTriangle.java @@ -0,0 +1,70 @@ +import java.awt.*; + +public class DrawingPaddleTriangle implements IDrawningObjectPaddle { + private AdditionalDirection _paddleDirect; + + @Override + public void SetPaddlesCount(int paddlesCount) { + for (AdditionalDirection item : _paddleDirect.values()) { + if (item.getCount() == paddlesCount) { + _paddleDirect = item; + return; + } + } + } + + @Override + public void DrawPaddles(Graphics gr, int _startPosPaddlesX, int _startPosPaddlessY, Color mainBrush) { + Graphics2D g = (Graphics2D) gr; + + Color br = new Color(0, 0, 0); + try { + br = mainBrush; + } catch (Exception e) { + } + _startPosPaddlesX += 40; + _startPosPaddlessY += 33; + if (_paddleDirect.getCount() >= 1) { + paintPaddleTriangle(g, _startPosPaddlesX - 3, _startPosPaddlessY + 5, _startPosPaddlessY + 16 + 5, mainBrush, false); + paintPaddle(g, _startPosPaddlesX, _startPosPaddlessY, _startPosPaddlessY + 16, mainBrush); + } + if (_paddleDirect.getCount() >= 2) { + paintPaddleTriangle(g, _startPosPaddlesX - 10 - 3, _startPosPaddlessY - 41 + 5, _startPosPaddlessY - 51 + 5, mainBrush, true); + paintPaddle(g, _startPosPaddlesX - 10, _startPosPaddlessY - 41, _startPosPaddlessY - 51, mainBrush); + } + if (_paddleDirect.getCount() >= 3) { + paintPaddleTriangle(g, _startPosPaddlesX - 20 - 3, _startPosPaddlessY + 5, _startPosPaddlessY + 16 + 5, mainBrush, false); + paintPaddle(g, _startPosPaddlesX - 20, _startPosPaddlessY, _startPosPaddlessY + 16, mainBrush); + } + } + + protected void paintPaddleTriangle(Graphics2D g, int _startPosX, int _startPosY1, int _startPosY2, Color pen, boolean need) { + try { + g.setPaint(pen); + } catch (Exception e) { + g.setPaint(Color.black); + } + if (need) { + g.fillPolygon(new int[]{_startPosX, _startPosX + 5, _startPosX + 10}, new int[]{_startPosY2, _startPosY2 - 10, _startPosY2}, 3); + g.setPaint(Color.black); + g.drawPolygon(new int[]{_startPosX, _startPosX + 5, _startPosX + 10}, new int[]{_startPosY2, _startPosY2 - 10, _startPosY2}, 3); + } else { + g.fillPolygon(new int[]{_startPosX, _startPosX + 5, _startPosX + 10}, new int[]{_startPosY2, _startPosY2 + 10, _startPosY2}, 3); + g.setPaint(Color.black); + g.drawPolygon(new int[]{_startPosX, _startPosX + 5, _startPosX + 10}, new int[]{_startPosY2, _startPosY2 + 10, _startPosY2}, 3); + } + } + + protected void paintPaddle(Graphics2D g, int _startPosX, int _startPosY1, int _startPosY2, Color pen) { + try { + g.setPaint(pen); + } catch (Exception e) { + g.setPaint(Color.black); + } + g.fillRect(_startPosX, _startPosY1, 4, 17); + g.fillOval(_startPosX - 1, _startPosY2, 6, 10); + g.setPaint(Color.black); + g.drawRect(_startPosX, _startPosY1, 4, 17); + g.drawOval(_startPosX - 1, _startPosY2, 6, 10); + } +} \ No newline at end of file diff --git a/src/DrawningHard2Paddle.java b/src/DrawningHard2Paddle.java deleted file mode 100644 index 789f250..0000000 --- a/src/DrawningHard2Paddle.java +++ /dev/null @@ -1,47 +0,0 @@ -import java.awt.*; - -public class DrawningHard2Paddle implements IDrawningObjectPaddle { - private AdditionalDirection _paddleEnum; - @Override - public void SetPaddlesCount(int paddlesCount) { - for (AdditionalDirection item: _paddleEnum.values()) { - if (item.getCount() == paddlesCount) { - _paddleEnum = item; - return; - } - } - } - @Override - public void DrawPaddles(Graphics gr, int _startPosPaddlesX, int _startPosPaddlessY, Color mainBrush) { - Graphics2D g=(Graphics2D)gr; - //цвет - Color br = new Color(0,0,0); - try { br = mainBrush; } - catch (Exception e) { - - } - _startPosPaddlesX +=40; - _startPosPaddlessY +=33; - if (_paddleEnum.getCount() >= 1) { - paintPaddle(g, _startPosPaddlesX, _startPosPaddlessY, _startPosPaddlessY + 16,mainBrush); - } - if (_paddleEnum.getCount() >= 2) { - paintPaddle(g, _startPosPaddlesX -10, _startPosPaddlessY -41, _startPosPaddlessY -51,mainBrush); - } - if (_paddleEnum.getCount() >= 3) { - paintPaddle(g, _startPosPaddlesX -20, _startPosPaddlessY, _startPosPaddlessY + 16,mainBrush); - - } - } - protected void paintPaddle(Graphics2D g, int _startPosX, int _startPosY1,int _startPosY2, Color pen){ - try { g.setPaint(pen); } - catch (Exception e) { - g.setPaint(Color.black); - } - g.fillRect(_startPosX,_startPosY1,4,17); - g.fillRect(_startPosX-5, _startPosY2, 13, 13); - g.setPaint(Color.black); - g.drawRect(_startPosX,_startPosY1,4,17); - g.drawRect(_startPosX-5, _startPosY2, 13, 13); - } -} diff --git a/src/DrawningMotorBoat.java b/src/DrawningMotorBoat.java index 3607b34..cecb9cd 100644 --- a/src/DrawningMotorBoat.java +++ b/src/DrawningMotorBoat.java @@ -1,77 +1,60 @@ import java.awt.*; -public class DrawningMotorBoat extends DrawingBoat{ - public DrawningMotorBoat(int speed, float weight, Color bodyColor, int paddleamount, Color dopColor, boolean attachment, boolean ripper) - { - super(speed, weight, bodyColor, paddleamount, 138, 78); - Boat = new EntityMotorBoat(speed, weight, bodyColor, dopColor, attachment, ripper); +public class DrawningMotorBoat extends DrawingBoat { + public DrawningMotorBoat(int speed, float weight, Color bodyColor, int paddleCount, Color dopColor, boolean nose, boolean side) { + super(speed, weight, bodyColor, paddleCount, 138, 78); + Boat = new EntityMotorBoat(speed, weight, bodyColor, dopColor, nose, side); } + @Override - public void paintComponent(Graphics gr) - { + public void paintComponent(Graphics gr) { boolean check = Boat instanceof EntityMotorBoat; if (!check) { return; } - EntityMotorBoat bulldozer = (EntityMotorBoat) Boat; - //_startPosY+=40; - Graphics2D g=(Graphics2D)gr; - Color dopBrush = bulldozer.DopColor(); + EntityMotorBoat boat = (EntityMotorBoat) Boat; + Graphics2D g = (Graphics2D) gr; + Color dopBrush = boat.DopColor(); gr.setColor(dopBrush); - g.fillOval( (int)_startPosX - 17, (int)_startPosY - 24, 14, 5); + g.fillOval((int) _startPosX - 17, (int) _startPosY - 24, 14, 5); gr.setColor(Color.BLACK); - g.drawOval((int) _startPosX - 17, (int)_startPosY - 24, 14, 5); + g.drawOval((int) _startPosX - 17, (int) _startPosY - 24, 14, 5); gr.setColor(dopBrush); - g.fillRect((int) _startPosX - 10, (int)_startPosY - 30, 10, 20); + g.fillRect((int) _startPosX - 10, (int) _startPosY - 30, 10, 20); gr.setColor(Color.BLACK); - g.drawRect( (int)_startPosX - 10, (int)_startPosY - 30, 10, 20); + g.drawRect((int) _startPosX - 10, (int) _startPosY - 30, 10, 20); int[] pointsx; int[] pointsy; - if (bulldozer.Attachment()) - { - pointsx = new int[]{(int)(_startPosX),(int)(_startPosX),(int)(_startPosX+50),(int)(_startPosX+50)}; - pointsy = new int[] - { - (int)(_startPosY-50),(int)(_startPosY+10),(int)(_startPosY),(int)(_startPosY-40) - }; + if (boat.Side()) { + pointsx = new int[]{(int) (_startPosX), (int) (_startPosX), (int) (_startPosX + 50), (int) (_startPosX + 50)}; + pointsy = new int[]{(int) (_startPosY - 50), (int) (_startPosY + 10), (int) (_startPosY), (int) (_startPosY - 40)}; gr.setColor(dopBrush); - g.fillPolygon(pointsx,pointsy,4); + g.fillPolygon(pointsx, pointsy, 4); gr.setColor(Color.BLACK); - g.drawPolygon(pointsx,pointsy,4); + g.drawPolygon(pointsx, pointsy, 4); } - - /* _startPosX -= 15; - _startPosY -= 5;*/ - if (bulldozer.Ripper()) - { - pointsx = new int[]{(int)(_startPosX)+50,(int)(_startPosX)+80,(int)(_startPosX+50)}; - pointsy = new int[]{(int)(_startPosY-40),(int)(_startPosY-20),(int)(_startPosY)}; + if (boat.Nose()) { + pointsx = new int[]{(int) (_startPosX) + 50, (int) (_startPosX) + 80, (int) (_startPosX + 50)}; + pointsy = new int[]{(int) (_startPosY - 40), (int) (_startPosY - 20), (int) (_startPosY)}; gr.setColor(dopBrush); - g.fillPolygon(pointsx,pointsy,3); + g.fillPolygon(pointsx, pointsy, 3); gr.setColor(Color.BLACK); - g.drawPolygon(pointsx,pointsy,3); + g.drawPolygon(pointsx, pointsy, 3); } - _startPosY-=40; - /* _startPosX += 15; - _startPosY += 5;*/ + _startPosY -= 40; super.paintComponent(gr); - _startPosY+=40; + _startPosY += 40; - pointsx = new int[] - { - (int)(_startPosX)+50,(int)(_startPosX)+57,(int)(_startPosX+50) }; - pointsy = new int[] - { - (int)(_startPosY-34),(int)(_startPosY-20),(int)(_startPosY-6) - }; + pointsx = new int[]{(int) (_startPosX) + 50, (int) (_startPosX) + 57, (int) (_startPosX + 50)}; + pointsy = new int[]{(int) (_startPosY - 34), (int) (_startPosY - 20), (int) (_startPosY - 6)}; gr.setColor(Color.CYAN); - g.fillPolygon(pointsx,pointsy,3); + g.fillPolygon(pointsx, pointsy, 3); gr.setColor(Color.BLACK); ((Graphics2D) gr).setStroke(new BasicStroke(1)); - g.drawPolygon(pointsx,pointsy,3); + g.drawPolygon(pointsx, pointsy, 3); } } diff --git a/src/DrawningObjectBoat.java b/src/DrawningObjectBoat.java index b9c62c5..f276617 100644 --- a/src/DrawningObjectBoat.java +++ b/src/DrawningObjectBoat.java @@ -12,22 +12,18 @@ public class DrawningObjectBoat implements IDrawningObject{ } return 0; } - @Override public void SetObject(int x, int y, int width, int height) { _boat.SetPosition(x+20, y+50, width, height); } - @Override public void MoveObject(Direction direction) { _boat.MoveTransport(direction); } - @Override public void DrawingObject(Graphics g) { _boat.paintComponent(g); } - @Override public float[] GetCurrentPosition() { diff --git a/src/EntityBoat.java b/src/EntityBoat.java index 5f02dd9..42dc614 100644 --- a/src/EntityBoat.java +++ b/src/EntityBoat.java @@ -3,7 +3,9 @@ import java.util.Random; public class EntityBoat { private int speed; - public int Speed() { return speed; } + public int Speed() { + return speed; + } private float weight; public float Weight() { return weight; @@ -12,10 +14,10 @@ public class EntityBoat { public Color BodyColor() { return bodyColor; } - public float Step() - { return Speed() * 20 / Weight(); } - public EntityBoat(int speed, float weight, Color bodyColor) - { + public float Step() { + return Speed() * 20 / Weight(); + } + public EntityBoat(int speed, float weight, Color bodyColor) { Random random = new Random(); this.speed = speed <= 0 ? random.nextInt(50, 150) : speed; this.weight = weight <= 0 ? random.nextInt(40, 70) : weight; diff --git a/src/EntityMotorBoat.java b/src/EntityMotorBoat.java index 62771ad..39949a1 100644 --- a/src/EntityMotorBoat.java +++ b/src/EntityMotorBoat.java @@ -1,21 +1,16 @@ import java.awt.*; - public class EntityMotorBoat extends EntityBoat{ - // Дополнительный цвет private Color dopColor; public Color DopColor() { return dopColor; } - // Признак наличия отвала - private boolean attachment; - public boolean Attachment() { return attachment; } - // Признак наличия рыхлителя - private boolean ripper; - public boolean Ripper() { return ripper; } - // Инициализация свойств - public EntityMotorBoat(int speed, float weight, Color bodyColor, Color dopColor, boolean attachment, boolean ripper) + private boolean nose; + public boolean Nose() { return nose; } + private boolean side; + public boolean Side() { return side; } + public EntityMotorBoat(int speed, float weight, Color bodyColor, Color dopColor, boolean nose, boolean side) { super(speed*100, weight, bodyColor); this.dopColor = dopColor; - this.attachment = attachment; - this.ripper = ripper; + this.nose = nose; + this.side = side; } } diff --git a/src/FormBoat.java b/src/FormBoat.java index c58e798..6765d3a 100644 --- a/src/FormBoat.java +++ b/src/FormBoat.java @@ -3,8 +3,6 @@ import java.awt.*; import java.awt.event.*; import java.util.Random; public class FormBoat extends JFrame { - - private JPanel mainPanel; private JPanel statusStrip; private JLabel toolStripStatusLabelSpeed; @@ -26,8 +24,6 @@ public class FormBoat extends JFrame { private int pictureBoxBoatWidth; private int pictureBoxBoatHeight; ButtonGroup buttonGroupPaddlesRadBut; - - /* public FormBoat() { super("Моторная лодка"); buttonGroupPaddlesRadBut = new ButtonGroup(); @@ -36,7 +32,6 @@ public class FormBoat extends JFrame { buttonGroupPaddlesRadBut.add(radioButtonPaddle3); setPreferredSize(new Dimension(1000, 700)); getContentPane().add(mainPanel); - buttonCreate.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { @@ -46,7 +41,7 @@ public class FormBoat extends JFrame { } Random random = new Random(); _boat = new DrawingBoat(random.nextInt(50, 150), random.nextInt(40, 70), new Color(random.nextInt(0, 256), - random.nextInt(0, 256), random.nextInt(0, 256)), GetRollersAmount()); + random.nextInt(0, 256), random.nextInt(0, 256)), GetPaddleCount()); SetData(); } }); @@ -60,7 +55,7 @@ public class FormBoat extends JFrame { Random random = new Random(); _boat = new DrawningMotorBoat(random.nextInt(30, 50), random.nextInt(1000, 2000), new Color(random.nextInt(0, 256), random.nextInt(0, 256), - random.nextInt(0, 256)), GetRollersAmount(), new Color(random.nextInt(0, 256), random.nextInt(0, 256), + random.nextInt(0, 256)), GetPaddleCount(), new Color(random.nextInt(0, 256), random.nextInt(0, 256), random.nextInt(0, 256)), random.nextBoolean(), random.nextBoolean()); SetData(); } @@ -79,7 +74,6 @@ public class FormBoat extends JFrame { pictureBoxBoat.add(_boat, BorderLayout.CENTER); } }); - //джижение ButtonsMove buttonsMove = new ButtonsMove(); buttonUp.setName("Up"); buttonLeft.setName("Left"); @@ -112,7 +106,6 @@ public class FormBoat extends JFrame { } } } - private void ChangePictureBoxBoatBorders() { char[] temp = pictureBoxBoat.getSize().toString().toCharArray(); for (int i = 0; i < temp.length; i++) { @@ -125,7 +118,7 @@ public class FormBoat extends JFrame { pictureBoxBoatWidth = Integer.parseInt(parameters[1]); pictureBoxBoatHeight = Integer.parseInt(parameters[2]); } - private int GetRollersAmount() { + private int GetPaddleCount() { if (radioButtonPaddle1.isSelected()) { return 1; } @@ -134,5 +127,5 @@ public class FormBoat extends JFrame { } else { return 3; } - }*/ + } } diff --git a/src/FormMap.java b/src/FormMap.java index f833c0c..60717ad 100644 --- a/src/FormMap.java +++ b/src/FormMap.java @@ -5,14 +5,12 @@ import java.awt.image.BufferedImage; import java.util.Random; public class FormMap extends JFrame { public static void main(String[] args) { - FormMap window = new FormMap(); window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); window.pack(); window.setLocationRelativeTo(null); window.setVisible(true); } - private JPanel mainPanel; private JPanel statusStrip; private JLabel toolStripStatusLabelSpeed; @@ -46,13 +44,12 @@ public class FormMap extends JFrame { buttonGroupPaddlesRadBut.add(radioButtonPaddle3); setPreferredSize(new Dimension(1000, 700)); getContentPane().add(mainPanel); - buttonCreate.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { Random random = new Random(); var _boat = new DrawingBoat(random.nextInt(50, 150), random.nextInt(40, 70), new Color(random.nextInt(0, 256), - random.nextInt(0, 256), random.nextInt(0, 256)), GetRollersAmount()); + random.nextInt(0, 256), random.nextInt(0, 256)), GetPaddleCount()); SetData(_boat); } }); @@ -62,7 +59,7 @@ public class FormMap extends JFrame { Random random = new Random(); var _boat = new DrawningMotorBoat(random.nextInt(30, 50), random.nextInt(1000, 2000), new Color(random.nextInt(0, 256), random.nextInt(0, 256), - random.nextInt(0, 256)), GetRollersAmount(), new Color(random.nextInt(0, 256), random.nextInt(0, 256), + random.nextInt(0, 256)), GetPaddleCount(), new Color(random.nextInt(0, 256), random.nextInt(0, 256), random.nextInt(0, 256)), random.nextBoolean(), random.nextBoolean()); SetData(_boat); } @@ -82,8 +79,6 @@ public class FormMap extends JFrame { } } }); - - //джижение ButtonsMove buttonsMove = new ButtonsMove(); buttonUp.setName("Up"); buttonLeft.setName("Left"); @@ -100,7 +95,6 @@ public class FormMap extends JFrame { pictureBoxBoat.remove(pictureLabel); } catch (Exception c) { } ChangePictureBoxBoatBorders(); - // _boat.SetPosition(random.nextInt(20, 100), random.nextInt(50, 100), pictureBoxBoatWidth, pictureBoxBoatHeight); toolStripStatusLabelSpeed.setText("Скорость: " + _boat.Boat.Speed()); toolStripStatusLabelWeight.setText("Вес: " + _boat.Boat.Weight()); toolStripStatusLabelBodyColor.setText("Цвет: " + Integer.toHexString(_boat.Boat.BodyColor().getRGB())); @@ -131,7 +125,6 @@ public class FormMap extends JFrame { pictureBoxBoat.add(pictureLabel, BorderLayout.CENTER); } } - private void ChangePictureBoxBoatBorders() { char[] temp = pictureBoxBoat.getSize().toString().toCharArray(); for (int i = 0; i < temp.length; i++) { @@ -144,7 +137,7 @@ public class FormMap extends JFrame { pictureBoxBoatWidth = Integer.parseInt(parameters[1]); pictureBoxBoatHeight = Integer.parseInt(parameters[2]); } - private int GetRollersAmount() { + private int GetPaddleCount() { if (radioButtonPaddle1.isSelected()) { return 1; } diff --git a/src/IDrawningObject.java b/src/IDrawningObject.java index 1a5f9ea..7f47ba9 100644 --- a/src/IDrawningObject.java +++ b/src/IDrawningObject.java @@ -2,12 +2,8 @@ import java.awt.*; public interface IDrawningObject { public float Step(); - // Установка позиции объекта void SetObject(int x, int y, int width, int height); - // Изменение направления пермещения объекта void MoveObject(Direction direction); - // Отрисовка объекта void DrawingObject(Graphics g); - // Получение текущей позиции объекта float[] GetCurrentPosition(); } \ No newline at end of file diff --git a/src/IDrawningObjectPaddle.java b/src/IDrawningObjectPaddle.java index dcb207d..c844b6a 100644 --- a/src/IDrawningObjectPaddle.java +++ b/src/IDrawningObjectPaddle.java @@ -1,8 +1,6 @@ import java.awt.*; public interface IDrawningObjectPaddle { - //свойство для передачи числового значения - void SetPaddlesCount(int rollersAmount); - //метод, принимающий параметры для отрисовки - void DrawPaddles(Graphics gr, int _startPosRollersX, int _startPosRollersY, Color mainBrush); + void SetPaddlesCount(int paddleCount); + void DrawPaddles(Graphics gr, int _startPosPadX, int _startPosPadY, Color mainBrush); } diff --git a/src/SeaMap.java b/src/SeaMap.java index 3912141..1b15a11 100644 --- a/src/SeaMap.java +++ b/src/SeaMap.java @@ -2,43 +2,35 @@ import java.awt.*; public class SeaMap extends SimpleMap { private final Color barrierColor = Color.BLUE; - // Цвет участка открытого private final Color roadColor = Color.CYAN; - @Override protected void GenerateMap() { _map = new int[100][100]; - _size_x = (float)_width / _map.length; - _size_y = (float)_height / _map[0].length; + _size_x = (float) _width / _map.length; + _size_y = (float) _height / _map[0].length; int counter = 0; - for (int i = 0; i < _map.length; ++i) - { - for (int j = 0; j < _map[0].length; ++j) - { + for (int i = 0; i < _map.length; ++i) { + for (int j = 0; j < _map[0].length; ++j) { _map[i][j] = _freeRoad; } } - while (counter < 10) - { + while (counter < 10) { int x = _random.nextInt(0, 100); int y = _random.nextInt(0, 100); - if (_map[x][y] == _freeRoad) - { + if (_map[x][y] == _freeRoad) { _map[x][y] = _barrier; counter++; } } } - @Override protected void DrawRoadPart(Graphics g, int i, int j) { g.setColor(roadColor); - g.fillRect((int)(i * _size_x), (int)(j * _size_y), (int)(i * (_size_x + 1)), (int)(j * (_size_y + 1))); + g.fillRect((int) (i * _size_x), (int) (j * _size_y), (int) (i * (_size_x + 1)), (int) (j * (_size_y + 1))); } - @Override protected void DrawBarrierPart(Graphics g, int i, int j) { g.setColor(barrierColor); - g.fillRect((int)(i * _size_x), (int)(j * _size_y),(int) (i * (_size_x + 1)), (int)(j * (_size_y + 1))); + g.fillRect((int) (i * _size_x), (int) (j * _size_y), (int) (i * (_size_x + 1)), (int) (j * (_size_y + 1))); } } \ No newline at end of file diff --git a/src/SimpleMap.java b/src/SimpleMap.java index b34bf51..01617ad 100644 --- a/src/SimpleMap.java +++ b/src/SimpleMap.java @@ -1,45 +1,36 @@ import java.awt.*; public class SimpleMap extends AbstractMap { - private final Color barrierColor = Color.BLACK; - // Цвет участка открытого private final Color roadColor = Color.GRAY; - @Override protected void GenerateMap() { _map = new int[100][100]; - _size_x = (float)_width / _map.length; - _size_y = (float)_height / _map[0].length; + _size_x = (float) _width / _map.length; + _size_y = (float) _height / _map[0].length; int counter = 0; - for (int i = 0; i < _map.length; ++i) - { - for (int j = 0; j < _map[0].length; ++j) - { + for (int i = 0; i < _map.length; ++i) { + for (int j = 0; j < _map[0].length; ++j) { _map[i][j] = _freeRoad; } } - while (counter < 10) - { + while (counter < 10) { int x = _random.nextInt(0, 100); int y = _random.nextInt(0, 100); - if (_map[x][y] == _freeRoad) - { + if (_map[x][y] == _freeRoad) { _map[x][y] = _barrier; counter++; } } } - @Override protected void DrawRoadPart(Graphics g, int i, int j) { g.setColor(roadColor); - g.fillRect((int)(i * _size_x), (int)(j * _size_y), (int)(i * (_size_x + 1)), (int)(j * (_size_y + 1))); + g.fillRect((int) (i * _size_x), (int) (j * _size_y), (int) (i * (_size_x + 1)), (int) (j * (_size_y + 1))); } - @Override protected void DrawBarrierPart(Graphics g, int i, int j) { g.setColor(barrierColor); - g.fillRect((int)(i * _size_x), (int)(j * _size_y),(int) (i * (_size_x + 1)), (int)(j * (_size_y + 1))); + g.fillRect((int) (i * _size_x), (int) (j * _size_y), (int) (i * (_size_x + 1)), (int) (j * (_size_y + 1))); } } \ No newline at end of file -- 2.25.1