Hard_version

This commit is contained in:
Mark Zaharchenko 2022-10-04 10:59:33 +04:00
parent 1ebbf7412c
commit 1c11f7062c
7 changed files with 98 additions and 12 deletions

View File

@ -40,7 +40,7 @@ public abstract class AbstractMap {
int x = _random.nextInt(0, 10); int x = _random.nextInt(0, 10);
int y = _random.nextInt(0, 10); int y = _random.nextInt(0, 10);
_drawingObject.SetObject(x, y, _width, _height); _drawingObject.SetObject(x, y, _width, _height);
return CheckCollision(); return !CheckCollision();
} }
private void DrawMapWithObject() private void DrawMapWithObject()
@ -93,9 +93,9 @@ public abstract class AbstractMap {
return false; 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 { try {
if (_map[x][y] == _barrier) if (_map[x][y] == _barrier)

View File

@ -3,10 +3,12 @@ package com.example.doubledeckerbus;
import javafx.scene.canvas.GraphicsContext; import javafx.scene.canvas.GraphicsContext;
import javafx.scene.paint.Color; import javafx.scene.paint.Color;
import java.util.Random;
public class DrawingBus { public class DrawingBus {
public EntityBus Bus; public EntityBus Bus;
public DrawingDoors Doors; public IDrawingDoors Doors;
public EntityBus getBus() { public EntityBus getBus() {
return Bus; return Bus;
@ -22,8 +24,13 @@ public class DrawingBus {
public DrawingBus(int speed, float weight, Color bodyColor, int countOfDoors) { public DrawingBus(int speed, float weight, Color bodyColor, int countOfDoors) {
Bus = new EntityBus(speed, weight, bodyColor); 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); Doors.setCountOfDoors(countOfDoors);
} }
public void SetPosition(int x, int y, int width, int height) { public void SetPosition(int x, int y, int width, int height) {
@ -81,7 +88,6 @@ public class DrawingBus {
return; return;
} }
gc.setFill(Bus.BodyColor); gc.setFill(Bus.BodyColor);
gc.fillRect(_startPosX, _startPosY + 10, 100, 30); gc.fillRect(_startPosX, _startPosY + 10, 100, 30);

View File

@ -3,10 +3,11 @@ package com.example.doubledeckerbus;
import javafx.scene.canvas.GraphicsContext; import javafx.scene.canvas.GraphicsContext;
import javafx.scene.paint.Color; import javafx.scene.paint.Color;
public class DrawingDoors { public class DrawingDoors implements IDrawingDoors {
private CountOfDoors _countOfDoors; 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.setFill(Color.BLACK);
gc.fillRect(_startPosX, _startPosY + 20, 10, 20); gc.fillRect(_startPosX, _startPosY + 20, 10, 20);
gc.fillRect(_startPosX + 20, _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()) { for (CountOfDoors item: CountOfDoors.values()) {
if (item.getId() == number) { if (item.getId() == count) {
_countOfDoors = item; _countOfDoors = item;
return; return;
} }
} }
} }
} }

View File

@ -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;
}
}
}
}

View File

@ -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;
}
}
}
}

View File

@ -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);
}

View File

@ -32,7 +32,7 @@ public class WaterMap extends AbstractMap{
@Override @Override
protected void DrawRoadPart(int i, int j) { protected void DrawRoadPart(int i, int j) {
if (_random.nextInt(0,10) == 9) { if (_random.nextInt(0,20) == 9) {
gc.setFill(Color.GREEN); gc.setFill(Color.GREEN);
} }
else { else {