Compare commits
9 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
c1cd71bd47 | ||
|
ca79a77693 | ||
|
f33808a992 | ||
|
f372f7e616 | ||
|
c1652c191a | ||
|
f40d570442 | ||
|
fd6752a9b4 | ||
|
d9d73ad660 | ||
|
116675a1e3 |
7
.idea/encodings.xml
generated
Normal file
7
.idea/encodings.xml
generated
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="Encoding">
|
||||||
|
<file url="file://$PROJECT_DIR$/src/main/java" charset="UTF-8" />
|
||||||
|
<file url="file://$PROJECT_DIR$/src/main/resources" charset="UTF-8" />
|
||||||
|
</component>
|
||||||
|
</project>
|
124
.idea/uiDesigner.xml
generated
Normal file
124
.idea/uiDesigner.xml
generated
Normal file
@ -0,0 +1,124 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="Palette2">
|
||||||
|
<group name="Swing">
|
||||||
|
<item class="com.intellij.uiDesigner.HSpacer" tooltip-text="Horizontal Spacer" icon="/com/intellij/uiDesigner/icons/hspacer.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="1" hsize-policy="6" anchor="0" fill="1" />
|
||||||
|
</item>
|
||||||
|
<item class="com.intellij.uiDesigner.VSpacer" tooltip-text="Vertical Spacer" icon="/com/intellij/uiDesigner/icons/vspacer.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="6" hsize-policy="1" anchor="0" fill="2" />
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JPanel" icon="/com/intellij/uiDesigner/icons/panel.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3" />
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JScrollPane" icon="/com/intellij/uiDesigner/icons/scrollPane.svg" removable="false" auto-create-binding="false" can-attach-label="true">
|
||||||
|
<default-constraints vsize-policy="7" hsize-policy="7" anchor="0" fill="3" />
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JButton" icon="/com/intellij/uiDesigner/icons/button.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="3" anchor="0" fill="1" />
|
||||||
|
<initial-values>
|
||||||
|
<property name="text" value="Button" />
|
||||||
|
</initial-values>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JRadioButton" icon="/com/intellij/uiDesigner/icons/radioButton.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
|
||||||
|
<initial-values>
|
||||||
|
<property name="text" value="RadioButton" />
|
||||||
|
</initial-values>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JCheckBox" icon="/com/intellij/uiDesigner/icons/checkBox.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
|
||||||
|
<initial-values>
|
||||||
|
<property name="text" value="CheckBox" />
|
||||||
|
</initial-values>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JLabel" icon="/com/intellij/uiDesigner/icons/label.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="0" anchor="8" fill="0" />
|
||||||
|
<initial-values>
|
||||||
|
<property name="text" value="Label" />
|
||||||
|
</initial-values>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JTextField" icon="/com/intellij/uiDesigner/icons/textField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
|
||||||
|
<preferred-size width="150" height="-1" />
|
||||||
|
</default-constraints>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JPasswordField" icon="/com/intellij/uiDesigner/icons/passwordField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
|
||||||
|
<preferred-size width="150" height="-1" />
|
||||||
|
</default-constraints>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JFormattedTextField" icon="/com/intellij/uiDesigner/icons/formattedTextField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
|
||||||
|
<preferred-size width="150" height="-1" />
|
||||||
|
</default-constraints>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JTextArea" icon="/com/intellij/uiDesigner/icons/textArea.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||||
|
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||||
|
<preferred-size width="150" height="50" />
|
||||||
|
</default-constraints>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JTextPane" icon="/com/intellij/uiDesigner/icons/textPane.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||||
|
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||||
|
<preferred-size width="150" height="50" />
|
||||||
|
</default-constraints>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JEditorPane" icon="/com/intellij/uiDesigner/icons/editorPane.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||||
|
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||||
|
<preferred-size width="150" height="50" />
|
||||||
|
</default-constraints>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JComboBox" icon="/com/intellij/uiDesigner/icons/comboBox.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="2" anchor="8" fill="1" />
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JTable" icon="/com/intellij/uiDesigner/icons/table.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||||
|
<preferred-size width="150" height="50" />
|
||||||
|
</default-constraints>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JList" icon="/com/intellij/uiDesigner/icons/list.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="6" hsize-policy="2" anchor="0" fill="3">
|
||||||
|
<preferred-size width="150" height="50" />
|
||||||
|
</default-constraints>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JTree" icon="/com/intellij/uiDesigner/icons/tree.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||||
|
<preferred-size width="150" height="50" />
|
||||||
|
</default-constraints>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JTabbedPane" icon="/com/intellij/uiDesigner/icons/tabbedPane.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
|
||||||
|
<preferred-size width="200" height="200" />
|
||||||
|
</default-constraints>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JSplitPane" icon="/com/intellij/uiDesigner/icons/splitPane.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
|
||||||
|
<preferred-size width="200" height="200" />
|
||||||
|
</default-constraints>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JSpinner" icon="/com/intellij/uiDesigner/icons/spinner.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JSlider" icon="/com/intellij/uiDesigner/icons/slider.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JSeparator" icon="/com/intellij/uiDesigner/icons/separator.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3" />
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JProgressBar" icon="/com/intellij/uiDesigner/icons/progressbar.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1" />
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JToolBar" icon="/com/intellij/uiDesigner/icons/toolbar.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1">
|
||||||
|
<preferred-size width="-1" height="20" />
|
||||||
|
</default-constraints>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JToolBar$Separator" icon="/com/intellij/uiDesigner/icons/toolbarSeparator.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="0" anchor="0" fill="1" />
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JScrollBar" icon="/com/intellij/uiDesigner/icons/scrollbar.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="6" hsize-policy="0" anchor="0" fill="2" />
|
||||||
|
</item>
|
||||||
|
</group>
|
||||||
|
</component>
|
||||||
|
</project>
|
6
.idea/vcs.xml
generated
Normal file
6
.idea/vcs.xml
generated
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="VcsDirectoryMappings">
|
||||||
|
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||||
|
</component>
|
||||||
|
</project>
|
2
pom.xml
2
pom.xml
@ -60,7 +60,7 @@
|
|||||||
<!-- Default configuration for running with: mvn clean javafx:run -->
|
<!-- Default configuration for running with: mvn clean javafx:run -->
|
||||||
<id>default-cli</id>
|
<id>default-cli</id>
|
||||||
<configuration>
|
<configuration>
|
||||||
<mainClass>com.example.aircraftcarrier/com.example.aircraftcarrier.HelloApplication
|
<mainClass>com.example.aircraftcarrier/AircraftCarrierApplication
|
||||||
</mainClass>
|
</mainClass>
|
||||||
<launcher>app</launcher>
|
<launcher>app</launcher>
|
||||||
<jlinkZipName>app</jlinkZipName>
|
<jlinkZipName>app</jlinkZipName>
|
||||||
|
@ -0,0 +1,26 @@
|
|||||||
|
package com.example.aircraftcarrier;
|
||||||
|
|
||||||
|
import javafx.application.Application;
|
||||||
|
import javafx.beans.value.ChangeListener;
|
||||||
|
import javafx.beans.value.ObservableValue;
|
||||||
|
import javafx.fxml.FXMLLoader;
|
||||||
|
import javafx.scene.Scene;
|
||||||
|
import javafx.stage.Stage;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
public class AircraftCarrierApplication extends Application {
|
||||||
|
@Override
|
||||||
|
public void start(Stage stage) throws IOException {
|
||||||
|
// FXMLLoader fxmlLoader = new FXMLLoader(AircraftCarrierApplication.class.getResource("/com/example/aircraftcarrier/AircraftCarrierView.fxml"));
|
||||||
|
FXMLLoader fxmlLoader = new FXMLLoader(AircraftCarrierApplication.class.getResource("/com/example/aircraftcarrier/ShipCollectionView.fxml"));
|
||||||
|
Scene scene = new Scene(fxmlLoader.load());
|
||||||
|
stage.setTitle("Hello!");
|
||||||
|
stage.setScene(scene);
|
||||||
|
stage.show();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
launch();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,113 @@
|
|||||||
|
package com.example.aircraftcarrier;
|
||||||
|
|
||||||
|
import com.example.aircraftcarrier.Logic.Aircraft.*;
|
||||||
|
import com.example.aircraftcarrier.Logic.Block.DrawingBlock;
|
||||||
|
import com.example.aircraftcarrier.Logic.Block.DrawingBlockCircle;
|
||||||
|
import com.example.aircraftcarrier.Logic.Block.DrawingBlockTriangle;
|
||||||
|
import com.example.aircraftcarrier.Logic.Block.IDrawingBlock;
|
||||||
|
import com.example.aircraftcarrier.Logic.Enum.DirectionType;
|
||||||
|
import com.example.aircraftcarrier.Logic.MovementStategy.*;
|
||||||
|
import javafx.event.Event;
|
||||||
|
import javafx.fxml.FXML;
|
||||||
|
import javafx.fxml.Initializable;
|
||||||
|
import javafx.scene.canvas.Canvas;
|
||||||
|
import javafx.scene.canvas.GraphicsContext;
|
||||||
|
import javafx.scene.control.Button;
|
||||||
|
import javafx.scene.control.ChoiceBox;
|
||||||
|
import javafx.scene.control.TextField;
|
||||||
|
import javafx.scene.input.KeyCode;
|
||||||
|
import javafx.scene.input.KeyEvent;
|
||||||
|
import javafx.scene.layout.AnchorPane;
|
||||||
|
import javafx.scene.paint.Color;
|
||||||
|
|
||||||
|
import java.net.URL;
|
||||||
|
import java.util.Random;
|
||||||
|
import java.util.ResourceBundle;
|
||||||
|
|
||||||
|
|
||||||
|
public class AircraftCarrierController implements Initializable {
|
||||||
|
Random random = new Random();
|
||||||
|
DrawingSimpleAircraftCarrier drawingAircraftCarrier;
|
||||||
|
AbstractStrategy strategy;
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
private AnchorPane Root;
|
||||||
|
@FXML
|
||||||
|
private Canvas canvas;
|
||||||
|
@FXML
|
||||||
|
private ChoiceBox<String> choiceBoxStrategy;
|
||||||
|
private final String[] strategyText = new String[]{"к центру", "к углу"};
|
||||||
|
|
||||||
|
public void setDrawing(DrawingSimpleAircraftCarrier drawingAircraftCarrier) {
|
||||||
|
this.drawingAircraftCarrier = drawingAircraftCarrier;
|
||||||
|
}
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
protected void ButtonStrategy_Click() {
|
||||||
|
if (drawingAircraftCarrier == null) return;
|
||||||
|
if (!choiceBoxStrategy.isDisable()) {
|
||||||
|
strategy = switch (choiceBoxStrategy.getValue()) {
|
||||||
|
case "к центру" -> new MoveToCenter();
|
||||||
|
case "к углу" -> new MoveToCorner();
|
||||||
|
default -> null;
|
||||||
|
};
|
||||||
|
if (strategy == null) return;
|
||||||
|
strategy.SetDate(new MoveableCarrier(drawingAircraftCarrier),
|
||||||
|
(int)Root.getWidth(),
|
||||||
|
(int)Root.getHeight()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if (strategy==null) return;
|
||||||
|
|
||||||
|
choiceBoxStrategy.setDisable(true);
|
||||||
|
strategy.MakeStep();
|
||||||
|
draw();
|
||||||
|
if (strategy.GetStatus() == StrategyStatus.Finish) {
|
||||||
|
choiceBoxStrategy.setDisable(false);
|
||||||
|
strategy = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void draw() {
|
||||||
|
canvas.getGraphicsContext2D().clearRect(0,0,canvas.getWidth(),canvas.getHeight());
|
||||||
|
drawingAircraftCarrier.Draw(canvas.getGraphicsContext2D());
|
||||||
|
}
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
protected void MoveEvent(Event e) {
|
||||||
|
if (drawingAircraftCarrier == null) return;
|
||||||
|
|
||||||
|
DirectionType directionType;
|
||||||
|
|
||||||
|
if (e instanceof KeyEvent keyEvent) {
|
||||||
|
directionType = switch (keyEvent.getCode()) {
|
||||||
|
case KeyCode.W -> DirectionType.Up;
|
||||||
|
case KeyCode.S -> DirectionType.Down;
|
||||||
|
case KeyCode.A -> DirectionType.Left;
|
||||||
|
case KeyCode.D -> DirectionType.Right;
|
||||||
|
default -> DirectionType.Unknown;
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
String direction = ((Button)e.getSource()).getId();
|
||||||
|
directionType = switch (direction) {
|
||||||
|
case "up" -> DirectionType.Up;
|
||||||
|
case "down" -> DirectionType.Down;
|
||||||
|
case "left" -> DirectionType.Left;
|
||||||
|
case "right" -> DirectionType.Right;
|
||||||
|
default -> DirectionType.Unknown;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
if (directionType == DirectionType.Unknown) return;
|
||||||
|
|
||||||
|
drawingAircraftCarrier.Move(directionType);
|
||||||
|
draw();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void initialize(URL url, ResourceBundle resourceBundle) {
|
||||||
|
canvas.widthProperty().bind(Root.widthProperty());
|
||||||
|
canvas.heightProperty().bind(Root.heightProperty());
|
||||||
|
choiceBoxStrategy.getItems().addAll(strategyText);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,38 @@
|
|||||||
|
package com.example.aircraftcarrier;
|
||||||
|
|
||||||
|
import javafx.beans.value.ChangeListener;
|
||||||
|
import javafx.beans.value.ObservableValue;
|
||||||
|
import javafx.fxml.FXML;
|
||||||
|
import javafx.fxml.Initializable;
|
||||||
|
import javafx.scene.control.ComboBox;
|
||||||
|
import javafx.scene.control.TextField;
|
||||||
|
|
||||||
|
import java.net.URL;
|
||||||
|
import java.util.ResourceBundle;
|
||||||
|
|
||||||
|
public class BlockDialogController implements Initializable {
|
||||||
|
@FXML
|
||||||
|
private ComboBox<String> ComboBoxShape;
|
||||||
|
private final String[] shapes = { "квадрат", "треугольник", "круг" };
|
||||||
|
@FXML
|
||||||
|
private TextField CountBlock;
|
||||||
|
@Override
|
||||||
|
public void initialize(URL url, ResourceBundle resourceBundle) {
|
||||||
|
ComboBoxShape.getItems().setAll(shapes);
|
||||||
|
CountBlock.textProperty().addListener(new ChangeListener<String>() {
|
||||||
|
@Override
|
||||||
|
public void changed(ObservableValue<? extends String> observableValue, String s, String t1) {
|
||||||
|
if (t1.matches("\\d{0,2}")) CountBlock.setText(t1);
|
||||||
|
else CountBlock.setText(s);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getCount() {
|
||||||
|
return Integer.parseInt(CountBlock.getText());
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getShape() {
|
||||||
|
return ComboBoxShape.getValue();
|
||||||
|
}
|
||||||
|
}
|
@ -1,23 +0,0 @@
|
|||||||
package com.example.aircraftcarrier;
|
|
||||||
|
|
||||||
import javafx.application.Application;
|
|
||||||
import javafx.fxml.FXMLLoader;
|
|
||||||
import javafx.scene.Scene;
|
|
||||||
import javafx.stage.Stage;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
public class HelloApplication extends Application {
|
|
||||||
@Override
|
|
||||||
public void start(Stage stage) throws IOException {
|
|
||||||
FXMLLoader fxmlLoader = new FXMLLoader(HelloApplication.class.getResource("hello-view.fxml"));
|
|
||||||
Scene scene = new Scene(fxmlLoader.load(), 320, 240);
|
|
||||||
stage.setTitle("Hello!");
|
|
||||||
stage.setScene(scene);
|
|
||||||
stage.show();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void main(String[] args) {
|
|
||||||
launch();
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,14 +0,0 @@
|
|||||||
package com.example.aircraftcarrier;
|
|
||||||
|
|
||||||
import javafx.fxml.FXML;
|
|
||||||
import javafx.scene.control.Label;
|
|
||||||
|
|
||||||
public class HelloController {
|
|
||||||
@FXML
|
|
||||||
private Label welcomeText;
|
|
||||||
|
|
||||||
@FXML
|
|
||||||
protected void onHelloButtonClick() {
|
|
||||||
welcomeText.setText("Welcome to JavaFX Application!");
|
|
||||||
}
|
|
||||||
}
|
|
@ -0,0 +1,70 @@
|
|||||||
|
package com.example.aircraftcarrier.Logic.Aircraft;
|
||||||
|
|
||||||
|
import com.example.aircraftcarrier.Logic.Block.DrawingBlock;
|
||||||
|
import com.example.aircraftcarrier.Logic.Block.DrawingBlockCircle;
|
||||||
|
import com.example.aircraftcarrier.Logic.Block.DrawingBlockTriangle;
|
||||||
|
import com.example.aircraftcarrier.Logic.Block.IDrawingBlock;
|
||||||
|
import com.example.aircraftcarrier.Logic.Entity.EntityAircraftCarrier;
|
||||||
|
import javafx.scene.canvas.GraphicsContext;
|
||||||
|
import javafx.scene.paint.Color;
|
||||||
|
|
||||||
|
public class DrawingAircraftCarrier extends DrawingSimpleAircraftCarrier {
|
||||||
|
public IDrawingBlock drawingBlock;
|
||||||
|
|
||||||
|
public DrawingAircraftCarrier() {super();}
|
||||||
|
|
||||||
|
public DrawingAircraftCarrier(
|
||||||
|
int speed,
|
||||||
|
int weight,
|
||||||
|
Color primaryColor,
|
||||||
|
Color secondaryColor,
|
||||||
|
boolean hasDeck,
|
||||||
|
boolean hasСabin,
|
||||||
|
int countBlock,
|
||||||
|
String shape
|
||||||
|
) {
|
||||||
|
super();
|
||||||
|
aircraftCarrier = new EntityAircraftCarrier(speed,
|
||||||
|
weight,
|
||||||
|
primaryColor,
|
||||||
|
secondaryColor,
|
||||||
|
hasDeck,
|
||||||
|
hasСabin);
|
||||||
|
if (shape != null) {
|
||||||
|
drawingBlock = switch (shape) {
|
||||||
|
case "квадрат" -> new DrawingBlock(countBlock);
|
||||||
|
case "треугольник" -> new DrawingBlockTriangle(countBlock);
|
||||||
|
case "круг" -> new DrawingBlockCircle(countBlock);
|
||||||
|
default -> null;
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
drawingBlock = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDrawingBlock(IDrawingBlock iDrawingBlock) {
|
||||||
|
drawingBlock = iDrawingBlock;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void Draw(GraphicsContext gc) {
|
||||||
|
if (aircraftCarrier == null) return;
|
||||||
|
|
||||||
|
if (aircraftCarrier instanceof EntityAircraftCarrier entityAircraftCarrier) {
|
||||||
|
|
||||||
|
super.Draw(gc);
|
||||||
|
|
||||||
|
if (entityAircraftCarrier.isHasDeck()) {
|
||||||
|
gc.setFill(entityAircraftCarrier.getPrimaryColor());
|
||||||
|
gc.fillRect(x + 50, y + 40, 55, 20);
|
||||||
|
}
|
||||||
|
if (entityAircraftCarrier.isHasСabin()) {
|
||||||
|
gc.setFill(entityAircraftCarrier.getSecondaryColor());
|
||||||
|
gc.fillRect(x + 105, y + 25, 30, 50);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (drawingBlock == null) return;
|
||||||
|
drawingBlock.Draw(gc, x, y, entityAircraftCarrier.getSecondaryColor());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,113 @@
|
|||||||
|
package com.example.aircraftcarrier.Logic.Aircraft;
|
||||||
|
|
||||||
|
import com.example.aircraftcarrier.Logic.Entity.EntitySimpleAircraftCarrier;
|
||||||
|
import com.example.aircraftcarrier.Logic.Enum.DirectionType;
|
||||||
|
import javafx.scene.canvas.GraphicsContext;
|
||||||
|
import javafx.scene.paint.Color;
|
||||||
|
|
||||||
|
public class DrawingSimpleAircraftCarrier {
|
||||||
|
public EntitySimpleAircraftCarrier aircraftCarrier;
|
||||||
|
protected int x;
|
||||||
|
protected int y;
|
||||||
|
private int widthCanvas;
|
||||||
|
private int heightCanvas;
|
||||||
|
private static final int widthPicture = 250;
|
||||||
|
private static final int heightPicture = 100;
|
||||||
|
|
||||||
|
public DrawingSimpleAircraftCarrier() {}
|
||||||
|
|
||||||
|
public DrawingSimpleAircraftCarrier(
|
||||||
|
int speed,
|
||||||
|
int weight,
|
||||||
|
Color primaryColor
|
||||||
|
) {
|
||||||
|
aircraftCarrier = new EntitySimpleAircraftCarrier(
|
||||||
|
speed,
|
||||||
|
weight,
|
||||||
|
primaryColor
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCanvasParam(int width, int height) {
|
||||||
|
if (x+widthPicture > width && y+heightPicture > height) return;
|
||||||
|
heightCanvas = height;
|
||||||
|
widthCanvas = width;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCanvasWidth(int width) {
|
||||||
|
if (x+widthPicture > width) return;
|
||||||
|
widthCanvas = width;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCanvasHeight(int height) {
|
||||||
|
if (y+heightPicture > height) return;
|
||||||
|
heightCanvas = height;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean setPosition(int newX, int newY) {
|
||||||
|
if (newX < 0 || newY < 0 || newX + widthPicture > widthCanvas || newY + heightPicture > heightCanvas) return false;
|
||||||
|
x = newX;
|
||||||
|
y = newY;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getX() {
|
||||||
|
return x;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getY() {
|
||||||
|
return y;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getWidthPicture() {
|
||||||
|
return widthPicture;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getHeightPicture() {
|
||||||
|
return heightPicture;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Draw(GraphicsContext gc) {
|
||||||
|
gc.setStroke(aircraftCarrier.getPrimaryColor());
|
||||||
|
gc.setLineWidth(5);
|
||||||
|
|
||||||
|
double[] X = new double[]{x,x+200,x+250,x+200,x};
|
||||||
|
double[] Y = new double[]{y,y,y+50,y+100,y+100};
|
||||||
|
gc.strokePolygon(X, Y,5);
|
||||||
|
|
||||||
|
gc.strokeOval(x+175,y+35,30,30);
|
||||||
|
|
||||||
|
gc.setStroke(Color.BLACK);
|
||||||
|
gc.setLineWidth(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean Move(DirectionType direction) {
|
||||||
|
switch (direction) {
|
||||||
|
case Up:
|
||||||
|
if (y - aircraftCarrier.getStep() > 0) {
|
||||||
|
y -= aircraftCarrier.getStep();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
case Down:
|
||||||
|
if (y + aircraftCarrier.getStep() + heightPicture < heightCanvas) {
|
||||||
|
y += aircraftCarrier.getStep();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
case Right:
|
||||||
|
if (x + aircraftCarrier.getStep() + widthPicture < widthCanvas) {
|
||||||
|
x += aircraftCarrier.getStep();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
case Left:
|
||||||
|
if (x - aircraftCarrier.getStep() > 0) {
|
||||||
|
x -= aircraftCarrier.getStep();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
default: return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,35 @@
|
|||||||
|
package com.example.aircraftcarrier.Logic.Block;
|
||||||
|
|
||||||
|
import com.example.aircraftcarrier.Logic.Enum.BlockCount;
|
||||||
|
import javafx.scene.canvas.GraphicsContext;
|
||||||
|
import javafx.scene.paint.Color;
|
||||||
|
|
||||||
|
public class DrawingBlock implements IDrawingBlock {
|
||||||
|
private BlockCount blockCount;
|
||||||
|
|
||||||
|
public DrawingBlock(int blockCountValue) {
|
||||||
|
this.blockCount = BlockCount.ConvertToBlockCount(blockCountValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setBlockCount(int blockCountValue) {
|
||||||
|
this.blockCount = BlockCount.ConvertToBlockCount(blockCountValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void DrawTwoBlock(GraphicsContext gc, int x, int y, Color color) {
|
||||||
|
gc.setFill(color);
|
||||||
|
gc.fillRect(x,y,10,10);
|
||||||
|
gc.fillRect(x+15,y,10,10);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Draw(GraphicsContext gc, int x, int y, Color color) {
|
||||||
|
switch (blockCount) {
|
||||||
|
case Six:
|
||||||
|
DrawTwoBlock(gc,x+20,y+50,color);
|
||||||
|
case Four:
|
||||||
|
DrawTwoBlock(gc,x+20,y+35,color);
|
||||||
|
case Two:
|
||||||
|
DrawTwoBlock(gc,x+20,y+20,color);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,35 @@
|
|||||||
|
package com.example.aircraftcarrier.Logic.Block;
|
||||||
|
|
||||||
|
import com.example.aircraftcarrier.Logic.Enum.BlockCount;
|
||||||
|
import javafx.scene.canvas.GraphicsContext;
|
||||||
|
import javafx.scene.paint.Color;
|
||||||
|
|
||||||
|
public class DrawingBlockCircle implements IDrawingBlock {
|
||||||
|
private BlockCount blockCount;
|
||||||
|
|
||||||
|
public DrawingBlockCircle(int blockCountValue) {
|
||||||
|
this.blockCount = BlockCount.ConvertToBlockCount(blockCountValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setBlockCount(int blockCountValue) {
|
||||||
|
this.blockCount = BlockCount.ConvertToBlockCount(blockCountValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void DrawTwoBlock(GraphicsContext gc, int x, int y, Color color) {
|
||||||
|
gc.setFill(color);
|
||||||
|
gc.fillOval(x,y,10,10);
|
||||||
|
gc.fillOval(x+15,y,10,10);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Draw(GraphicsContext gc, int x, int y, Color color) {
|
||||||
|
switch (blockCount) {
|
||||||
|
case Six:
|
||||||
|
DrawTwoBlock(gc,x+20,y+50,color);
|
||||||
|
case Four:
|
||||||
|
DrawTwoBlock(gc,x+20,y+35,color);
|
||||||
|
case Two:
|
||||||
|
DrawTwoBlock(gc,x+20,y+20,color);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,40 @@
|
|||||||
|
package com.example.aircraftcarrier.Logic.Block;
|
||||||
|
|
||||||
|
import com.example.aircraftcarrier.Logic.Enum.BlockCount;
|
||||||
|
import javafx.scene.canvas.GraphicsContext;
|
||||||
|
import javafx.scene.paint.Color;
|
||||||
|
|
||||||
|
public class DrawingBlockTriangle implements IDrawingBlock {
|
||||||
|
private BlockCount blockCount;
|
||||||
|
|
||||||
|
|
||||||
|
public DrawingBlockTriangle(int blockCountValue) {
|
||||||
|
this.blockCount = BlockCount.ConvertToBlockCount(blockCountValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setBlockCount(int blockCountValue) {
|
||||||
|
this.blockCount = BlockCount.ConvertToBlockCount(blockCountValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void DrawTwoBlock(GraphicsContext gc, int x, int y, Color color) {
|
||||||
|
gc.setFill(color);
|
||||||
|
double[] X_first = new double[]{x+5,x+10,x};
|
||||||
|
double[] Y_first = new double[]{y,y+10,y+10};
|
||||||
|
double[] X_second = new double[]{x+15+5,x+15+10,x+15};
|
||||||
|
double[] Y_second = Y_first;
|
||||||
|
gc.fillPolygon(X_first, Y_first,3);
|
||||||
|
gc.fillPolygon(X_second, Y_second,3);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Draw(GraphicsContext gc, int x, int y, Color color) {
|
||||||
|
switch (blockCount) {
|
||||||
|
case Six:
|
||||||
|
DrawTwoBlock(gc,x+20,y+50,color);
|
||||||
|
case Four:
|
||||||
|
DrawTwoBlock(gc,x+20,y+35,color);
|
||||||
|
case Two:
|
||||||
|
DrawTwoBlock(gc,x+20,y+20,color);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,10 @@
|
|||||||
|
package com.example.aircraftcarrier.Logic.Block;
|
||||||
|
|
||||||
|
import javafx.scene.canvas.GraphicsContext;
|
||||||
|
import javafx.scene.paint.Color;
|
||||||
|
|
||||||
|
public interface IDrawingBlock {
|
||||||
|
void setBlockCount(int blockCountValue);
|
||||||
|
|
||||||
|
void Draw(GraphicsContext gc, int x, int y, Color color);
|
||||||
|
}
|
@ -0,0 +1,54 @@
|
|||||||
|
package com.example.aircraftcarrier.Logic.CollectionGenericObjects;
|
||||||
|
|
||||||
|
import com.example.aircraftcarrier.Logic.Aircraft.DrawingSimpleAircraftCarrier;
|
||||||
|
import javafx.scene.canvas.GraphicsContext;
|
||||||
|
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
|
public abstract class AbstractCompany {
|
||||||
|
|
||||||
|
protected static final int _placeSizeWidth = 300;
|
||||||
|
protected static final int _placeSizeHeight = 150;
|
||||||
|
protected final int _pictureWidth;
|
||||||
|
protected final int _pictureHeight;
|
||||||
|
|
||||||
|
protected ICollectionGenericObjects<DrawingSimpleAircraftCarrier> _collection;
|
||||||
|
public AbstractCompany(int pictureWidth, int pictureHeight, ICollectionGenericObjects<DrawingSimpleAircraftCarrier> collection) {
|
||||||
|
_pictureWidth = pictureWidth;
|
||||||
|
_pictureHeight = pictureHeight;
|
||||||
|
_collection = collection;
|
||||||
|
_collection.SetMaxCount(GetMaxCount());
|
||||||
|
}
|
||||||
|
|
||||||
|
private int GetMaxCount() {
|
||||||
|
return (_pictureWidth / _placeSizeWidth) * (_pictureHeight / _placeSizeHeight);
|
||||||
|
};
|
||||||
|
|
||||||
|
public static boolean add(AbstractCompany company, DrawingSimpleAircraftCarrier aircraftCarrier) {
|
||||||
|
return company != null && company._collection != null && company._collection.Insert(aircraftCarrier);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean remove(AbstractCompany company, int pos){
|
||||||
|
return company != null & company._collection != null & company._collection.Remove(pos);
|
||||||
|
}
|
||||||
|
|
||||||
|
public DrawingSimpleAircraftCarrier GetRandom() {
|
||||||
|
Random random = new Random();
|
||||||
|
return _collection == null ? null : _collection.Get(random.nextInt(GetMaxCount()));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Show(GraphicsContext gc) {
|
||||||
|
gc.clearRect(0, 0, _pictureWidth, _pictureHeight);
|
||||||
|
DrawBackground(gc);
|
||||||
|
SetObjectPosition();
|
||||||
|
for (int i = 0; i < _collection.count(); i++)
|
||||||
|
{
|
||||||
|
DrawingSimpleAircraftCarrier obj = _collection.Get(i);
|
||||||
|
if (obj == null) continue;
|
||||||
|
obj.Draw(gc);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected abstract void DrawBackground(GraphicsContext gc);
|
||||||
|
protected abstract void SetObjectPosition();
|
||||||
|
}
|
@ -0,0 +1,59 @@
|
|||||||
|
package com.example.aircraftcarrier.Logic.CollectionGenericObjects;
|
||||||
|
|
||||||
|
import com.example.aircraftcarrier.Logic.Aircraft.DrawingSimpleAircraftCarrier;
|
||||||
|
import javafx.scene.canvas.GraphicsContext;
|
||||||
|
import javafx.scene.paint.Color;
|
||||||
|
|
||||||
|
public class DocksService extends AbstractCompany {
|
||||||
|
|
||||||
|
public DocksService(int pictureWidth, int pictureHeight, ICollectionGenericObjects<DrawingSimpleAircraftCarrier> collection) {
|
||||||
|
super(pictureWidth, pictureHeight, collection);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void DrawBackground(GraphicsContext gc) {
|
||||||
|
for (int i = 0; i < _pictureWidth / _placeSizeWidth; i++)
|
||||||
|
{
|
||||||
|
for (int j = 0; j < _pictureHeight / _placeSizeHeight; j++)
|
||||||
|
{
|
||||||
|
double[] X = {
|
||||||
|
i*_placeSizeWidth+250,
|
||||||
|
i*_placeSizeWidth,
|
||||||
|
i*_placeSizeWidth,
|
||||||
|
i*_placeSizeWidth+250,
|
||||||
|
};
|
||||||
|
double[] Y = {
|
||||||
|
j*_placeSizeHeight,
|
||||||
|
j*_placeSizeHeight,
|
||||||
|
j*_placeSizeHeight+_placeSizeHeight,
|
||||||
|
j*_placeSizeHeight+_placeSizeHeight,
|
||||||
|
};
|
||||||
|
gc.setLineWidth(5);
|
||||||
|
gc.strokePolyline(X,Y,4);
|
||||||
|
gc.setLineWidth(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void SetObjectPosition() {
|
||||||
|
int maxXPositionCount = _pictureWidth / _placeSizeWidth;
|
||||||
|
int maxYPositionCount = _pictureHeight / _placeSizeHeight;
|
||||||
|
int xpos = 0;
|
||||||
|
int ypos = maxYPositionCount;
|
||||||
|
|
||||||
|
for (int i = 0; i < _collection.count(); i++) {
|
||||||
|
DrawingSimpleAircraftCarrier obj = _collection.Get(i);
|
||||||
|
if (obj != null) {
|
||||||
|
obj.setCanvasParam(_pictureWidth,_pictureHeight);
|
||||||
|
obj.setPosition(xpos * _placeSizeWidth + 10, (ypos-1) * _placeSizeHeight + 10);
|
||||||
|
}
|
||||||
|
xpos++;
|
||||||
|
if (xpos >= maxXPositionCount)
|
||||||
|
{
|
||||||
|
xpos = 0;
|
||||||
|
ypos--;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,10 @@
|
|||||||
|
package com.example.aircraftcarrier.Logic.CollectionGenericObjects;
|
||||||
|
|
||||||
|
public interface ICollectionGenericObjects<T> {
|
||||||
|
int count();
|
||||||
|
void SetMaxCount(int count);
|
||||||
|
boolean Insert(T obj);
|
||||||
|
boolean Insert(T obj, int position);
|
||||||
|
boolean Remove(int position);
|
||||||
|
T Get(int position);
|
||||||
|
}
|
@ -0,0 +1,76 @@
|
|||||||
|
package com.example.aircraftcarrier.Logic.CollectionGenericObjects;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
public class MassiveGenericObjects<T> implements ICollectionGenericObjects<T> {
|
||||||
|
private T[] _collection;
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
public MassiveGenericObjects() {
|
||||||
|
this._collection = (T[]) new Object[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int count() {
|
||||||
|
return _collection.length;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
public void SetMaxCount(int count) {
|
||||||
|
if (count > 0) {
|
||||||
|
_collection = (T[]) new Object[count];
|
||||||
|
Arrays.fill(_collection,null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean _checkRange(int pos) {
|
||||||
|
return (pos >= 0 && pos < _collection.length);
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean _checkAndInsert(T obj, int pos)
|
||||||
|
{
|
||||||
|
if (_collection[pos] == null)
|
||||||
|
{
|
||||||
|
_collection[pos] = obj;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean Insert(T obj) {
|
||||||
|
for (int i = 0; i< _collection.length;i++){
|
||||||
|
if (_checkAndInsert(obj,i)) return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean Insert(T obj, int position) {
|
||||||
|
if (!_checkRange(position)) return false;
|
||||||
|
if (_checkAndInsert(obj, position)) return true;
|
||||||
|
for (int i = position + 1; i < _collection.length; i++)
|
||||||
|
{
|
||||||
|
if (_checkAndInsert(obj, i)) return true;
|
||||||
|
}
|
||||||
|
for (int i = 0; i < position; i++)
|
||||||
|
{
|
||||||
|
if (_checkAndInsert(obj, i)) return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean Remove(int position) {
|
||||||
|
if (!_checkRange(position) || _collection[position] == null) return false;
|
||||||
|
_collection[position] = null;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public T Get(int position) {
|
||||||
|
if (_checkRange(position)) return _collection[position];
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,36 @@
|
|||||||
|
package com.example.aircraftcarrier.Logic.Entity;
|
||||||
|
|
||||||
|
import javafx.scene.paint.Color;
|
||||||
|
|
||||||
|
public class EntityAircraftCarrier extends EntitySimpleAircraftCarrier {
|
||||||
|
private Color SecondaryColor;
|
||||||
|
private boolean HasDeck;
|
||||||
|
private boolean HasСabin;
|
||||||
|
|
||||||
|
|
||||||
|
public EntityAircraftCarrier(
|
||||||
|
int speed,
|
||||||
|
double weight,
|
||||||
|
Color primaryColor,
|
||||||
|
Color secondaryColor,
|
||||||
|
boolean hasDeck,
|
||||||
|
boolean hasСabin
|
||||||
|
) {
|
||||||
|
super(speed,weight,primaryColor);
|
||||||
|
this.SecondaryColor = secondaryColor;
|
||||||
|
this.HasDeck = hasDeck;
|
||||||
|
this.HasСabin = hasСabin;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Color getSecondaryColor() {
|
||||||
|
return SecondaryColor;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isHasDeck() {
|
||||||
|
return HasDeck;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isHasСabin() {
|
||||||
|
return HasСabin;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,35 @@
|
|||||||
|
package com.example.aircraftcarrier.Logic.Entity;
|
||||||
|
|
||||||
|
import javafx.scene.paint.Color;
|
||||||
|
|
||||||
|
public class EntitySimpleAircraftCarrier {
|
||||||
|
private int Speed;
|
||||||
|
private double Weight;
|
||||||
|
private Color PrimaryColor;
|
||||||
|
|
||||||
|
public EntitySimpleAircraftCarrier(
|
||||||
|
int speed,
|
||||||
|
double weight,
|
||||||
|
Color primaryColor
|
||||||
|
) {
|
||||||
|
this.Speed = speed;
|
||||||
|
this.Weight = weight;
|
||||||
|
this.PrimaryColor = primaryColor;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getSpeed() {
|
||||||
|
return Speed;
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getWeight() {
|
||||||
|
return Weight;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Color getPrimaryColor() {
|
||||||
|
return PrimaryColor;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getStep() {
|
||||||
|
return (int) (Speed * 100 / Weight);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,31 @@
|
|||||||
|
package com.example.aircraftcarrier.Logic.Enum;
|
||||||
|
|
||||||
|
public enum BlockCount {
|
||||||
|
Two(2),
|
||||||
|
Four(4),
|
||||||
|
Six(6),
|
||||||
|
Other();
|
||||||
|
|
||||||
|
private Integer count;
|
||||||
|
|
||||||
|
BlockCount() {
|
||||||
|
this.count = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
BlockCount(int count) {
|
||||||
|
this.count = count;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static BlockCount ConvertToBlockCount(int count) {
|
||||||
|
return switch (count) {
|
||||||
|
case 2 -> Two;
|
||||||
|
case 4 -> Four;
|
||||||
|
case 6 -> Six;
|
||||||
|
default -> Other;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getCount() {
|
||||||
|
return count;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,9 @@
|
|||||||
|
package com.example.aircraftcarrier.Logic.Enum;
|
||||||
|
|
||||||
|
public enum DirectionType {
|
||||||
|
Unknown,
|
||||||
|
Up,
|
||||||
|
Down,
|
||||||
|
Right,
|
||||||
|
Left;
|
||||||
|
}
|
@ -0,0 +1,72 @@
|
|||||||
|
package com.example.aircraftcarrier.Logic.MovementStategy;
|
||||||
|
|
||||||
|
public abstract class AbstractStrategy {
|
||||||
|
private IMoveableObject moveableObject;
|
||||||
|
private StrategyStatus status = StrategyStatus.NotInit;
|
||||||
|
protected int FieldWidth;
|
||||||
|
protected int FieldHeight;
|
||||||
|
|
||||||
|
public int getFieldWidth() {
|
||||||
|
return FieldWidth;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getFieldHeight() {
|
||||||
|
return FieldHeight;
|
||||||
|
}
|
||||||
|
|
||||||
|
public StrategyStatus GetStatus() {
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SetDate(IMoveableObject moveableObject,
|
||||||
|
int width,
|
||||||
|
int height) {
|
||||||
|
if (moveableObject == null) {
|
||||||
|
status = StrategyStatus.NotInit;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
status = StrategyStatus.InProgress;
|
||||||
|
this.moveableObject = moveableObject;
|
||||||
|
this.FieldWidth = width;
|
||||||
|
this.FieldHeight = height;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void MakeStep() {
|
||||||
|
if(status != StrategyStatus.InProgress) return;
|
||||||
|
if (IsTargetDestination()) {
|
||||||
|
status = StrategyStatus.Finish;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
MoveToTarget();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected abstract void MoveToTarget();
|
||||||
|
protected abstract boolean IsTargetDestination();
|
||||||
|
|
||||||
|
protected boolean MoveLeft() {
|
||||||
|
return MoveTo(MovementDirection.Left);
|
||||||
|
}
|
||||||
|
protected boolean MoveRight() {
|
||||||
|
return MoveTo(MovementDirection.Right);
|
||||||
|
}
|
||||||
|
protected boolean MoveUp() {
|
||||||
|
return MoveTo(MovementDirection.Up);
|
||||||
|
}
|
||||||
|
protected boolean MoveDown() {
|
||||||
|
return MoveTo(MovementDirection.Down);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected ObjectParameters GetObjectParameters() {
|
||||||
|
return moveableObject.GetObjectPosition();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected Integer GetStep() {
|
||||||
|
if (status != StrategyStatus.InProgress) return null;
|
||||||
|
return moveableObject.GetStep();
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean MoveTo(MovementDirection direction) {
|
||||||
|
if (moveableObject==null || status != StrategyStatus.InProgress) return false;
|
||||||
|
return moveableObject.TryMoveObject(direction);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,7 @@
|
|||||||
|
package com.example.aircraftcarrier.Logic.MovementStategy;
|
||||||
|
|
||||||
|
public interface IMoveableObject {
|
||||||
|
ObjectParameters GetObjectPosition();
|
||||||
|
int GetStep();
|
||||||
|
boolean TryMoveObject(MovementDirection direction);
|
||||||
|
}
|
@ -0,0 +1,32 @@
|
|||||||
|
package com.example.aircraftcarrier.Logic.MovementStategy;
|
||||||
|
|
||||||
|
public class MoveToCenter extends AbstractStrategy {
|
||||||
|
@Override
|
||||||
|
protected void MoveToTarget() {
|
||||||
|
ObjectParameters objectParameters = GetObjectParameters();
|
||||||
|
if (objectParameters == null) return;
|
||||||
|
int diffX = objectParameters.CenterX() - getFieldWidth()/2;
|
||||||
|
if (Math.abs(diffX) > GetStep()) {
|
||||||
|
if (diffX > 0) {
|
||||||
|
MoveLeft();
|
||||||
|
} else { MoveRight(); }
|
||||||
|
}
|
||||||
|
|
||||||
|
int diffY = objectParameters.CenterY() - getFieldHeight()/2;
|
||||||
|
if (Math.abs(diffY) > GetStep()) {
|
||||||
|
if (diffY > 0) {
|
||||||
|
MoveUp();
|
||||||
|
} else { MoveDown(); }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected boolean IsTargetDestination() {
|
||||||
|
ObjectParameters objectParameters = GetObjectParameters();
|
||||||
|
if (objectParameters == null) return false;
|
||||||
|
return objectParameters.CenterX() - GetStep() <= getFieldWidth()/2 &&
|
||||||
|
objectParameters.CenterX() + GetStep() >= getFieldWidth()/2 &&
|
||||||
|
objectParameters.CenterY() - GetStep() <= getFieldHeight()/2 &&
|
||||||
|
objectParameters.CenterY() + GetStep() >= getFieldHeight()/2;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,25 @@
|
|||||||
|
package com.example.aircraftcarrier.Logic.MovementStategy;
|
||||||
|
|
||||||
|
public class MoveToCorner extends AbstractStrategy {
|
||||||
|
@Override
|
||||||
|
protected void MoveToTarget() {
|
||||||
|
ObjectParameters objectParameters = GetObjectParameters();
|
||||||
|
if (objectParameters == null) return;
|
||||||
|
int diffX = objectParameters.RightBorder() - getFieldWidth();
|
||||||
|
if (Math.abs(diffX) > GetStep()) {
|
||||||
|
MoveRight();
|
||||||
|
}
|
||||||
|
|
||||||
|
int diffY = objectParameters.BottomBorder() - getFieldHeight();
|
||||||
|
if (Math.abs(diffY) > GetStep()) {
|
||||||
|
MoveDown();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
protected boolean IsTargetDestination() {
|
||||||
|
ObjectParameters objectParameters = GetObjectParameters();
|
||||||
|
if (objectParameters == null) return false;
|
||||||
|
return objectParameters.RightBorder() + GetStep() >= getFieldWidth() &&
|
||||||
|
objectParameters.RightBorder() + GetStep() >= getFieldHeight();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,42 @@
|
|||||||
|
package com.example.aircraftcarrier.Logic.MovementStategy;
|
||||||
|
|
||||||
|
import com.example.aircraftcarrier.Logic.Aircraft.DrawingSimpleAircraftCarrier;
|
||||||
|
import com.example.aircraftcarrier.Logic.Enum.DirectionType;
|
||||||
|
|
||||||
|
public class MoveableCarrier implements IMoveableObject {
|
||||||
|
private final DrawingSimpleAircraftCarrier drawingSimpleAircraftCarrier;
|
||||||
|
|
||||||
|
public MoveableCarrier(DrawingSimpleAircraftCarrier drawingSimpleAircraftCarrier) {
|
||||||
|
this.drawingSimpleAircraftCarrier = drawingSimpleAircraftCarrier;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ObjectParameters GetObjectPosition() {
|
||||||
|
if (drawingSimpleAircraftCarrier == null || drawingSimpleAircraftCarrier.aircraftCarrier == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return new ObjectParameters(drawingSimpleAircraftCarrier);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int GetStep() {
|
||||||
|
return drawingSimpleAircraftCarrier.aircraftCarrier.getStep();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean TryMoveObject(MovementDirection direction) {
|
||||||
|
if (drawingSimpleAircraftCarrier == null || drawingSimpleAircraftCarrier.aircraftCarrier == null)
|
||||||
|
return false;
|
||||||
|
return drawingSimpleAircraftCarrier.Move(GetDirectionType(direction));
|
||||||
|
}
|
||||||
|
|
||||||
|
private static DirectionType GetDirectionType(MovementDirection direction) {
|
||||||
|
return switch (direction) {
|
||||||
|
case Up -> DirectionType.Up;
|
||||||
|
case Down -> DirectionType.Down;
|
||||||
|
case Left -> DirectionType.Left;
|
||||||
|
case Right -> DirectionType.Right;
|
||||||
|
default -> DirectionType.Unknown;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,8 @@
|
|||||||
|
package com.example.aircraftcarrier.Logic.MovementStategy;
|
||||||
|
|
||||||
|
public enum MovementDirection {
|
||||||
|
Up,
|
||||||
|
Down,
|
||||||
|
Left,
|
||||||
|
Right
|
||||||
|
}
|
@ -0,0 +1,43 @@
|
|||||||
|
package com.example.aircraftcarrier.Logic.MovementStategy;
|
||||||
|
|
||||||
|
import com.example.aircraftcarrier.Logic.Aircraft.DrawingSimpleAircraftCarrier;
|
||||||
|
|
||||||
|
public class ObjectParameters {
|
||||||
|
private final int x;
|
||||||
|
private final int y;
|
||||||
|
private final int width;
|
||||||
|
private final int height;
|
||||||
|
|
||||||
|
public ObjectParameters(int x, int y, int width, int height) {
|
||||||
|
this.x = x;
|
||||||
|
this.y = y;
|
||||||
|
this.width = width;
|
||||||
|
this.height = height;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ObjectParameters(DrawingSimpleAircraftCarrier drawingSimpleAircraftCarrier) {
|
||||||
|
this.x = drawingSimpleAircraftCarrier.getX();
|
||||||
|
this.y = drawingSimpleAircraftCarrier.getY();
|
||||||
|
this.width = drawingSimpleAircraftCarrier.getWidthPicture();
|
||||||
|
this.height = drawingSimpleAircraftCarrier.getHeightPicture();
|
||||||
|
}
|
||||||
|
|
||||||
|
public int LeftBorder() {
|
||||||
|
return x;
|
||||||
|
}
|
||||||
|
public int RightBorder() {
|
||||||
|
return x+width;
|
||||||
|
}
|
||||||
|
public int TopBorder() {
|
||||||
|
return y;
|
||||||
|
}
|
||||||
|
public int BottomBorder() {
|
||||||
|
return y+height;
|
||||||
|
}
|
||||||
|
public int CenterX() {
|
||||||
|
return x+width / 2;
|
||||||
|
}
|
||||||
|
public int CenterY() {
|
||||||
|
return y+height/2;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,7 @@
|
|||||||
|
package com.example.aircraftcarrier.Logic.MovementStategy;
|
||||||
|
|
||||||
|
public enum StrategyStatus {
|
||||||
|
NotInit,
|
||||||
|
InProgress,
|
||||||
|
Finish
|
||||||
|
}
|
@ -0,0 +1,212 @@
|
|||||||
|
package com.example.aircraftcarrier;
|
||||||
|
|
||||||
|
import com.example.aircraftcarrier.Logic.Aircraft.DrawingAircraftCarrier;
|
||||||
|
import com.example.aircraftcarrier.Logic.Aircraft.DrawingSimpleAircraftCarrier;
|
||||||
|
import com.example.aircraftcarrier.Logic.Block.DrawingBlock;
|
||||||
|
import com.example.aircraftcarrier.Logic.Block.DrawingBlockCircle;
|
||||||
|
import com.example.aircraftcarrier.Logic.Block.DrawingBlockTriangle;
|
||||||
|
import com.example.aircraftcarrier.Logic.Block.IDrawingBlock;
|
||||||
|
import com.example.aircraftcarrier.Logic.CollectionGenericObjects.AbstractCompany;
|
||||||
|
import com.example.aircraftcarrier.Logic.CollectionGenericObjects.DocksService;
|
||||||
|
import com.example.aircraftcarrier.Logic.CollectionGenericObjects.MassiveGenericObjects;
|
||||||
|
import javafx.beans.value.ChangeListener;
|
||||||
|
import javafx.beans.value.ObservableValue;
|
||||||
|
import javafx.fxml.FXML;
|
||||||
|
import javafx.fxml.FXMLLoader;
|
||||||
|
import javafx.fxml.Initializable;
|
||||||
|
import javafx.scene.Scene;
|
||||||
|
import javafx.scene.canvas.Canvas;
|
||||||
|
import javafx.scene.control.*;
|
||||||
|
import javafx.scene.layout.AnchorPane;
|
||||||
|
import javafx.scene.paint.Color;
|
||||||
|
import javafx.stage.Stage;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.util.Random;
|
||||||
|
import java.util.ResourceBundle;
|
||||||
|
|
||||||
|
public class ShipCollectionController implements Initializable {
|
||||||
|
|
||||||
|
private AbstractCompany _company;
|
||||||
|
Random random = new Random();
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
private TextField IdField;
|
||||||
|
@FXML
|
||||||
|
private Canvas canvasCollection;
|
||||||
|
@FXML
|
||||||
|
private ComboBox<String> comboBoxStorage;
|
||||||
|
private final String[] storageText = new String[]{"Хранилище"};
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
protected void ComboBox_Choice() {
|
||||||
|
System.out.println(comboBoxStorage.getValue());
|
||||||
|
switch (comboBoxStorage.getValue())
|
||||||
|
{
|
||||||
|
case "Хранилище":
|
||||||
|
_company = new DocksService(
|
||||||
|
(int)canvasCollection.getWidth(),
|
||||||
|
(int)canvasCollection.getHeight(),
|
||||||
|
new MassiveGenericObjects<DrawingSimpleAircraftCarrier>()
|
||||||
|
);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
_company.Show(canvasCollection.getGraphicsContext2D());
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Color GetColor(Random random) {
|
||||||
|
Color c = Color.rgb(random.nextInt(256),random.nextInt(256),random.nextInt(256));
|
||||||
|
DialogPane dp = new DialogPane();
|
||||||
|
|
||||||
|
ColorPicker asd = new ColorPicker();
|
||||||
|
asd.setValue(c);
|
||||||
|
|
||||||
|
dp.setContent(asd);
|
||||||
|
|
||||||
|
dp.getButtonTypes().setAll(ButtonType.YES, ButtonType.NO);
|
||||||
|
Dialog<ButtonType> dialog = new Dialog<>();
|
||||||
|
dialog.setDialogPane(dp);
|
||||||
|
dialog.showAndWait();
|
||||||
|
if (dialog.getResult() == ButtonType.YES) { c = asd.getValue(); }
|
||||||
|
return c;
|
||||||
|
}
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
protected void ButtonCreateSimple_Click() {
|
||||||
|
if (_company == null) return;
|
||||||
|
DrawingSimpleAircraftCarrier drawingAircraftCarrier;
|
||||||
|
drawingAircraftCarrier = new DrawingSimpleAircraftCarrier(
|
||||||
|
random.nextInt(100) + 100,
|
||||||
|
random.nextInt(1000) + 1000,
|
||||||
|
GetColor(random)
|
||||||
|
);
|
||||||
|
|
||||||
|
drawingAircraftCarrier.setCanvasWidth((int) canvasCollection.getWidth());
|
||||||
|
drawingAircraftCarrier.setCanvasHeight((int) canvasCollection.getHeight());
|
||||||
|
AbstractCompany.add(_company,drawingAircraftCarrier);
|
||||||
|
_company.Show(canvasCollection.getGraphicsContext2D());
|
||||||
|
}
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
protected void ButtonCreate_Click() {
|
||||||
|
if (_company == null) return;
|
||||||
|
|
||||||
|
int inputCount;
|
||||||
|
String shape;
|
||||||
|
|
||||||
|
try {
|
||||||
|
FXMLLoader dialogLoader = new FXMLLoader(
|
||||||
|
AircraftCarrierApplication.class.getResource(
|
||||||
|
"/com/example/aircraftcarrier/BlockDialogView.fxml"
|
||||||
|
)
|
||||||
|
);
|
||||||
|
DialogPane blockPane = dialogLoader.load();
|
||||||
|
BlockDialogController blockDialogController = dialogLoader.getController();
|
||||||
|
Dialog<Object> s = new Dialog<>();
|
||||||
|
s.setDialogPane(blockPane);
|
||||||
|
s.showAndWait();
|
||||||
|
|
||||||
|
shape = blockDialogController.getShape();
|
||||||
|
inputCount = blockDialogController.getCount();
|
||||||
|
} catch (Exception ignore) {
|
||||||
|
inputCount = 0;
|
||||||
|
shape = "";
|
||||||
|
}
|
||||||
|
|
||||||
|
DrawingAircraftCarrier drawingAircraftCarrier = new DrawingAircraftCarrier(
|
||||||
|
random.nextInt(100) + 100,
|
||||||
|
random.nextInt(1000) + 1000,
|
||||||
|
GetColor(random),
|
||||||
|
GetColor(random),
|
||||||
|
random.nextBoolean(),
|
||||||
|
random.nextBoolean(),
|
||||||
|
inputCount,
|
||||||
|
shape
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
drawingAircraftCarrier.setCanvasWidth((int) canvasCollection.getWidth());
|
||||||
|
drawingAircraftCarrier.setCanvasHeight((int) canvasCollection.getHeight());
|
||||||
|
|
||||||
|
AbstractCompany.add(_company,drawingAircraftCarrier);
|
||||||
|
_company.Show(canvasCollection.getGraphicsContext2D());
|
||||||
|
}
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
private void ButtonTest_Click() {
|
||||||
|
if (_company == null) return;
|
||||||
|
DrawingSimpleAircraftCarrier aircraft = null;
|
||||||
|
int counter = 100;
|
||||||
|
while (aircraft == null & counter > 0) {
|
||||||
|
aircraft = _company.GetRandom();
|
||||||
|
counter--;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (aircraft == null) return;
|
||||||
|
|
||||||
|
FXMLLoader fxmlLoader = new FXMLLoader(
|
||||||
|
AircraftCarrierApplication.class.getResource(
|
||||||
|
"/com/example/aircraftcarrier/AircraftCarrierView.fxml"
|
||||||
|
)
|
||||||
|
);
|
||||||
|
try {
|
||||||
|
AnchorPane Pane = fxmlLoader.load();
|
||||||
|
AircraftCarrierController controller = fxmlLoader.getController();
|
||||||
|
Stage stage = new Stage();
|
||||||
|
Scene scene = new Scene(Pane);
|
||||||
|
stage.setScene(scene);
|
||||||
|
controller.setDrawing(aircraft);
|
||||||
|
stage.show();
|
||||||
|
controller.draw();
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
private void ButtonDeleteAircraft_Click() {
|
||||||
|
if (IdField.getText().isEmpty() || _company == null) return;
|
||||||
|
|
||||||
|
Alert alert = new Alert(Alert.AlertType.NONE);
|
||||||
|
alert.setTitle("Удаление");
|
||||||
|
alert.setContentText("вы действительно хотите удалить " + IdField.getText());
|
||||||
|
alert.getButtonTypes().setAll(ButtonType.YES,ButtonType.NO);
|
||||||
|
alert.showAndWait();
|
||||||
|
ButtonType res = alert.resultProperty().getValue();
|
||||||
|
|
||||||
|
if (res == ButtonType.NO || res == ButtonType.CLOSE) return;
|
||||||
|
|
||||||
|
int pos = Integer.parseInt(IdField.getText());
|
||||||
|
if (AbstractCompany.remove(_company, pos)) {
|
||||||
|
Alert correct = new Alert(Alert.AlertType.NONE);
|
||||||
|
alert.setTitle("Успешно");
|
||||||
|
correct.setContentText("объект был удален");
|
||||||
|
correct.getButtonTypes().setAll(ButtonType.OK);
|
||||||
|
correct.showAndWait();
|
||||||
|
|
||||||
|
_company.Show(canvasCollection.getGraphicsContext2D());
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
Alert incorrect = new Alert(Alert.AlertType.NONE);
|
||||||
|
incorrect.setContentText("объект не удален");
|
||||||
|
incorrect.getButtonTypes().setAll(ButtonType.OK);
|
||||||
|
incorrect.showAndWait();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void initialize(URL url, ResourceBundle resourceBundle) {
|
||||||
|
comboBoxStorage.getItems().addAll(storageText);
|
||||||
|
IdField.textProperty().addListener(new ChangeListener<String>() {
|
||||||
|
@Override
|
||||||
|
public void changed(ObservableValue<? extends String> observableValue, String oldValue, String newValue) {
|
||||||
|
if(newValue.matches("\\d{0,2}")) {
|
||||||
|
IdField.setText(newValue);
|
||||||
|
} else {
|
||||||
|
IdField.setText(oldValue);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
@ -5,4 +5,12 @@ module com.example.aircraftcarrier {
|
|||||||
|
|
||||||
opens com.example.aircraftcarrier to javafx.fxml;
|
opens com.example.aircraftcarrier to javafx.fxml;
|
||||||
exports com.example.aircraftcarrier;
|
exports com.example.aircraftcarrier;
|
||||||
|
exports com.example.aircraftcarrier.Logic.Aircraft;
|
||||||
|
opens com.example.aircraftcarrier.Logic.Aircraft to javafx.fxml;
|
||||||
|
exports com.example.aircraftcarrier.Logic.Entity;
|
||||||
|
opens com.example.aircraftcarrier.Logic.Entity to javafx.fxml;
|
||||||
|
exports com.example.aircraftcarrier.Logic.Enum;
|
||||||
|
opens com.example.aircraftcarrier.Logic.Enum to javafx.fxml;
|
||||||
|
exports com.example.aircraftcarrier.Logic.Block;
|
||||||
|
opens com.example.aircraftcarrier.Logic.Block to javafx.fxml;
|
||||||
}
|
}
|
@ -0,0 +1,17 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
|
||||||
|
<?import javafx.scene.canvas.*?>
|
||||||
|
<?import javafx.scene.control.*?>
|
||||||
|
<?import javafx.scene.layout.*?>
|
||||||
|
|
||||||
|
<AnchorPane fx:id="Root" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" onKeyPressed="#MoveEvent" prefHeight="600.0" prefWidth="800.0" xmlns="http://javafx.com/javafx/17.0.2-ea" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.example.aircraftcarrier.AircraftCarrierController">
|
||||||
|
<children>
|
||||||
|
<Canvas fx:id="canvas" height="600.0" width="800.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0" />
|
||||||
|
<Button fx:id="up" layoutX="524.4" layoutY="324.4" minHeight="25.0" minWidth="25.0" mnemonicParsing="false" onAction="#MoveEvent" style="-fx-background-image: url("up-arrow.png"); -fx-background-size: stretch;" AnchorPane.bottomAnchor="50.0" AnchorPane.rightAnchor="50.0" />
|
||||||
|
<Button fx:id="right" layoutX="554.4" layoutY="354.4" minHeight="25.0" minWidth="25.0" mnemonicParsing="false" onAction="#MoveEvent" style="-fx-background-image: url("right-arrow.png"); -fx-background-size: stretch;" AnchorPane.bottomAnchor="20.0" AnchorPane.rightAnchor="20.0" />
|
||||||
|
<Button fx:id="down" layoutX="524.4" layoutY="354.4" minHeight="25.0" minWidth="25.0" mnemonicParsing="false" onAction="#MoveEvent" style="-fx-background-image: url("down-arrow.png"); -fx-background-size: stretch;" AnchorPane.bottomAnchor="20.0" AnchorPane.rightAnchor="50.0" />
|
||||||
|
<Button fx:id="left" layoutX="494.4" layoutY="354.4" minHeight="25.0" minWidth="25.0" mnemonicParsing="false" onAction="#MoveEvent" style="-fx-background-image: url("left-arrow.png"); -fx-background-size: stretch;" AnchorPane.bottomAnchor="20.0" AnchorPane.rightAnchor="80.0" />
|
||||||
|
<ChoiceBox fx:id="choiceBoxStrategy" layoutX="469.0" layoutY="14.0" prefHeight="26.0" prefWidth="110.0" AnchorPane.rightAnchor="20.600000000000023" AnchorPane.topAnchor="14.0" />
|
||||||
|
<Button layoutX="543.0" layoutY="44.0" mnemonicParsing="false" onAction="#ButtonStrategy_Click" text="шаг" AnchorPane.rightAnchor="20.200000000000045" AnchorPane.topAnchor="44.0" />
|
||||||
|
</children>
|
||||||
|
</AnchorPane>
|
@ -0,0 +1,21 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
|
||||||
|
<?import javafx.scene.control.*?>
|
||||||
|
<?import javafx.scene.layout.*?>
|
||||||
|
|
||||||
|
<DialogPane prefHeight="120.0" prefWidth="250.0" xmlns="http://javafx.com/javafx/17.0.2-ea" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.example.aircraftcarrier.BlockDialogController">
|
||||||
|
<content>
|
||||||
|
<VBox minHeight="150.0" minWidth="250.0" prefHeight="150.0" prefWidth="265.0">
|
||||||
|
<children>
|
||||||
|
<Label text="Форма блоков" />
|
||||||
|
<ComboBox minWidth="-Infinity" prefWidth="230.0" fx:id="ComboBoxShape" />
|
||||||
|
<Label text="Количество блоков" />
|
||||||
|
<TextField fx:id="CountBlock" />
|
||||||
|
</children>
|
||||||
|
</VBox>
|
||||||
|
</content>
|
||||||
|
<buttonTypes>
|
||||||
|
<ButtonType fx:constant="OK" />
|
||||||
|
<ButtonType fx:constant="CANCEL" />
|
||||||
|
</buttonTypes>
|
||||||
|
</DialogPane>
|
@ -0,0 +1,32 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
|
||||||
|
<?import javafx.scene.canvas.*?>
|
||||||
|
<?import javafx.scene.control.*?>
|
||||||
|
<?import javafx.scene.layout.*?>
|
||||||
|
|
||||||
|
<BorderPane prefHeight="600.0" prefWidth="800.0" xmlns="http://javafx.com/javafx/17.0.2-ea" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.example.aircraftcarrier.ShipCollectionController">
|
||||||
|
<right>
|
||||||
|
<BorderPane prefHeight="400.0" prefWidth="200.0" BorderPane.alignment="CENTER">
|
||||||
|
<center>
|
||||||
|
<AnchorPane>
|
||||||
|
<children>
|
||||||
|
<Button layoutX="64.0" layoutY="38.0" mnemonicParsing="false" onAction="#ButtonCreateSimple_Click" text="Создать Авианосец" AnchorPane.leftAnchor="10.0" AnchorPane.rightAnchor="10.0" AnchorPane.topAnchor="55.0" />
|
||||||
|
<Button layoutX="64.0" layoutY="82.0" mnemonicParsing="false" onAction="#ButtonCreate_Click" text="Создать супер Авианосец" AnchorPane.leftAnchor="10.0" AnchorPane.rightAnchor="10.0" AnchorPane.topAnchor="90.0" />
|
||||||
|
<Button layoutX="64.0" layoutY="132.0" mnemonicParsing="false" onAction="#ButtonDeleteAircraft_Click" text="Удалить Авианосец" AnchorPane.leftAnchor="10.0" AnchorPane.rightAnchor="10.0" AnchorPane.topAnchor="160.0" />
|
||||||
|
<Button layoutX="64.0" layoutY="166.0" mnemonicParsing="false" onAction="#ButtonTest_Click" text="Тесты" AnchorPane.bottomAnchor="55.0" AnchorPane.leftAnchor="10.0" AnchorPane.rightAnchor="10.0" />
|
||||||
|
<Button layoutX="64.0" layoutY="216.0" mnemonicParsing="false" text="Обновить" AnchorPane.bottomAnchor="20.0" AnchorPane.leftAnchor="10.0" AnchorPane.rightAnchor="10.0" />
|
||||||
|
<ComboBox fx:id="comboBoxStorage" layoutX="23.0" layoutY="14.0" onAction="#ComboBox_Choice" prefWidth="150.0" AnchorPane.leftAnchor="10.0" AnchorPane.rightAnchor="10.0" AnchorPane.topAnchor="20.0" />
|
||||||
|
<TextField fx:id="IdField" layoutX="24.0" layoutY="108.0" promptText="номер" AnchorPane.leftAnchor="10.0" AnchorPane.rightAnchor="10.0" AnchorPane.topAnchor="125.0" />
|
||||||
|
</children>
|
||||||
|
</AnchorPane>
|
||||||
|
</center>
|
||||||
|
</BorderPane>
|
||||||
|
</right>
|
||||||
|
<center>
|
||||||
|
<AnchorPane BorderPane.alignment="CENTER">
|
||||||
|
<children>
|
||||||
|
<Canvas fx:id="canvasCollection" height="600.0" width="600.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0" />
|
||||||
|
</children>
|
||||||
|
</AnchorPane>
|
||||||
|
</center>
|
||||||
|
</BorderPane>
|
@ -1,16 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
|
|
||||||
<?import javafx.geometry.Insets?>
|
|
||||||
<?import javafx.scene.control.Label?>
|
|
||||||
<?import javafx.scene.layout.VBox?>
|
|
||||||
|
|
||||||
<?import javafx.scene.control.Button?>
|
|
||||||
<VBox alignment="CENTER" spacing="20.0" xmlns:fx="http://javafx.com/fxml"
|
|
||||||
fx:controller="com.example.aircraftcarrier.HelloController">
|
|
||||||
<padding>
|
|
||||||
<Insets bottom="20.0" left="20.0" right="20.0" top="20.0"/>
|
|
||||||
</padding>
|
|
||||||
|
|
||||||
<Label fx:id="welcomeText"/>
|
|
||||||
<Button text="Hello!" onAction="#onHelloButtonClick"/>
|
|
||||||
</VBox>
|
|
BIN
src/main/resources/down-arrow.png
Normal file
BIN
src/main/resources/down-arrow.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.1 KiB |
BIN
src/main/resources/left-arrow.png
Normal file
BIN
src/main/resources/left-arrow.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.1 KiB |
BIN
src/main/resources/right-arrow.png
Normal file
BIN
src/main/resources/right-arrow.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 361 B |
BIN
src/main/resources/up-arrow.png
Normal file
BIN
src/main/resources/up-arrow.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.1 KiB |
Loading…
x
Reference in New Issue
Block a user