lab 3 prerelease
This commit is contained in:
parent
ca79a77693
commit
c1cd71bd47
@ -40,7 +40,6 @@ public class AircraftCarrierController implements Initializable {
|
||||
|
||||
public void setDrawing(DrawingSimpleAircraftCarrier drawingAircraftCarrier) {
|
||||
this.drawingAircraftCarrier = drawingAircraftCarrier;
|
||||
draw();
|
||||
}
|
||||
|
||||
@FXML
|
||||
@ -62,14 +61,14 @@ public class AircraftCarrierController implements Initializable {
|
||||
|
||||
choiceBoxStrategy.setDisable(true);
|
||||
strategy.MakeStep();
|
||||
drawingAircraftCarrier.Draw(canvas.getGraphicsContext2D());
|
||||
draw();
|
||||
if (strategy.GetStatus() == StrategyStatus.Finish) {
|
||||
choiceBoxStrategy.setDisable(false);
|
||||
strategy = null;
|
||||
}
|
||||
}
|
||||
|
||||
private void draw() {
|
||||
public void draw() {
|
||||
canvas.getGraphicsContext2D().clearRect(0,0,canvas.getWidth(),canvas.getHeight());
|
||||
drawingAircraftCarrier.Draw(canvas.getGraphicsContext2D());
|
||||
}
|
||||
|
@ -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,5 +1,8 @@
|
||||
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;
|
||||
@ -16,7 +19,9 @@ public class DrawingAircraftCarrier extends DrawingSimpleAircraftCarrier {
|
||||
Color primaryColor,
|
||||
Color secondaryColor,
|
||||
boolean hasDeck,
|
||||
boolean hasСabin
|
||||
boolean hasСabin,
|
||||
int countBlock,
|
||||
String shape
|
||||
) {
|
||||
super();
|
||||
aircraftCarrier = new EntityAircraftCarrier(speed,
|
||||
@ -25,6 +30,16 @@ public class DrawingAircraftCarrier extends DrawingSimpleAircraftCarrier {
|
||||
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) {
|
||||
|
@ -7,6 +7,10 @@ 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);
|
||||
}
|
||||
|
@ -7,7 +7,9 @@ import javafx.scene.paint.Color;
|
||||
public class DrawingBlockCircle implements IDrawingBlock {
|
||||
private BlockCount blockCount;
|
||||
|
||||
public DrawingBlockCircle() {}
|
||||
public DrawingBlockCircle(int blockCountValue) {
|
||||
this.blockCount = BlockCount.ConvertToBlockCount(blockCountValue);
|
||||
}
|
||||
|
||||
public void setBlockCount(int blockCountValue) {
|
||||
this.blockCount = BlockCount.ConvertToBlockCount(blockCountValue);
|
||||
|
@ -7,7 +7,10 @@ import javafx.scene.paint.Color;
|
||||
public class DrawingBlockTriangle implements IDrawingBlock {
|
||||
private BlockCount blockCount;
|
||||
|
||||
public DrawingBlockTriangle() {}
|
||||
|
||||
public DrawingBlockTriangle(int blockCountValue) {
|
||||
this.blockCount = BlockCount.ConvertToBlockCount(blockCountValue);
|
||||
}
|
||||
|
||||
public void setBlockCount(int blockCountValue) {
|
||||
this.blockCount = BlockCount.ConvertToBlockCount(blockCountValue);
|
||||
|
@ -29,7 +29,7 @@ public abstract class AbstractCompany {
|
||||
}
|
||||
|
||||
public static boolean remove(AbstractCompany company, int pos){
|
||||
return company != null && company._collection != null && company._collection.Remove(pos);
|
||||
return company != null & company._collection != null & company._collection.Remove(pos);
|
||||
}
|
||||
|
||||
public DrawingSimpleAircraftCarrier GetRandom() {
|
||||
@ -44,7 +44,7 @@ public abstract class AbstractCompany {
|
||||
for (int i = 0; i < _collection.count(); i++)
|
||||
{
|
||||
DrawingSimpleAircraftCarrier obj = _collection.Get(i);
|
||||
if (obj == null) return;
|
||||
if (obj == null) continue;
|
||||
obj.Draw(gc);
|
||||
}
|
||||
}
|
||||
|
@ -44,10 +44,10 @@ public class DocksService extends AbstractCompany {
|
||||
|
||||
for (int i = 0; i < _collection.count(); i++) {
|
||||
DrawingSimpleAircraftCarrier obj = _collection.Get(i);
|
||||
if (obj == null) { continue; }
|
||||
System.out.println(i);
|
||||
obj.setCanvasParam(_pictureWidth,_pictureHeight);
|
||||
obj.setPosition(xpos * _placeSizeWidth + 10, (ypos-1) * _placeSizeHeight + 10);
|
||||
if (obj != null) {
|
||||
obj.setCanvasParam(_pictureWidth,_pictureHeight);
|
||||
obj.setPosition(xpos * _placeSizeWidth + 10, (ypos-1) * _placeSizeHeight + 10);
|
||||
}
|
||||
xpos++;
|
||||
if (xpos >= maxXPositionCount)
|
||||
{
|
||||
|
@ -3,6 +3,8 @@ 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;
|
||||
@ -34,12 +36,8 @@ public class ShipCollectionController implements Initializable {
|
||||
@FXML
|
||||
private Canvas canvasCollection;
|
||||
@FXML
|
||||
private AnchorPane wrapperCanvas;
|
||||
@FXML
|
||||
private ComboBox<String> comboBoxStorage;
|
||||
private final String[] storageText = new String[]{"Хранилище"};
|
||||
@FXML
|
||||
private static ColorPicker asdd1;
|
||||
|
||||
@FXML
|
||||
protected void ComboBox_Choice() {
|
||||
@ -59,26 +57,18 @@ public class ShipCollectionController implements Initializable {
|
||||
|
||||
private static Color GetColor(Random random) {
|
||||
Color c = Color.rgb(random.nextInt(256),random.nextInt(256),random.nextInt(256));
|
||||
// //TODO: доделать
|
||||
// asdd1.setVisible(false);
|
||||
// asdd1.sho
|
||||
// ColorPicker colorPicker = new ColorPicker(c);
|
||||
// Button confirmButton = new Button("Установить");
|
||||
// confirmButton.setAlignment(Pos.CENTER_RIGHT);
|
||||
//
|
||||
// HBox buttonBox = new HBox(confirmButton);
|
||||
// buttonBox.setAlignment(Pos.TOP_RIGHT);
|
||||
// buttonBox.setPadding(new Insets(10, 10, 10, 10));
|
||||
// VBox root = new VBox(colorPicker, buttonBox);
|
||||
//
|
||||
//
|
||||
//
|
||||
// Stage colorStage = new Stage();
|
||||
// colorStage.setScene(new Scene(root));
|
||||
//
|
||||
// confirmButton.setOnAction(event -> colorStage.close());
|
||||
//
|
||||
// colorStage.showAndWait();
|
||||
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;
|
||||
}
|
||||
|
||||
@ -101,24 +91,45 @@ public class ShipCollectionController implements Initializable {
|
||||
@FXML
|
||||
protected void ButtonCreate_Click() {
|
||||
if (_company == null) return;
|
||||
DrawingAircraftCarrier drawingAircraftCarrier;
|
||||
drawingAircraftCarrier = new DrawingAircraftCarrier(
|
||||
|
||||
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()
|
||||
random.nextBoolean(),
|
||||
inputCount,
|
||||
shape
|
||||
);
|
||||
|
||||
IDrawingBlock imo = new DrawingBlock();
|
||||
imo.setBlockCount(2);
|
||||
drawingAircraftCarrier.setDrawingBlock(imo);
|
||||
|
||||
drawingAircraftCarrier.setCanvasWidth((int) canvasCollection.getWidth());
|
||||
drawingAircraftCarrier.setCanvasHeight((int) canvasCollection.getHeight());
|
||||
|
||||
System.out.println( AbstractCompany.add(_company,drawingAircraftCarrier));
|
||||
AbstractCompany.add(_company,drawingAircraftCarrier);
|
||||
_company.Show(canvasCollection.getGraphicsContext2D());
|
||||
}
|
||||
|
||||
@ -142,11 +153,12 @@ public class ShipCollectionController implements Initializable {
|
||||
try {
|
||||
AnchorPane Pane = fxmlLoader.load();
|
||||
AircraftCarrierController controller = fxmlLoader.getController();
|
||||
controller.setDrawing(aircraft);
|
||||
Stage stage = new Stage();
|
||||
Scene scene = new Scene(Pane);
|
||||
stage.setScene(scene);
|
||||
stage.showAndWait();
|
||||
controller.setDrawing(aircraft);
|
||||
stage.show();
|
||||
controller.draw();
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
@ -186,8 +198,6 @@ public class ShipCollectionController implements Initializable {
|
||||
@Override
|
||||
public void initialize(URL url, ResourceBundle resourceBundle) {
|
||||
comboBoxStorage.getItems().addAll(storageText);
|
||||
// canvasCollection.widthProperty().bind(wrapperCanvas.widthProperty());
|
||||
// canvasCollection.heightProperty().bind(wrapperCanvas.heightProperty());
|
||||
IdField.textProperty().addListener(new ChangeListener<String>() {
|
||||
@Override
|
||||
public void changed(ObservableValue<? extends String> observableValue, String oldValue, String newValue) {
|
||||
|
@ -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>
|
@ -23,7 +23,7 @@
|
||||
</BorderPane>
|
||||
</right>
|
||||
<center>
|
||||
<AnchorPane fx:id="wrapperCanvas" BorderPane.alignment="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>
|
||||
|
Loading…
x
Reference in New Issue
Block a user