From b74e5b9fba9077eb5cc753ea8b96f62cca8bde1e Mon Sep 17 00:00:00 2001 From: prodigygirl Date: Sat, 22 Oct 2022 21:11:43 +0400 Subject: [PATCH 01/16] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=BA=D0=BE=D0=BD=D1=81=D1=82=D1=80?= =?UTF-8?q?=D1=83=D0=BA=D1=82=D0=BE=D1=80=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/DrawingArmoredCar.java | 5 ++--- src/main/java/EntityArmoredCar.java | 2 +- src/main/java/FormArmoredCar.java | 3 +-- 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/src/main/java/DrawingArmoredCar.java b/src/main/java/DrawingArmoredCar.java index b4fa674..a3bd38b 100644 --- a/src/main/java/DrawingArmoredCar.java +++ b/src/main/java/DrawingArmoredCar.java @@ -22,9 +22,8 @@ public class DrawingArmoredCar { return armoredCar; } - public void Init(int speed, float weight, Color bodyColor) { - this.armoredCar = new EntityArmoredCar(); - this.armoredCar.init(speed, weight, bodyColor); + public DrawingArmoredCar(int speed, float weight, Color bodyColor) { + this.armoredCar = new EntityArmoredCar(speed, weight, bodyColor); Random r = new Random(); this.drawingCaterpillar = new DrawingCaterpillar(); this.drawingCaterpillar.Init(r.nextInt(4, 7), bodyColor); diff --git a/src/main/java/EntityArmoredCar.java b/src/main/java/EntityArmoredCar.java index f1d54e5..4ad1d9f 100644 --- a/src/main/java/EntityArmoredCar.java +++ b/src/main/java/EntityArmoredCar.java @@ -7,7 +7,7 @@ public class EntityArmoredCar { private Color bodyColor; public float step; - public void init(int speed, float weight, Color bodyColor) { + public EntityArmoredCar(int speed, float weight, Color bodyColor) { this.speed = speed; this.weight = weight; this.bodyColor = bodyColor; diff --git a/src/main/java/FormArmoredCar.java b/src/main/java/FormArmoredCar.java index 045cdaa..923ab88 100644 --- a/src/main/java/FormArmoredCar.java +++ b/src/main/java/FormArmoredCar.java @@ -42,8 +42,7 @@ public class FormArmoredCar extends JFrame{ @Override public void actionPerformed(ActionEvent actionEvent) { Random rnd = new Random(); - armoredCar = new DrawingArmoredCar(); - armoredCar.Init(rnd.nextInt(100,300), rnd.nextInt(1000, 2000), + armoredCar = new DrawingArmoredCar(rnd.nextInt(100,300), rnd.nextInt(1000, 2000), new Color(rnd.nextInt(256), rnd.nextInt(256), rnd.nextInt(256))); armoredCar.SetPosition(rnd.nextInt(10, 100), rnd.nextInt(10, 100), -- 2.25.1 From 4d09e5187d9915adf842d208be041769064bc35e Mon Sep 17 00:00:00 2001 From: prodigygirl Date: Sat, 22 Oct 2022 21:42:08 +0400 Subject: [PATCH 02/16] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=B2=D1=82=D0=BE=D1=80=D0=BE=D0=B3?= =?UTF-8?q?=D0=BE=20=D0=BA=D0=BE=D0=BD=D1=81=D1=82=D1=80=D1=83=D0=BA=D1=82?= =?UTF-8?q?=D0=BE=D1=80=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/DrawingArmoredCar.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/main/java/DrawingArmoredCar.java b/src/main/java/DrawingArmoredCar.java index a3bd38b..6b0fe3f 100644 --- a/src/main/java/DrawingArmoredCar.java +++ b/src/main/java/DrawingArmoredCar.java @@ -12,9 +12,9 @@ public class DrawingArmoredCar { private int pictureHeight; - private static final int carWidth = 80; + private int carWidth = 80; - private static final int carHeight = 50; + private int carHeight = 50; private DrawingCaterpillar drawingCaterpillar; @@ -29,6 +29,12 @@ public class DrawingArmoredCar { this.drawingCaterpillar.Init(r.nextInt(4, 7), bodyColor); } + protected DrawingArmoredCar(int speed, float weight, Color bodyColor, int carWidth, int carHeight) { + this(speed, weight, bodyColor); + this.carWidth = carWidth; + this.carHeight = carHeight; + } + public void SetPosition(int x, int y, int width, int height) { if (x >= 0 && y >= 0 && x + carWidth < width && y + carHeight < height) { startPosX = x; -- 2.25.1 From 5e6e077ef5adad0dec10ea782c2004acd7dacc88 Mon Sep 17 00:00:00 2001 From: prodigygirl Date: Sat, 22 Oct 2022 21:56:39 +0400 Subject: [PATCH 03/16] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=BA=D0=BB=D0=B0=D1=81=D1=81=D0=BE?= =?UTF-8?q?=D0=B2=20=D0=B4=D0=BB=D1=8F=20=D0=BF=D1=80=D0=BE=D0=B4=D0=B2?= =?UTF-8?q?=D0=B8=D0=BD=D1=83=D1=82=D0=BE=D0=B3=D0=BE=20=D0=BE=D0=B1=D1=8A?= =?UTF-8?q?=D0=B5=D0=BA=D1=82=D0=B0,=20=D0=B8=D0=B7=D0=BC=D0=B5=D0=BD?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=BC=D0=BE=D0=B4=D0=B8=D1=84=D0=B8?= =?UTF-8?q?=D0=BA=D0=B0=D1=82=D0=BE=D1=80=D0=BE=D0=B2=20=D0=BF=D0=BE=D0=BB?= =?UTF-8?q?=D0=B5=D0=B9=20=D0=BA=D0=BB=D0=B0=D1=81=D1=81=D0=B0=20=D0=B1?= =?UTF-8?q?=D0=B0=D0=B7=D0=BE=D0=B2=D0=BE=D0=B3=D0=BE=20=D0=BE=D0=B1=D1=8A?= =?UTF-8?q?=D0=B5=D0=BA=D1=82=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/DrawingArmoredCar.java | 8 ++++---- src/main/java/DrawingTank.java | 30 ++++++++++++++++++++++++++++ src/main/java/EntityTank.java | 26 ++++++++++++++++++++++++ 3 files changed, 60 insertions(+), 4 deletions(-) create mode 100644 src/main/java/DrawingTank.java create mode 100644 src/main/java/EntityTank.java diff --git a/src/main/java/DrawingArmoredCar.java b/src/main/java/DrawingArmoredCar.java index 6b0fe3f..005bfc6 100644 --- a/src/main/java/DrawingArmoredCar.java +++ b/src/main/java/DrawingArmoredCar.java @@ -2,11 +2,11 @@ import java.awt.*; import java.util.Random; public class DrawingArmoredCar { - private EntityArmoredCar armoredCar; + protected EntityArmoredCar armoredCar; - private float startPosX; + protected float startPosX; - private float startPosY; + protected float startPosY; private int pictureWidth; @@ -16,7 +16,7 @@ public class DrawingArmoredCar { private int carHeight = 50; - private DrawingCaterpillar drawingCaterpillar; + protected DrawingCaterpillar drawingCaterpillar; public EntityArmoredCar getArmoredCar() { return armoredCar; diff --git a/src/main/java/DrawingTank.java b/src/main/java/DrawingTank.java new file mode 100644 index 0000000..844548e --- /dev/null +++ b/src/main/java/DrawingTank.java @@ -0,0 +1,30 @@ +import java.awt.*; + +public class DrawingTank extends DrawingArmoredCar{ + public DrawingTank(int speed, float weight, Color bodyColor, Color dopColor, + boolean towerWeapon, boolean AMachineGun) { + super(speed, weight, bodyColor); + armoredCar = new EntityTank(speed, weight, bodyColor, dopColor, towerWeapon, AMachineGun); + } + @Override + public void DrawTransport(Graphics2D g) { + if (!(armoredCar instanceof EntityTank tank)) { + return; + } + + if (tank.isTowerWeapon()) { + g.setColor(tank.getDopColor()); + g.fillRect((int)startPosX + 40, (int)startPosY, 5, 20); + g.fillRect((int)startPosX + 40, (int)startPosY, 40, 5); + g.fillOval((int)startPosX + 27, (int)startPosY + 7, 30, 10); + } + if (tank.isAMachineGun()) { + g.setColor(tank.getDopColor()); + g.fillRect((int)startPosX + 60, (int)startPosY + 15, 7, 10); + g.fillRect((int)startPosX + 60, (int)startPosY + 17, 20, 5); + } + startPosY += 10; + super.DrawTransport(g); + startPosY -= 10; + } +} diff --git a/src/main/java/EntityTank.java b/src/main/java/EntityTank.java new file mode 100644 index 0000000..e8b0211 --- /dev/null +++ b/src/main/java/EntityTank.java @@ -0,0 +1,26 @@ +import java.awt.*; + +public class EntityTank extends EntityArmoredCar{ + private Color dopColor; + private boolean towerWeapon; + private boolean AMachineGun; + + public Color getDopColor() { + return dopColor; + } + + public boolean isTowerWeapon() { + return towerWeapon; + } + + public boolean isAMachineGun() { + return AMachineGun; + } + + public EntityTank(int speed, float weight, Color bodyColor, Color dopColor, boolean towerWeapon, boolean AMachineGun) { + super(speed, weight, bodyColor); + this.dopColor = dopColor; + this.towerWeapon = towerWeapon; + this.AMachineGun = AMachineGun; + } +} -- 2.25.1 From 2fd750d255a7962846ffe65d2b00b6fe7381bb7a Mon Sep 17 00:00:00 2001 From: prodigygirl Date: Sat, 22 Oct 2022 22:46:44 +0400 Subject: [PATCH 04/16] =?UTF-8?q?=D0=9F=D0=B5=D1=80=D0=B5=D0=B2=D0=BE?= =?UTF-8?q?=D0=B4=20=D0=BD=D0=B0=20=D0=BA=D0=BE=D0=BD=D1=81=D1=82=D1=80?= =?UTF-8?q?=D1=83=D0=BA=D1=82=D0=BE=D1=80=D1=8B=202?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/DrawingArmoredCar.java | 3 +-- src/main/java/DrawingCaterpillar.java | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/main/java/DrawingArmoredCar.java b/src/main/java/DrawingArmoredCar.java index 005bfc6..5e25e8b 100644 --- a/src/main/java/DrawingArmoredCar.java +++ b/src/main/java/DrawingArmoredCar.java @@ -25,8 +25,7 @@ public class DrawingArmoredCar { public DrawingArmoredCar(int speed, float weight, Color bodyColor) { this.armoredCar = new EntityArmoredCar(speed, weight, bodyColor); Random r = new Random(); - this.drawingCaterpillar = new DrawingCaterpillar(); - this.drawingCaterpillar.Init(r.nextInt(4, 7), bodyColor); + this.drawingCaterpillar = new DrawingCaterpillar(r.nextInt(4, 7), bodyColor); } protected DrawingArmoredCar(int speed, float weight, Color bodyColor, int carWidth, int carHeight) { diff --git a/src/main/java/DrawingCaterpillar.java b/src/main/java/DrawingCaterpillar.java index ae2fb0c..2270ca6 100644 --- a/src/main/java/DrawingCaterpillar.java +++ b/src/main/java/DrawingCaterpillar.java @@ -4,7 +4,7 @@ public class DrawingCaterpillar { private NumRinks numRinks = NumRinks.Four; private Color color; - public void Init(int n, Color color) { + public DrawingCaterpillar(int n, Color color) { setNumRinks(n); this.color = color; } -- 2.25.1 From 107ff418db5795c7dcdeb68d3af1eb3416b49f8a Mon Sep 17 00:00:00 2001 From: prodigygirl Date: Sat, 22 Oct 2022 22:50:30 +0400 Subject: [PATCH 05/16] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=BC=D0=B5=D1=82=D0=BE=D0=B4=D0=B0?= =?UTF-8?q?=20=D0=BF=D0=BE=D0=BB=D1=83=D1=87=D0=B5=D0=BD=D0=B8=D1=8F=20?= =?UTF-8?q?=D0=BA=D0=BE=D0=BE=D1=80=D0=B4=D0=B8=D0=BD=D0=B0=D1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/DrawingArmoredCar.java | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/main/java/DrawingArmoredCar.java b/src/main/java/DrawingArmoredCar.java index 5e25e8b..7766833 100644 --- a/src/main/java/DrawingArmoredCar.java +++ b/src/main/java/DrawingArmoredCar.java @@ -1,4 +1,5 @@ import java.awt.*; +import java.util.HashMap; import java.util.Random; public class DrawingArmoredCar { @@ -120,4 +121,14 @@ public class DrawingArmoredCar { startPosY = pictureHeight - carHeight; } } + + public HashMap GetCurrentPosition() + { + HashMap hashMap = new HashMap(); + hashMap.put("Left", startPosX); + hashMap.put("Right", startPosX + carWidth); + hashMap.put("Top", startPosY); + hashMap.put("Bottom", startPosY + carHeight); + return hashMap; + } } -- 2.25.1 From cdb5b9f8fe1d0e32f26f7a17b20737118d9a186c Mon Sep 17 00:00:00 2001 From: prodigygirl Date: Sat, 22 Oct 2022 22:50:54 +0400 Subject: [PATCH 06/16] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=B8=D0=BD=D1=82=D0=B5=D1=80=D1=84?= =?UTF-8?q?=D0=B5=D0=B9=D1=81=D0=B0=20=D0=B8=20=D0=BA=D0=BB=D0=B0=D1=81?= =?UTF-8?q?=D1=81=D0=B0=20=D0=BE=D1=82=D1=80=D0=B8=D1=81=D0=BE=D0=B2=D0=BA?= =?UTF-8?q?=D0=B8=20=D0=BE=D0=B1=D1=8A=D0=B5=D0=BA=D1=82=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/DrawingObjectArmoredCar.java | 40 ++++++++++++++++++++++ src/main/java/IDrawingObject.java | 14 ++++++++ 2 files changed, 54 insertions(+) create mode 100644 src/main/java/DrawingObjectArmoredCar.java create mode 100644 src/main/java/IDrawingObject.java diff --git a/src/main/java/DrawingObjectArmoredCar.java b/src/main/java/DrawingObjectArmoredCar.java new file mode 100644 index 0000000..6868e1e --- /dev/null +++ b/src/main/java/DrawingObjectArmoredCar.java @@ -0,0 +1,40 @@ +import java.awt.*; +import java.util.HashMap; + +public class DrawingObjectArmoredCar implements IDrawingObject{ + private DrawingArmoredCar armoredCar = null; + + public DrawingObjectArmoredCar(DrawingArmoredCar armoredCar) { + this.armoredCar = armoredCar; + } + + @Override + public float getStep() { + if (armoredCar != null) + return armoredCar.armoredCar.step; + return 0; + } + + @Override + public void SetObject(int x, int y, int width, int height) { + if (armoredCar != null) + armoredCar.SetPosition(x, y, width, height); + } + + @Override + public void MoveObject(Direction direction) { + if (armoredCar != null) + armoredCar.MoveTransport(direction); + } + + @Override + public void DrawingObject(Graphics2D g) { + if (armoredCar != null) + armoredCar.DrawTransport(g); + } + + @Override + public HashMap GetCurrentPosition() { + return armoredCar.GetCurrentPosition(); + } +} diff --git a/src/main/java/IDrawingObject.java b/src/main/java/IDrawingObject.java new file mode 100644 index 0000000..cf65865 --- /dev/null +++ b/src/main/java/IDrawingObject.java @@ -0,0 +1,14 @@ +import java.awt.*; +import java.util.HashMap; + +public interface IDrawingObject { + float getStep(); + + void SetObject(int x, int y, int width, int height); + + void MoveObject(Direction direction); + + void DrawingObject(Graphics2D g); + + HashMap GetCurrentPosition(); +} -- 2.25.1 From e720b435c51ad1a6f7e706d9899a7cd3cae6dc94 Mon Sep 17 00:00:00 2001 From: prodigygirl Date: Sat, 22 Oct 2022 22:53:40 +0400 Subject: [PATCH 07/16] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=B0=D0=B1=D1=81=D1=82=D1=80=D0=B0?= =?UTF-8?q?=D0=BA=D1=82=D0=BD=D0=BE=D0=B3=D0=BE=20=D0=BA=D0=BB=D0=B0=D1=81?= =?UTF-8?q?=D1=81=D0=B0=20=D0=BA=D0=B0=D1=80=D1=82=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/AbstractMap.java | 186 +++++++++++++++++++++++++++++++++ 1 file changed, 186 insertions(+) create mode 100644 src/main/java/AbstractMap.java diff --git a/src/main/java/AbstractMap.java b/src/main/java/AbstractMap.java new file mode 100644 index 0000000..c0af228 --- /dev/null +++ b/src/main/java/AbstractMap.java @@ -0,0 +1,186 @@ +import java.awt.*; +import java.awt.image.BufferedImage; +import java.util.HashMap; +import java.util.Random; + +public abstract class AbstractMap { + private IDrawingObject 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 Image CreateMap(int width, int height, IDrawingObject drawingObject) + { + this.width = width; + this.height = height; + this.drawingObject = drawingObject; + GenerateMap(); + while (!SetObjectOnMap()) + { + GenerateMap(); + } + return DrawMapWithObject(); + } + public Image MoveObject(Direction direction) + { + boolean flag = true; + float step = drawingObject.getStep(); + + HashMap hashMap = drawingObject.GetCurrentPosition(); + float left = hashMap.get("Left"); + float right = hashMap.get("Right"); + float top = hashMap.get("Top"); + float bottom = hashMap.get("Bottom"); + + int x1_obj_next = (int)((left - step) / size_x); + int y1_obj_next = (int)((top - step) / size_y); + int x2_obj_next = (int)((right + step) / size_x); + int y2_obj_next = (int)((bottom + step) / size_y); + + int x1_obj_current = (int)(left / size_x); + int y1_obj_current = (int)(top / size_y); + int x2_obj_current = (int)(right / size_x); + int y2_obj_current = (int)(bottom / size_y); + + // Проверка возможности перемещения + switch (direction) + { + case Left: + { + if (x1_obj_next < 0) + flag = false; + else + { + for (int i = x1_obj_next; i <= x1_obj_current; i++) + { + for (int j = y1_obj_current; j <= y2_obj_current; j++) + { + if (map[i][j] == _barrier) + flag = false; + } + } + } + break; + } + case Right: + { + if (x2_obj_next >= map.length) + flag = false; + else + { + for (int i = x2_obj_current; i <= x2_obj_next; i++) + { + for (int j = y1_obj_current; j <= y2_obj_current; j++) + { + if (map[i][j] == _barrier) + flag = false; + } + } + } + break; + } + case Up: + { + if (y1_obj_next < 0) + flag = false; + else + { + for (int i = x1_obj_current; i <= x2_obj_current; i++) + { + for (int j = y1_obj_next; j <= y1_obj_current; j++) + { + if (map[i][j] == _barrier) + flag = false; + } + } + } + break; + } + case Down: + { + if (y2_obj_next >= map.length) + flag = false; + else + { + for (int i = x1_obj_current; i <= x2_obj_current; i++) + { + for (int j = y2_obj_current; j <= y2_obj_next; j++) + { + if (map[i][j] == _barrier) + flag = false; + } + } + } + break; + } + } + + if (flag) + { + drawingObject.MoveObject(direction); + } + return DrawMapWithObject(); + } + 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); + + HashMap hashMap = drawingObject.GetCurrentPosition(); + float left = hashMap.get("Left"); + float right = hashMap.get("Right"); + float top = hashMap.get("Top"); + float bottom = hashMap.get("Bottom"); + + for (int i = (int)(x / size_x); i <= (int) (right / size_x); i++) + { + for (int j = (int)(y / size_y); j <= (int) (bottom / size_y); j++) + { + if (map[i][j] == _barrier) + { + return false; + } + } + } + return true; + } + private Image DrawMapWithObject() + { + BufferedImage img = new BufferedImage(width, height, BufferedImage.TYPE_INT_BGR); + if (drawingObject == null || map == null) + return img; + + Graphics2D gr = img.createGraphics(); + + 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 img; + } + protected abstract void GenerateMap(); + protected abstract void DrawRoadPart(Graphics2D g, int i, int j); + protected abstract void DrawBarrierPart(Graphics2D g, int i, int j); +} -- 2.25.1 From 25dad761456ef9e3d9b60d4e7ba3137c5cbc1716 Mon Sep 17 00:00:00 2001 From: prodigygirl Date: Sat, 22 Oct 2022 22:54:34 +0400 Subject: [PATCH 08/16] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=BA=D0=B0=D1=80=D1=82=D1=8B=20Sim?= =?UTF-8?q?pleMap?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/SimpleMap.java | 42 ++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 src/main/java/SimpleMap.java diff --git a/src/main/java/SimpleMap.java b/src/main/java/SimpleMap.java new file mode 100644 index 0000000..984b144 --- /dev/null +++ b/src/main/java/SimpleMap.java @@ -0,0 +1,42 @@ +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 < 50) + { + int x = random.nextInt(100); + int y = random.nextInt(100); + if (map[x][y] == _freeRoad) + { + map[x][y] = _barrier; + counter++; + } + } + } + + @Override + protected void DrawRoadPart(Graphics2D g, int i, int j) { + g.setColor(roadColor); + g.fillRect(i * (int)size_x, j * (int)size_y, (int)size_x, (int)size_y); + } + + @Override + protected void DrawBarrierPart(Graphics2D g, int i, int j) { + g.setColor(barrierColor); + g.fillRect(i * (int)size_x, j * (int)size_y, (int)size_x, (int)size_y); + } +} -- 2.25.1 From 4e3c6f6598cf6909bc1ee075df45835bb76840a8 Mon Sep 17 00:00:00 2001 From: prodigygirl Date: Sun, 23 Oct 2022 17:23:10 +0400 Subject: [PATCH 09/16] =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2?= =?UTF-8?q?=D0=BB=D0=B5=D0=BD=D0=B8=D1=8F,=20=D0=B7=D0=B0=D0=BC=D0=B5?= =?UTF-8?q?=D0=BD=D0=B0=20=D1=86=D0=B2=D0=B5=D1=82=D0=BE=D0=B2=20SimpleMap?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/AbstractMap.java | 4 +++- src/main/java/SimpleMap.java | 10 +++++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/main/java/AbstractMap.java b/src/main/java/AbstractMap.java index c0af228..773a30e 100644 --- a/src/main/java/AbstractMap.java +++ b/src/main/java/AbstractMap.java @@ -26,8 +26,11 @@ public abstract class AbstractMap { } return DrawMapWithObject(); } + public Image MoveObject(Direction direction) { + if (drawingObject == null) + return null; boolean flag = true; float step = drawingObject.getStep(); @@ -47,7 +50,6 @@ public abstract class AbstractMap { int x2_obj_current = (int)(right / size_x); int y2_obj_current = (int)(bottom / size_y); - // Проверка возможности перемещения switch (direction) { case Left: diff --git a/src/main/java/SimpleMap.java b/src/main/java/SimpleMap.java index 984b144..0cc26ec 100644 --- a/src/main/java/SimpleMap.java +++ b/src/main/java/SimpleMap.java @@ -2,7 +2,7 @@ import java.awt.*; public class SimpleMap extends AbstractMap{ private final Color barrierColor = Color.BLACK; - private final Color roadColor = Color.GRAY; + private final Color roadColor = Color.DARK_GRAY; @Override protected void GenerateMap() { map = new int[100][100]; @@ -31,12 +31,16 @@ public class SimpleMap extends AbstractMap{ @Override protected void DrawRoadPart(Graphics2D g, int i, int j) { g.setColor(roadColor); - g.fillRect(i * (int)size_x, j * (int)size_y, (int)size_x, (int)size_y); + int new_size_x = Math.round(size_x); + int new_size_y = Math.round(size_y); + g.fillRect(i * new_size_x, j * new_size_y, new_size_x, new_size_y); } @Override protected void DrawBarrierPart(Graphics2D g, int i, int j) { g.setColor(barrierColor); - g.fillRect(i * (int)size_x, j * (int)size_y, (int)size_x, (int)size_y); + int new_size_x = Math.round(size_x); + int new_size_y = Math.round(size_y); + g.fillRect(i * new_size_x, j * new_size_y, new_size_x, new_size_y); } } -- 2.25.1 From e2ac836193a29b82e4a9b8ffd4ed50ec43087bc6 Mon Sep 17 00:00:00 2001 From: prodigygirl Date: Sun, 23 Oct 2022 17:26:58 +0400 Subject: [PATCH 10/16] =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2?= =?UTF-8?q?=D0=BB=D0=B5=D0=BD=D0=B8=D1=8F=20=D0=B2=20=D0=BE=D1=82=D1=80?= =?UTF-8?q?=D0=B8=D1=81=D0=BE=D0=B2=D0=BA=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/DrawingArmoredCar.java | 16 +++++++++------- src/main/java/DrawingTank.java | 6 +++--- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/main/java/DrawingArmoredCar.java b/src/main/java/DrawingArmoredCar.java index 7766833..689c551 100644 --- a/src/main/java/DrawingArmoredCar.java +++ b/src/main/java/DrawingArmoredCar.java @@ -89,17 +89,19 @@ public class DrawingArmoredCar { { return; } - // отрисовка корпуса и гусеницы g2d.setPaint(armoredCar.getBodyColor()); - g2d.fillRect((int ) startPosX + 20, (int) startPosY, 40, 20); + // отрисовка корпуса и гусеницы + int new_startPosX = Math.round(startPosX); + int new_startPosY = Math.round(startPosY); + g2d.fillRect(new_startPosX + 20, new_startPosY, 40, 20); g2d.setPaint(Color.LIGHT_GRAY); - g2d.fillRect((int ) startPosX, (int ) startPosY + 20, 80, 20); + g2d.fillRect(new_startPosX, new_startPosY + 20, 80, 20); - g2d.fillOval((int ) startPosX, (int ) startPosY + 30, 20, 20); - g2d.fillOval((int ) startPosX + 80 - 20, (int ) startPosY + 30, 20, 20); - g2d.fillRect((int ) startPosX + 15, (int ) startPosY + 20, 60, 30); + g2d.fillOval(new_startPosX, new_startPosY + 30, 20, 20); + g2d.fillOval(new_startPosX + 80 - 20, new_startPosY + 30, 20, 20); + g2d.fillRect(new_startPosX + 15, new_startPosY + 20, 60, 30); // отрисовка катков в гусенице - drawingCaterpillar.DrawCaterpillar(g2d, (int)startPosX, (int)startPosY); + drawingCaterpillar.DrawCaterpillar(g2d, new_startPosX, new_startPosY); } public void ChangeBorders(int width, int height) diff --git a/src/main/java/DrawingTank.java b/src/main/java/DrawingTank.java index 844548e..225a19e 100644 --- a/src/main/java/DrawingTank.java +++ b/src/main/java/DrawingTank.java @@ -3,7 +3,7 @@ import java.awt.*; public class DrawingTank extends DrawingArmoredCar{ public DrawingTank(int speed, float weight, Color bodyColor, Color dopColor, boolean towerWeapon, boolean AMachineGun) { - super(speed, weight, bodyColor); + super(speed, weight, bodyColor, 80, 60); armoredCar = new EntityTank(speed, weight, bodyColor, dopColor, towerWeapon, AMachineGun); } @Override @@ -23,8 +23,8 @@ public class DrawingTank extends DrawingArmoredCar{ g.fillRect((int)startPosX + 60, (int)startPosY + 15, 7, 10); g.fillRect((int)startPosX + 60, (int)startPosY + 17, 20, 5); } - startPosY += 10; + startPosY += 5; super.DrawTransport(g); - startPosY -= 10; + startPosY -= 5; } } -- 2.25.1 From b500486bd03b155da6b72c5ff0e5175ada5f818d Mon Sep 17 00:00:00 2001 From: prodigygirl Date: Sun, 23 Oct 2022 17:28:13 +0400 Subject: [PATCH 11/16] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=B2=D0=BE=D0=B7=D0=BC=D0=BE=D0=B6?= =?UTF-8?q?=D0=BD=D0=BE=D1=81=D1=82=D0=B8=20=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2?= =?UTF-8?q?=D0=BB=D1=8F=D1=82=D1=8C=20=D0=BF=D1=80=D0=BE=D0=B4=D0=B2=D0=B8?= =?UTF-8?q?=D0=BD=D1=83=D1=82=D1=8B=D0=B9=20=D0=BE=D0=B1=D1=8A=D0=B5=D0=BA?= =?UTF-8?q?=D1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/FormArmoredCar.form | 18 +++++++++++++----- src/main/java/FormArmoredCar.java | 31 +++++++++++++++++++++++++------ 2 files changed, 38 insertions(+), 11 deletions(-) diff --git a/src/main/java/FormArmoredCar.form b/src/main/java/FormArmoredCar.form index e82df6d..5cbc8f9 100644 --- a/src/main/java/FormArmoredCar.form +++ b/src/main/java/FormArmoredCar.form @@ -22,7 +22,7 @@ - + @@ -40,7 +40,7 @@ - + @@ -49,7 +49,7 @@ - + @@ -60,7 +60,7 @@ - + @@ -69,7 +69,7 @@ - + @@ -77,6 +77,14 @@ + + + + + + + + diff --git a/src/main/java/FormArmoredCar.java b/src/main/java/FormArmoredCar.java index 923ab88..cfea465 100644 --- a/src/main/java/FormArmoredCar.java +++ b/src/main/java/FormArmoredCar.java @@ -17,6 +17,7 @@ public class FormArmoredCar extends JFrame{ private JLabel labelSpeed; private JLabel labelWeight; private JLabel labelColor; + private JButton buttonCreate_Modif; private DrawingArmoredCar armoredCar; @@ -45,12 +46,7 @@ public class FormArmoredCar extends JFrame{ armoredCar = new DrawingArmoredCar(rnd.nextInt(100,300), rnd.nextInt(1000, 2000), new Color(rnd.nextInt(256), rnd.nextInt(256), rnd.nextInt(256))); - armoredCar.SetPosition(rnd.nextInt(10, 100), rnd.nextInt(10, 100), - drawPanel.getWidth(), drawPanel.getHeight()); - - labelSpeed.setText("Скорость: " + armoredCar.getArmoredCar().getSpeed()); - labelWeight.setText("Вес: " + armoredCar.getArmoredCar().getWeight()); - labelColor.setText("Цвет: " + armoredCar.getArmoredCar().getBodyColor().getRGB()); + setData(); } }); @@ -93,6 +89,20 @@ public class FormArmoredCar extends JFrame{ setContentPane(mainPanel); setVisible(true); + buttonCreate_Modif.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + Random rnd = new Random(); + armoredCar = new DrawingTank(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)), + 1==rnd.nextInt(0, 2), 1==rnd.nextInt(0, 2)); + setData(); + } + }); } private void createUIComponents() { @@ -108,4 +118,13 @@ public class FormArmoredCar extends JFrame{ } }; } + + private void setData() + { + Random rnd = new Random(); + armoredCar.SetPosition(rnd.nextInt(10, 100), rnd.nextInt(10, 100), drawPanel.getWidth(), drawPanel.getHeight()); + labelSpeed.setText("Скорость: " + armoredCar.getArmoredCar().getSpeed()); + labelWeight.setText("Вес: " + armoredCar.getArmoredCar().getWeight()); + labelColor.setText("Цвет: " + armoredCar.getArmoredCar().getBodyColor().getRGB()); + } } \ No newline at end of file -- 2.25.1 From 7b254d18b96ca346f590ae43c66ef837d68d0260 Mon Sep 17 00:00:00 2001 From: prodigygirl Date: Sun, 23 Oct 2022 17:29:00 +0400 Subject: [PATCH 12/16] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=BD=D0=BE=D0=B2=D0=BE=D0=B9=20?= =?UTF-8?q?=D1=84=D0=BE=D1=80=D0=BC=D1=8B=20=D0=9A=D0=B0=D1=80=D1=82=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/FormMap.form | 129 +++++++++++++++++++++++++++++++ src/main/java/FormMap.java | 151 +++++++++++++++++++++++++++++++++++++ src/main/java/Program.java | 3 +- 3 files changed, 282 insertions(+), 1 deletion(-) create mode 100644 src/main/java/FormMap.form create mode 100644 src/main/java/FormMap.java diff --git a/src/main/java/FormMap.form b/src/main/java/FormMap.form new file mode 100644 index 0000000..5dcacd8 --- /dev/null +++ b/src/main/java/FormMap.form @@ -0,0 +1,129 @@ + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
diff --git a/src/main/java/FormMap.java b/src/main/java/FormMap.java new file mode 100644 index 0000000..868daa7 --- /dev/null +++ b/src/main/java/FormMap.java @@ -0,0 +1,151 @@ +import javax.swing.*; +import java.awt.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.ComponentAdapter; +import java.awt.event.ComponentEvent; +import java.awt.image.BufferedImage; +import java.util.Objects; +import java.util.Random; + +public class FormMap extends JFrame { + private JPanel drawPanel; + private JButton buttonCreate; + private JButton buttonRight; + private JButton buttonUp; + private JButton buttonDown; + private JButton buttonLeft; + private JButton buttonCreate_Modif; + private JLabel labelSpeed; + private JLabel labelWeight; + private JLabel labelColor; + private JComboBox mapSelectorComboBox; + private JPanel mainPanel; + + private AbstractMap abstractMap; + private Image img; + public FormMap() { + super("Карта"); + abstractMap = new SimpleMap(); + + setBounds(100, 100, 700, 700); + setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + + labelSpeed.setText("Скорость: "); + labelWeight.setText("Вес: "); + labelColor.setText("Цвет: "); + + buttonCreate.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent actionEvent) { + Random rnd = new Random(); + DrawingArmoredCar armoredCar = new DrawingArmoredCar(rnd.nextInt(100,300), rnd.nextInt(1000, 2000), + new Color(rnd.nextInt(256), rnd.nextInt(256), rnd.nextInt(256))); + setData(armoredCar); + } + }); + + buttonUp.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent actionEvent) { + if (abstractMap != null) { + img = abstractMap.MoveObject(Direction.Up); + drawPanel.repaint(); + } + } + }); + + buttonDown.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent actionEvent) { + if (abstractMap != null) { + img = abstractMap.MoveObject(Direction.Down); + drawPanel.repaint(); + } + } + }); + + buttonLeft.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent actionEvent) { + if (abstractMap != null) { + img = abstractMap.MoveObject(Direction.Left); + drawPanel.repaint(); + } + } + }); + + buttonRight.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent actionEvent) { + if (abstractMap != null) { + img = abstractMap.MoveObject(Direction.Right); + drawPanel.repaint(); + } + } + }); + + setContentPane(mainPanel); + setVisible(true); + buttonCreate_Modif.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + Random rnd = new Random(); + DrawingTank tank = new DrawingTank(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)), + 1==rnd.nextInt(0, 2), 1==rnd.nextInt(0, 2)); + setData(tank); + } + }); + mapSelectorComboBox.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + String name = (String) mapSelectorComboBox.getSelectedItem(); + switch (name) + { + case "Простая карта": + abstractMap = new SimpleMap(); + break; + + case "Карта 1": + abstractMap = new MyMapWooden(); + break; + case "Карта 2": + //abstractMap = new MyMapWooden(); + break; + } + //setData(); + } + }); + } + + private void createUIComponents() { + drawPanel = new JPanel() { + @Override + public void paintComponent(Graphics g) { + super.paintComponent(g); + g.drawImage(img, 0, 0, this); + super.repaint(); + } + }; + } + + private void setData(DrawingArmoredCar drawingArmoredCar) + { + if (abstractMap != null) + img = abstractMap.CreateMap(drawPanel.getWidth(), drawPanel.getHeight(), new DrawingObjectArmoredCar(drawingArmoredCar)); + + labelSpeed.setText("Скорость: " + drawingArmoredCar.getArmoredCar().getSpeed()); + labelWeight.setText("Вес: " + drawingArmoredCar.getArmoredCar().getWeight()); + labelColor.setText("Цвет: " + drawingArmoredCar.getArmoredCar().getBodyColor().getRGB()); + } +} + + + + + diff --git a/src/main/java/Program.java b/src/main/java/Program.java index 2d1f91a..1683846 100644 --- a/src/main/java/Program.java +++ b/src/main/java/Program.java @@ -1,5 +1,6 @@ public class Program { public static void main(String[] args) { - new FormArmoredCar(); + //new FormArmoredCar(); + new FormMap(); } } -- 2.25.1 From 492f45eb92c8f0dca049f38f1b0a29ef69ec6fe9 Mon Sep 17 00:00:00 2001 From: prodigygirl Date: Sun, 23 Oct 2022 17:37:23 +0400 Subject: [PATCH 13/16] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=B4=D0=B2=D1=83=D1=85=20=D1=80?= =?UTF-8?q?=D0=B5=D0=B0=D0=BB=D0=B8=D0=B7=D0=B0=D1=86=D0=B8=D0=B9=20=D1=81?= =?UTF-8?q?=D0=B2=D0=BE=D0=B8=D1=85=20=D0=BA=D0=B0=D1=80=D1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/MyMapLabyrinth.java | 65 +++++++++++++++++++++++++++++++ src/main/java/MyMapWooden.java | 46 ++++++++++++++++++++++ 2 files changed, 111 insertions(+) create mode 100644 src/main/java/MyMapLabyrinth.java create mode 100644 src/main/java/MyMapWooden.java diff --git a/src/main/java/MyMapLabyrinth.java b/src/main/java/MyMapLabyrinth.java new file mode 100644 index 0000000..a832924 --- /dev/null +++ b/src/main/java/MyMapLabyrinth.java @@ -0,0 +1,65 @@ +import java.awt.*; + +public class MyMapLabyrinth extends AbstractMap{ + private final Color barrierColor = Color.BLUE; + private final Color roadColor = Color.BLACK; + @Override + protected void GenerateMap() { + map = new int[50][50]; + 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 < 20) + { + int x = random.nextInt(0, 50); + int y = random.nextInt(0, 50); + int number = random.nextInt(1, 16); + if (counter < 5) { + if (number + x > map.length) + { + number = map.length - x - 1; + } + for (int i = x; i < x + number; ++i) + { + map[i][y] = _barrier; + } + } else + { + if (number + y > map[0].length) + { + number = map[0].length - y - 1; + } + for (int i = y; i < y + number; ++i) + { + map[x][i] = _barrier; + } + } + counter++; + + } + } + + @Override + protected void DrawRoadPart(Graphics2D g, int i, int j) { + g.setColor(roadColor); + int new_size_x = Math.round(size_x); + int new_size_y = Math.round(size_y); + g.fillRect(i * new_size_x, j * new_size_y, new_size_x, new_size_y); + } + + @Override + protected void DrawBarrierPart(Graphics2D g, int i, int j) { + g.setColor(barrierColor); + int new_size_x = Math.round(size_x); + int new_size_y = Math.round(size_y); + g.fillRect(i * new_size_x, j * new_size_y, new_size_x, new_size_y); + } +} diff --git a/src/main/java/MyMapWooden.java b/src/main/java/MyMapWooden.java new file mode 100644 index 0000000..224ad4d --- /dev/null +++ b/src/main/java/MyMapWooden.java @@ -0,0 +1,46 @@ +import java.awt.*; + +public class MyMapWooden extends AbstractMap{ + private final Color barrierColor = new Color(45, 77, 44); + private final Color roadColor = new Color(105, 70, 35); + @Override + protected void GenerateMap() { + map = new int[10][10]; + 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(10); + int y = random.nextInt(10); + if (map[x][y] == _freeRoad) + { + map[x][y] = _barrier; + counter++; + } + } + } + + @Override + protected void DrawRoadPart(Graphics2D g, int i, int j) { + g.setColor(roadColor); + int new_size_x = Math.round(size_x); + int new_size_y = Math.round(size_y); + g.fillRect(i * new_size_x, j * new_size_y, new_size_x, new_size_y); + } + + @Override + protected void DrawBarrierPart(Graphics2D g, int i, int j) { + g.setColor(barrierColor); + int new_size_x = Math.round(size_x); + int new_size_y = Math.round(size_y); + g.fillRect(i * new_size_x, j * new_size_y, new_size_x, new_size_y); + } +} -- 2.25.1 From 3db14138cda5bc5331a502e5f16e9c7721251c24 Mon Sep 17 00:00:00 2001 From: prodigygirl Date: Sun, 23 Oct 2022 17:37:34 +0400 Subject: [PATCH 14/16] =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2?= =?UTF-8?q?=D0=BB=D0=B5=D0=BD=D0=B8=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/FormMap.java | 4 +--- src/main/java/Program.java | 1 - 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/src/main/java/FormMap.java b/src/main/java/FormMap.java index 868daa7..8d70e44 100644 --- a/src/main/java/FormMap.java +++ b/src/main/java/FormMap.java @@ -110,15 +110,13 @@ public class FormMap extends JFrame { case "Простая карта": abstractMap = new SimpleMap(); break; - case "Карта 1": abstractMap = new MyMapWooden(); break; case "Карта 2": - //abstractMap = new MyMapWooden(); + abstractMap = new MyMapLabyrinth(); break; } - //setData(); } }); } diff --git a/src/main/java/Program.java b/src/main/java/Program.java index 1683846..ff7ede6 100644 --- a/src/main/java/Program.java +++ b/src/main/java/Program.java @@ -1,6 +1,5 @@ public class Program { public static void main(String[] args) { - //new FormArmoredCar(); new FormMap(); } } -- 2.25.1 From a19996af002930b2cab13b526a7f5da67af8e91f Mon Sep 17 00:00:00 2001 From: prodigygirl Date: Sun, 23 Oct 2022 18:03:05 +0400 Subject: [PATCH 15/16] =?UTF-8?q?=D0=92=D1=8B=D0=BF=D0=BE=D0=BB=D0=BD?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=B7=D0=B0=D0=B4=D0=B0=D0=BD=D0=B8?= =?UTF-8?q?=D1=8F=20=D1=81=20=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5=D0=BC=20=D0=98=D0=BD=D1=82=D0=B5=D1=80=D0=94?= =?UTF-8?q?=D0=BE=D0=BF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/DrawingArmoredCar.java | 6 ++- src/main/java/DrawingCaterpillar.java | 2 +- src/main/java/DrawingCrossCaterpillar.java | 43 +++++++++++++++++++++ src/main/java/DrawingDoubleCaterpillar.java | 40 +++++++++++++++++++ src/main/java/IDrawingCaterpillar.java | 7 ++++ 5 files changed, 95 insertions(+), 3 deletions(-) create mode 100644 src/main/java/DrawingCrossCaterpillar.java create mode 100644 src/main/java/DrawingDoubleCaterpillar.java create mode 100644 src/main/java/IDrawingCaterpillar.java diff --git a/src/main/java/DrawingArmoredCar.java b/src/main/java/DrawingArmoredCar.java index 689c551..0bf1818 100644 --- a/src/main/java/DrawingArmoredCar.java +++ b/src/main/java/DrawingArmoredCar.java @@ -17,7 +17,7 @@ public class DrawingArmoredCar { private int carHeight = 50; - protected DrawingCaterpillar drawingCaterpillar; + protected IDrawingCaterpillar drawingCaterpillar; public EntityArmoredCar getArmoredCar() { return armoredCar; @@ -26,7 +26,9 @@ public class DrawingArmoredCar { public DrawingArmoredCar(int speed, float weight, Color bodyColor) { this.armoredCar = new EntityArmoredCar(speed, weight, bodyColor); Random r = new Random(); - this.drawingCaterpillar = new DrawingCaterpillar(r.nextInt(4, 7), bodyColor); + IDrawingCaterpillar[] realisations = new IDrawingCaterpillar[]{new DrawingCaterpillar(r.nextInt(4, 7), bodyColor), + new DrawingCrossCaterpillar(r.nextInt(4, 7), bodyColor), new DrawingDoubleCaterpillar(r.nextInt(4, 7), bodyColor)}; + this.drawingCaterpillar = realisations[r.nextInt(3)]; } protected DrawingArmoredCar(int speed, float weight, Color bodyColor, int carWidth, int carHeight) { diff --git a/src/main/java/DrawingCaterpillar.java b/src/main/java/DrawingCaterpillar.java index 2270ca6..96946b9 100644 --- a/src/main/java/DrawingCaterpillar.java +++ b/src/main/java/DrawingCaterpillar.java @@ -1,6 +1,6 @@ import java.awt.*; -public class DrawingCaterpillar { +public class DrawingCaterpillar implements IDrawingCaterpillar { private NumRinks numRinks = NumRinks.Four; private Color color; diff --git a/src/main/java/DrawingCrossCaterpillar.java b/src/main/java/DrawingCrossCaterpillar.java new file mode 100644 index 0000000..4b5efa4 --- /dev/null +++ b/src/main/java/DrawingCrossCaterpillar.java @@ -0,0 +1,43 @@ +import java.awt.*; + +public class DrawingCrossCaterpillar implements IDrawingCaterpillar{ + private NumRinks numRinks = NumRinks.Four; + private Color color; + + public DrawingCrossCaterpillar(int n, Color color) { + setNumRinks(n); + this.color = color; + } + + @Override + public void setNumRinks(int n) { + switch (n) { + case 4 -> numRinks = NumRinks.Four; + + case 5 -> numRinks = NumRinks.Five; + + case 6 -> numRinks = NumRinks.Six; + + default -> { + break; + } + } + } + + @Override + public void DrawCaterpillar(Graphics2D g2d, int startPosX, int startPosY) { + color = color != null ? color : Color.YELLOW; + + int size = numRinks == NumRinks.Four ? 15 : 10; + int dist = numRinks == NumRinks.Four ? 20 : 13; + startPosX = numRinks == NumRinks.Five ? startPosX + 5 : startPosX; + for (int i = 0; i < numRinks.val(); i++) { + g2d.setPaint(color); + g2d.fillOval(startPosX + dist * i, startPosY + 30, size, size); + g2d.setColor(Color.BLACK); + g2d.setStroke(new BasicStroke(3)); + g2d.drawLine(startPosX + dist * i, startPosY + 30, startPosX + dist * i + size, startPosY + 30 + size); + g2d.drawLine(startPosX + dist * i + size, startPosY + 30, startPosX + dist * i, startPosY + 30 + size); + } + } +} diff --git a/src/main/java/DrawingDoubleCaterpillar.java b/src/main/java/DrawingDoubleCaterpillar.java new file mode 100644 index 0000000..e5966a3 --- /dev/null +++ b/src/main/java/DrawingDoubleCaterpillar.java @@ -0,0 +1,40 @@ +import java.awt.*; + +public class DrawingDoubleCaterpillar implements IDrawingCaterpillar{ + private NumRinks numRinks = NumRinks.Four; + private Color color; + + public DrawingDoubleCaterpillar(int n, Color color) { + setNumRinks(n); + this.color = color; + } + + @Override + public void setNumRinks(int n) { + switch (n) { + case 4 -> numRinks = NumRinks.Four; + + case 5 -> numRinks = NumRinks.Five; + + case 6 -> numRinks = NumRinks.Six; + + default -> { + break; + } + } + } + + @Override + public void DrawCaterpillar(Graphics2D g2d, int startPosX, int startPosY) { + color = color != null ? color : Color.YELLOW; + int size = numRinks == NumRinks.Four ? 15 : 10; + int dist = numRinks == NumRinks.Four ? 20 : 13; + startPosX = numRinks == NumRinks.Five ? startPosX + 5 : startPosX; + for (int i = 0; i < numRinks.val(); i++) { + g2d.setPaint(color); + g2d.fillOval(startPosX + dist * i, startPosY + 30, size, size); + g2d.setPaint(Color.WHITE); + g2d.fillOval(startPosX + dist * i + size/4, startPosY + 30 + size/4, size/2, size/2); + } + } +} diff --git a/src/main/java/IDrawingCaterpillar.java b/src/main/java/IDrawingCaterpillar.java new file mode 100644 index 0000000..50bda28 --- /dev/null +++ b/src/main/java/IDrawingCaterpillar.java @@ -0,0 +1,7 @@ +import java.awt.*; + +public interface IDrawingCaterpillar { + void setNumRinks(int n); + + void DrawCaterpillar(Graphics2D g2d, int startPosX, int startPosY); +} -- 2.25.1 From 588661f02756031619565719ef925e00611293d9 Mon Sep 17 00:00:00 2001 From: prodigygirl Date: Tue, 1 Nov 2022 13:45:38 +0400 Subject: [PATCH 16/16] =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2?= =?UTF-8?q?=D0=BB=D0=B5=D0=BD=D0=B8=D1=8F:=20=D0=B4=D0=BE=D0=B1=D0=B0?= =?UTF-8?q?=D0=B2=D0=BB=D0=B5=D0=BD=20=D0=B2=D1=8B=D0=B7=D0=BE=D0=B2=20?= =?UTF-8?q?=D0=BC=D0=B5=D1=82=D0=BE=D0=B4=D0=B0=20=D0=B4=D0=BB=D1=8F=20?= =?UTF-8?q?=D0=BF=D0=B5=D1=80=D0=B5=D0=B4=D0=B0=D1=87=D0=B8=20=D0=BF=D0=B0?= =?UTF-8?q?=D1=80=D0=B0=D0=BC=D0=B5=D1=82=D1=80=D0=B0=20=D0=BA=D0=BE=D0=BB?= =?UTF-8?q?=D0=B8=D1=87=D0=B5=D1=81=D1=82=D0=B2=D0=B0=20=D0=BA=D0=B0=D1=82?= =?UTF-8?q?=D0=BA=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/DrawingArmoredCar.java | 8 ++++++-- src/main/java/DrawingCaterpillar.java | 7 +++---- src/main/java/DrawingCrossCaterpillar.java | 3 +-- src/main/java/DrawingDoubleCaterpillar.java | 3 +-- 4 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/main/java/DrawingArmoredCar.java b/src/main/java/DrawingArmoredCar.java index 0bf1818..70b39aa 100644 --- a/src/main/java/DrawingArmoredCar.java +++ b/src/main/java/DrawingArmoredCar.java @@ -25,10 +25,14 @@ public class DrawingArmoredCar { public DrawingArmoredCar(int speed, float weight, Color bodyColor) { this.armoredCar = new EntityArmoredCar(speed, weight, bodyColor); + IDrawingCaterpillar[] realisations = new IDrawingCaterpillar[]{ + new DrawingCaterpillar(bodyColor), + new DrawingCrossCaterpillar(bodyColor), + new DrawingDoubleCaterpillar(bodyColor)}; Random r = new Random(); - IDrawingCaterpillar[] realisations = new IDrawingCaterpillar[]{new DrawingCaterpillar(r.nextInt(4, 7), bodyColor), - new DrawingCrossCaterpillar(r.nextInt(4, 7), bodyColor), new DrawingDoubleCaterpillar(r.nextInt(4, 7), bodyColor)}; + int num = r.nextInt(4, 7); this.drawingCaterpillar = realisations[r.nextInt(3)]; + drawingCaterpillar.setNumRinks(num); } protected DrawingArmoredCar(int speed, float weight, Color bodyColor, int carWidth, int carHeight) { diff --git a/src/main/java/DrawingCaterpillar.java b/src/main/java/DrawingCaterpillar.java index 96946b9..6cf873a 100644 --- a/src/main/java/DrawingCaterpillar.java +++ b/src/main/java/DrawingCaterpillar.java @@ -4,11 +4,10 @@ public class DrawingCaterpillar implements IDrawingCaterpillar { private NumRinks numRinks = NumRinks.Four; private Color color; - public DrawingCaterpillar(int n, Color color) { - setNumRinks(n); + public DrawingCaterpillar(Color color) { this.color = color; } - + @Override public void setNumRinks(int n) { switch (n) { case 4 -> numRinks = NumRinks.Four; @@ -22,7 +21,7 @@ public class DrawingCaterpillar implements IDrawingCaterpillar { } } } - + @Override public void DrawCaterpillar(Graphics2D g2d, int startPosX, int startPosY) { color = color != null ? color : Color.YELLOW; diff --git a/src/main/java/DrawingCrossCaterpillar.java b/src/main/java/DrawingCrossCaterpillar.java index 4b5efa4..98d7238 100644 --- a/src/main/java/DrawingCrossCaterpillar.java +++ b/src/main/java/DrawingCrossCaterpillar.java @@ -4,8 +4,7 @@ public class DrawingCrossCaterpillar implements IDrawingCaterpillar{ private NumRinks numRinks = NumRinks.Four; private Color color; - public DrawingCrossCaterpillar(int n, Color color) { - setNumRinks(n); + public DrawingCrossCaterpillar(Color color) { this.color = color; } diff --git a/src/main/java/DrawingDoubleCaterpillar.java b/src/main/java/DrawingDoubleCaterpillar.java index e5966a3..ed7da51 100644 --- a/src/main/java/DrawingDoubleCaterpillar.java +++ b/src/main/java/DrawingDoubleCaterpillar.java @@ -4,8 +4,7 @@ public class DrawingDoubleCaterpillar implements IDrawingCaterpillar{ private NumRinks numRinks = NumRinks.Four; private Color color; - public DrawingDoubleCaterpillar(int n, Color color) { - setNumRinks(n); + public DrawingDoubleCaterpillar(Color color) { this.color = color; } -- 2.25.1