diff --git a/DoubleDeckerBus/src/main/java/com/example/doubledeckerbus/AbstractMap.java b/DoubleDeckerBus/src/main/java/com/example/doubledeckerbus/AbstractMap.java index 0c8d9fb..d321e80 100644 --- a/DoubleDeckerBus/src/main/java/com/example/doubledeckerbus/AbstractMap.java +++ b/DoubleDeckerBus/src/main/java/com/example/doubledeckerbus/AbstractMap.java @@ -40,7 +40,7 @@ public abstract class AbstractMap { int x = _random.nextInt(0, 10); int y = _random.nextInt(0, 10); _drawingObject.SetObject(x, y, _width, _height); - return CheckCollision(); + return !CheckCollision(); } private void DrawMapWithObject() @@ -93,9 +93,9 @@ public abstract class AbstractMap { return false; } - for (int y = startY; y <= endY; y++) + for (int y = startY; y <= endY + 1; y++) { - for (int x = startX; x <= endX; x++) + for (int x = startX; x <= endX + 1; x++) { try { if (_map[x][y] == _barrier) diff --git a/DoubleDeckerBus/src/main/java/com/example/doubledeckerbus/DrawingBus.java b/DoubleDeckerBus/src/main/java/com/example/doubledeckerbus/DrawingBus.java index a15beae..d64807d 100644 --- a/DoubleDeckerBus/src/main/java/com/example/doubledeckerbus/DrawingBus.java +++ b/DoubleDeckerBus/src/main/java/com/example/doubledeckerbus/DrawingBus.java @@ -3,10 +3,12 @@ package com.example.doubledeckerbus; import javafx.scene.canvas.GraphicsContext; import javafx.scene.paint.Color; +import java.util.Random; + public class DrawingBus { public EntityBus Bus; - public DrawingDoors Doors; + public IDrawingDoors Doors; public EntityBus getBus() { return Bus; @@ -22,8 +24,13 @@ public class DrawingBus { public DrawingBus(int speed, float weight, Color bodyColor, int countOfDoors) { Bus = new EntityBus(speed, weight, bodyColor); - Doors = new DrawingDoors(); + switch (new Random().nextInt(3)) { + case 0 -> Doors = new DrawingTriangleDoors(); + case 1 -> Doors = new DrawingDoors(); + case 2 -> Doors = new DrawingEllipsoidDoors(); + } Doors.setCountOfDoors(countOfDoors); + } public void SetPosition(int x, int y, int width, int height) { @@ -81,7 +88,6 @@ public class DrawingBus { return; } - gc.setFill(Bus.BodyColor); gc.fillRect(_startPosX, _startPosY + 10, 100, 30); diff --git a/DoubleDeckerBus/src/main/java/com/example/doubledeckerbus/DrawingDoors.java b/DoubleDeckerBus/src/main/java/com/example/doubledeckerbus/DrawingDoors.java index 7c902d7..4bb4c6b 100644 --- a/DoubleDeckerBus/src/main/java/com/example/doubledeckerbus/DrawingDoors.java +++ b/DoubleDeckerBus/src/main/java/com/example/doubledeckerbus/DrawingDoors.java @@ -3,10 +3,11 @@ package com.example.doubledeckerbus; import javafx.scene.canvas.GraphicsContext; import javafx.scene.paint.Color; -public class DrawingDoors { +public class DrawingDoors implements IDrawingDoors { private CountOfDoors _countOfDoors; - public void DrawDoors(GraphicsContext gc, int _startPosX, int _startPosY) { + @Override + public void DrawDoors(GraphicsContext gc, float _startPosX, float _startPosY) { gc.setFill(Color.BLACK); gc.fillRect(_startPosX, _startPosY + 20, 10, 20); gc.fillRect(_startPosX + 20, _startPosY + 20, 10, 20); @@ -19,13 +20,13 @@ public class DrawingDoors { } } - public void setCountOfDoors(int number) { + @Override + public void setCountOfDoors(int count) { for (CountOfDoors item: CountOfDoors.values()) { - if (item.getId() == number) { + if (item.getId() == count) { _countOfDoors = item; return; } } - } } diff --git a/DoubleDeckerBus/src/main/java/com/example/doubledeckerbus/DrawingEllipsoidDoors.java b/DoubleDeckerBus/src/main/java/com/example/doubledeckerbus/DrawingEllipsoidDoors.java new file mode 100644 index 0000000..df8290d --- /dev/null +++ b/DoubleDeckerBus/src/main/java/com/example/doubledeckerbus/DrawingEllipsoidDoors.java @@ -0,0 +1,33 @@ +package com.example.doubledeckerbus; + +import javafx.scene.canvas.GraphicsContext; +import javafx.scene.paint.Color; + +public class DrawingEllipsoidDoors implements IDrawingDoors{ + private CountOfDoors _countOfDoors; + + @Override + public void DrawDoors(GraphicsContext gc, float _startPosX, float _startPosY) { + gc.setFill(Color.GRAY); + gc.fillOval(_startPosX, _startPosY + 20, 10, 20); + gc.fillOval(_startPosX + 20, _startPosY + 20, 10, 20); + gc.fillOval(_startPosX + 40, _startPosY + 20, 10, 20); + if (_countOfDoors.getId() >= 4) { + gc.fillOval(_startPosX + 60, _startPosY + 20, 10, 20); + } + if (_countOfDoors.getId() >= 5) { + gc.fillOval(_startPosX + 80, _startPosY + 20, 10, 20); + } + } + + @Override + public void setCountOfDoors(int count) { + for (CountOfDoors item: CountOfDoors.values()) { + if (item.getId() == count) { + _countOfDoors = item; + return; + } + } + } + +} diff --git a/DoubleDeckerBus/src/main/java/com/example/doubledeckerbus/DrawingTriangleDoors.java b/DoubleDeckerBus/src/main/java/com/example/doubledeckerbus/DrawingTriangleDoors.java new file mode 100644 index 0000000..54b6fb8 --- /dev/null +++ b/DoubleDeckerBus/src/main/java/com/example/doubledeckerbus/DrawingTriangleDoors.java @@ -0,0 +1,37 @@ +package com.example.doubledeckerbus; + +import javafx.scene.canvas.GraphicsContext; +import javafx.scene.paint.Color; + +public class DrawingTriangleDoors implements IDrawingDoors{ + private CountOfDoors _countOfDoors; + + public void FillTriangle(GraphicsContext gc, float x, float y) { + gc.fillPolygon(new double[] {(double) x, (double) (x + 5), (double) (x + 10)}, + new double[] {(double) y + 20, (double) (y), (double) y + 20}, 3) ; + } + + @Override + public void DrawDoors(GraphicsContext gc, float _startPosX, float _startPosY) { + gc.setFill(Color.BLUE); + FillTriangle(gc, _startPosX, _startPosY + 20); + FillTriangle(gc,_startPosX + 20, _startPosY + 20); + FillTriangle(gc,_startPosX + 40, _startPosY + 20); + if (_countOfDoors.getId() >= 4) { + FillTriangle(gc, _startPosX + 60, _startPosY + 20); + } + if (_countOfDoors.getId() >= 5) { + FillTriangle(gc, _startPosX + 80, _startPosY + 20); + } + } + + @Override + public void setCountOfDoors(int count) { + for (CountOfDoors item: CountOfDoors.values()) { + if (item.getId() == count) { + _countOfDoors = item; + return; + } + } + } +} diff --git a/DoubleDeckerBus/src/main/java/com/example/doubledeckerbus/IDrawingDoors.java b/DoubleDeckerBus/src/main/java/com/example/doubledeckerbus/IDrawingDoors.java new file mode 100644 index 0000000..93c5e5c --- /dev/null +++ b/DoubleDeckerBus/src/main/java/com/example/doubledeckerbus/IDrawingDoors.java @@ -0,0 +1,9 @@ +package com.example.doubledeckerbus; + +import javafx.scene.canvas.GraphicsContext; +import javafx.scene.paint.Color; + +public interface IDrawingDoors { + void DrawDoors(GraphicsContext gc, float _startPosX, float _startPosY); + void setCountOfDoors(int count); +} diff --git a/DoubleDeckerBus/src/main/java/com/example/doubledeckerbus/WaterMap.java b/DoubleDeckerBus/src/main/java/com/example/doubledeckerbus/WaterMap.java index 6d3e2b3..1fc868a 100644 --- a/DoubleDeckerBus/src/main/java/com/example/doubledeckerbus/WaterMap.java +++ b/DoubleDeckerBus/src/main/java/com/example/doubledeckerbus/WaterMap.java @@ -32,7 +32,7 @@ public class WaterMap extends AbstractMap{ @Override protected void DrawRoadPart(int i, int j) { - if (_random.nextInt(0,10) == 9) { + if (_random.nextInt(0,20) == 9) { gc.setFill(Color.GREEN); } else {