Compare commits
3 Commits
Author | SHA1 | Date | |
---|---|---|---|
123e9751c9 | |||
e1886e850b | |||
088578d34c |
@ -1,119 +0,0 @@
|
|||||||
package com.example.doubledeckerbus;
|
|
||||||
|
|
||||||
import javafx.scene.canvas.GraphicsContext;
|
|
||||||
|
|
||||||
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;
|
|
||||||
|
|
||||||
protected GraphicsContext gc;
|
|
||||||
|
|
||||||
public void CreateMap(int width, int height, IDrawingObject drawingObject, GraphicsContext gc)
|
|
||||||
{
|
|
||||||
_width = width;
|
|
||||||
_height = height;
|
|
||||||
_drawingObject = drawingObject;
|
|
||||||
this.gc = gc;
|
|
||||||
GenerateMap();
|
|
||||||
while (!SetObjectOnMap())
|
|
||||||
{
|
|
||||||
GenerateMap();
|
|
||||||
}
|
|
||||||
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);
|
|
||||||
return !CheckCollision();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void DrawMapWithObject()
|
|
||||||
{
|
|
||||||
if (_drawingObject == null || _map == null)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (int i = 0; i < _map.length; ++i)
|
|
||||||
{
|
|
||||||
for (int j = 0; j < _map[0].length; ++j)
|
|
||||||
{
|
|
||||||
if (_map[i][j] == _freeRoad)
|
|
||||||
{
|
|
||||||
DrawRoadPart(i, j);
|
|
||||||
}
|
|
||||||
else if (_map[i][j] == _barrier)
|
|
||||||
{
|
|
||||||
DrawBarrierPart(i, j);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
_drawingObject.DrawingObject(gc);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void MoveObject(Direction direction)
|
|
||||||
{
|
|
||||||
_drawingObject.MoveObject(direction);
|
|
||||||
if (CheckCollision()) {
|
|
||||||
switch (direction) {
|
|
||||||
case Left -> _drawingObject.MoveObject(Direction.Right);
|
|
||||||
case Right -> _drawingObject.MoveObject(Direction.Left);
|
|
||||||
case Up -> _drawingObject.MoveObject(Direction.Down);
|
|
||||||
case Down -> _drawingObject.MoveObject(Direction.Up);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
DrawMapWithObject();
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean CheckCollision() {
|
|
||||||
var pos = _drawingObject.GetCurrentPosition();
|
|
||||||
int startX = (int)((pos.Left) / _size_x);
|
|
||||||
int endX = (int)((pos.Right) / _size_x);
|
|
||||||
int startY = (int)((pos.Top) / _size_y);
|
|
||||||
int endY = (int)((pos.Bottom) / _size_y);
|
|
||||||
|
|
||||||
if (startX < 0 || startY < 0 || endX > _map[0].length || endY > _map.length) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (int y = startY; y <= endY + 1; y++)
|
|
||||||
{
|
|
||||||
for (int x = startX; x <= endX + 1; x++)
|
|
||||||
{
|
|
||||||
try {
|
|
||||||
if (_map[x][y] == _barrier)
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (ArrayIndexOutOfBoundsException e) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
protected abstract void GenerateMap();
|
|
||||||
protected abstract void DrawRoadPart(int i, int j);
|
|
||||||
protected abstract void DrawBarrierPart(int i, int j);
|
|
||||||
}
|
|
@ -4,70 +4,53 @@ import javafx.beans.InvalidationListener;
|
|||||||
import javafx.collections.FXCollections;
|
import javafx.collections.FXCollections;
|
||||||
import javafx.collections.ObservableList;
|
import javafx.collections.ObservableList;
|
||||||
import javafx.event.ActionEvent;
|
import javafx.event.ActionEvent;
|
||||||
import javafx.event.Event;
|
|
||||||
import javafx.event.EventHandler;
|
|
||||||
import javafx.fxml.FXML;
|
import javafx.fxml.FXML;
|
||||||
import javafx.fxml.FXMLLoader;
|
|
||||||
import javafx.scene.Scene;
|
|
||||||
import javafx.scene.canvas.Canvas;
|
import javafx.scene.canvas.Canvas;
|
||||||
import javafx.scene.canvas.GraphicsContext;
|
import javafx.scene.canvas.GraphicsContext;
|
||||||
import javafx.scene.control.*;
|
import javafx.scene.control.Button;
|
||||||
|
import javafx.scene.control.ChoiceBox;
|
||||||
|
import javafx.scene.control.Label;
|
||||||
import javafx.scene.layout.AnchorPane;
|
import javafx.scene.layout.AnchorPane;
|
||||||
import javafx.scene.paint.Color;
|
import javafx.scene.paint.Color;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.Optional;
|
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
import static com.example.doubledeckerbus.ControllerMapWithSetBus._mapBusesCollectionGeneric;
|
|
||||||
|
|
||||||
public class ControllerBus {
|
public class ControllerBus {
|
||||||
|
|
||||||
public static DrawingBus _bus;
|
private DrawingBus _bus;
|
||||||
public DrawingBus SelectedBus;
|
ObservableList<Integer> countOfDoors = FXCollections.observableArrayList(3, 4, 5);
|
||||||
protected ObservableList<Integer> countOfDoors = FXCollections.observableArrayList(3, 4, 5);
|
|
||||||
@FXML
|
@FXML
|
||||||
protected Button buttonCreate;
|
private Button buttonCreate;
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
protected Button buttonSelectBus;
|
private Button buttonDown;
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
protected Button buttonDown;
|
private Button buttonLeft;
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
protected Button buttonLeft;
|
private Button buttonRight;
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
protected Button buttonRight;
|
private Button buttonUp;
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
protected Button buttonUp;
|
private Canvas canvasBus;
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
protected Canvas canvasBus;
|
private AnchorPane pictureBoxBus;
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
protected AnchorPane pictureBoxBus;
|
private Label statusColor;
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
protected Label statusColor;
|
private Label statusSpeed;
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
protected Label statusSpeed;
|
private Label statusWeight;
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
protected Label statusWeight;
|
private ChoiceBox<Integer> choiceDoors;
|
||||||
|
|
||||||
@FXML
|
|
||||||
protected ChoiceBox<Integer> choiceDoors;
|
|
||||||
|
|
||||||
@FXML
|
|
||||||
private ColorPicker bodyColorPicker;
|
|
||||||
|
|
||||||
@FXML
|
|
||||||
private ColorPicker extraColorPicker;
|
|
||||||
|
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
void ButtonCreate_Click(ActionEvent event) {
|
void ButtonCreate_Click(ActionEvent event) {
|
||||||
@ -75,28 +58,18 @@ public class ControllerBus {
|
|||||||
pictureBoxBus.heightProperty().addListener(listener);
|
pictureBoxBus.heightProperty().addListener(listener);
|
||||||
|
|
||||||
Random rnd = new Random();
|
Random rnd = new Random();
|
||||||
|
_bus = new DrawingBus();
|
||||||
_bus = new DrawingBus(rnd.nextInt(100, 300), rnd.nextFloat(1000, 2000),
|
_bus.Init(rnd.nextInt(100, 300), rnd.nextFloat(1000, 2000),
|
||||||
bodyColorPicker.getValue(), choiceDoors.getValue());
|
Color.rgb(rnd.nextInt(0, 256), rnd.nextInt(0, 256), rnd.nextInt(0, 256)), choiceDoors.getValue());
|
||||||
_bus.SetPosition(rnd.nextInt(10, 100), rnd.nextInt(10, 100),
|
_bus.SetPosition(rnd.nextInt(10, 100), rnd.nextInt(10, 100), (int) pictureBoxBus.getWidth(), (int) pictureBoxBus.getHeight());
|
||||||
(int) pictureBoxBus.getWidth(), (int) pictureBoxBus.getHeight());
|
|
||||||
BorderChanged();
|
|
||||||
}
|
|
||||||
|
|
||||||
void SetData() {
|
|
||||||
Random rnd = new Random();
|
|
||||||
_bus.SetPosition(rnd.nextInt(10, 100), rnd.nextInt(10, 100),
|
|
||||||
(int) pictureBoxBus.getWidth(), (int) pictureBoxBus.getHeight());
|
|
||||||
statusSpeed.setText("Скорость: %s".formatted(_bus.Bus.Speed));
|
statusSpeed.setText("Скорость: %s".formatted(_bus.Bus.Speed));
|
||||||
statusWeight.setText("Вес: %s".formatted(_bus.Bus.Weight));
|
statusWeight.setText("Вес: %s".formatted(_bus.Bus.Weight));
|
||||||
statusColor.setText("Цвет: %s".formatted(_bus.Bus.BodyColor));
|
statusColor.setText("Цвет: %s".formatted(_bus.Bus.BodyColor));
|
||||||
|
BorderChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
void ButtonMove_Click(ActionEvent event) {
|
void ButtonMove_Click(ActionEvent event) {
|
||||||
pictureBoxBus.widthProperty().addListener(listener);
|
|
||||||
pictureBoxBus.heightProperty().addListener(listener);
|
|
||||||
|
|
||||||
if (_bus == null) return;
|
if (_bus == null) return;
|
||||||
String name = ((Button) event.getSource()).getId();
|
String name = ((Button) event.getSource()).getId();
|
||||||
switch (name) {
|
switch (name) {
|
||||||
@ -112,18 +85,13 @@ public class ControllerBus {
|
|||||||
public void initialize() {
|
public void initialize() {
|
||||||
choiceDoors.setItems(countOfDoors);
|
choiceDoors.setItems(countOfDoors);
|
||||||
choiceDoors.setValue(3);
|
choiceDoors.setValue(3);
|
||||||
if (_bus != null) {
|
|
||||||
Draw();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
InvalidationListener listener = o -> BorderChanged();
|
InvalidationListener listener = o -> BorderChanged();
|
||||||
|
|
||||||
private void Draw()
|
private void Draw()
|
||||||
{
|
{
|
||||||
GraphicsContext gc = canvasBus.getGraphicsContext2D();
|
GraphicsContext gc = canvasBus.getGraphicsContext2D();
|
||||||
gc.setFill(Color.WHITE);
|
|
||||||
gc.fillRect(0, 0, pictureBoxBus.getWidth(), pictureBoxBus.getHeight());
|
|
||||||
_bus.DrawTransport(gc);
|
_bus.DrawTransport(gc);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -134,49 +102,4 @@ public class ControllerBus {
|
|||||||
Draw();
|
Draw();
|
||||||
}
|
}
|
||||||
|
|
||||||
@FXML
|
|
||||||
private void ButtonCreateExtra_Click(ActionEvent event) {
|
|
||||||
pictureBoxBus.widthProperty().addListener(listener);
|
|
||||||
pictureBoxBus.heightProperty().addListener(listener);
|
|
||||||
Random rnd = new Random();
|
|
||||||
_bus = new DrawingDDB(rnd.nextInt(300), rnd.nextInt(2000),
|
|
||||||
bodyColorPicker.getValue(), choiceDoors.getValue(),
|
|
||||||
extraColorPicker.getValue(), rnd.nextBoolean(), rnd.nextBoolean());
|
|
||||||
SetData();
|
|
||||||
BorderChanged();
|
|
||||||
}
|
|
||||||
@FXML
|
|
||||||
private void ButtonSelectBus_Click(ActionEvent event) throws IOException {
|
|
||||||
SelectedBus = _bus;
|
|
||||||
|
|
||||||
if (SelectedBus == null) {
|
|
||||||
Alert alert = new Alert(Alert.AlertType.INFORMATION);
|
|
||||||
alert.setTitle("SelectBus");
|
|
||||||
alert.setContentText("Вы не создали объект");
|
|
||||||
Optional<ButtonType> option = alert.showAndWait();
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
|
|
||||||
DrawingObjectBus bus = new DrawingObjectBus(SelectedBus);
|
|
||||||
|
|
||||||
if (ControllerMapWithSetBus.AddNewBus(bus) != -1) {
|
|
||||||
Alert alert = new Alert(Alert.AlertType.INFORMATION);
|
|
||||||
alert.setTitle("SelectBus");
|
|
||||||
alert.setContentText("Вы создали объект");
|
|
||||||
Optional<ButtonType> option = alert.showAndWait();
|
|
||||||
} else {
|
|
||||||
Alert alert = new Alert(Alert.AlertType.INFORMATION);
|
|
||||||
alert.setTitle("SelectBus");
|
|
||||||
alert.setContentText("Не удалось добавить объект");
|
|
||||||
Optional<ButtonType> option = alert.showAndWait();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
_bus = null;
|
|
||||||
FXMLLoader fxmlLoader = new FXMLLoader(Form.class.getResource("FormMapWithSetBus.fxml"));
|
|
||||||
Scene scene = new Scene(fxmlLoader.load());
|
|
||||||
Form.myStage.setTitle("DoubleDeckerBus");
|
|
||||||
Form.myStage.setScene(scene);
|
|
||||||
Form.myStage.show();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -1,187 +0,0 @@
|
|||||||
package com.example.doubledeckerbus;
|
|
||||||
|
|
||||||
import javafx.event.ActionEvent;
|
|
||||||
import javafx.fxml.FXML;
|
|
||||||
import javafx.scene.canvas.Canvas;
|
|
||||||
import javafx.scene.canvas.GraphicsContext;
|
|
||||||
import javafx.scene.control.Button;
|
|
||||||
import javafx.scene.control.CheckBox;
|
|
||||||
import javafx.scene.control.Label;
|
|
||||||
import javafx.scene.control.Spinner;
|
|
||||||
import javafx.scene.input.*;
|
|
||||||
import javafx.scene.layout.Background;
|
|
||||||
import javafx.scene.layout.Region;
|
|
||||||
import javafx.scene.paint.Color;
|
|
||||||
import javafx.scene.paint.Paint;
|
|
||||||
import javafx.stage.Stage;
|
|
||||||
|
|
||||||
import java.util.function.Consumer;
|
|
||||||
|
|
||||||
public class ControllerBusConfig {
|
|
||||||
DataFormat colorFormat = DataFormat.lookupMimeType("SerializableColor");
|
|
||||||
DataFormat additionalElementFormat = DataFormat.lookupMimeType("IDrawningAdditionalElement");
|
|
||||||
private Stage _stage;
|
|
||||||
private DrawingBus _bus = null;
|
|
||||||
|
|
||||||
private Event<DrawingBus> addBus;
|
|
||||||
|
|
||||||
public void SetStage(Stage stage)
|
|
||||||
{
|
|
||||||
_stage = stage;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void AddEvent(Consumer<DrawingBus> ev)
|
|
||||||
{
|
|
||||||
addBus.AddListener(ev);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void DrawBus()
|
|
||||||
{
|
|
||||||
GraphicsContext gc = canvasObject.getGraphicsContext2D();
|
|
||||||
gc.clearRect(0, 0, canvasObject.getWidth(), canvasObject.getHeight());
|
|
||||||
if (_bus == null)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
_bus.SetPosition(5, 5, (int)canvasObject.getWidth(), (int)canvasObject.getHeight());
|
|
||||||
_bus.DrawTransport(gc);
|
|
||||||
}
|
|
||||||
|
|
||||||
@FXML
|
|
||||||
private Canvas canvasObject;
|
|
||||||
|
|
||||||
@FXML
|
|
||||||
private CheckBox checkBoxSecondStage;
|
|
||||||
|
|
||||||
@FXML
|
|
||||||
private CheckBox checkBoxLadder;
|
|
||||||
|
|
||||||
@FXML
|
|
||||||
private Spinner<Integer> spinnerSpeed = new Spinner<>();
|
|
||||||
|
|
||||||
@FXML
|
|
||||||
private Spinner<Integer> spinnerDoors = new Spinner<>();
|
|
||||||
|
|
||||||
@FXML
|
|
||||||
private Spinner<Integer> spinnerWeight = new Spinner<>();
|
|
||||||
|
|
||||||
@FXML
|
|
||||||
public void initialize()
|
|
||||||
{
|
|
||||||
if (colorFormat == null)
|
|
||||||
{
|
|
||||||
colorFormat = new DataFormat("SerializableColor");
|
|
||||||
}
|
|
||||||
if (additionalElementFormat == null)
|
|
||||||
{
|
|
||||||
additionalElementFormat = new DataFormat("IDrawningAdditionalElement");
|
|
||||||
}
|
|
||||||
addBus = new Event<>();
|
|
||||||
}
|
|
||||||
|
|
||||||
@FXML
|
|
||||||
void ButtonOk_Click(ActionEvent event) {
|
|
||||||
if (_bus != null)
|
|
||||||
{
|
|
||||||
addBus.Broadcast(_bus);
|
|
||||||
}
|
|
||||||
if (_stage != null)
|
|
||||||
{
|
|
||||||
_stage.close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@FXML
|
|
||||||
void CanvasObject_OnDragDropped(DragEvent event) {
|
|
||||||
Dragboard db = event.getDragboard();
|
|
||||||
switch (db.getString())
|
|
||||||
{
|
|
||||||
case "labelSimpleObject" -> _bus = new DrawingBus(spinnerSpeed.getValue(),
|
|
||||||
spinnerWeight.getValue(), Color.WHITE, spinnerDoors.getValue());
|
|
||||||
case "labelModifiedObject" -> _bus = new DrawingDDB(spinnerSpeed.getValue(),
|
|
||||||
spinnerWeight.getValue(), Color.WHITE, spinnerDoors.getValue(), Color.BLACK,
|
|
||||||
checkBoxSecondStage.isSelected(), checkBoxLadder.isSelected());
|
|
||||||
case "labelTriangle" -> _bus.ChangeDoor(new DrawingTriangleDoors());
|
|
||||||
case "labelOval" -> _bus.ChangeDoor(new DrawingEllipsoidDoors());
|
|
||||||
case "labelRect" -> _bus.ChangeDoor(new DrawingDoors());
|
|
||||||
}
|
|
||||||
DrawBus();
|
|
||||||
event.consume();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@FXML
|
|
||||||
void CanvasObject_OnDragOver(DragEvent event) {
|
|
||||||
if (event.getDragboard().hasString())
|
|
||||||
{
|
|
||||||
event.acceptTransferModes(TransferMode.COPY_OR_MOVE);
|
|
||||||
}
|
|
||||||
event.consume();
|
|
||||||
}
|
|
||||||
|
|
||||||
@FXML
|
|
||||||
void LabelBaseColor_OnDragDropped(DragEvent event) {
|
|
||||||
if (_bus == null)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Dragboard db = event.getDragboard();
|
|
||||||
|
|
||||||
_bus.Bus.BodyColor = ((SerializableColor)(db.getContent(colorFormat))).getFXColor();
|
|
||||||
event.consume();
|
|
||||||
DrawBus();
|
|
||||||
}
|
|
||||||
|
|
||||||
@FXML
|
|
||||||
void LabelColor_OnDragOver(DragEvent event) {
|
|
||||||
if (event.getDragboard().hasContent(colorFormat))
|
|
||||||
{
|
|
||||||
event.acceptTransferModes(TransferMode.COPY_OR_MOVE);
|
|
||||||
}
|
|
||||||
event.consume();
|
|
||||||
}
|
|
||||||
|
|
||||||
@FXML
|
|
||||||
void LabelDopColor_OnDragDropped(DragEvent event) {
|
|
||||||
if (_bus == null || !(_bus.Bus instanceof EntityDDB ddb))
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Dragboard db = event.getDragboard();
|
|
||||||
|
|
||||||
ddb.ExtraColor = ((SerializableColor)(db.getContent(colorFormat))).getFXColor();
|
|
||||||
event.consume();
|
|
||||||
DrawBus();
|
|
||||||
}
|
|
||||||
|
|
||||||
@FXML
|
|
||||||
void LabelObject_OnDragDetected(MouseEvent event) {
|
|
||||||
Label labelObject = (Label)(event.getSource());
|
|
||||||
Dragboard db = labelObject.startDragAndDrop(TransferMode.ANY);
|
|
||||||
|
|
||||||
ClipboardContent content = new ClipboardContent();
|
|
||||||
content.putString(((Label)(event.getSource())).getId());
|
|
||||||
db.setContent(content);
|
|
||||||
|
|
||||||
event.consume();
|
|
||||||
}
|
|
||||||
|
|
||||||
@FXML
|
|
||||||
void RegionColor_OnDragDetected(MouseEvent event) {
|
|
||||||
Region region = (Region)(event.getSource());
|
|
||||||
Dragboard db = region.startDragAndDrop(TransferMode.ANY);
|
|
||||||
|
|
||||||
Background regionBackground = region.getBackground();
|
|
||||||
Paint regionPaint = regionBackground.getFills().get(0).getFill();
|
|
||||||
if (regionPaint instanceof Color)
|
|
||||||
{
|
|
||||||
ClipboardContent content = new ClipboardContent();
|
|
||||||
content.put(colorFormat, new SerializableColor((Color)regionPaint));
|
|
||||||
db.setContent(content);
|
|
||||||
}
|
|
||||||
event.consume();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,297 +0,0 @@
|
|||||||
package com.example.doubledeckerbus;
|
|
||||||
import javafx.collections.FXCollections;
|
|
||||||
import javafx.collections.ObservableList;
|
|
||||||
import javafx.event.ActionEvent;
|
|
||||||
import javafx.fxml.FXML;
|
|
||||||
import javafx.fxml.FXMLLoader;
|
|
||||||
import javafx.scene.Scene;
|
|
||||||
import javafx.scene.canvas.Canvas;
|
|
||||||
import javafx.scene.canvas.GraphicsContext;
|
|
||||||
import javafx.scene.control.*;
|
|
||||||
import javafx.scene.layout.AnchorPane;
|
|
||||||
import javafx.scene.paint.Color;
|
|
||||||
import javafx.stage.Stage;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Objects;
|
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
|
|
||||||
public class ControllerMapWithSetBus {
|
|
||||||
static MapWithSetBusesGeneric<DrawingObjectBus, AbstractMap> _mapBusesCollectionGeneric;
|
|
||||||
private final HashMap<String, AbstractMap> _mapsDict = new HashMap<>();
|
|
||||||
{
|
|
||||||
_mapsDict.put("Простая карта", new SimpleMap());
|
|
||||||
_mapsDict.put("Водная карта", new WaterMap());
|
|
||||||
}
|
|
||||||
AbstractMap map = new SimpleMap();
|
|
||||||
|
|
||||||
public static int AddNewBus (DrawingObjectBus bus) {
|
|
||||||
return _mapsCollection.GetId(selected).add(bus);
|
|
||||||
}
|
|
||||||
static public MapsCollection _mapsCollection;
|
|
||||||
|
|
||||||
static String selected;
|
|
||||||
|
|
||||||
static String map_name = "Простая карта";
|
|
||||||
protected ObservableList<String> countOfMap = FXCollections.observableArrayList("Простая карта", "Водная карта");
|
|
||||||
|
|
||||||
@FXML
|
|
||||||
private Canvas canvasBus;
|
|
||||||
|
|
||||||
@FXML
|
|
||||||
private ChoiceBox<String> comboBoxSelectorMap;
|
|
||||||
|
|
||||||
@FXML
|
|
||||||
private AnchorPane pictureBoxBus;
|
|
||||||
|
|
||||||
@FXML
|
|
||||||
private TextField textBoxPosition;
|
|
||||||
|
|
||||||
@FXML
|
|
||||||
private ListView<String> listViewMaps;
|
|
||||||
|
|
||||||
@FXML
|
|
||||||
private TextField TextFieldMap;
|
|
||||||
|
|
||||||
@FXML
|
|
||||||
private void initialize(){
|
|
||||||
gc = canvasBus.getGraphicsContext2D();
|
|
||||||
if (selected != null) {
|
|
||||||
ShowStorage();
|
|
||||||
}
|
|
||||||
if (_mapsCollection == null)
|
|
||||||
_mapsCollection = new MapsCollection((int) canvasBus.getWidth(), (int) canvasBus.getHeight());
|
|
||||||
comboBoxSelectorMap.setItems(countOfMap);
|
|
||||||
comboBoxSelectorMap.setValue(map_name);
|
|
||||||
listViewMaps.getSelectionModel().selectedItemProperty()
|
|
||||||
.addListener((observableValue, s, t1) -> {
|
|
||||||
selected = t1;
|
|
||||||
ShowStorage();
|
|
||||||
});
|
|
||||||
listViewMaps.setItems(_mapsCollection.toObserveList());
|
|
||||||
}
|
|
||||||
|
|
||||||
GraphicsContext gc;
|
|
||||||
private void FirstIncome() {
|
|
||||||
if (!Objects.equals(comboBoxSelectorMap.getValue(), map_name)) {
|
|
||||||
map_name = comboBoxSelectorMap.getValue();
|
|
||||||
switch (map_name) {
|
|
||||||
case "Простая карта" -> map = new SimpleMap();
|
|
||||||
case "Водная карта" -> map = new WaterMap();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void ReloadMaps()
|
|
||||||
{
|
|
||||||
int index = listViewMaps.getSelectionModel().getSelectedIndex();
|
|
||||||
|
|
||||||
ObservableList<String> listMaps = FXCollections.observableArrayList();
|
|
||||||
|
|
||||||
listMaps.addAll(_mapsCollection.Keys());
|
|
||||||
listViewMaps.setItems(listMaps);
|
|
||||||
|
|
||||||
if (listMaps.size() > 0 && (index == -1 || index >= listMaps.size()))
|
|
||||||
{
|
|
||||||
listViewMaps.getSelectionModel().select(0);
|
|
||||||
}
|
|
||||||
else if (listMaps.size() > 0 && index > -1)
|
|
||||||
{
|
|
||||||
listViewMaps.getSelectionModel().select(index);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@FXML
|
|
||||||
private void ButtonAddBus_Click(ActionEvent event) throws IOException {
|
|
||||||
if (listViewMaps.getSelectionModel().selectedItemProperty().isNull().get())
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
Stage stageBus = new Stage();
|
|
||||||
FXMLLoader fxmlLoader = new FXMLLoader(Form.class.getResource("FormBusConfig.fxml"));
|
|
||||||
Scene sceneBus = new Scene(fxmlLoader.load());
|
|
||||||
|
|
||||||
stageBus.setScene(sceneBus);
|
|
||||||
stageBus.show();
|
|
||||||
|
|
||||||
ControllerBusConfig controller = fxmlLoader.getController();
|
|
||||||
controller.AddEvent(this::AddBus);
|
|
||||||
controller.SetStage(stageBus);
|
|
||||||
|
|
||||||
FirstIncome();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void AddBus(DrawingBus bus) {
|
|
||||||
if (listViewMaps.getSelectionModel().selectedItemProperty().isNull().get())
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
DrawingObjectBus objectBus = new DrawingObjectBus(bus);
|
|
||||||
String selectedMapName = listViewMaps.getSelectionModel().getSelectedItem();
|
|
||||||
|
|
||||||
Alert alert;
|
|
||||||
if (selectedMapName != null && selectedMapName.length() != 0 && _mapsCollection.get(selectedMapName).add(objectBus) != -1)
|
|
||||||
{
|
|
||||||
alert = new Alert(Alert.AlertType.INFORMATION, "Объект добавлен", ButtonType.OK);
|
|
||||||
_mapsCollection.get(selectedMapName).ShowSet(gc);
|
|
||||||
ShowStorage();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
alert = new Alert(Alert.AlertType.ERROR, "Не удалось добавить объект", ButtonType.OK);
|
|
||||||
}
|
|
||||||
alert.showAndWait();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@FXML
|
|
||||||
private void ButtonAddMap_Click(ActionEvent event)
|
|
||||||
{
|
|
||||||
if ((Objects.equals(TextFieldMap.getText(), "")))
|
|
||||||
{
|
|
||||||
Alert alert = new Alert(Alert.AlertType.INFORMATION);
|
|
||||||
alert.setTitle("SelectMap");
|
|
||||||
alert.setContentText("Не все данные заполнены");
|
|
||||||
Optional<ButtonType> option = alert.showAndWait();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!_mapsDict.containsKey(comboBoxSelectorMap.getValue()))
|
|
||||||
{
|
|
||||||
Alert alert = new Alert(Alert.AlertType.INFORMATION);
|
|
||||||
alert.setTitle("SelectMap");
|
|
||||||
alert.setContentText("Нет такой карты");
|
|
||||||
Optional<ButtonType> option = alert.showAndWait();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
_mapsCollection.AddMap(TextFieldMap.getText(), _mapsDict.get(comboBoxSelectorMap.getValue()));
|
|
||||||
ReloadMaps();
|
|
||||||
ShowStorage();
|
|
||||||
}
|
|
||||||
@FXML
|
|
||||||
private void ButtonDeleteMap_Click(ActionEvent event)
|
|
||||||
{
|
|
||||||
if (listViewMaps.getSelectionModel().selectedItemProperty().isNull().get())
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
_mapsCollection.DelMap(listViewMaps.getSelectionModel().getSelectedItem());
|
|
||||||
ReloadMaps();
|
|
||||||
ShowStorage();
|
|
||||||
}
|
|
||||||
|
|
||||||
@FXML
|
|
||||||
private void ButtonDeleteEditBus_Click(ActionEvent event) throws IOException {
|
|
||||||
if (selected == null)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
DrawingObjectBus deleteBus = _mapsCollection.get(selected).getDeletedBus();
|
|
||||||
if (deleteBus != null) {
|
|
||||||
ControllerBus._bus = deleteBus.getBus();
|
|
||||||
FXMLLoader fxmlLoader = new FXMLLoader(Form.class.getResource("FormBus.fxml"));
|
|
||||||
Scene scene = new Scene(fxmlLoader.load());
|
|
||||||
Form.myStage.setTitle("DoubleDeckerBus");
|
|
||||||
Form.myStage.setScene(scene);
|
|
||||||
Form.myStage.show();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@FXML
|
|
||||||
private void ButtonRemoveBus_Click(ActionEvent event)
|
|
||||||
{
|
|
||||||
FirstIncome();
|
|
||||||
if (Objects.equals(textBoxPosition.getText(), ""))
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
Alert alert = new Alert(Alert.AlertType.CONFIRMATION);
|
|
||||||
alert.setTitle("RemoveBus");
|
|
||||||
alert.setHeaderText("Вы действительно хотите удалить объект?");
|
|
||||||
|
|
||||||
Optional<ButtonType> option = alert.showAndWait();
|
|
||||||
if (option.get() == ButtonType.CANCEL) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
int pos;
|
|
||||||
try {
|
|
||||||
pos = Integer.parseInt(textBoxPosition.getText());
|
|
||||||
if (pos < 1 || pos > _mapsCollection.GetId(selected).getCount()) return;
|
|
||||||
}
|
|
||||||
catch (Exception e) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (_mapsCollection.GetId(selected).remove(pos) != null)
|
|
||||||
{
|
|
||||||
alert = new Alert(Alert.AlertType.WARNING);
|
|
||||||
alert.setTitle("RemoveBus");
|
|
||||||
alert.setContentText("Вы удалили объект");
|
|
||||||
option = alert.showAndWait();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
alert = new Alert(Alert.AlertType.WARNING);
|
|
||||||
alert.setTitle("RemoveBus");
|
|
||||||
alert.setContentText("Не удалось удалить объект");
|
|
||||||
option = alert.showAndWait();
|
|
||||||
}
|
|
||||||
ShowStorage();
|
|
||||||
}
|
|
||||||
|
|
||||||
@FXML
|
|
||||||
private void ButtonShowStorage_Click(ActionEvent event)
|
|
||||||
{
|
|
||||||
FirstIncome();
|
|
||||||
ShowStorage();
|
|
||||||
}
|
|
||||||
|
|
||||||
@FXML
|
|
||||||
private void ButtonShowOnMap_Click(ActionEvent event) {
|
|
||||||
FirstIncome();
|
|
||||||
ShowMap();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void ShowMap() {
|
|
||||||
if (selected == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
gc.setFill(Color.WHITE);
|
|
||||||
gc.fillRect(0, 0, canvasBus.getWidth(), canvasBus.getHeight());
|
|
||||||
_mapsCollection.GetId(selected).ShowOnMap(gc);
|
|
||||||
}
|
|
||||||
|
|
||||||
@FXML
|
|
||||||
private void ButtonMove_Click(ActionEvent event)
|
|
||||||
{
|
|
||||||
if (selected == null)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
String name = ((Button) event.getSource()).getId();
|
|
||||||
Direction dir = Direction.None;
|
|
||||||
switch (name) {
|
|
||||||
case "buttonUp" -> dir = Direction.Up;
|
|
||||||
case "buttonDown" -> dir = Direction.Down;
|
|
||||||
case "buttonLeft" -> dir = Direction.Left;
|
|
||||||
case "buttonRight" -> dir = Direction.Right;
|
|
||||||
}
|
|
||||||
_mapsCollection.GetId(selected).MoveObject(dir);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void ShowStorage() {
|
|
||||||
if (selected == null)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
gc.setFill(Color.WHITE);
|
|
||||||
gc.clearRect(0, 0, canvasBus.getWidth(), canvasBus.getHeight());
|
|
||||||
_mapsCollection.GetId(selected).ShowSet(gc);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
@ -1,165 +0,0 @@
|
|||||||
package com.example.doubledeckerbus;
|
|
||||||
|
|
||||||
import javafx.beans.InvalidationListener;
|
|
||||||
import javafx.collections.FXCollections;
|
|
||||||
import javafx.collections.ObservableList;
|
|
||||||
import javafx.event.ActionEvent;
|
|
||||||
import javafx.fxml.FXML;
|
|
||||||
import javafx.fxml.FXMLLoader;
|
|
||||||
import javafx.scene.Scene;
|
|
||||||
import javafx.scene.canvas.Canvas;
|
|
||||||
import javafx.scene.canvas.GraphicsContext;
|
|
||||||
import javafx.scene.control.*;
|
|
||||||
import javafx.scene.layout.AnchorPane;
|
|
||||||
import javafx.scene.paint.Color;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.Optional;
|
|
||||||
import java.util.Random;
|
|
||||||
|
|
||||||
import static com.example.doubledeckerbus.ControllerMapWithSetBus._mapBusesCollectionGeneric;
|
|
||||||
|
|
||||||
public class ControllerPolymorph {
|
|
||||||
protected DrawingBus _bus;
|
|
||||||
protected DrawingPolymorphBus<EntityBus, IDrawingDoors> polymorphBus;
|
|
||||||
public DrawingBus SelectedBus;
|
|
||||||
protected ObservableList<Integer> countOfDoors = FXCollections.observableArrayList(3, 4, 5);
|
|
||||||
|
|
||||||
@FXML
|
|
||||||
protected Button buttonCreate;
|
|
||||||
|
|
||||||
@FXML
|
|
||||||
protected Canvas canvasBus;
|
|
||||||
|
|
||||||
@FXML
|
|
||||||
protected AnchorPane pictureBoxBus;
|
|
||||||
|
|
||||||
@FXML
|
|
||||||
protected Label statusColor;
|
|
||||||
|
|
||||||
@FXML
|
|
||||||
protected Label statusSpeed;
|
|
||||||
|
|
||||||
@FXML
|
|
||||||
protected Label statusWeight;
|
|
||||||
|
|
||||||
@FXML
|
|
||||||
protected ChoiceBox<Integer> choiceDoors;
|
|
||||||
|
|
||||||
@FXML
|
|
||||||
void ButtonCreate_Click(ActionEvent event) {
|
|
||||||
pictureBoxBus.widthProperty().addListener(listener);
|
|
||||||
pictureBoxBus.heightProperty().addListener(listener);
|
|
||||||
|
|
||||||
Random rnd = new Random();
|
|
||||||
IDrawingDoors door = null;
|
|
||||||
switch (rnd.nextInt(3)) {
|
|
||||||
case (0) -> door = new DrawingDoors();
|
|
||||||
case (1) -> door = new DrawingEllipsoidDoors();
|
|
||||||
case (2) -> door = new DrawingTriangleDoors();
|
|
||||||
}
|
|
||||||
door.setCountOfDoors(choiceDoors.getValue());
|
|
||||||
|
|
||||||
EntityBus bus = new EntityBus(rnd.nextInt(300), rnd.nextInt(2000),
|
|
||||||
Color.rgb(rnd.nextInt(256), rnd.nextInt(256), rnd.nextInt(256)));
|
|
||||||
|
|
||||||
polymorphBus.AddDoors(door);
|
|
||||||
polymorphBus.AddEntity(bus);
|
|
||||||
|
|
||||||
_bus = polymorphBus.CreateBus();
|
|
||||||
SetData();
|
|
||||||
BorderChanged();
|
|
||||||
}
|
|
||||||
|
|
||||||
void SetData() {
|
|
||||||
Random rnd = new Random();
|
|
||||||
_bus.SetPosition(rnd.nextInt(10, 100), rnd.nextInt(10, 100), (int) pictureBoxBus.getWidth(), (int) pictureBoxBus.getHeight());
|
|
||||||
statusSpeed.setText("Скорость: %s".formatted(_bus.Bus.Speed));
|
|
||||||
statusWeight.setText("Вес: %s".formatted(_bus.Bus.Weight));
|
|
||||||
statusColor.setText("Цвет: %s".formatted(_bus.Bus.BodyColor));
|
|
||||||
}
|
|
||||||
|
|
||||||
@FXML
|
|
||||||
public void initialize() {
|
|
||||||
polymorphBus = new DrawingPolymorphBus<>(100, 100);
|
|
||||||
choiceDoors.setItems(countOfDoors);
|
|
||||||
choiceDoors.setValue(3);
|
|
||||||
|
|
||||||
}
|
|
||||||
InvalidationListener listener = o -> BorderChanged();
|
|
||||||
|
|
||||||
private void Draw()
|
|
||||||
{
|
|
||||||
GraphicsContext gc = canvasBus.getGraphicsContext2D();
|
|
||||||
gc.setFill(Color.WHITE);
|
|
||||||
gc.fillRect(0, 0, pictureBoxBus.getWidth(), pictureBoxBus.getHeight());
|
|
||||||
_bus.DrawTransport(gc);
|
|
||||||
}
|
|
||||||
|
|
||||||
void BorderChanged() {
|
|
||||||
canvasBus.setWidth(pictureBoxBus.getWidth());
|
|
||||||
canvasBus.setHeight(pictureBoxBus.getHeight());
|
|
||||||
_bus.ChangeBorders((int) pictureBoxBus.getWidth(), (int) pictureBoxBus.getHeight());
|
|
||||||
Draw();
|
|
||||||
}
|
|
||||||
|
|
||||||
@FXML
|
|
||||||
private void ButtonCreateExtra_Click(ActionEvent event) {
|
|
||||||
pictureBoxBus.widthProperty().addListener(listener);
|
|
||||||
pictureBoxBus.heightProperty().addListener(listener);
|
|
||||||
Random rnd = new Random();
|
|
||||||
IDrawingDoors door = null;
|
|
||||||
switch (rnd.nextInt(3)) {
|
|
||||||
case (0) -> door = new DrawingDoors();
|
|
||||||
case (1) -> door = new DrawingEllipsoidDoors();
|
|
||||||
case (2) -> door = new DrawingTriangleDoors();
|
|
||||||
}
|
|
||||||
door.setCountOfDoors(choiceDoors.getValue());
|
|
||||||
|
|
||||||
EntityDDB ddb_bus = new EntityDDB(rnd.nextInt(300), rnd.nextInt(2000),
|
|
||||||
Color.rgb(rnd.nextInt(256), rnd.nextInt(256), rnd.nextInt(256)),
|
|
||||||
Color.rgb(rnd.nextInt(256), rnd.nextInt(256), rnd.nextInt(256)),
|
|
||||||
rnd.nextBoolean(), rnd.nextBoolean());
|
|
||||||
|
|
||||||
polymorphBus.AddDoors(door);
|
|
||||||
polymorphBus.AddEntity(ddb_bus);
|
|
||||||
|
|
||||||
_bus = polymorphBus.CreateBus();
|
|
||||||
SetData();
|
|
||||||
BorderChanged();
|
|
||||||
}
|
|
||||||
@FXML
|
|
||||||
private void ButtonSelectBus_Click(ActionEvent event) throws IOException {
|
|
||||||
SelectedBus = _bus;
|
|
||||||
|
|
||||||
if (SelectedBus == null) {
|
|
||||||
Alert alert = new Alert(Alert.AlertType.INFORMATION);
|
|
||||||
alert.setTitle("SelectBus");
|
|
||||||
alert.setContentText("Вы не создали объект");
|
|
||||||
Optional<ButtonType> option = alert.showAndWait();
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
|
|
||||||
DrawingObjectBus bus = new DrawingObjectBus(SelectedBus);
|
|
||||||
|
|
||||||
if (_mapBusesCollectionGeneric.add(bus) != -1) {
|
|
||||||
Alert alert = new Alert(Alert.AlertType.INFORMATION);
|
|
||||||
alert.setTitle("SelectBus");
|
|
||||||
alert.setContentText("Вы создали объект");
|
|
||||||
Optional<ButtonType> option = alert.showAndWait();
|
|
||||||
} else {
|
|
||||||
Alert alert = new Alert(Alert.AlertType.INFORMATION);
|
|
||||||
alert.setTitle("SelectBus");
|
|
||||||
alert.setContentText("Не удалось добавить объект");
|
|
||||||
Optional<ButtonType> option = alert.showAndWait();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
FXMLLoader fxmlLoader = new FXMLLoader(Form.class.getResource("FormMapWithSetBus.fxml"));
|
|
||||||
Scene scene = new Scene(fxmlLoader.load());
|
|
||||||
Form.myStage.setTitle("DoubleDeckerBus");
|
|
||||||
Form.myStage.setScene(scene);
|
|
||||||
Form.myStage.show();
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,7 +1,6 @@
|
|||||||
package com.example.doubledeckerbus;
|
package com.example.doubledeckerbus;
|
||||||
|
|
||||||
public enum Direction {
|
public enum Direction {
|
||||||
None(0),
|
|
||||||
Up(1),
|
Up(1),
|
||||||
Down(2),
|
Down(2),
|
||||||
Left(3),
|
Left(3),
|
||||||
|
@ -3,67 +3,38 @@ 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 IDrawingDoors Doors;
|
public DrawingDoors Doors;
|
||||||
int _speed;
|
|
||||||
float _weight;
|
public EntityBus getBus() {
|
||||||
Color _bodyColor;
|
return Bus;
|
||||||
int _countOfDoors = 3;
|
}
|
||||||
|
|
||||||
private static final int _null = -1000;
|
private static final int _null = -1000;
|
||||||
protected float _startPosX;
|
private float _startPosX;
|
||||||
protected float _startPosY;
|
private float _startPosY;
|
||||||
private int _pictureWidth;
|
private int _pictureWidth;
|
||||||
private int _pictureHeight;
|
private int _pictureHeight;
|
||||||
private static final int _busWidth = 100;
|
private static final int _busWidth = 100;
|
||||||
private static final int _busHeight = 50;
|
private static final int _busHeight = 50;
|
||||||
|
|
||||||
public DrawingBus(int speed, float weight, Color bodyColor, int countOfDoors) {
|
public void Init(int speed, float weight, Color bodyColor, int countOfDoors) {
|
||||||
Bus = CreateBus(speed, weight, bodyColor, countOfDoors);
|
Bus = new EntityBus();
|
||||||
}
|
Bus.Init(speed, weight, bodyColor);
|
||||||
|
Doors = new DrawingDoors();
|
||||||
private EntityBus CreateBus(int speed, float weight, Color bodyColor, int countOfDoors) {
|
|
||||||
_speed = speed;
|
|
||||||
_weight = weight;
|
|
||||||
_bodyColor = bodyColor;
|
|
||||||
_countOfDoors = countOfDoors;
|
|
||||||
EntityBus bus = new EntityBus(speed, weight, bodyColor);
|
|
||||||
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);
|
||||||
return bus;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public void ChangeDoor(IDrawingDoors door) {
|
|
||||||
Doors = door;
|
|
||||||
Doors.setCountOfDoors(_countOfDoors);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public DrawingBus(int speed, float weight, Color bodyColor) {
|
|
||||||
Bus = new EntityBus(speed, weight, bodyColor);
|
|
||||||
}
|
|
||||||
|
|
||||||
public DrawingBus(EntityBus bus, IDrawingDoors doors) {
|
|
||||||
Bus = bus;
|
|
||||||
Doors = doors;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetPosition(int x, int y, int width, int height) {
|
public void SetPosition(int x, int y, int width, int height) {
|
||||||
if (width <= _busWidth || height <= _busHeight) {
|
if (x < 0 || y < 0) return;
|
||||||
|
|
||||||
|
if (_pictureWidth <= _busWidth || _pictureHeight <= _busHeight) {
|
||||||
_pictureWidth = _null;
|
_pictureWidth = _null;
|
||||||
_pictureHeight = _null;
|
_pictureHeight = _null;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
_startPosX = x;
|
_startPosX = x;
|
||||||
_startPosY = y;
|
_startPosY = y;
|
||||||
_pictureWidth = width;
|
_pictureWidth = width;
|
||||||
@ -112,7 +83,7 @@ public class DrawingBus {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
gc.clearRect(0, 0, _pictureWidth, _pictureHeight);
|
||||||
gc.setFill(Bus.BodyColor);
|
gc.setFill(Bus.BodyColor);
|
||||||
gc.fillRect(_startPosX, _startPosY + 10, 100, 30);
|
gc.fillRect(_startPosX, _startPosY + 10, 100, 30);
|
||||||
|
|
||||||
@ -150,8 +121,4 @@ public class DrawingBus {
|
|||||||
_startPosY = _pictureHeight - _busHeight;
|
_startPosY = _pictureHeight - _busHeight;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Position GetCurrentPosition() {
|
|
||||||
return new Position(_startPosX, _startPosX + _busWidth, _startPosY, _startPosY + _busHeight);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -1,72 +0,0 @@
|
|||||||
package com.example.doubledeckerbus;
|
|
||||||
|
|
||||||
import javafx.scene.canvas.GraphicsContext;
|
|
||||||
import javafx.scene.paint.Color;
|
|
||||||
|
|
||||||
public class DrawingDDB extends DrawingBus{
|
|
||||||
Color _extraColor;
|
|
||||||
boolean _ladder;
|
|
||||||
boolean _secondStage;
|
|
||||||
|
|
||||||
public DrawingDDB(int speed, float weight, Color bodyColor, int countOfDoors,
|
|
||||||
Color extraColor, boolean ladder, boolean secondStage) {
|
|
||||||
super(speed, weight, bodyColor, countOfDoors);
|
|
||||||
Bus = CreateDDB(speed, weight, bodyColor, countOfDoors, extraColor, ladder, secondStage);
|
|
||||||
}
|
|
||||||
|
|
||||||
private EntityDDB CreateDDB(int speed, float weight, Color bodyColor, int countOfDoors,
|
|
||||||
Color extraColor, boolean ladder, boolean secondStage) {
|
|
||||||
_speed = speed;
|
|
||||||
_weight = weight;
|
|
||||||
_bodyColor = bodyColor;
|
|
||||||
_countOfDoors = countOfDoors;
|
|
||||||
_extraColor = extraColor;
|
|
||||||
_ladder = ladder;
|
|
||||||
_secondStage = secondStage;
|
|
||||||
return new EntityDDB(speed, weight, bodyColor, extraColor, ladder, secondStage);
|
|
||||||
}
|
|
||||||
|
|
||||||
public DrawingDDB(int speed, float weight, Color bodyColor, Color extraColor, boolean ladder, boolean secondStage) {
|
|
||||||
super(speed, weight, bodyColor);
|
|
||||||
Bus = new EntityDDB(speed, weight, bodyColor, extraColor, ladder, secondStage);
|
|
||||||
}
|
|
||||||
|
|
||||||
public DrawingDDB(EntityBus bus, IDrawingDoors doors) {
|
|
||||||
super(bus, doors);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void DrawTransport(GraphicsContext gc)
|
|
||||||
{
|
|
||||||
if (Bus == null) return;
|
|
||||||
|
|
||||||
_startPosY += 30;
|
|
||||||
super.DrawTransport(gc);
|
|
||||||
_startPosY -= 30;
|
|
||||||
EntityDDB ddb = (EntityDDB) Bus;
|
|
||||||
|
|
||||||
gc.setFill(ddb.ExtraColor);
|
|
||||||
if (ddb.SecondStage) {
|
|
||||||
gc.fillRect(_startPosX, _startPosY + 10, 100, 30);
|
|
||||||
gc.setFill(Color.BLACK);
|
|
||||||
gc.fillRect(_startPosX + 30, _startPosY + 20, 10, 20);
|
|
||||||
|
|
||||||
gc.setFill(Color.BLUE);
|
|
||||||
gc.fillOval(_startPosX + 10, _startPosY + 15, 10, 15);
|
|
||||||
gc.fillOval(_startPosX + 50, _startPosY + 15, 10, 15);
|
|
||||||
gc.fillOval(_startPosX + 70, _startPosY + 15, 10, 15);
|
|
||||||
gc.fillOval(_startPosX + 90, _startPosY + 15, 10, 15);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ddb.Ladder) {
|
|
||||||
gc.strokeLine(_startPosX, _startPosY + 70, _startPosX, _startPosY + 10);
|
|
||||||
gc.strokeLine(_startPosX + 10, _startPosY + 70, _startPosX + 10, _startPosY + 10);
|
|
||||||
|
|
||||||
gc.strokeLine(_startPosX, _startPosY + 20, _startPosX + 10, _startPosY + 20);
|
|
||||||
gc.strokeLine(_startPosX, _startPosY + 30, _startPosX + 10, _startPosY + 30);
|
|
||||||
gc.strokeLine(_startPosX, _startPosY + 40, _startPosX + 10, _startPosY + 40);
|
|
||||||
gc.strokeLine(_startPosX, _startPosY + 50, _startPosX + 10, _startPosY + 50);
|
|
||||||
gc.strokeLine(_startPosX, _startPosY + 60, _startPosX + 10, _startPosY + 60);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -3,11 +3,10 @@ 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 implements IDrawingDoors {
|
public class DrawingDoors {
|
||||||
private CountOfDoors _countOfDoors;
|
private CountOfDoors _countOfDoors;
|
||||||
|
|
||||||
@Override
|
public void DrawDoors(GraphicsContext gc, int _startPosX, int _startPosY) {
|
||||||
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);
|
||||||
@ -20,13 +19,13 @@ public class DrawingDoors implements IDrawingDoors {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
public void setCountOfDoors(int number) {
|
||||||
public void setCountOfDoors(int count) {
|
|
||||||
for (CountOfDoors item: CountOfDoors.values()) {
|
for (CountOfDoors item: CountOfDoors.values()) {
|
||||||
if (item.getId() == count) {
|
if (item.getId() == number) {
|
||||||
_countOfDoors = item;
|
_countOfDoors = item;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,33 +0,0 @@
|
|||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,46 +0,0 @@
|
|||||||
package com.example.doubledeckerbus;
|
|
||||||
|
|
||||||
import javafx.scene.canvas.GraphicsContext;
|
|
||||||
|
|
||||||
public class DrawingObjectBus implements IDrawingObject {
|
|
||||||
private DrawingBus _bus = null;
|
|
||||||
|
|
||||||
public DrawingObjectBus(DrawingBus bus)
|
|
||||||
{
|
|
||||||
_bus = bus;
|
|
||||||
}
|
|
||||||
|
|
||||||
public float Step() {
|
|
||||||
if (_bus != null && _bus.Bus != null) {
|
|
||||||
return _bus.Bus.Step;
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Position GetCurrentPosition()
|
|
||||||
{
|
|
||||||
if (_bus != null) {
|
|
||||||
return _bus.GetCurrentPosition();
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void MoveObject(Direction direction)
|
|
||||||
{
|
|
||||||
_bus.MoveTransport(direction);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void SetObject(int x, int y, int width, int height)
|
|
||||||
{
|
|
||||||
_bus.SetPosition(x, y, width, height);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void DrawingObject(GraphicsContext gc)
|
|
||||||
{
|
|
||||||
_bus.DrawTransport(gc);
|
|
||||||
}
|
|
||||||
|
|
||||||
public DrawingBus getBus() {
|
|
||||||
return _bus;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,45 +0,0 @@
|
|||||||
package com.example.doubledeckerbus;
|
|
||||||
|
|
||||||
import java.util.Random;
|
|
||||||
|
|
||||||
public class DrawingPolymorphBus<T extends EntityBus, U extends IDrawingDoors> {
|
|
||||||
Object[] buses;
|
|
||||||
Object[] doors;
|
|
||||||
|
|
||||||
int busesCount = 0;
|
|
||||||
int doorsCount = 0;
|
|
||||||
|
|
||||||
public DrawingPolymorphBus(int busesCount, int doorsCount) {
|
|
||||||
buses = new Object[busesCount];
|
|
||||||
doors = new Object[doorsCount];
|
|
||||||
}
|
|
||||||
|
|
||||||
public int AddEntity(T boat)
|
|
||||||
{
|
|
||||||
if(busesCount < buses.length){
|
|
||||||
buses[busesCount] = boat;
|
|
||||||
return busesCount++;
|
|
||||||
}
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int AddDoors(U paddle)
|
|
||||||
{
|
|
||||||
if(doorsCount < doors.length){
|
|
||||||
doors[doorsCount]=paddle;
|
|
||||||
return doorsCount++;
|
|
||||||
}
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
public DrawingBus CreateBus() {
|
|
||||||
int idBus = new Random().nextInt(busesCount);
|
|
||||||
int idDoor = new Random().nextInt(doorsCount);
|
|
||||||
T selectedBus = (T)buses[idBus];
|
|
||||||
U selectedDoors = (U)doors[idDoor];
|
|
||||||
if (selectedBus instanceof EntityDDB) {
|
|
||||||
return new DrawingDDB(selectedBus, selectedDoors);
|
|
||||||
}
|
|
||||||
return new DrawingBus(selectedBus, selectedDoors);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,37 +0,0 @@
|
|||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -10,7 +10,7 @@ public class EntityBus {
|
|||||||
public Color BodyColor;
|
public Color BodyColor;
|
||||||
public float Step;
|
public float Step;
|
||||||
|
|
||||||
public EntityBus(int speed, float weight, Color bodyColor)
|
public void Init(int speed, float weight, Color bodyColor)
|
||||||
{
|
{
|
||||||
Random rnd = new Random();
|
Random rnd = new Random();
|
||||||
Speed = (speed <= 0) ? rnd.nextInt(50, 150): speed;
|
Speed = (speed <= 0) ? rnd.nextInt(50, 150): speed;
|
||||||
|
@ -1,33 +0,0 @@
|
|||||||
package com.example.doubledeckerbus;
|
|
||||||
|
|
||||||
import javafx.scene.paint.Color;
|
|
||||||
|
|
||||||
public class EntityDDB extends EntityBus {
|
|
||||||
|
|
||||||
public Color ExtraColor;
|
|
||||||
|
|
||||||
public boolean Ladder;
|
|
||||||
|
|
||||||
public boolean SecondStage;
|
|
||||||
|
|
||||||
|
|
||||||
private void setExtraColor(Color extraColor) {
|
|
||||||
ExtraColor = extraColor;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void setLadder(boolean ladder) {
|
|
||||||
Ladder = ladder;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void setSecondStage(boolean secondStage) {
|
|
||||||
SecondStage = secondStage;
|
|
||||||
}
|
|
||||||
|
|
||||||
public EntityDDB(int speed, float height, Color bodyColor, Color extraColor, boolean ladder, boolean secondStage)
|
|
||||||
{
|
|
||||||
super(speed, height, bodyColor);
|
|
||||||
ExtraColor = extraColor;
|
|
||||||
Ladder = ladder;
|
|
||||||
SecondStage = secondStage;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,17 +0,0 @@
|
|||||||
package com.example.doubledeckerbus;
|
|
||||||
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.function.Consumer;
|
|
||||||
|
|
||||||
public class Event<T> {
|
|
||||||
private final Set<Consumer<T>> listeners = new HashSet<>();
|
|
||||||
|
|
||||||
public void AddListener(Consumer<T> listener) {
|
|
||||||
listeners.add(listener);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Broadcast(T args) {
|
|
||||||
listeners.forEach(x -> x.accept(args));
|
|
||||||
}
|
|
||||||
}
|
|
@ -8,16 +8,13 @@ import javafx.stage.Stage;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
public class Form extends Application {
|
public class Form extends Application {
|
||||||
static Stage myStage;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void start(Stage stage) throws IOException {
|
public void start(Stage stage) throws IOException {
|
||||||
FXMLLoader fxmlLoader = new FXMLLoader(Form.class.getResource("FormMapWithSetBus.fxml"));
|
FXMLLoader fxmlLoader = new FXMLLoader(Form.class.getResource("hello-view.fxml"));
|
||||||
Scene scene = new Scene(fxmlLoader.load());
|
Scene scene = new Scene(fxmlLoader.load());
|
||||||
myStage = stage;
|
stage.setTitle("DoubleDeckerBus");
|
||||||
myStage.setTitle("DoubleDeckerBus");
|
stage.setScene(scene);
|
||||||
myStage.setScene(scene);
|
stage.show();
|
||||||
myStage.show();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
@ -1,9 +0,0 @@
|
|||||||
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);
|
|
||||||
}
|
|
@ -1,15 +0,0 @@
|
|||||||
package com.example.doubledeckerbus;
|
|
||||||
|
|
||||||
import javafx.scene.canvas.GraphicsContext;
|
|
||||||
|
|
||||||
public interface IDrawingObject {
|
|
||||||
float Step = -1;
|
|
||||||
|
|
||||||
void SetObject(int x, int y, int width, int height);
|
|
||||||
|
|
||||||
void MoveObject(Direction direction);
|
|
||||||
|
|
||||||
void DrawingObject(GraphicsContext g);
|
|
||||||
|
|
||||||
Position GetCurrentPosition();
|
|
||||||
}
|
|
@ -1,151 +0,0 @@
|
|||||||
package com.example.doubledeckerbus;
|
|
||||||
|
|
||||||
import javafx.scene.canvas.GraphicsContext;
|
|
||||||
import javafx.scene.paint.Color;
|
|
||||||
|
|
||||||
import java.util.Stack;
|
|
||||||
|
|
||||||
public class MapWithSetBusesGeneric<T extends IDrawingObject, U extends AbstractMap> {
|
|
||||||
private final int _pictureWidth;
|
|
||||||
private final int _pictureHeight;
|
|
||||||
private final int _placeSizeWidth = 210;
|
|
||||||
private final int _placeSizeHeight = 90;
|
|
||||||
private final SetBusesGeneric<T> _setBuses;
|
|
||||||
private final Stack<T> _deletedBuses;
|
|
||||||
private U _map;
|
|
||||||
|
|
||||||
public MapWithSetBusesGeneric(int picWidth, int picHeight, U map)
|
|
||||||
{
|
|
||||||
int width = picWidth / _placeSizeWidth;
|
|
||||||
int height = picHeight / _placeSizeHeight;
|
|
||||||
_setBuses = new SetBusesGeneric<T>(width * height);
|
|
||||||
_pictureWidth = picWidth;
|
|
||||||
_pictureHeight = picHeight;
|
|
||||||
_map = map;
|
|
||||||
_deletedBuses = new Stack<>();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void changeMap(U map) {
|
|
||||||
_map = map;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int add(T bus)
|
|
||||||
{
|
|
||||||
return _setBuses.Insert(bus);
|
|
||||||
}
|
|
||||||
|
|
||||||
public T remove(int position)
|
|
||||||
{
|
|
||||||
T deletedBus = _setBuses.Remove(position);
|
|
||||||
_deletedBuses.push(deletedBus);
|
|
||||||
return deletedBus;
|
|
||||||
}
|
|
||||||
|
|
||||||
public T getDeletedBus(){
|
|
||||||
if(_deletedBuses.empty())
|
|
||||||
return null;
|
|
||||||
return _deletedBuses.pop();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void ShowSet(GraphicsContext gc)
|
|
||||||
{
|
|
||||||
DrawBackground(gc);
|
|
||||||
DrawBuses(gc);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void ShowOnMap(GraphicsContext gc)
|
|
||||||
{
|
|
||||||
Shaking();
|
|
||||||
for (var bus: _setBuses.GetBuses())
|
|
||||||
{
|
|
||||||
if (bus != null)
|
|
||||||
{
|
|
||||||
_map.CreateMap(_pictureWidth, _pictureHeight, bus, gc);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public void MoveObject(Direction direction)
|
|
||||||
{
|
|
||||||
if (_map != null)
|
|
||||||
{
|
|
||||||
_map.MoveObject(direction);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void Shaking()
|
|
||||||
{
|
|
||||||
int j = _setBuses.Count() - 1;
|
|
||||||
for (int i = 0; i < _setBuses.Count(); i++)
|
|
||||||
{
|
|
||||||
if (_setBuses.Get(i) == null)
|
|
||||||
{
|
|
||||||
for (; j > i; j--)
|
|
||||||
{
|
|
||||||
var bus = _setBuses.Get(j);
|
|
||||||
if (bus != null)
|
|
||||||
{
|
|
||||||
_setBuses.Insert(bus, i);
|
|
||||||
_setBuses.Remove(j);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (j <= i)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void DrawBackground(GraphicsContext gc)
|
|
||||||
{
|
|
||||||
gc.setFill(Color.BLACK);
|
|
||||||
for (int i = 0; i < _pictureWidth / _placeSizeWidth; i++)
|
|
||||||
{
|
|
||||||
for (int j = 0; j < _pictureHeight / _placeSizeHeight + 1; ++j)
|
|
||||||
{//линия рамзетки места
|
|
||||||
gc.strokeLine(i * _placeSizeWidth, j * _placeSizeHeight,
|
|
||||||
i * _placeSizeWidth + _placeSizeWidth / 2, j * _placeSizeHeight);
|
|
||||||
}
|
|
||||||
gc.strokeLine(i * _placeSizeWidth, 0, i * _placeSizeWidth, (_pictureHeight / _placeSizeHeight) * _placeSizeHeight);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void DrawBuses(GraphicsContext gc) {
|
|
||||||
int width = _pictureWidth / _placeSizeWidth;
|
|
||||||
int height = _pictureHeight / _placeSizeHeight;
|
|
||||||
|
|
||||||
int currentWidth = width - 1;
|
|
||||||
int currentHeight = 0;
|
|
||||||
|
|
||||||
for (var bus: _setBuses.GetBuses()) {
|
|
||||||
if (bus == null){
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
bus.SetObject(currentWidth * _placeSizeWidth,
|
|
||||||
currentHeight * _placeSizeHeight,
|
|
||||||
_pictureWidth, _pictureHeight);
|
|
||||||
bus.DrawingObject(gc);
|
|
||||||
|
|
||||||
if (currentWidth > 0)
|
|
||||||
currentWidth--;
|
|
||||||
else {
|
|
||||||
currentWidth = width - 1;
|
|
||||||
currentHeight++;
|
|
||||||
}
|
|
||||||
if (currentHeight > height) return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getCount() {
|
|
||||||
return _setBuses.Count();
|
|
||||||
}
|
|
||||||
|
|
||||||
public T getBus(int ind){
|
|
||||||
return _setBuses.Get(ind);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,65 +0,0 @@
|
|||||||
package com.example.doubledeckerbus;
|
|
||||||
|
|
||||||
import javafx.collections.FXCollections;
|
|
||||||
import javafx.collections.ObservableList;
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class MapsCollection {
|
|
||||||
HashMap<String, MapWithSetBusesGeneric<DrawingObjectBus, AbstractMap>> _mapStorages;
|
|
||||||
|
|
||||||
public List<String> Keys() {
|
|
||||||
return _mapStorages.keySet().stream().toList();
|
|
||||||
}
|
|
||||||
|
|
||||||
private int _pictureWidth;
|
|
||||||
|
|
||||||
private int _pictureHeight;
|
|
||||||
|
|
||||||
public MapsCollection(int pictureWidth, int pictureHeight)
|
|
||||||
{
|
|
||||||
_mapStorages = new HashMap<>();
|
|
||||||
_pictureWidth = pictureWidth;
|
|
||||||
_pictureHeight = pictureHeight;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void AddMap(String name, AbstractMap map)
|
|
||||||
{
|
|
||||||
if (Keys().contains(name)) return;
|
|
||||||
_mapStorages.put(name, new MapWithSetBusesGeneric<DrawingObjectBus, AbstractMap>(_pictureWidth, _pictureHeight, map));
|
|
||||||
}
|
|
||||||
|
|
||||||
public void DelMap(String name)
|
|
||||||
{
|
|
||||||
_mapStorages.remove(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
public MapWithSetBusesGeneric<DrawingObjectBus, AbstractMap> GetId(String id)
|
|
||||||
{
|
|
||||||
return _mapStorages.get(id);
|
|
||||||
}
|
|
||||||
|
|
||||||
public ObservableList<String> toObserveList() {
|
|
||||||
ObservableList<String> result = FXCollections.observableArrayList();
|
|
||||||
result.addAll(_mapStorages.keySet());
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
public MapWithSetBusesGeneric<DrawingObjectBus, AbstractMap> get(String id) {
|
|
||||||
if (_mapStorages.containsKey(id))
|
|
||||||
{
|
|
||||||
return _mapStorages.get(id);
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public DrawingObjectBus get(String name, int id) {
|
|
||||||
if (_mapStorages.containsKey(name))
|
|
||||||
{
|
|
||||||
return _mapStorages.get(name).getBus(id);
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,15 +0,0 @@
|
|||||||
package com.example.doubledeckerbus;
|
|
||||||
|
|
||||||
public class Position {
|
|
||||||
public float Left;
|
|
||||||
public float Right;
|
|
||||||
public float Top;
|
|
||||||
public float Bottom;
|
|
||||||
|
|
||||||
public Position (float left, float right, float top, float bottom) {
|
|
||||||
Left = left;
|
|
||||||
Right = right;
|
|
||||||
Top = top;
|
|
||||||
Bottom = bottom;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,26 +0,0 @@
|
|||||||
package com.example.doubledeckerbus;
|
|
||||||
|
|
||||||
import java.io.Serializable;
|
|
||||||
import javafx.scene.paint.Color;
|
|
||||||
|
|
||||||
public class SerializableColor implements Serializable
|
|
||||||
{
|
|
||||||
private final double red;
|
|
||||||
private final double green;
|
|
||||||
private final double blue;
|
|
||||||
private final double alpha;
|
|
||||||
|
|
||||||
public SerializableColor(Color color)
|
|
||||||
{
|
|
||||||
red = color.getRed();
|
|
||||||
green = color.getGreen();
|
|
||||||
blue = color.getBlue();
|
|
||||||
alpha = color.getOpacity();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Color getFXColor()
|
|
||||||
{
|
|
||||||
return new Color(red, green, blue, alpha);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,64 +0,0 @@
|
|||||||
package com.example.doubledeckerbus;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Objects;
|
|
||||||
|
|
||||||
|
|
||||||
class SetBusesGeneric<T> {
|
|
||||||
private ArrayList<T> _places;
|
|
||||||
private int BusyPlaces = 0;
|
|
||||||
|
|
||||||
private int _maxCount;
|
|
||||||
|
|
||||||
public SetBusesGeneric(int count) {
|
|
||||||
_maxCount = count;
|
|
||||||
_places = new ArrayList<>();
|
|
||||||
}
|
|
||||||
|
|
||||||
public int Insert(T bus)
|
|
||||||
{
|
|
||||||
return Insert(bus, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
public int Insert(T bus, int position)
|
|
||||||
{
|
|
||||||
if (position < 0 || position >= _maxCount || BusyPlaces == _maxCount) return -1;
|
|
||||||
|
|
||||||
BusyPlaces++;
|
|
||||||
_places.add(position, bus);
|
|
||||||
return position;
|
|
||||||
}
|
|
||||||
|
|
||||||
public T Remove(int position)
|
|
||||||
{
|
|
||||||
if (position < 0 || position >= _maxCount) return null;
|
|
||||||
T savedBus = _places.get(position - 1);
|
|
||||||
_places.set(position - 1, null);
|
|
||||||
return savedBus;
|
|
||||||
}
|
|
||||||
|
|
||||||
public T Get(int position)
|
|
||||||
{
|
|
||||||
if (position < 0 || position >= _maxCount) return null;
|
|
||||||
return _places.get(position);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public ArrayList<T> GetBuses() {
|
|
||||||
ArrayList<T> result = new ArrayList<>();
|
|
||||||
for (var bus: _places) {
|
|
||||||
if (bus != null){
|
|
||||||
result.add(bus);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int Count() {
|
|
||||||
return _places.size();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
@ -1,44 +0,0 @@
|
|||||||
package com.example.doubledeckerbus;
|
|
||||||
|
|
||||||
import javafx.scene.paint.Color;
|
|
||||||
|
|
||||||
public class SimpleMap extends AbstractMap{
|
|
||||||
@Override
|
|
||||||
protected void GenerateMap() {
|
|
||||||
_map = new int[100][100];
|
|
||||||
_size_x = (float)_width / _map.length;
|
|
||||||
_size_y = (float)_height / _map[0].length;
|
|
||||||
|
|
||||||
for (int i = 0; i < _map.length; ++i)
|
|
||||||
{
|
|
||||||
for (int j = 0; j < _map[0].length; ++j)
|
|
||||||
{
|
|
||||||
_map[i][j] = _freeRoad;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int counter = 0;
|
|
||||||
while (counter < 20)
|
|
||||||
{
|
|
||||||
int x = _random.nextInt(0, 100);
|
|
||||||
int y = _random.nextInt(0, 100);
|
|
||||||
if (_map[x][y] == _freeRoad)
|
|
||||||
{
|
|
||||||
_map[x][y] = _barrier;
|
|
||||||
counter++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void DrawRoadPart(int i, int j) {
|
|
||||||
gc.setFill(Color.GRAY);
|
|
||||||
gc.fillRect(i * _size_x, j * _size_y, i * (_size_x + 1), j * (_size_y + 1));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void DrawBarrierPart(int i, int j) {
|
|
||||||
gc.setFill(Color.BLACK);
|
|
||||||
gc.fillRect(i * _size_x, j * _size_y, i * (_size_x + 1), j * (_size_y + 1));
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,49 +0,0 @@
|
|||||||
package com.example.doubledeckerbus;
|
|
||||||
|
|
||||||
import javafx.scene.paint.Color;
|
|
||||||
|
|
||||||
public class WaterMap extends AbstractMap{
|
|
||||||
@Override
|
|
||||||
protected void GenerateMap() {
|
|
||||||
_map = new int[100][100];
|
|
||||||
_size_x = (float)_width / _map.length;
|
|
||||||
_size_y = (float)_height / _map[0].length;
|
|
||||||
|
|
||||||
for (int i = 0; i < _map.length; ++i)
|
|
||||||
{
|
|
||||||
for (int j = 0; j < _map[0].length; ++j)
|
|
||||||
{
|
|
||||||
_map[i][j] = _freeRoad;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int counter = 0;
|
|
||||||
while (counter < 50)
|
|
||||||
{
|
|
||||||
int x = _random.nextInt(0, 100);
|
|
||||||
int y = _random.nextInt(0, 100);
|
|
||||||
if (_map[x][y] == _freeRoad)
|
|
||||||
{
|
|
||||||
_map[x][y] = _barrier;
|
|
||||||
counter++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void DrawRoadPart(int i, int j) {
|
|
||||||
if (_random.nextInt(0,20) == 9) {
|
|
||||||
gc.setFill(Color.GREEN);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
gc.setFill(Color.LIGHTGREEN);
|
|
||||||
}
|
|
||||||
gc.fillRect(i * _size_x, j * _size_y, i * (_size_x + 1), j * (_size_y + 1));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void DrawBarrierPart(int i, int j) {
|
|
||||||
gc.setFill(Color.BLUE);
|
|
||||||
gc.fillRect(i * _size_x, j * _size_y, i * (_size_x + 1), j * (_size_y + 1));
|
|
||||||
}
|
|
||||||
}
|
|
@ -4,7 +4,6 @@ module com.example.doubledeckerbus {
|
|||||||
|
|
||||||
requires org.controlsfx.controls;
|
requires org.controlsfx.controls;
|
||||||
requires org.kordamp.bootstrapfx.core;
|
requires org.kordamp.bootstrapfx.core;
|
||||||
requires javafx.graphics;
|
|
||||||
|
|
||||||
opens com.example.doubledeckerbus to javafx.fxml;
|
opens com.example.doubledeckerbus to javafx.fxml;
|
||||||
exports com.example.doubledeckerbus;
|
exports com.example.doubledeckerbus;
|
||||||
|
@ -1,76 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
|
|
||||||
<?import javafx.scene.canvas.Canvas?>
|
|
||||||
<?import javafx.scene.control.Button?>
|
|
||||||
<?import javafx.scene.control.CheckBox?>
|
|
||||||
<?import javafx.scene.control.Label?>
|
|
||||||
<?import javafx.scene.control.Spinner?>
|
|
||||||
<?import javafx.scene.control.SpinnerValueFactory.IntegerSpinnerValueFactory?>
|
|
||||||
<?import javafx.scene.layout.Pane?>
|
|
||||||
<?import javafx.scene.layout.Region?>
|
|
||||||
<?import javafx.scene.layout.StackPane?>
|
|
||||||
|
|
||||||
<Pane fx:id="root" prefHeight="395.0" prefWidth="642.0" xmlns="http://javafx.com/javafx/18" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.example.doubledeckerbus.ControllerBusConfig">
|
|
||||||
<Pane layoutX="5.0" layoutY="5.0" prefHeight="379.0" prefWidth="307">
|
|
||||||
<Label layoutX="18.0" layoutY="18.0" text="Скорость">
|
|
||||||
Speed:
|
|
||||||
</Label>
|
|
||||||
<Label layoutX="181.0" layoutY="18.0" text="Вес:">
|
|
||||||
Weight:
|
|
||||||
</Label>
|
|
||||||
<Spinner fx:id="spinnerSpeed" layoutX="90.0" layoutY="14.0" prefWidth="70">
|
|
||||||
<valueFactory>
|
|
||||||
<SpinnerValueFactory.IntegerSpinnerValueFactory initialValue="100" max="300" min="100" />
|
|
||||||
</valueFactory>
|
|
||||||
</Spinner>
|
|
||||||
<Spinner fx:id="spinnerWeight" layoutX="222.0" layoutY="14.0" prefWidth="70">
|
|
||||||
<valueFactory>
|
|
||||||
<SpinnerValueFactory.IntegerSpinnerValueFactory initialValue="100" max="2000" min="1000" />
|
|
||||||
</valueFactory>
|
|
||||||
</Spinner>
|
|
||||||
<Pane layoutX="12.0" layoutY="131.0" prefHeight="126.0" prefWidth="280.0">
|
|
||||||
<Region layoutX="25.0" layoutY="9.0" onDragDetected="#RegionColor_OnDragDetected" prefHeight="46.0" prefWidth="46.0" style="-fx-background-color: orangered;" />
|
|
||||||
<Region layoutX="79.0" layoutY="9.0" onDragDetected="#RegionColor_OnDragDetected" prefHeight="46.0" prefWidth="46.0" style="-fx-background-color: yellowgreen;" />
|
|
||||||
<Region layoutX="140.0" layoutY="9.0" onDragDetected="#RegionColor_OnDragDetected" prefHeight="46.0" prefWidth="46.0" style="-fx-background-color: cornflowerblue;" />
|
|
||||||
<Region layoutX="197.0" layoutY="9.0" onDragDetected="#RegionColor_OnDragDetected" prefHeight="46.0" prefWidth="46.0" style="-fx-background-color: yellow;" />
|
|
||||||
<Region layoutX="25.0" layoutY="66.0" onDragDetected="#RegionColor_OnDragDetected" prefHeight="46.0" prefWidth="46.0" style="-fx-background-color: white;" />
|
|
||||||
<Region layoutX="79.0" layoutY="66.0" onDragDetected="#RegionColor_OnDragDetected" prefHeight="46.0" prefWidth="46.0" style="-fx-background-color: gray;" />
|
|
||||||
<Region layoutX="140.0" layoutY="66.0" onDragDetected="#RegionColor_OnDragDetected" prefHeight="46.0" prefWidth="46.0" style="-fx-background-color: black;" />
|
|
||||||
<Region layoutX="197.0" layoutY="66.0" onDragDetected="#RegionColor_OnDragDetected" prefHeight="46.0" prefWidth="46.0" style="-fx-background-color: purple;" />
|
|
||||||
</Pane>
|
|
||||||
<CheckBox fx:id="checkBoxLadder" layoutX="188.0" layoutY="110.0" text="Второй этаж" />
|
|
||||||
<CheckBox fx:id="checkBoxSecondStage" layoutX="8" layoutY="110" prefHeight="18.0" prefWidth="135.0" text="Лестница" />
|
|
||||||
<Label fx:id="labelSimpleObject" alignment="CENTER" layoutX="14.0" layoutY="282.0" onDragDetected="#LabelObject_OnDragDetected" prefHeight="30" prefWidth="127.0" style="-fx-border-color: black;" textOverrun="CLIP">
|
|
||||||
Simple
|
|
||||||
</Label>
|
|
||||||
<Label fx:id="labelModifiedObject" alignment="CENTER" layoutX="165.0" layoutY="282.0" onDragDetected="#LabelObject_OnDragDetected" prefHeight="30" prefWidth="135.0" style="-fx-border-color: black;">
|
|
||||||
Modified
|
|
||||||
</Label>
|
|
||||||
<Label layoutX="101.0" layoutY="56.0" text="Двери">
|
|
||||||
Track rollers
|
|
||||||
</Label>
|
|
||||||
<Spinner fx:id="spinnerDoors" layoutX="150.0" layoutY="52.0" prefWidth="70">
|
|
||||||
<valueFactory>
|
|
||||||
<SpinnerValueFactory.IntegerSpinnerValueFactory initialValue="1" max="5" min="3" />
|
|
||||||
</valueFactory>
|
|
||||||
</Spinner>
|
|
||||||
<Label fx:id="labelTriangle" alignment="CENTER" layoutX="14.0" layoutY="331.0" onDragDetected="#LabelObject_OnDragDetected" prefHeight="30" prefWidth="97.0" style="-fx-border-color: black;" text="Треугольник" textOverrun="CLIP" />
|
|
||||||
<Label fx:id="labelOval" alignment="CENTER" layoutX="128.0" layoutY="331.0" onDragDetected="#LabelObject_OnDragDetected" prefHeight="30" prefWidth="52.0" style="-fx-border-color: black;" text="Овал" textOverrun="CLIP" />
|
|
||||||
<Label fx:id="labelRect" alignment="CENTER" layoutX="199.0" layoutY="331.0" onDragDetected="#LabelObject_OnDragDetected" prefHeight="30" prefWidth="90.0" style="-fx-border-color: black;" text="Квадрат" textOverrun="CLIP" />
|
|
||||||
</Pane>
|
|
||||||
<Label alignment="CENTER" layoutX="356.0" layoutY="52.0" onDragDropped="#LabelBaseColor_OnDragDropped" onDragOver="#LabelColor_OnDragOver" prefHeight="30" prefWidth="127.0" style="-fx-border-color: black;" text="Цвет">
|
|
||||||
Color
|
|
||||||
</Label>
|
|
||||||
<Label alignment="CENTER" layoutX="499.0" layoutY="52.0" onDragDropped="#LabelDopColor_OnDragDropped" onDragOver="#LabelColor_OnDragOver" prefHeight="30" prefWidth="119.0" style="-fx-border-color: black;" text="Доп цвет">
|
|
||||||
Dop Color
|
|
||||||
</Label>
|
|
||||||
<StackPane layoutX="352.0" layoutY="137.0" onDragDropped="#CanvasObject_OnDragDropped" onDragOver="#CanvasObject_OnDragOver" prefHeight="152.0" prefWidth="262.0" style="-fx-border-color: #b8becc; -fx-border-radius: 5; -fx-border-width: 2;">
|
|
||||||
<Canvas fx:id="canvasObject" height="152.0" width="267.0" />
|
|
||||||
</StackPane>
|
|
||||||
<Button fx:id="buttonAdd" layoutX="367.0" layoutY="350.0" onAction="#ButtonOk_Click" prefHeight="26" prefWidth="90" text="Создать">
|
|
||||||
Add
|
|
||||||
</Button>
|
|
||||||
<Button fx:id="buttonCancel" layoutX="522.0" layoutY="350.0" prefHeight="26" prefWidth="90" text="Отмена">
|
|
||||||
Cancel
|
|
||||||
</Button>
|
|
||||||
</Pane>
|
|
@ -1,104 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
|
|
||||||
<?import javafx.scene.Group?>
|
|
||||||
<?import javafx.scene.canvas.Canvas?>
|
|
||||||
<?import javafx.scene.control.Button?>
|
|
||||||
<?import javafx.scene.control.ChoiceBox?>
|
|
||||||
<?import javafx.scene.control.ListView?>
|
|
||||||
<?import javafx.scene.control.TextField?>
|
|
||||||
<?import javafx.scene.image.Image?>
|
|
||||||
<?import javafx.scene.image.ImageView?>
|
|
||||||
<?import javafx.scene.layout.AnchorPane?>
|
|
||||||
<?import javafx.scene.layout.ColumnConstraints?>
|
|
||||||
<?import javafx.scene.layout.GridPane?>
|
|
||||||
<?import javafx.scene.layout.RowConstraints?>
|
|
||||||
|
|
||||||
<GridPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="745.0" prefWidth="819.0" xmlns="http://javafx.com/javafx/18" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.example.doubledeckerbus.ControllerMapWithSetBus">
|
|
||||||
<columnConstraints>
|
|
||||||
<ColumnConstraints hgrow="ALWAYS" maxWidth="463.0" minWidth="10.0" percentWidth="70.0" prefWidth="423.0" />
|
|
||||||
<ColumnConstraints hgrow="NEVER" maxWidth="294.0" minWidth="10.0" percentWidth="30.0" prefWidth="177.0" />
|
|
||||||
</columnConstraints>
|
|
||||||
<rowConstraints>
|
|
||||||
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
|
|
||||||
</rowConstraints>
|
|
||||||
<children>
|
|
||||||
<AnchorPane fx:id="pictureBoxBus" prefHeight="9.9999999E7" prefWidth="9.9999999E7">
|
|
||||||
<children>
|
|
||||||
<Canvas fx:id="canvasBus" height="745.0" width="573.0" />
|
|
||||||
</children>
|
|
||||||
</AnchorPane>
|
|
||||||
<Group GridPane.columnIndex="1" />
|
|
||||||
<GridPane GridPane.columnIndex="1">
|
|
||||||
<columnConstraints>
|
|
||||||
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" percentWidth="100.0" prefWidth="100.0" />
|
|
||||||
</columnConstraints>
|
|
||||||
<rowConstraints>
|
|
||||||
<RowConstraints maxHeight="120.0" minHeight="0.0" prefHeight="34.0" vgrow="SOMETIMES" />
|
|
||||||
<RowConstraints maxHeight="200.0" minHeight="10.0" prefHeight="24.0" vgrow="SOMETIMES" />
|
|
||||||
<RowConstraints maxHeight="200.0" minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
|
|
||||||
<RowConstraints maxHeight="200.0" minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
|
|
||||||
<RowConstraints maxHeight="200.0" minHeight="8.0" prefHeight="27.0" vgrow="SOMETIMES" />
|
|
||||||
<RowConstraints maxHeight="269.0" minHeight="10.0" prefHeight="65.0" vgrow="SOMETIMES" />
|
|
||||||
<RowConstraints maxHeight="250.0" minHeight="0.0" prefHeight="44.0" vgrow="SOMETIMES" />
|
|
||||||
<RowConstraints maxHeight="272.0" minHeight="10.0" prefHeight="34.0" vgrow="SOMETIMES" />
|
|
||||||
<RowConstraints maxHeight="272.0" minHeight="10.0" prefHeight="34.0" vgrow="SOMETIMES" />
|
|
||||||
<RowConstraints maxHeight="272.0" minHeight="0.0" prefHeight="46.0" vgrow="SOMETIMES" />
|
|
||||||
<RowConstraints maxHeight="272.0" minHeight="0.0" prefHeight="46.0" vgrow="SOMETIMES" />
|
|
||||||
<RowConstraints maxHeight="272.0" minHeight="10.0" prefHeight="134.0" vgrow="SOMETIMES" />
|
|
||||||
</rowConstraints>
|
|
||||||
<children>
|
|
||||||
<ChoiceBox fx:id="comboBoxSelectorMap" prefHeight="50.0" prefWidth="9.9999999E7" GridPane.rowIndex="1" />
|
|
||||||
<Button fx:id="buttonAddBus" mnemonicParsing="false" onAction="#ButtonAddBus_Click" prefHeight="50.0" prefWidth="9.999999999E9" text="Добавить автобус" GridPane.rowIndex="5" />
|
|
||||||
<TextField fx:id="textBoxPosition" GridPane.rowIndex="6" />
|
|
||||||
<Button fx:id="buttonRemoveCar" mnemonicParsing="false" onAction="#ButtonRemoveBus_Click" prefHeight="63.0" prefWidth="9.999999999E9" text="Удалить автобус" GridPane.rowIndex="7" />
|
|
||||||
<Button fx:id="buttonShowMap" mnemonicParsing="false" onAction="#ButtonShowOnMap_Click" prefHeight="63.0" prefWidth="9.99999999999E11" text="Посмотреть карту" GridPane.rowIndex="10" />
|
|
||||||
<AnchorPane prefHeight="157.0" prefWidth="332.0" GridPane.rowIndex="11">
|
|
||||||
<children>
|
|
||||||
<Button fx:id="buttonLeft" layoutX="38.0" layoutY="52.0" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" mnemonicParsing="false" onAction="#ButtonMove_Click" prefHeight="30.0" prefWidth="30.0" AnchorPane.bottomAnchor="52.0" AnchorPane.rightAnchor="111.0">
|
|
||||||
<graphic>
|
|
||||||
<ImageView fitHeight="27.0" fitWidth="10.0" pickOnBounds="true" preserveRatio="true">
|
|
||||||
<image>
|
|
||||||
<Image url="@images/LeftArrow.png" />
|
|
||||||
</image>
|
|
||||||
</ImageView>
|
|
||||||
</graphic>
|
|
||||||
</Button>
|
|
||||||
<Button fx:id="buttonDown" layoutX="68.0" layoutY="82.0" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" mnemonicParsing="false" onAction="#ButtonMove_Click" prefHeight="30.0" prefWidth="30.0" AnchorPane.bottomAnchor="22.0" AnchorPane.rightAnchor="81.0">
|
|
||||||
<graphic>
|
|
||||||
<ImageView fitHeight="27.0" fitWidth="10.0" pickOnBounds="true" preserveRatio="true">
|
|
||||||
<image>
|
|
||||||
<Image url="@images/DownArrow.png" />
|
|
||||||
</image>
|
|
||||||
</ImageView>
|
|
||||||
</graphic>
|
|
||||||
</Button>
|
|
||||||
<Button fx:id="buttonRight" layoutX="98.0" layoutY="52.0" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" mnemonicParsing="false" onAction="#ButtonMove_Click" prefHeight="30.0" prefWidth="30.0" AnchorPane.bottomAnchor="52.0" AnchorPane.rightAnchor="51.0">
|
|
||||||
<graphic>
|
|
||||||
<ImageView fitHeight="27.0" fitWidth="10.0" pickOnBounds="true" preserveRatio="true">
|
|
||||||
<image>
|
|
||||||
<Image url="@images/RightArrow.png" />
|
|
||||||
</image>
|
|
||||||
</ImageView>
|
|
||||||
</graphic>
|
|
||||||
</Button>
|
|
||||||
<Button fx:id="buttonUp" layoutX="68.0" layoutY="22.0" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" mnemonicParsing="false" onAction="#ButtonMove_Click" prefHeight="30.0" prefWidth="30.0" AnchorPane.bottomAnchor="82.0" AnchorPane.rightAnchor="81.0">
|
|
||||||
<graphic>
|
|
||||||
<ImageView fitHeight="27.0" fitWidth="10.0" pickOnBounds="true" preserveRatio="true">
|
|
||||||
<image>
|
|
||||||
<Image url="@images/UpArrow.png" />
|
|
||||||
</image>
|
|
||||||
</ImageView>
|
|
||||||
</graphic>
|
|
||||||
</Button>
|
|
||||||
</children>
|
|
||||||
</AnchorPane>
|
|
||||||
<Button fx:id="buttonShowStorage" mnemonicParsing="false" onAction="#ButtonShowStorage_Click" prefHeight="50.0" prefWidth="1.0E16" text="Посмотреть хранилище" GridPane.rowIndex="9" />
|
|
||||||
<TextField fx:id="TextFieldMap" />
|
|
||||||
<Button fx:id="Map" mnemonicParsing="false" onAction="#ButtonAddMap_Click" prefHeight="50.0" prefWidth="9.999999999E9" text="Добавить карту" GridPane.rowIndex="2" />
|
|
||||||
<ListView fx:id="listViewMaps" prefHeight="200.0" prefWidth="200.0" GridPane.rowIndex="3" />
|
|
||||||
<Button fx:id="buttonDeleteMap" mnemonicParsing="false" onAction="#ButtonDeleteMap_Click" prefHeight="50.0" prefWidth="9.999999999E9" text="Удалить карту" GridPane.rowIndex="4" />
|
|
||||||
<Button fx:id="ButtonDeleteEditBus" mnemonicParsing="false" onAction="#ButtonDeleteEditBus_Click" prefHeight="63.0" prefWidth="9.999999999E9" text="Вернуть автобус" GridPane.rowIndex="8" />
|
|
||||||
</children>
|
|
||||||
</GridPane>
|
|
||||||
</children>
|
|
||||||
</GridPane>
|
|
@ -1,43 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
|
|
||||||
<?import javafx.geometry.Insets?>
|
|
||||||
<?import javafx.scene.canvas.Canvas?>
|
|
||||||
<?import javafx.scene.control.Button?>
|
|
||||||
<?import javafx.scene.control.ChoiceBox?>
|
|
||||||
<?import javafx.scene.control.Label?>
|
|
||||||
<?import javafx.scene.layout.AnchorPane?>
|
|
||||||
<?import javafx.scene.layout.ColumnConstraints?>
|
|
||||||
<?import javafx.scene.layout.GridPane?>
|
|
||||||
<?import javafx.scene.layout.HBox?>
|
|
||||||
<?import javafx.scene.layout.RowConstraints?>
|
|
||||||
|
|
||||||
<GridPane alignment="CENTER" prefHeight="691.0" prefWidth="1041.0" xmlns="http://javafx.com/javafx/18" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.example.doubledeckerbus.ControllerPolymorph">
|
|
||||||
<columnConstraints>
|
|
||||||
<ColumnConstraints hgrow="ALWAYS" minWidth="10.0" percentWidth="100.0" />
|
|
||||||
</columnConstraints>
|
|
||||||
<rowConstraints>
|
|
||||||
<RowConstraints fillHeight="false" maxHeight="1.7976931348623157E308" percentHeight="90.0" vgrow="ALWAYS" />
|
|
||||||
<RowConstraints fillHeight="false" maxHeight="-Infinity" minHeight="-Infinity" percentHeight="10.0" prefHeight="31.0" vgrow="NEVER" />
|
|
||||||
</rowConstraints>
|
|
||||||
<children>
|
|
||||||
<HBox alignment="CENTER_LEFT" prefHeight="57.0" prefWidth="777.0" spacing="20.0" GridPane.rowIndex="1">
|
|
||||||
<children>
|
|
||||||
<Label fx:id="statusSpeed" text="Скорость:" />
|
|
||||||
<Label fx:id="statusWeight" text="Вес:" />
|
|
||||||
<Label fx:id="statusColor" text="Цвет:" />
|
|
||||||
<Label text="Колл-во дверей:" />
|
|
||||||
<ChoiceBox fx:id="choiceDoors" prefHeight="24.0" prefWidth="58.0" />
|
|
||||||
</children>
|
|
||||||
</HBox>
|
|
||||||
<AnchorPane fx:id="pictureBoxBus" maxHeight="2000000.0" maxWidth="2000000.0" minHeight="0.0" minWidth="0.0" prefHeight="603.0" prefWidth="1020.0">
|
|
||||||
<children>
|
|
||||||
<Canvas fx:id="canvasBus" layoutY="38.0" AnchorPane.leftAnchor="0.0" AnchorPane.topAnchor="0.0" />
|
|
||||||
<Button fx:id="buttonCreate" layoutX="6.0" layoutY="565.0" mnemonicParsing="false" onAction="#ButtonCreate_Click" text="Создать" AnchorPane.bottomAnchor="14.0" AnchorPane.leftAnchor="6.0" />
|
|
||||||
<Button fx:id="buttonCreateExtra" layoutX="90.0" layoutY="565.0" mnemonicParsing="false" onAction="#ButtonCreateExtra_Click" text="Продвинутый объект" AnchorPane.bottomAnchor="14.0" AnchorPane.leftAnchor="90.0" />
|
|
||||||
</children>
|
|
||||||
</AnchorPane>
|
|
||||||
</children>
|
|
||||||
<padding>
|
|
||||||
<Insets bottom="10.0" left="10.0" right="10.0" top="10.0" />
|
|
||||||
</padding>
|
|
||||||
</GridPane>
|
|
@ -4,7 +4,6 @@
|
|||||||
<?import javafx.scene.canvas.Canvas?>
|
<?import javafx.scene.canvas.Canvas?>
|
||||||
<?import javafx.scene.control.Button?>
|
<?import javafx.scene.control.Button?>
|
||||||
<?import javafx.scene.control.ChoiceBox?>
|
<?import javafx.scene.control.ChoiceBox?>
|
||||||
<?import javafx.scene.control.ColorPicker?>
|
|
||||||
<?import javafx.scene.control.Label?>
|
<?import javafx.scene.control.Label?>
|
||||||
<?import javafx.scene.image.Image?>
|
<?import javafx.scene.image.Image?>
|
||||||
<?import javafx.scene.image.ImageView?>
|
<?import javafx.scene.image.ImageView?>
|
||||||
@ -28,15 +27,13 @@
|
|||||||
<Label fx:id="statusSpeed" text="Скорость:" />
|
<Label fx:id="statusSpeed" text="Скорость:" />
|
||||||
<Label fx:id="statusWeight" text="Вес:" />
|
<Label fx:id="statusWeight" text="Вес:" />
|
||||||
<Label fx:id="statusColor" text="Цвет:" />
|
<Label fx:id="statusColor" text="Цвет:" />
|
||||||
<ColorPicker fx:id="bodyColorPicker" />
|
|
||||||
<ColorPicker fx:id="extraColorPicker" />
|
|
||||||
<Label text="Колл-во дверей:" />
|
<Label text="Колл-во дверей:" />
|
||||||
<ChoiceBox fx:id="choiceDoors" prefHeight="24.0" prefWidth="58.0" />
|
<ChoiceBox fx:id="choiceDoors" prefHeight="24.0" prefWidth="58.0" />
|
||||||
</children>
|
</children>
|
||||||
</HBox>
|
</HBox>
|
||||||
<AnchorPane fx:id="pictureBoxBus" maxHeight="2000000.0" maxWidth="2000000.0" minHeight="0.0" minWidth="0.0" prefHeight="603.0" prefWidth="1020.0">
|
<AnchorPane fx:id="pictureBoxBus" maxHeight="2000000.0" maxWidth="2000000.0" minHeight="0.0" minWidth="0.0" prefHeight="603.0" prefWidth="1020.0">
|
||||||
<children>
|
<children>
|
||||||
<Canvas fx:id="canvasBus" height="603.0" layoutY="38.0" width="1021.0" AnchorPane.leftAnchor="0.0" AnchorPane.topAnchor="0.0" />
|
<Canvas fx:id="canvasBus" layoutY="38.0" AnchorPane.leftAnchor="0.0" AnchorPane.topAnchor="0.0" />
|
||||||
<Button fx:id="buttonLeft" layoutX="975.0" layoutY="427.0" mnemonicParsing="false" onAction="#ButtonMove_Click" prefHeight="0.0" prefWidth="0.0" AnchorPane.bottomAnchor="40.0" AnchorPane.rightAnchor="60.0">
|
<Button fx:id="buttonLeft" layoutX="975.0" layoutY="427.0" mnemonicParsing="false" onAction="#ButtonMove_Click" prefHeight="0.0" prefWidth="0.0" AnchorPane.bottomAnchor="40.0" AnchorPane.rightAnchor="60.0">
|
||||||
<graphic>
|
<graphic>
|
||||||
<ImageView fitHeight="27.0" fitWidth="10.0" pickOnBounds="true" preserveRatio="true">
|
<ImageView fitHeight="27.0" fitWidth="10.0" pickOnBounds="true" preserveRatio="true">
|
||||||
@ -69,9 +66,7 @@
|
|||||||
</image>
|
</image>
|
||||||
</ImageView>
|
</ImageView>
|
||||||
</graphic></Button>
|
</graphic></Button>
|
||||||
<Button fx:id="buttonCreate" layoutX="6.0" layoutY="565.0" mnemonicParsing="false" onAction="#ButtonCreate_Click" text="Создать" AnchorPane.bottomAnchor="14.0" AnchorPane.leftAnchor="6.0" />
|
<Button fx:id="buttonCreate" layoutY="455.0" mnemonicParsing="false" onAction="#ButtonCreate_Click" text="Создать" AnchorPane.bottomAnchor="14.0" AnchorPane.leftAnchor="0.0" />
|
||||||
<Button fx:id="buttonCreateExtra" layoutX="90.0" layoutY="565.0" mnemonicParsing="false" onAction="#ButtonCreateExtra_Click" text="Продвинутый объект" AnchorPane.bottomAnchor="14.0" AnchorPane.leftAnchor="90.0" />
|
|
||||||
<Button fx:id="buttonSelectBus" layoutX="840.0" layoutY="565.0" mnemonicParsing="false" onAction="#ButtonSelectBus_Click" text="Выбрать" AnchorPane.bottomAnchor="14.0" AnchorPane.rightAnchor="104.0" />
|
|
||||||
</children>
|
</children>
|
||||||
</AnchorPane>
|
</AnchorPane>
|
||||||
</children>
|
</children>
|
Loading…
Reference in New Issue
Block a user