лаба01 простая версия на джаве закончена
This commit is contained in:
parent
9d85732740
commit
ad362f0fab
8
.idea/inspectionProfiles/Project_Default.xml
generated
Normal file
8
.idea/inspectionProfiles/Project_Default.xml
generated
Normal file
@ -0,0 +1,8 @@
|
||||
<component name="InspectionProjectProfileManager">
|
||||
<profile version="1.0">
|
||||
<option name="myName" value="Project Default" />
|
||||
<inspection_tool class="EnhancedSwitchMigration" enabled="true" level="WARNING" enabled_by_default="true">
|
||||
<option name="myMaxNumberStatementsForBranch" value="1" />
|
||||
</inspection_tool>
|
||||
</profile>
|
||||
</component>
|
@ -1,16 +1,65 @@
|
||||
package kvr.missilecruiser_hard;
|
||||
|
||||
import javafx.event.ActionEvent;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.scene.control.Button;
|
||||
import javafx.scene.paint.Color;
|
||||
import javafx.scene.canvas.Canvas;
|
||||
import javafx.scene.canvas.GraphicsContext;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
public class ControllerMissileCruiser
|
||||
{
|
||||
private DrawingMissileCruiser drawingMissileCruiser;
|
||||
private GraphicsContext graphicsContext;
|
||||
private Random random;
|
||||
|
||||
@FXML
|
||||
private Canvas mainCanvas;
|
||||
|
||||
@FXML
|
||||
private void initialize() {
|
||||
drawingMissileCruiser = new DrawingMissileCruiser();
|
||||
graphicsContext = mainCanvas.getGraphicsContext2D();
|
||||
|
||||
random = new Random();
|
||||
}
|
||||
|
||||
private void DrawOnCanvas(){
|
||||
drawingMissileCruiser.DrawTransport(graphicsContext);
|
||||
}
|
||||
|
||||
@FXML
|
||||
protected void buttonCreate_Click() {
|
||||
drawingMissileCruiser.Init(
|
||||
random.nextInt(100, 300), random.nextInt(1000, 3000),
|
||||
Color.rgb(random.nextInt(0, 256), random.nextInt(0, 256), random.nextInt(0, 256)),
|
||||
Color.rgb(random.nextInt(0, 256), random.nextInt(0, 256), random.nextInt(0, 256)),
|
||||
random.nextBoolean(), random.nextBoolean(), random.nextBoolean()
|
||||
);
|
||||
|
||||
drawingMissileCruiser.SetPictureSize((int) mainCanvas.getWidth(), (int) mainCanvas.getHeight());
|
||||
drawingMissileCruiser.SetPosition(random.nextInt(10, 100), random.nextInt(10, 100));
|
||||
|
||||
DrawOnCanvas();
|
||||
}
|
||||
|
||||
@FXML
|
||||
protected void buttonsMove_Click() {
|
||||
//System.out.println(System.getProperty("java.class.path"));
|
||||
protected void buttonsMove_Click(ActionEvent event) {
|
||||
String name = ((Button) event.getSource()).getId();
|
||||
|
||||
boolean result = switch (name) {
|
||||
case "buttonUp" -> drawingMissileCruiser.MoveTransport(DirectionType.Up);
|
||||
case "buttonDown" -> drawingMissileCruiser.MoveTransport(DirectionType.Down);
|
||||
case "buttonLeft" -> drawingMissileCruiser.MoveTransport(DirectionType.Left);
|
||||
case "buttonRight" -> drawingMissileCruiser.MoveTransport(DirectionType.Right);
|
||||
default -> false;
|
||||
};
|
||||
|
||||
if (result)
|
||||
{
|
||||
DrawOnCanvas();
|
||||
}
|
||||
}
|
||||
}
|
@ -4,6 +4,8 @@ import javafx.scene.canvas.GraphicsContext;
|
||||
import javafx.scene.image.Image;
|
||||
import javafx.scene.paint.Color;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public class DrawingMissileCruiser {
|
||||
/// Класс-сущность
|
||||
private EntityMissileCruiser entityMissileCruiser;
|
||||
@ -139,10 +141,10 @@ public class DrawingMissileCruiser {
|
||||
}
|
||||
}
|
||||
|
||||
private final Image cruiserContourImg = new Image("images/cruiser_contour.png");
|
||||
private final Image vlsSideImg = new Image("images/cruiser_vls_sides.png");
|
||||
private final Image vlsCenterImg = new Image("images/cruiser_vls_center.png");
|
||||
private final Image helipadImg = new Image("images/cruiser_helipad.png");
|
||||
public Image cruiserContourImg = new Image(Objects.requireNonNull(getClass().getResource("images/cruiser_contour.png")).toExternalForm());
|
||||
public Image vlsSideImg = new Image(Objects.requireNonNull(getClass().getResource("images/cruiser_vls_sides.png")).toExternalForm());
|
||||
public Image vlsCenterImg = new Image(Objects.requireNonNull(getClass().getResource("images/cruiser_vls_center.png")).toExternalForm());
|
||||
public Image helipadImg = new Image(Objects.requireNonNull(getClass().getResource("images/cruiser_helipad.png")).toExternalForm());
|
||||
|
||||
/// <summary>
|
||||
/// Прорисовка объекта
|
||||
@ -155,20 +157,18 @@ public class DrawingMissileCruiser {
|
||||
return;
|
||||
}
|
||||
|
||||
double[][] contourPolygon = new double[][] {
|
||||
{posX + 11, posY},
|
||||
{posX + 116, posY},
|
||||
{posX + 149, posY + 17},
|
||||
{posX + 116, posY + 34},
|
||||
{posX + 10, posY + 34},
|
||||
{posX, posY + 29},
|
||||
{posX, posY + 5}
|
||||
// Fuck JavaFX, I had to use SUBPIXEL offsets to not see antialiasing artifacts
|
||||
double[] contourPolygonX = new double[] {
|
||||
posX + 10.75, posX + 116.25, posX + 150, posX + 116.25, posX + 10.75, posX + 0.5, posX + 0.5
|
||||
};
|
||||
double[] contourPolygonY = new double[] {
|
||||
posY + 0.5, posY + 0.5, posY + 17.5, posY + 34.5, posY + 34.5, posY + 29.5, posY + 5.5
|
||||
};
|
||||
|
||||
gc.clearRect(0, 0, pictureWidth, pictureHeight);
|
||||
|
||||
gc.setFill(entityMissileCruiser.getPrimaryColor());
|
||||
gc.fillPolygon(contourPolygon[0], contourPolygon[1], contourPolygon.length);
|
||||
gc.fillPolygon(contourPolygonX, contourPolygonY, contourPolygonX.length);
|
||||
|
||||
if (entityMissileCruiser.getVLS_Sides())
|
||||
{
|
||||
@ -186,7 +186,7 @@ public class DrawingMissileCruiser {
|
||||
if (entityMissileCruiser.getHelipad())
|
||||
{
|
||||
gc.setFill(entityMissileCruiser.getSecondaryColor());
|
||||
gc.fillOval(posX + 2, posY + 9, 16, 16);
|
||||
gc.fillOval(posX + 2.5, posY + 9.5, 16, 16);
|
||||
gc.drawImage(helipadImg, posX, posY, entityWidth, entityHeight);
|
||||
}
|
||||
|
||||
|
@ -1,13 +1,15 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<?import javafx.scene.canvas.Canvas?>
|
||||
<?import javafx.scene.control.Button?>
|
||||
<?import javafx.scene.layout.AnchorPane?>
|
||||
<?import javafx.scene.text.Font?>
|
||||
|
||||
<AnchorPane maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" minHeight="500.0" minWidth="900.0" stylesheets="@StylesMissileCruiser.css" xmlns="http://javafx.com/javafx/null" xmlns:fx="http://javafx.com/fxml/1" fx:controller="kvr.missilecruiser_hard.ControllerMissileCruiser">
|
||||
<Canvas fx:id="mainCanvas" height="500.0" width="900.0" />
|
||||
<Button id="buttonCreate" layoutX="14.0" layoutY="455.0" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" minHeight="30.0" minWidth="100.0" mnemonicParsing="false" onAction="#buttonCreate_Click" text="Создать" AnchorPane.bottomAnchor="14.0" AnchorPane.leftAnchor="14.0">
|
||||
<font>
|
||||
<Font size="14.0" />
|
||||
<Font size="16.0" />
|
||||
</font>
|
||||
</Button>
|
||||
<Button id="buttonRight" layoutX="846.0" layoutY="446.0" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" minHeight="40.0" minWidth="40.0" mnemonicParsing="false" onAction="#buttonsMove_Click" AnchorPane.bottomAnchor="14.0" AnchorPane.rightAnchor="14.0" />
|
||||
|
Binary file not shown.
After Width: | Height: | Size: 1.0 KiB |
Binary file not shown.
After Width: | Height: | Size: 703 B |
Binary file not shown.
After Width: | Height: | Size: 623 B |
Binary file not shown.
After Width: | Height: | Size: 647 B |
Loading…
x
Reference in New Issue
Block a user