Доработанная лабораторная работа №1
This commit is contained in:
parent
d913385e2b
commit
a883536277
@ -6,4 +6,8 @@ module org.projectcleaningcar.projectcleaningcar {
|
|||||||
|
|
||||||
opens org.projectcleaningcar.projectcleaningcar to javafx.fxml;
|
opens org.projectcleaningcar.projectcleaningcar to javafx.fxml;
|
||||||
exports org.projectcleaningcar.projectcleaningcar;
|
exports org.projectcleaningcar.projectcleaningcar;
|
||||||
|
exports org.projectcleaningcar.projectcleaningcar.Entities;
|
||||||
|
opens org.projectcleaningcar.projectcleaningcar.Entities to javafx.fxml;
|
||||||
|
exports org.projectcleaningcar.projectcleaningcar.Drawnings;
|
||||||
|
opens org.projectcleaningcar.projectcleaningcar.Drawnings to javafx.fxml;
|
||||||
}
|
}
|
@ -1,4 +1,4 @@
|
|||||||
package org.projectcleaningcar.projectcleaningcar;
|
package org.projectcleaningcar.projectcleaningcar.Drawnings;
|
||||||
|
|
||||||
public enum DirectionType {
|
public enum DirectionType {
|
||||||
Up,
|
Up,
|
@ -1,21 +1,19 @@
|
|||||||
package org.projectcleaningcar.projectcleaningcar;
|
package org.projectcleaningcar.projectcleaningcar.Drawnings;
|
||||||
import javafx.scene.canvas.GraphicsContext;
|
import javafx.scene.canvas.GraphicsContext;
|
||||||
import javafx.scene.paint.Color;
|
import javafx.scene.paint.Color;
|
||||||
|
import org.projectcleaningcar.projectcleaningcar.Entities.EntityCleaningCar;
|
||||||
|
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Класс, отвечающий за прорисовку и перемещение объекта-сущности
|
* Класс, отвечающий за прорисовку и перемещение объекта-сущности
|
||||||
*/
|
*/
|
||||||
public class DrawningCleaningCar {
|
public class DrawningCleaningCar{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Класс-сущность
|
* Класс-сущность
|
||||||
*/
|
*/
|
||||||
private EntityCleaningCar entityCleaningCar;
|
private EntityCleaningCar entityCleaningCar;
|
||||||
public EntityCleaningCar getEntityCleaningCar() {
|
|
||||||
return entityCleaningCar;
|
|
||||||
}
|
|
||||||
private DrawningCleaningCarWheel drawningCleaningCarWheel;
|
private DrawningCleaningCarWheel drawningCleaningCarWheel;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -31,7 +29,7 @@ public class DrawningCleaningCar {
|
|||||||
/**
|
/**
|
||||||
* Левая координата прорисовки автомобиля
|
* Левая координата прорисовки автомобиля
|
||||||
*/
|
*/
|
||||||
private int startPosX ;
|
private int startPosX;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Верхняя координата прорисовки автомобиля
|
* Верхняя координата прорисовки автомобиля
|
||||||
@ -112,30 +110,33 @@ public class DrawningCleaningCar {
|
|||||||
*/
|
*/
|
||||||
public boolean moveTransport(DirectionType direction) {
|
public boolean moveTransport(DirectionType direction) {
|
||||||
double step = entityCleaningCar.getStep();
|
double step = entityCleaningCar.getStep();
|
||||||
switch (direction) {
|
return switch (direction) {
|
||||||
case Left:
|
case Left -> {
|
||||||
if (startPosX - step > 0) {
|
if (startPosX - step > 0) {
|
||||||
startPosX -= step;
|
startPosX -= (int) step;
|
||||||
}
|
}
|
||||||
return true;
|
yield true;
|
||||||
case Up:
|
}
|
||||||
|
case Up -> {
|
||||||
if (startPosY - step > 0) {
|
if (startPosY - step > 0) {
|
||||||
startPosY -= step;
|
startPosY -= (int) step;
|
||||||
}
|
}
|
||||||
return true;
|
yield true;
|
||||||
case Right:
|
}
|
||||||
|
case Right -> {
|
||||||
if (startPosX + drawingCleaningCarWidth + step < pictureWidth) {
|
if (startPosX + drawingCleaningCarWidth + step < pictureWidth) {
|
||||||
startPosX += step;
|
startPosX += (int) step;
|
||||||
}
|
}
|
||||||
return true;
|
yield true;
|
||||||
case Down:
|
}
|
||||||
|
case Down -> {
|
||||||
if (startPosY + drawingCleaningCarHeight + step < pictureHeight) {
|
if (startPosY + drawingCleaningCarHeight + step < pictureHeight) {
|
||||||
startPosY += step;
|
startPosY += (int) step;
|
||||||
}
|
}
|
||||||
return true;
|
yield true;
|
||||||
default:
|
}
|
||||||
return false;
|
default -> false;
|
||||||
}
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -185,7 +186,7 @@ public class DrawningCleaningCar {
|
|||||||
gc.strokePolygon(xPoints, yPoints, 3);
|
gc.strokePolygon(xPoints, yPoints, 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
drawningCleaningCarWheel.drawCleaningCarWheel(gc, Color.valueOf("black"), startPosX, startPosY);
|
drawningCleaningCarWheel.drawCleaningCarWheel(gc, startPosX, startPosY);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1,6 +1,7 @@
|
|||||||
package org.projectcleaningcar.projectcleaningcar;
|
package org.projectcleaningcar.projectcleaningcar.Drawnings;
|
||||||
import javafx.scene.canvas.GraphicsContext;
|
import javafx.scene.canvas.GraphicsContext;
|
||||||
import javafx.scene.paint.Color;
|
import javafx.scene.paint.Color;
|
||||||
|
import org.projectcleaningcar.projectcleaningcar.WheelCount;
|
||||||
|
|
||||||
public class DrawningCleaningCarWheel {
|
public class DrawningCleaningCarWheel {
|
||||||
private WheelCount wheelCount;
|
private WheelCount wheelCount;
|
||||||
@ -14,7 +15,7 @@ public class DrawningCleaningCarWheel {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void drawCleaningCarWheel(GraphicsContext gc, Color color, int startPosX, int startPosY) {
|
public void drawCleaningCarWheel(GraphicsContext gc, int startPosX, int startPosY) {
|
||||||
gc.setFill(Color.BLACK);
|
gc.setFill(Color.BLACK);
|
||||||
int wheels = wheelCount.getEnumNumber();
|
int wheels = wheelCount.getEnumNumber();
|
||||||
switch(wheels) {
|
switch(wheels) {
|
@ -1,4 +1,4 @@
|
|||||||
package org.projectcleaningcar.projectcleaningcar;
|
package org.projectcleaningcar.projectcleaningcar.Entities;
|
||||||
import javafx.scene.paint.Color;
|
import javafx.scene.paint.Color;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -8,32 +8,32 @@ public class EntityCleaningCar {
|
|||||||
/**
|
/**
|
||||||
* Скорость
|
* Скорость
|
||||||
*/
|
*/
|
||||||
private int speed;
|
private final int speed;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Вес
|
* Вес
|
||||||
*/
|
*/
|
||||||
private double weight;
|
private final double weight;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Основной цвет
|
* Основной цвет
|
||||||
*/
|
*/
|
||||||
private Color bodyColor;
|
private final Color bodyColor;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Дополнительный цвет (для опциональных элементов)
|
* Дополнительный цвет (для опциональных элементов)
|
||||||
*/
|
*/
|
||||||
private Color additionalColor;
|
private final Color additionalColor;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Признак (опция) наличия бака под воду
|
* Признак (опция) наличия бака под воду
|
||||||
*/
|
*/
|
||||||
private boolean waterTank;
|
private final boolean waterTank;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Признак (опция) наличия подметательной щётки
|
* Признак (опция) наличия подметательной щётки
|
||||||
*/
|
*/
|
||||||
private boolean sweepingBrush;
|
private final boolean sweepingBrush;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Конструктор для инициализации полей объекта-класса подметально-уборочной машины
|
* Конструктор для инициализации полей объекта-класса подметально-уборочной машины
|
||||||
@ -64,51 +64,19 @@ public class EntityCleaningCar {
|
|||||||
|
|
||||||
// Геттеры и сеттеры
|
// Геттеры и сеттеры
|
||||||
|
|
||||||
public int getSpeed() {
|
|
||||||
return speed;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setSpeed(int speed) {
|
|
||||||
this.speed = speed;
|
|
||||||
}
|
|
||||||
|
|
||||||
public double getWeight() {
|
|
||||||
return weight;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setWeight(double weight) {
|
|
||||||
this.weight = weight;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Color getBodyColor() {
|
public Color getBodyColor() {
|
||||||
return bodyColor;
|
return bodyColor;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setBodyColor(Color bodyColor) {
|
|
||||||
this.bodyColor = bodyColor;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Color getAdditionalColor() {
|
public Color getAdditionalColor() {
|
||||||
return additionalColor;
|
return additionalColor;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setAdditionalColor(Color additionalColor) {
|
|
||||||
this.additionalColor = additionalColor;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isWaterTank() {
|
public boolean isWaterTank() {
|
||||||
return waterTank;
|
return waterTank;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setWaterTank(boolean waterTank) {
|
|
||||||
this.waterTank = waterTank;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isSweepingBrush() {
|
public boolean isSweepingBrush() {
|
||||||
return sweepingBrush;
|
return sweepingBrush;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setSweepingBrush(boolean sweepingBrush) {
|
|
||||||
this.sweepingBrush = sweepingBrush;
|
|
||||||
}
|
|
||||||
}
|
}
|
@ -10,6 +10,9 @@ import javafx.scene.paint.Color;
|
|||||||
import javafx.scene.control.Button;
|
import javafx.scene.control.Button;
|
||||||
import javafx.scene.canvas.Canvas;
|
import javafx.scene.canvas.Canvas;
|
||||||
import javafx.scene.canvas.GraphicsContext;
|
import javafx.scene.canvas.GraphicsContext;
|
||||||
|
import org.projectcleaningcar.projectcleaningcar.Drawnings.DirectionType;
|
||||||
|
import org.projectcleaningcar.projectcleaningcar.Drawnings.DrawningCleaningCar;
|
||||||
|
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@ -47,7 +50,7 @@ public class FormCleaningCar extends Application {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
private void buttonCreateCleaningCar(ActionEvent event) {
|
private void buttonCreateCleaningCar() {
|
||||||
Random random = new Random();
|
Random random = new Random();
|
||||||
_drawningCleaningCar = new DrawningCleaningCar();
|
_drawningCleaningCar = new DrawningCleaningCar();
|
||||||
_drawningCleaningCar.init(random.nextInt(300 - 100 + 1) + 100,
|
_drawningCleaningCar.init(random.nextInt(300 - 100 + 1) + 100,
|
||||||
@ -66,22 +69,13 @@ public class FormCleaningCar extends Application {
|
|||||||
if (_drawningCleaningCar == null) return;
|
if (_drawningCleaningCar == null) return;
|
||||||
if (canvasCleaningCar.getWidth() == 0 || canvasCleaningCar.getHeight() == 0) return;
|
if (canvasCleaningCar.getWidth() == 0 || canvasCleaningCar.getHeight() == 0) return;
|
||||||
String name = ((Button) event.getSource()).getId();
|
String name = ((Button) event.getSource()).getId();
|
||||||
boolean result = false;
|
boolean result = switch (name) {
|
||||||
|
case "Up" -> _drawningCleaningCar.moveTransport(DirectionType.Up);
|
||||||
switch (name){
|
case "Down" -> _drawningCleaningCar.moveTransport(DirectionType.Down);
|
||||||
case "Up":
|
case "Left" -> _drawningCleaningCar.moveTransport(DirectionType.Left);
|
||||||
result = _drawningCleaningCar.moveTransport(DirectionType.Up);
|
case "Right" -> _drawningCleaningCar.moveTransport(DirectionType.Right);
|
||||||
break;
|
default -> false;
|
||||||
case "Down":
|
};
|
||||||
result = _drawningCleaningCar.moveTransport(DirectionType.Down);
|
|
||||||
break;
|
|
||||||
case "Left":
|
|
||||||
result = _drawningCleaningCar.moveTransport(DirectionType.Left);
|
|
||||||
break;
|
|
||||||
case "Right":
|
|
||||||
result = _drawningCleaningCar.moveTransport(DirectionType.Right);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(result) draw();
|
if(result) draw();
|
||||||
}
|
}
|
||||||
|
@ -14,10 +14,5 @@ public enum WheelCount {
|
|||||||
public int getEnumNumber() {
|
public int getEnumNumber() {
|
||||||
return enumNumber;
|
return enumNumber;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return String.valueOf(enumNumber);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user