Доработанная лабораторная работа №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;
|
||||
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 {
|
||||
Up,
|
@ -1,21 +1,19 @@
|
||||
package org.projectcleaningcar.projectcleaningcar;
|
||||
package org.projectcleaningcar.projectcleaningcar.Drawnings;
|
||||
import javafx.scene.canvas.GraphicsContext;
|
||||
import javafx.scene.paint.Color;
|
||||
import org.projectcleaningcar.projectcleaningcar.Entities.EntityCleaningCar;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
/**
|
||||
* Класс, отвечающий за прорисовку и перемещение объекта-сущности
|
||||
*/
|
||||
public class DrawningCleaningCar {
|
||||
public class DrawningCleaningCar{
|
||||
|
||||
/**
|
||||
* Класс-сущность
|
||||
*/
|
||||
private EntityCleaningCar entityCleaningCar;
|
||||
public EntityCleaningCar getEntityCleaningCar() {
|
||||
return entityCleaningCar;
|
||||
}
|
||||
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) {
|
||||
double step = entityCleaningCar.getStep();
|
||||
switch (direction) {
|
||||
case Left:
|
||||
return switch (direction) {
|
||||
case Left -> {
|
||||
if (startPosX - step > 0) {
|
||||
startPosX -= step;
|
||||
startPosX -= (int) step;
|
||||
}
|
||||
return true;
|
||||
case Up:
|
||||
yield true;
|
||||
}
|
||||
case Up -> {
|
||||
if (startPosY - step > 0) {
|
||||
startPosY -= step;
|
||||
startPosY -= (int) step;
|
||||
}
|
||||
return true;
|
||||
case Right:
|
||||
yield true;
|
||||
}
|
||||
case Right -> {
|
||||
if (startPosX + drawingCleaningCarWidth + step < pictureWidth) {
|
||||
startPosX += step;
|
||||
startPosX += (int) step;
|
||||
}
|
||||
return true;
|
||||
case Down:
|
||||
yield true;
|
||||
}
|
||||
case Down -> {
|
||||
if (startPosY + drawingCleaningCarHeight + step < pictureHeight) {
|
||||
startPosY += step;
|
||||
startPosY += (int) step;
|
||||
}
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
yield true;
|
||||
}
|
||||
default -> false;
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
@ -185,7 +186,7 @@ public class DrawningCleaningCar {
|
||||
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.paint.Color;
|
||||
import org.projectcleaningcar.projectcleaningcar.WheelCount;
|
||||
|
||||
public class DrawningCleaningCarWheel {
|
||||
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);
|
||||
int wheels = wheelCount.getEnumNumber();
|
||||
switch(wheels) {
|
@ -1,4 +1,4 @@
|
||||
package org.projectcleaningcar.projectcleaningcar;
|
||||
package org.projectcleaningcar.projectcleaningcar.Entities;
|
||||
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() {
|
||||
return bodyColor;
|
||||
}
|
||||
|
||||
public void setBodyColor(Color bodyColor) {
|
||||
this.bodyColor = bodyColor;
|
||||
}
|
||||
|
||||
public Color getAdditionalColor() {
|
||||
return additionalColor;
|
||||
}
|
||||
|
||||
public void setAdditionalColor(Color additionalColor) {
|
||||
this.additionalColor = additionalColor;
|
||||
}
|
||||
|
||||
public boolean isWaterTank() {
|
||||
return waterTank;
|
||||
}
|
||||
|
||||
public void setWaterTank(boolean waterTank) {
|
||||
this.waterTank = waterTank;
|
||||
}
|
||||
|
||||
public boolean isSweepingBrush() {
|
||||
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.canvas.Canvas;
|
||||
import javafx.scene.canvas.GraphicsContext;
|
||||
import org.projectcleaningcar.projectcleaningcar.Drawnings.DirectionType;
|
||||
import org.projectcleaningcar.projectcleaningcar.Drawnings.DrawningCleaningCar;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
import java.io.IOException;
|
||||
@ -47,7 +50,7 @@ public class FormCleaningCar extends Application {
|
||||
}
|
||||
|
||||
@FXML
|
||||
private void buttonCreateCleaningCar(ActionEvent event) {
|
||||
private void buttonCreateCleaningCar() {
|
||||
Random random = new Random();
|
||||
_drawningCleaningCar = new DrawningCleaningCar();
|
||||
_drawningCleaningCar.init(random.nextInt(300 - 100 + 1) + 100,
|
||||
@ -66,22 +69,13 @@ public class FormCleaningCar extends Application {
|
||||
if (_drawningCleaningCar == null) return;
|
||||
if (canvasCleaningCar.getWidth() == 0 || canvasCleaningCar.getHeight() == 0) return;
|
||||
String name = ((Button) event.getSource()).getId();
|
||||
boolean result = false;
|
||||
|
||||
switch (name){
|
||||
case "Up":
|
||||
result = _drawningCleaningCar.moveTransport(DirectionType.Up);
|
||||
break;
|
||||
case "Down":
|
||||
result = _drawningCleaningCar.moveTransport(DirectionType.Down);
|
||||
break;
|
||||
case "Left":
|
||||
result = _drawningCleaningCar.moveTransport(DirectionType.Left);
|
||||
break;
|
||||
case "Right":
|
||||
result = _drawningCleaningCar.moveTransport(DirectionType.Right);
|
||||
break;
|
||||
}
|
||||
boolean result = switch (name) {
|
||||
case "Up" -> _drawningCleaningCar.moveTransport(DirectionType.Up);
|
||||
case "Down" -> _drawningCleaningCar.moveTransport(DirectionType.Down);
|
||||
case "Left" -> _drawningCleaningCar.moveTransport(DirectionType.Left);
|
||||
case "Right" -> _drawningCleaningCar.moveTransport(DirectionType.Right);
|
||||
default -> false;
|
||||
};
|
||||
|
||||
if(result) draw();
|
||||
}
|
||||
|
@ -14,10 +14,5 @@ public enum WheelCount {
|
||||
public int getEnumNumber() {
|
||||
return enumNumber;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.valueOf(enumNumber);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user