lab2 release
This commit is contained in:
parent
f40d570442
commit
c1652c191a
@ -1,8 +1,7 @@
|
||||
package com.example.aircraftcarrier;
|
||||
|
||||
import com.example.aircraftcarrier.Logic.Drawing.DrawingSimpleAircraftCarrier;
|
||||
import com.example.aircraftcarrier.Logic.Drawing.*;
|
||||
import com.example.aircraftcarrier.Logic.Enum.DirectionType;
|
||||
import com.example.aircraftcarrier.Logic.Drawing.DrawingAircraftCarrier;
|
||||
import com.example.aircraftcarrier.Logic.MovementStategy.*;
|
||||
import javafx.event.Event;
|
||||
import javafx.fxml.FXML;
|
||||
@ -35,6 +34,9 @@ public class AircraftCarrierController implements Initializable {
|
||||
@FXML
|
||||
private ChoiceBox<String> choiceBoxStrategy;
|
||||
private String[] strategyText = new String[]{"к центру", "к углу"};
|
||||
@FXML
|
||||
private ChoiceBox<String> choiceBoxShape;
|
||||
private String[] shapeText = new String[]{"квадрат", "треугольник", "круг"};
|
||||
|
||||
@FXML
|
||||
protected void ButtonStrategy_Click() {
|
||||
@ -107,8 +109,16 @@ public class AircraftCarrierController implements Initializable {
|
||||
|
||||
try {
|
||||
DrawingAircraftCarrier a = (DrawingAircraftCarrier) drawingAircraftCarrier;
|
||||
a.setDrawingBlock(Integer.parseInt(inputCountBlocks.getCharacters().toString()));
|
||||
} catch (NumberFormatException ignored) {}
|
||||
int countBlock = Integer.parseInt(inputCountBlocks.getCharacters().toString());
|
||||
IDrawingBlock imo = switch (choiceBoxShape.getValue()) {
|
||||
case "квадрат" -> new DrawingBlock();
|
||||
case "треугольник" -> new DrawingBlockTriangle();
|
||||
case "круг" -> new DrawingBlockCircle();
|
||||
default -> throw new Exception("нет нужной опции");
|
||||
};
|
||||
imo.setBlockCount(countBlock);
|
||||
a.setDrawingBlock(imo);
|
||||
} catch (Exception ignored) {}
|
||||
|
||||
drawingAircraftCarrier.setCanvasWidth((int) canvas.getWidth());
|
||||
drawingAircraftCarrier.setCanvasHeight((int) canvas.getHeight());
|
||||
@ -159,5 +169,6 @@ public class AircraftCarrierController implements Initializable {
|
||||
canvas.widthProperty().bind(Root.widthProperty());
|
||||
canvas.heightProperty().bind(Root.heightProperty());
|
||||
choiceBoxStrategy.getItems().addAll(strategyText);
|
||||
choiceBoxShape.getItems().addAll(shapeText);
|
||||
}
|
||||
}
|
@ -1,11 +1,12 @@
|
||||
package com.example.aircraftcarrier.Logic.Drawing;
|
||||
|
||||
import com.example.aircraftcarrier.Logic.Entity.EntityAircraftCarrier;
|
||||
import com.example.aircraftcarrier.Logic.MovementStategy.IMoveableObject;
|
||||
import javafx.scene.canvas.GraphicsContext;
|
||||
import javafx.scene.paint.Color;
|
||||
|
||||
public class DrawingAircraftCarrier extends DrawingSimpleAircraftCarrier {
|
||||
public DrawingBlock drawingBlock;
|
||||
public IDrawingBlock drawingBlock;
|
||||
public DrawingAircraftCarrier(
|
||||
int speed,
|
||||
int weight,
|
||||
@ -23,9 +24,8 @@ public class DrawingAircraftCarrier extends DrawingSimpleAircraftCarrier {
|
||||
hasСabin);
|
||||
}
|
||||
|
||||
public void setDrawingBlock(int count) {
|
||||
drawingBlock = new DrawingBlock();
|
||||
drawingBlock.setBlockCount(count);
|
||||
public void setDrawingBlock(IDrawingBlock iDrawingBlock) {
|
||||
drawingBlock = iDrawingBlock;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -37,7 +37,7 @@ public class DrawingAircraftCarrier extends DrawingSimpleAircraftCarrier {
|
||||
super.Draw(gc);
|
||||
|
||||
if (entityAircraftCarrier.isHasDeck()) {
|
||||
gc.setFill(aircraftCarrier.getPrimaryColor());
|
||||
gc.setFill(entityAircraftCarrier.getPrimaryColor());
|
||||
gc.fillRect(x + 50, y + 40, 55, 20);
|
||||
}
|
||||
if (entityAircraftCarrier.isHasСabin()) {
|
||||
|
@ -4,7 +4,7 @@ import com.example.aircraftcarrier.Logic.Enum.BlockCount;
|
||||
import javafx.scene.canvas.GraphicsContext;
|
||||
import javafx.scene.paint.Color;
|
||||
|
||||
public class DrawingBlock {
|
||||
public class DrawingBlock implements IDrawingBlock {
|
||||
private BlockCount blockCount;
|
||||
|
||||
public void setBlockCount(int blockCountValue) {
|
||||
|
@ -0,0 +1,36 @@
|
||||
package com.example.aircraftcarrier.Logic.Drawing;
|
||||
|
||||
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() {}
|
||||
public DrawingBlockCircle(int blockCountValue) {
|
||||
this.blockCount = BlockCount.GetBlockCount(blockCountValue);
|
||||
}
|
||||
|
||||
public void setBlockCount(int blockCountValue) {
|
||||
this.blockCount = BlockCount.GetBlockCount(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.Drawing;
|
||||
|
||||
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() {}
|
||||
public DrawingBlockTriangle(int blockCountValue) {
|
||||
this.blockCount = BlockCount.GetBlockCount(blockCountValue);
|
||||
}
|
||||
|
||||
public void setBlockCount(int blockCountValue) {
|
||||
this.blockCount = BlockCount.GetBlockCount(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.Drawing;
|
||||
|
||||
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);
|
||||
}
|
@ -16,5 +16,6 @@
|
||||
<TextField fx:id="inputCountBlocks" layoutX="446.0" layoutY="14.0" promptText="количество блоков" AnchorPane.rightAnchor="20.0" AnchorPane.topAnchor="20.0" />
|
||||
<ChoiceBox fx:id="choiceBoxStrategy" layoutX="430.0" layoutY="46.0" prefHeight="26.0" prefWidth="110.0" AnchorPane.rightAnchor="20.0" AnchorPane.topAnchor="50.0" />
|
||||
<Button layoutX="524.0" layoutY="83.0" mnemonicParsing="false" onAction="#ButtonStrategy_Click" text="шаг" AnchorPane.rightAnchor="20.0" AnchorPane.topAnchor="80.0" />
|
||||
<ChoiceBox fx:id="choiceBoxShape" layoutX="469.0" layoutY="116.0" prefHeight="26.0" prefWidth="110.0" AnchorPane.rightAnchor="20.599999999999994" AnchorPane.topAnchor="110.0" />
|
||||
</children>
|
||||
</AnchorPane>
|
||||
|
Loading…
x
Reference in New Issue
Block a user