Hard Version stable
This commit is contained in:
parent
59b1e80ad4
commit
3297c45e04
@ -1,11 +1,14 @@
|
||||
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.scene.canvas.Canvas;
|
||||
import javafx.scene.canvas.GraphicsContext;
|
||||
import javafx.scene.control.Button;
|
||||
import javafx.scene.control.ChoiceBox;
|
||||
import javafx.scene.control.Label;
|
||||
import javafx.scene.layout.AnchorPane;
|
||||
import javafx.scene.paint.Color;
|
||||
@ -15,6 +18,7 @@ import java.util.Random;
|
||||
public class ControllerBus {
|
||||
|
||||
private DrawingBus _bus;
|
||||
ObservableList<Integer> countOfDoors = FXCollections.observableArrayList(3, 4, 5);
|
||||
@FXML
|
||||
private Button buttonCreate;
|
||||
|
||||
@ -45,13 +49,8 @@ public class ControllerBus {
|
||||
@FXML
|
||||
private Label statusWeight;
|
||||
|
||||
InvalidationListener listener = o -> BorderChanged();
|
||||
|
||||
private void Draw()
|
||||
{
|
||||
GraphicsContext gc = canvasBus.getGraphicsContext2D();
|
||||
_bus.DrawTransport(gc);
|
||||
}
|
||||
@FXML
|
||||
private ChoiceBox<Integer> choiceDoors;
|
||||
|
||||
@FXML
|
||||
void ButtonCreate_Click(ActionEvent event) {
|
||||
@ -61,7 +60,7 @@ public class ControllerBus {
|
||||
Random rnd = new Random();
|
||||
_bus = new DrawingBus();
|
||||
_bus.Init(rnd.nextInt(100, 300), rnd.nextFloat(1000, 2000),
|
||||
Color.rgb(rnd.nextInt(0, 256), rnd.nextInt(0, 256), rnd.nextInt(0, 256)));
|
||||
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), (int) pictureBoxBus.getWidth(), (int) pictureBoxBus.getHeight());
|
||||
statusSpeed.setText("Скорость: %s".formatted(_bus.Bus.Speed));
|
||||
statusWeight.setText("Вес: %s".formatted(_bus.Bus.Weight));
|
||||
@ -82,6 +81,20 @@ public class ControllerBus {
|
||||
Draw();
|
||||
}
|
||||
|
||||
@FXML
|
||||
public void initialize() {
|
||||
choiceDoors.setItems(countOfDoors);
|
||||
choiceDoors.setValue(3);
|
||||
}
|
||||
|
||||
InvalidationListener listener = o -> BorderChanged();
|
||||
|
||||
private void Draw()
|
||||
{
|
||||
GraphicsContext gc = canvasBus.getGraphicsContext2D();
|
||||
_bus.DrawTransport(gc);
|
||||
}
|
||||
|
||||
void BorderChanged() {
|
||||
canvasBus.setWidth(pictureBoxBus.getWidth());
|
||||
canvasBus.setHeight(pictureBoxBus.getHeight());
|
||||
|
@ -0,0 +1,18 @@
|
||||
package com.example.doubledeckerbus;
|
||||
|
||||
public enum CountOfDoors {
|
||||
|
||||
ThreeDoors(3),
|
||||
FourDoors(4),
|
||||
FiveDoors(5);
|
||||
|
||||
private final int id;
|
||||
CountOfDoors(int value){
|
||||
id = value;
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
}
|
@ -1,5 +1,11 @@
|
||||
package com.example.doubledeckerbus;
|
||||
|
||||
public enum Direction {
|
||||
Up, Down, Left, Right
|
||||
Up(1),
|
||||
Down(2),
|
||||
Left(3),
|
||||
Right(4);
|
||||
Direction(int value){}
|
||||
|
||||
}
|
||||
|
||||
|
@ -6,6 +6,8 @@ import javafx.scene.paint.Color;
|
||||
public class DrawingBus {
|
||||
public EntityBus Bus;
|
||||
|
||||
public DrawingDoors Doors;
|
||||
|
||||
public EntityBus getBus() {
|
||||
return Bus;
|
||||
}
|
||||
@ -18,9 +20,11 @@ public class DrawingBus {
|
||||
private static final int _busWidth = 100;
|
||||
private static final int _busHeight = 50;
|
||||
|
||||
public void Init(int speed, float weight, Color bodyColor) {
|
||||
public void Init(int speed, float weight, Color bodyColor, int countOfDoors) {
|
||||
Bus = new EntityBus();
|
||||
Bus.Init(speed, weight, bodyColor);
|
||||
Doors = new DrawingDoors();
|
||||
Doors.setCountOfDoors(countOfDoors);
|
||||
}
|
||||
|
||||
public void SetPosition(int x, int y, int width, int height) {
|
||||
@ -81,11 +85,8 @@ public class DrawingBus {
|
||||
gc.setFill(Bus.BodyColor);
|
||||
gc.fillRect(_startPosX, _startPosY + 10, 100, 30);
|
||||
|
||||
//Дверь
|
||||
gc.setFill(Color.BLACK);
|
||||
gc.fillRect(_startPosX + 30, _startPosY + 20, 10, 20);
|
||||
|
||||
//Колеса
|
||||
gc.setFill(Color.BLACK);
|
||||
gc.fillOval(_startPosX + 7, _startPosY + 35, 10, 10);
|
||||
gc.fillOval(_startPosX + 77, _startPosY + 35, 10, 10);
|
||||
|
||||
@ -96,6 +97,8 @@ public class DrawingBus {
|
||||
gc.fillOval(_startPosX + 70, _startPosY + 15, 10, 15);
|
||||
gc.fillOval(_startPosX + 90, _startPosY + 15, 10, 15);
|
||||
|
||||
//Дверь
|
||||
Doors.DrawDoors(gc, (int)_startPosX, (int)_startPosY);
|
||||
}
|
||||
|
||||
public void ChangeBorders(int width, int height) {
|
||||
|
@ -0,0 +1,31 @@
|
||||
package com.example.doubledeckerbus;
|
||||
|
||||
import javafx.scene.canvas.GraphicsContext;
|
||||
import javafx.scene.paint.Color;
|
||||
|
||||
public class DrawingDoors {
|
||||
private CountOfDoors _countOfDoors;
|
||||
|
||||
public void DrawDoors(GraphicsContext gc, int _startPosX, int _startPosY) {
|
||||
gc.setFill(Color.BLACK);
|
||||
gc.fillRect(_startPosX, _startPosY + 20, 10, 20);
|
||||
gc.fillRect(_startPosX + 20, _startPosY + 20, 10, 20);
|
||||
gc.fillRect(_startPosX + 40, _startPosY + 20, 10, 20);
|
||||
if (_countOfDoors.getId() >= 4) {
|
||||
gc.fillRect(_startPosX + 60, _startPosY + 20, 10, 20);
|
||||
}
|
||||
if (_countOfDoors.getId() >= 5) {
|
||||
gc.fillRect(_startPosX + 80, _startPosY + 20, 10, 20);
|
||||
}
|
||||
}
|
||||
|
||||
public void setCountOfDoors(int number) {
|
||||
for (CountOfDoors item: CountOfDoors.values()) {
|
||||
if (item.getId() == number) {
|
||||
_countOfDoors = item;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -12,7 +12,7 @@ public class FormBus extends Application {
|
||||
public void start(Stage stage) throws IOException {
|
||||
FXMLLoader fxmlLoader = new FXMLLoader(FormBus.class.getResource("hello-view.fxml"));
|
||||
Scene scene = new Scene(fxmlLoader.load());
|
||||
stage.setTitle("Hello!");
|
||||
stage.setTitle("DoubleDeckerBus");
|
||||
stage.setScene(scene);
|
||||
stage.show();
|
||||
}
|
||||
|
@ -3,6 +3,7 @@
|
||||
<?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.image.Image?>
|
||||
<?import javafx.scene.image.ImageView?>
|
||||
@ -26,6 +27,8 @@
|
||||
<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">
|
||||
|
Loading…
Reference in New Issue
Block a user