Compare commits
6 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
15eade5983 | ||
|
f1e4928445 | ||
|
a95007b753 | ||
|
970a1b77b3 | ||
|
025940e303 | ||
|
0f2092b72c |
9
.idea/PIbd-22_Turner_I.A._AntiAircraftGun._Hard.iml
Normal file
9
.idea/PIbd-22_Turner_I.A._AntiAircraftGun._Hard.iml
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<module type="JAVA_MODULE" version="4">
|
||||||
|
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||||
|
<exclude-output />
|
||||||
|
<content url="file://$MODULE_DIR$" />
|
||||||
|
<orderEntry type="inheritedJdk" />
|
||||||
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
|
</component>
|
||||||
|
</module>
|
124
AntiAircraftGun/.idea/uiDesigner.xml
Normal file
124
AntiAircraftGun/.idea/uiDesigner.xml
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>
|
@ -0,0 +1,242 @@
|
|||||||
|
package com.example.antiaircraftgun;
|
||||||
|
|
||||||
|
import javafx.scene.canvas.GraphicsContext;
|
||||||
|
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
|
public abstract class AbstractMap {
|
||||||
|
private IDrawingObject _drawingObject = null;
|
||||||
|
private GraphicsContext _graphicsContext = null;
|
||||||
|
protected int[][] _map = null;
|
||||||
|
protected int _width;
|
||||||
|
protected int _height;
|
||||||
|
protected float _size_x;
|
||||||
|
protected float _size_y;
|
||||||
|
protected final Random _random = new Random();
|
||||||
|
protected final int _freeRoad = 0;
|
||||||
|
protected final int _barrier = 1;
|
||||||
|
|
||||||
|
public void CreateMap(int width, int height, IDrawingObject drawingObject, GraphicsContext gc)
|
||||||
|
{
|
||||||
|
_width = width;
|
||||||
|
_height = height;
|
||||||
|
_drawingObject = drawingObject;
|
||||||
|
_graphicsContext = gc;
|
||||||
|
GenerateMap();
|
||||||
|
while (!SetObjectOnMap())
|
||||||
|
{
|
||||||
|
GenerateMap();
|
||||||
|
}
|
||||||
|
DrawMapWithObject();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void MoveObject(Direction direction)
|
||||||
|
{
|
||||||
|
boolean roadIsClear = true;
|
||||||
|
|
||||||
|
float[] position = _drawingObject.GetCurrentPosition();
|
||||||
|
int xNumOfCells;
|
||||||
|
int yNumOfCells;
|
||||||
|
int xObjOffset;
|
||||||
|
int yObjOffset;
|
||||||
|
|
||||||
|
switch (direction)
|
||||||
|
{
|
||||||
|
case Up:
|
||||||
|
xNumOfCells = (int)Math.ceil((position[2] - position[0]) / _size_x);
|
||||||
|
yNumOfCells = (int)Math.ceil(_drawingObject.GetStep() / _size_y);
|
||||||
|
xObjOffset = (int)(position[0] / _size_x);
|
||||||
|
yObjOffset = (int)Math.floor(position[1] / _size_y);
|
||||||
|
|
||||||
|
for (int i = 0; i < yNumOfCells; i++)
|
||||||
|
{
|
||||||
|
if (!roadIsClear)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
for (int j = 0; j < xNumOfCells; j++)
|
||||||
|
{
|
||||||
|
if (yObjOffset - i < 0 || xObjOffset + j >= _map[0].length)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (_map[xObjOffset + j][yObjOffset - i] == _barrier)
|
||||||
|
{
|
||||||
|
roadIsClear = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case Down:
|
||||||
|
xNumOfCells = (int)Math.ceil((position[2] - position[0]) / _size_x);
|
||||||
|
yNumOfCells = (int)Math.ceil(_drawingObject.GetStep() / _size_y);
|
||||||
|
xObjOffset = (int)(position[0] / _size_x);
|
||||||
|
yObjOffset = (int)Math.ceil(position[3]/ _size_y);
|
||||||
|
|
||||||
|
for (int i = 0; i < yNumOfCells; i++)
|
||||||
|
{
|
||||||
|
if (!roadIsClear)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
for (int j = 0; j < xNumOfCells; j++)
|
||||||
|
{
|
||||||
|
if (yObjOffset + i >= _map.length || xObjOffset + j >= _map[0].length)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (_map[xObjOffset + j][yObjOffset + i] == _barrier)
|
||||||
|
{
|
||||||
|
roadIsClear = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case Left:
|
||||||
|
xNumOfCells = (int)Math.ceil(_drawingObject.GetStep() / _size_x);
|
||||||
|
yNumOfCells = (int)Math.ceil((position[3] - position[1]) / _size_y);
|
||||||
|
xObjOffset = (int)Math.floor(position[0] / _size_x);
|
||||||
|
yObjOffset = (int)(position[1] / _size_y);
|
||||||
|
|
||||||
|
for (int i = 0; i < yNumOfCells; i++)
|
||||||
|
{
|
||||||
|
if (!roadIsClear)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
for (int j = 0; j < xNumOfCells; j++)
|
||||||
|
{
|
||||||
|
if (yObjOffset + i >= _map.length || xObjOffset - j < 0)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (_map[xObjOffset - j][yObjOffset + i] == _barrier)
|
||||||
|
{
|
||||||
|
roadIsClear = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case Right:
|
||||||
|
xNumOfCells = (int)Math.ceil(_drawingObject.GetStep() / _size_x);
|
||||||
|
yNumOfCells = (int)Math.ceil((position[3] - position[1]) / _size_y);
|
||||||
|
xObjOffset = (int)(position[2] / _size_x);
|
||||||
|
yObjOffset = (int)Math.ceil(position[1] / _size_y);
|
||||||
|
|
||||||
|
for (int i = 0; i < yNumOfCells; i++)
|
||||||
|
{
|
||||||
|
if (!roadIsClear)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
for (int j = 0; j < xNumOfCells; j++)
|
||||||
|
{
|
||||||
|
if (yObjOffset + i >= _map.length || xObjOffset + j >= _map[0].length)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (_map[xObjOffset + j][yObjOffset + i] == _barrier)
|
||||||
|
{
|
||||||
|
roadIsClear = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (roadIsClear)
|
||||||
|
{
|
||||||
|
_drawingObject.MoveObject(direction);
|
||||||
|
}
|
||||||
|
DrawMapWithObject();
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean SetObjectOnMap()
|
||||||
|
{
|
||||||
|
if (_drawingObject == null || _map == null)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
int x = _random.nextInt(0, 10);
|
||||||
|
int y = _random.nextInt(0, 10);
|
||||||
|
|
||||||
|
float[] position = _drawingObject.GetCurrentPosition();
|
||||||
|
int xNumOfCells = (int)Math.ceil(position[2] / _size_x) - (int)Math.floor(position[0] / _size_x);
|
||||||
|
int yNumOfCells = (int)Math.ceil(position[3] / _size_y) - (int)Math.floor(position[1] / _size_y);
|
||||||
|
int xObjOffset = (int)(x / _size_x);
|
||||||
|
int yObjOffset = (int)(y / _size_y);
|
||||||
|
|
||||||
|
while (y < _height - (position[3] - position[1]))
|
||||||
|
{
|
||||||
|
while (x < _width - (position[2] - position[0]))
|
||||||
|
{
|
||||||
|
if (AreaIsFree(xNumOfCells, yNumOfCells, xObjOffset, yObjOffset))
|
||||||
|
{
|
||||||
|
_drawingObject.SetObject(x, y, _width, _height);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
x += (int)_size_x;
|
||||||
|
xObjOffset = (int)(x / _size_x);
|
||||||
|
}
|
||||||
|
x = 0;
|
||||||
|
y += (int)_size_y;
|
||||||
|
yObjOffset = (int)(y / _size_y);
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean AreaIsFree(int xNumOfCells, int yNumOfCells, int xObjOffset, int yObjOffset)
|
||||||
|
{
|
||||||
|
for (int i = 0; i <= yNumOfCells; i++)
|
||||||
|
{
|
||||||
|
for (int j = 0; j <= xNumOfCells; j++)
|
||||||
|
{
|
||||||
|
if (yObjOffset + i >= _map.length || xObjOffset + j >= _map[0].length)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (_map[xObjOffset + j][yObjOffset + i] == _barrier)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void DrawMapWithObject()
|
||||||
|
{
|
||||||
|
if (_drawingObject == null || _map == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < _map.length; ++i)
|
||||||
|
{
|
||||||
|
for (int j = 0; j < _map[0].length; ++j)
|
||||||
|
{
|
||||||
|
if (_map[i][j] == _freeRoad)
|
||||||
|
{
|
||||||
|
DrawRoadPart(_graphicsContext, i, j);
|
||||||
|
}
|
||||||
|
else if (_map[i][j] == _barrier)
|
||||||
|
{
|
||||||
|
DrawBarrierPart(_graphicsContext, i, j);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_drawingObject.DrawingObject(_graphicsContext);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected abstract void GenerateMap();
|
||||||
|
protected abstract void DrawRoadPart(GraphicsContext gc, int i, int j);
|
||||||
|
protected abstract void DrawBarrierPart(GraphicsContext gc, int i, int j);
|
||||||
|
}
|
@ -0,0 +1,242 @@
|
|||||||
|
package com.example.antiaircraftgun;
|
||||||
|
|
||||||
|
import javafx.event.ActionEvent;
|
||||||
|
import javafx.fxml.FXML;
|
||||||
|
import javafx.scene.canvas.Canvas;
|
||||||
|
import javafx.scene.canvas.GraphicsContext;
|
||||||
|
import javafx.scene.control.Button;
|
||||||
|
import javafx.scene.control.ColorPicker;
|
||||||
|
import javafx.scene.control.ComboBox;
|
||||||
|
import javafx.scene.control.Label;
|
||||||
|
import javafx.scene.layout.FlowPane;
|
||||||
|
import javafx.scene.layout.Pane;
|
||||||
|
import javafx.scene.paint.Color;
|
||||||
|
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
|
public class ControllerArmoredCar {
|
||||||
|
@FXML
|
||||||
|
private Pane root;
|
||||||
|
@FXML
|
||||||
|
private Canvas canvas;
|
||||||
|
@FXML
|
||||||
|
private FlowPane flowPane;
|
||||||
|
@FXML
|
||||||
|
private Label labelSpeedValue;
|
||||||
|
@FXML
|
||||||
|
private Label labelWeightValue;
|
||||||
|
@FXML
|
||||||
|
private ComboBox<String> comboBoxNumOfRollers;
|
||||||
|
@FXML
|
||||||
|
private ComboBox<String> comboBoxOrnamentType;
|
||||||
|
@FXML
|
||||||
|
private Button buttonCreate;
|
||||||
|
@FXML
|
||||||
|
private Button buttonCreateModif;
|
||||||
|
@FXML
|
||||||
|
private Button buttonLeft;
|
||||||
|
@FXML
|
||||||
|
private Button buttonRight;
|
||||||
|
@FXML
|
||||||
|
private Button buttonUp;
|
||||||
|
@FXML
|
||||||
|
private Button buttonDown;
|
||||||
|
@FXML
|
||||||
|
private Button buttonSelectArmoredCar;
|
||||||
|
@FXML
|
||||||
|
private ColorPicker bodyColorPicker;
|
||||||
|
@FXML
|
||||||
|
private ColorPicker dopColorPicker;
|
||||||
|
private final double rootPadding = 10.0;
|
||||||
|
private DrawingArmoredCar _armoredCar;
|
||||||
|
private boolean bodyColorPickerChanged = false;
|
||||||
|
private boolean dopColorPickerChanged = false;
|
||||||
|
|
||||||
|
public DrawingArmoredCar GetSelectedArmoredCar()
|
||||||
|
{
|
||||||
|
return _armoredCar;
|
||||||
|
}
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
public void initialize()
|
||||||
|
{
|
||||||
|
buttonCreate.setTranslateX(rootPadding);
|
||||||
|
|
||||||
|
root.widthProperty().addListener((obs, oldVal, newVal) ->
|
||||||
|
{
|
||||||
|
UpdateGUI();
|
||||||
|
if (_armoredCar != null)
|
||||||
|
{
|
||||||
|
_armoredCar.ChangeBorders((int) canvas.getWidth(), (int) canvas.getHeight());
|
||||||
|
}
|
||||||
|
Draw();
|
||||||
|
});
|
||||||
|
root.heightProperty().addListener((obs, oldVal, newVal) ->
|
||||||
|
{
|
||||||
|
UpdateGUI();
|
||||||
|
if (_armoredCar != null)
|
||||||
|
{
|
||||||
|
_armoredCar.ChangeBorders((int) canvas.getWidth(), (int) canvas.getHeight());
|
||||||
|
}
|
||||||
|
Draw();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
void ButtonCreate_Click()
|
||||||
|
{
|
||||||
|
Random rnd = new Random();
|
||||||
|
if (!bodyColorPickerChanged)
|
||||||
|
{
|
||||||
|
bodyColorPicker.setValue(Color.rgb(rnd.nextInt(256), rnd.nextInt(256), rnd.nextInt(256)));
|
||||||
|
}
|
||||||
|
_armoredCar = new DrawingArmoredCar(rnd.nextInt(200) + 100, rnd.nextInt(1000) + 1000,
|
||||||
|
bodyColorPicker.getValue());
|
||||||
|
SetData();
|
||||||
|
Draw();
|
||||||
|
}
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
void ButtonCreateModif_Click()
|
||||||
|
{
|
||||||
|
Random rnd = new Random();
|
||||||
|
if (!bodyColorPickerChanged)
|
||||||
|
{
|
||||||
|
bodyColorPicker.setValue(Color.rgb(rnd.nextInt(256), rnd.nextInt(256), rnd.nextInt(256)));
|
||||||
|
}
|
||||||
|
if (!dopColorPickerChanged)
|
||||||
|
{
|
||||||
|
dopColorPicker.setValue(Color.rgb(rnd.nextInt(256), rnd.nextInt(256), rnd.nextInt(256)));
|
||||||
|
}
|
||||||
|
_armoredCar = new DrawingAntiAircraftGun(rnd.nextInt(200) + 100, rnd.nextInt(1000) + 1000,
|
||||||
|
bodyColorPicker.getValue(), dopColorPicker.getValue(), (rnd.nextInt(2) != 0), (rnd.nextInt(2) != 0));
|
||||||
|
SetData();
|
||||||
|
Draw();
|
||||||
|
}
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
void ButtonMove_Click(ActionEvent event)
|
||||||
|
{
|
||||||
|
if (_armoredCar == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
String buttonName = ((Button)event.getSource()).getId();
|
||||||
|
switch (buttonName)
|
||||||
|
{
|
||||||
|
case "buttonUp" -> _armoredCar.MoveTransport(Direction.Up);
|
||||||
|
case "buttonDown" -> _armoredCar.MoveTransport(Direction.Down);
|
||||||
|
case "buttonLeft" -> _armoredCar.MoveTransport(Direction.Left);
|
||||||
|
case "buttonRight" -> _armoredCar.MoveTransport(Direction.Right);
|
||||||
|
}
|
||||||
|
Draw();
|
||||||
|
}
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
private void ComboBoxOrnamentType_Changed()
|
||||||
|
{
|
||||||
|
if (_armoredCar != null)
|
||||||
|
{
|
||||||
|
ChangeDrawingRollers();
|
||||||
|
Draw();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
private void ComboBoxNumOfRollers_Changed()
|
||||||
|
{
|
||||||
|
if (_armoredCar != null)
|
||||||
|
{
|
||||||
|
_armoredCar.GetDrawingRollers().SetNumberRollers(Integer.parseInt(comboBoxNumOfRollers.getValue()));
|
||||||
|
Draw();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@FXML
|
||||||
|
private void BodyColorPicker_Changed()
|
||||||
|
{
|
||||||
|
bodyColorPickerChanged = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
private void DopColorPicker_Changed()
|
||||||
|
{
|
||||||
|
dopColorPickerChanged = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ChangeDrawingRollers()
|
||||||
|
{
|
||||||
|
if (_armoredCar != null)
|
||||||
|
{
|
||||||
|
IDrawingAdditionalElement newDrawingRollers = switch (comboBoxOrnamentType.getValue())
|
||||||
|
{
|
||||||
|
case "None" -> new DrawingRollers(_armoredCar.GetArmoredCar().GetBodyColor());
|
||||||
|
case "Rectangle" -> new DrawingRectangleOrnamentRollers(_armoredCar.GetArmoredCar().GetBodyColor());
|
||||||
|
case "Oval" ->
|
||||||
|
new DrawingOvalOrnamentRollers(_armoredCar.GetArmoredCar().GetBodyColor());
|
||||||
|
default -> null;
|
||||||
|
};
|
||||||
|
if (newDrawingRollers != null)
|
||||||
|
{
|
||||||
|
_armoredCar.SetDrawingRollers(newDrawingRollers);
|
||||||
|
_armoredCar.GetDrawingRollers().SetNumberRollers(Integer.parseInt(comboBoxNumOfRollers.getValue()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void UpdateGUI()
|
||||||
|
{
|
||||||
|
double rootWidth = root.getWidth();
|
||||||
|
double rootHeight = root.getHeight();
|
||||||
|
|
||||||
|
double flowPaneHeight = flowPane.getHeight();
|
||||||
|
double buttonCreateHeight = buttonCreate.getHeight();
|
||||||
|
|
||||||
|
canvas.setWidth(rootWidth);
|
||||||
|
flowPane.setPrefWidth(rootWidth);
|
||||||
|
canvas.setHeight(rootHeight - flowPaneHeight);
|
||||||
|
flowPane.setTranslateY(rootHeight - flowPaneHeight);
|
||||||
|
|
||||||
|
buttonCreate.setTranslateY(rootHeight - flowPaneHeight - buttonCreateHeight - rootPadding);
|
||||||
|
buttonCreateModif.setTranslateY(rootHeight - flowPaneHeight - buttonCreateHeight - rootPadding);
|
||||||
|
|
||||||
|
int buttonMoveSize = 30;
|
||||||
|
int distanceBetweenButtons = 5;
|
||||||
|
buttonUp.setTranslateY(rootHeight - flowPaneHeight - buttonMoveSize * 2.0 - rootPadding -
|
||||||
|
distanceBetweenButtons);
|
||||||
|
buttonUp.setTranslateX(rootWidth - rootPadding - buttonMoveSize * 2.0 - distanceBetweenButtons);
|
||||||
|
|
||||||
|
buttonDown.setTranslateY(rootHeight - flowPaneHeight - buttonMoveSize - rootPadding);
|
||||||
|
buttonDown.setTranslateX(rootWidth- rootPadding - buttonMoveSize * 2.0 - distanceBetweenButtons);
|
||||||
|
|
||||||
|
buttonLeft.setTranslateY(rootHeight - flowPaneHeight - buttonMoveSize - rootPadding);
|
||||||
|
buttonLeft.setTranslateX(rootWidth - rootPadding - buttonMoveSize * 3.0 -
|
||||||
|
distanceBetweenButtons * 2.0);
|
||||||
|
|
||||||
|
buttonRight.setTranslateY(rootHeight - flowPaneHeight - buttonMoveSize - rootPadding);
|
||||||
|
buttonRight.setTranslateX(rootWidth - rootPadding - buttonMoveSize);
|
||||||
|
|
||||||
|
buttonSelectArmoredCar.setTranslateY(rootHeight - flowPaneHeight - buttonCreateHeight - rootPadding);
|
||||||
|
buttonSelectArmoredCar.setTranslateX(rootWidth - rootPadding - buttonMoveSize * 3.0 -
|
||||||
|
distanceBetweenButtons * 3.0 - buttonSelectArmoredCar.getWidth());
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Draw()
|
||||||
|
{
|
||||||
|
GraphicsContext gc = canvas.getGraphicsContext2D();
|
||||||
|
gc.clearRect(0.0, 0.0, canvas.getWidth(), canvas.getHeight());
|
||||||
|
|
||||||
|
if (_armoredCar != null)
|
||||||
|
{
|
||||||
|
_armoredCar.DrawTransport(gc);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void SetData()
|
||||||
|
{
|
||||||
|
ChangeDrawingRollers();
|
||||||
|
Random rnd = new Random();
|
||||||
|
_armoredCar.SetPosition(rnd.nextInt(90) + 10, rnd.nextInt(90) + 5, (int) canvas.getWidth(), (int) canvas.getHeight());
|
||||||
|
labelSpeedValue.setText(Integer.toString(_armoredCar.GetArmoredCar().GetSpeed()));
|
||||||
|
labelWeightValue.setText(Double.toString(_armoredCar.GetArmoredCar().GetWeight()));
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,280 @@
|
|||||||
|
package com.example.antiaircraftgun;
|
||||||
|
|
||||||
|
import javafx.event.ActionEvent;
|
||||||
|
import javafx.fxml.FXML;
|
||||||
|
import javafx.fxml.FXMLLoader;
|
||||||
|
import javafx.scene.Scene;
|
||||||
|
import javafx.scene.canvas.Canvas;
|
||||||
|
import javafx.scene.control.*;
|
||||||
|
import javafx.scene.layout.FlowPane;
|
||||||
|
import javafx.scene.layout.Pane;
|
||||||
|
import javafx.stage.Stage;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
public class ControllerMapWithSetArmoredCars
|
||||||
|
{
|
||||||
|
@FXML
|
||||||
|
private Pane root;
|
||||||
|
@FXML
|
||||||
|
private Canvas canvas;
|
||||||
|
@FXML
|
||||||
|
private Pane paneRight;
|
||||||
|
@FXML
|
||||||
|
private Label labelTools;
|
||||||
|
@FXML
|
||||||
|
private ComboBox<String> comboBoxSelectorMap;
|
||||||
|
@FXML
|
||||||
|
private Button buttonAddArmoredVehicle;
|
||||||
|
@FXML
|
||||||
|
private TextField textFieldPosition;
|
||||||
|
@FXML
|
||||||
|
private Button buttonLeft;
|
||||||
|
@FXML
|
||||||
|
private Button buttonRight;
|
||||||
|
@FXML
|
||||||
|
private Button buttonUp;
|
||||||
|
@FXML
|
||||||
|
private Button buttonDown;
|
||||||
|
private MapWithSetArmoredCarsGeneric<DrawingObjectArmoredCar, AbstractMap> _mapArmoredCarsCollectionGeneric;
|
||||||
|
@FXML
|
||||||
|
public void initialize()
|
||||||
|
{
|
||||||
|
textFieldPosition.textProperty().addListener((ov, oldValue, newValue) ->
|
||||||
|
{
|
||||||
|
if (Objects.equals(newValue, ""))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (newValue.length() > 2) {
|
||||||
|
String s = newValue.substring(0, 2);
|
||||||
|
textFieldPosition.setText(s);
|
||||||
|
}
|
||||||
|
if (!newValue.matches("[0-9]+"))
|
||||||
|
{
|
||||||
|
textFieldPosition.setText(oldValue);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
root.widthProperty().addListener((obs, oldVal, newVal) ->
|
||||||
|
{
|
||||||
|
UpdateGUI();
|
||||||
|
});
|
||||||
|
|
||||||
|
root.heightProperty().addListener((obs, oldVal, newVal) ->
|
||||||
|
{
|
||||||
|
UpdateGUI();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
@FXML
|
||||||
|
private void ComboBoxSelectorMap_Changed()
|
||||||
|
{
|
||||||
|
AbstractMap map = switch (comboBoxSelectorMap.getValue())
|
||||||
|
{
|
||||||
|
case "Simple map" -> new SimpleMap();
|
||||||
|
case "Training ground map" -> new TrainingGroundMap();
|
||||||
|
case "Desert map" -> new DesertMap();
|
||||||
|
default -> null;
|
||||||
|
};
|
||||||
|
if (map != null)
|
||||||
|
{
|
||||||
|
_mapArmoredCarsCollectionGeneric = new MapWithSetArmoredCarsGeneric<DrawingObjectArmoredCar, AbstractMap>(
|
||||||
|
(int)canvas.getWidth(), (int)canvas.getHeight(), map, DrawingObjectArmoredCar.class, canvas.getGraphicsContext2D());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_mapArmoredCarsCollectionGeneric = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@FXML
|
||||||
|
public void ButtonAddArmoredCar_Click() throws IOException
|
||||||
|
{
|
||||||
|
if (_mapArmoredCarsCollectionGeneric == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Stage stageArmoredCar = new Stage();
|
||||||
|
FXMLLoader fxmlLoader = new FXMLLoader(FormArmoredCar.class.getResource("form-armored-vehicle-view.fxml"));
|
||||||
|
Scene sceneArmoredCar = new Scene(fxmlLoader.load(), 600, 400);
|
||||||
|
|
||||||
|
FirstUpdateArmoredCarGUI(sceneArmoredCar, stageArmoredCar, fxmlLoader);
|
||||||
|
|
||||||
|
stageArmoredCar.setTitle("Armored car");
|
||||||
|
stageArmoredCar.setScene(sceneArmoredCar);
|
||||||
|
stageArmoredCar.show();
|
||||||
|
}
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
private void ButtonRemoveArmoredCar_Click()
|
||||||
|
{
|
||||||
|
String stringPosition = textFieldPosition.getText();
|
||||||
|
if (stringPosition == null || stringPosition.length() == 0)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Alert removeAlert = new Alert(Alert.AlertType.CONFIRMATION, "Remove object?", ButtonType.YES, ButtonType.NO);
|
||||||
|
removeAlert.showAndWait();
|
||||||
|
|
||||||
|
Alert infoAlert;
|
||||||
|
if (removeAlert.getResult() == ButtonType.YES)
|
||||||
|
{
|
||||||
|
int pos = Integer.parseInt(stringPosition);
|
||||||
|
if (_mapArmoredCarsCollectionGeneric.Delete(pos) != null)
|
||||||
|
{
|
||||||
|
infoAlert = new Alert(Alert.AlertType.INFORMATION, "Object removed", ButtonType.OK);
|
||||||
|
_mapArmoredCarsCollectionGeneric.ShowSet();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
infoAlert = new Alert(Alert.AlertType.INFORMATION, "Failed to remove object", ButtonType.OK);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
infoAlert = new Alert(Alert.AlertType.INFORMATION, "Remove operation canceled", ButtonType.OK);
|
||||||
|
}
|
||||||
|
infoAlert.showAndWait();
|
||||||
|
}
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
private void ButtonShowStorage_Click()
|
||||||
|
{
|
||||||
|
if (_mapArmoredCarsCollectionGeneric == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_mapArmoredCarsCollectionGeneric.ShowSet();
|
||||||
|
}
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
private void ButtonShowOnMap_Click()
|
||||||
|
{
|
||||||
|
if (_mapArmoredCarsCollectionGeneric == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_mapArmoredCarsCollectionGeneric.ShowOnMap();
|
||||||
|
}
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
private void ButtonMove_Click(ActionEvent event)
|
||||||
|
{
|
||||||
|
if (_mapArmoredCarsCollectionGeneric == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
String buttonName = ((Button)event.getSource()).getId();
|
||||||
|
Direction dir = switch (buttonName)
|
||||||
|
{
|
||||||
|
case "buttonUp" -> Direction.Up;
|
||||||
|
case "buttonDown" -> Direction.Down;
|
||||||
|
case "buttonLeft" -> Direction.Left;
|
||||||
|
case "buttonRight" -> Direction.Right;
|
||||||
|
default -> Direction.None;
|
||||||
|
};
|
||||||
|
_mapArmoredCarsCollectionGeneric.MoveObject(dir);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void UpdateGUI()
|
||||||
|
{
|
||||||
|
double rootWidth = root.getWidth();
|
||||||
|
double rootHeight = root.getHeight();
|
||||||
|
double rightPaneWidth = paneRight.getWidth();
|
||||||
|
|
||||||
|
canvas.setWidth(rootWidth - rightPaneWidth);
|
||||||
|
canvas.setHeight(rootHeight);
|
||||||
|
|
||||||
|
paneRight.setTranslateX(rootWidth - rightPaneWidth);
|
||||||
|
paneRight.setPrefHeight(rootHeight);
|
||||||
|
|
||||||
|
int _distanceBetweenMoveButtons = 5;
|
||||||
|
double moveButtonsSize = 30.0;
|
||||||
|
double moveButtonsXMargin = (rightPaneWidth - moveButtonsSize * 3.0 - _distanceBetweenMoveButtons * 2.0) / 2.0;
|
||||||
|
|
||||||
|
int rightPaneMargin = 5;
|
||||||
|
buttonUp.setTranslateY(rootHeight - moveButtonsSize * 2.0 - _distanceBetweenMoveButtons - rightPaneMargin);
|
||||||
|
buttonUp.setTranslateX(rootWidth - moveButtonsSize * 2.0 - moveButtonsXMargin - _distanceBetweenMoveButtons);
|
||||||
|
|
||||||
|
buttonDown.setTranslateY(rootHeight - moveButtonsSize - rightPaneMargin);
|
||||||
|
buttonDown.setTranslateX(rootWidth - moveButtonsSize * 2.0 - moveButtonsXMargin - _distanceBetweenMoveButtons);
|
||||||
|
|
||||||
|
buttonLeft.setTranslateY(rootHeight - moveButtonsSize - rightPaneMargin);
|
||||||
|
buttonLeft.setTranslateX(rootWidth - moveButtonsSize * 3.0 - moveButtonsXMargin - _distanceBetweenMoveButtons * 2.0);
|
||||||
|
|
||||||
|
buttonRight.setTranslateY(rootHeight - moveButtonsSize - rightPaneMargin);
|
||||||
|
buttonRight.setTranslateX(rootWidth - moveButtonsSize - moveButtonsXMargin);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void FirstUpdateArmoredCarGUI(Scene scene, Stage stageArmoredCar, FXMLLoader fxmlLoader)
|
||||||
|
{
|
||||||
|
Pane root = (Pane)scene.lookup("#root");
|
||||||
|
Canvas canvas = (Canvas)scene.lookup("#canvas");
|
||||||
|
Button buttonCreate = (Button)scene.lookup("#buttonCreate");
|
||||||
|
Button buttonCreateModif = (Button)scene.lookup("#buttonCreateModif");
|
||||||
|
Button buttonUp = (Button)scene.lookup("#buttonUp");
|
||||||
|
Button buttonLeft = (Button)scene.lookup("#buttonLeft");
|
||||||
|
Button buttonRight = (Button)scene.lookup("#buttonRight");
|
||||||
|
Button buttonDown = (Button)scene.lookup("#buttonDown");
|
||||||
|
Button buttonSelectArmoredCar = (Button)scene.lookup("#buttonSelectArmoredCar");
|
||||||
|
FlowPane flowPane = (FlowPane)scene.lookup("#flowPane");
|
||||||
|
|
||||||
|
root.applyCss();
|
||||||
|
root.layout();
|
||||||
|
|
||||||
|
double flowPaneHeight = flowPane.getHeight();
|
||||||
|
double buttonCreateHeight = buttonCreate.getHeight();
|
||||||
|
double buttonCreateWidth = buttonCreate.getWidth();
|
||||||
|
double rootWidth = root.getWidth();
|
||||||
|
double rootHeight = root.getHeight();
|
||||||
|
double rootPadding = 10.0;
|
||||||
|
double distanceBetweenButtons = 5.0;
|
||||||
|
double buttonMoveSize = 30.0;
|
||||||
|
|
||||||
|
canvas.setWidth(rootWidth);
|
||||||
|
flowPane.setPrefWidth(rootWidth);
|
||||||
|
canvas.setHeight(rootHeight - flowPaneHeight);
|
||||||
|
flowPane.setTranslateY(rootHeight - flowPaneHeight);
|
||||||
|
buttonCreateModif.setTranslateX(rootPadding + buttonCreateWidth + distanceBetweenButtons);
|
||||||
|
buttonCreate.setTranslateY(rootHeight - flowPaneHeight - buttonCreateHeight - rootPadding);
|
||||||
|
buttonCreateModif.setTranslateY(rootHeight - flowPaneHeight - buttonCreateHeight - rootPadding);
|
||||||
|
|
||||||
|
buttonUp.setTranslateY(rootHeight - flowPaneHeight - buttonMoveSize * 2.0 - rootPadding -
|
||||||
|
distanceBetweenButtons);
|
||||||
|
buttonUp.setTranslateX(rootWidth - rootPadding - buttonMoveSize * 2.0 - distanceBetweenButtons);
|
||||||
|
|
||||||
|
buttonDown.setTranslateY(rootHeight - flowPaneHeight - buttonMoveSize - rootPadding);
|
||||||
|
buttonDown.setTranslateX(rootWidth- rootPadding - buttonMoveSize * 2.0 - distanceBetweenButtons);
|
||||||
|
|
||||||
|
buttonLeft.setTranslateY(rootHeight - flowPaneHeight - buttonMoveSize - rootPadding);
|
||||||
|
buttonLeft.setTranslateX(rootWidth - rootPadding - buttonMoveSize * 3.0 - distanceBetweenButtons * 2.0);
|
||||||
|
|
||||||
|
buttonRight.setTranslateY(rootHeight - flowPaneHeight - buttonMoveSize - rootPadding);
|
||||||
|
buttonRight.setTranslateX(rootWidth - rootPadding - buttonMoveSize);
|
||||||
|
|
||||||
|
buttonSelectArmoredCar.setTranslateY(rootHeight - flowPaneHeight - buttonCreateHeight - rootPadding);
|
||||||
|
buttonSelectArmoredCar.setTranslateX(rootWidth - rootPadding - buttonMoveSize * 3.0 -
|
||||||
|
distanceBetweenButtons * 3.0 - buttonSelectArmoredCar.getWidth());
|
||||||
|
|
||||||
|
buttonSelectArmoredCar.setOnAction(e ->
|
||||||
|
{
|
||||||
|
stageArmoredCar.close();
|
||||||
|
ControllerArmoredCar controllerArmoredCar = fxmlLoader.getController();
|
||||||
|
DrawingObjectArmoredCar armoredCar = new DrawingObjectArmoredCar(controllerArmoredCar.GetSelectedArmoredCar());
|
||||||
|
|
||||||
|
Alert alert;
|
||||||
|
if (_mapArmoredCarsCollectionGeneric.Add(armoredCar) != -1)
|
||||||
|
{
|
||||||
|
alert = new Alert(Alert.AlertType.INFORMATION, "Object added", ButtonType.OK);
|
||||||
|
_mapArmoredCarsCollectionGeneric.ShowSet();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
alert = new Alert(Alert.AlertType.ERROR, "Failed to add object", ButtonType.OK);
|
||||||
|
}
|
||||||
|
alert.showAndWait();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,181 @@
|
|||||||
|
package com.example.antiaircraftgun;
|
||||||
|
|
||||||
|
import javafx.event.ActionEvent;
|
||||||
|
import javafx.fxml.FXML;
|
||||||
|
import javafx.scene.canvas.Canvas;
|
||||||
|
import javafx.scene.canvas.GraphicsContext;
|
||||||
|
import javafx.scene.control.Button;
|
||||||
|
import javafx.scene.control.Label;
|
||||||
|
import javafx.scene.layout.FlowPane;
|
||||||
|
import javafx.scene.layout.Pane;
|
||||||
|
import javafx.scene.paint.Color;
|
||||||
|
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
|
public class ControllerSetMixedArmoredCars
|
||||||
|
{
|
||||||
|
@FXML
|
||||||
|
private Pane root;
|
||||||
|
@FXML
|
||||||
|
private Canvas canvas;
|
||||||
|
@FXML
|
||||||
|
private FlowPane flowPane;
|
||||||
|
@FXML
|
||||||
|
private Label labelSpeedValue;
|
||||||
|
@FXML
|
||||||
|
private Label labelWeightValue;
|
||||||
|
@FXML
|
||||||
|
private Label labelBodyColorValue;
|
||||||
|
@FXML
|
||||||
|
private Button buttonCreate;
|
||||||
|
@FXML
|
||||||
|
private Button buttonLeft;
|
||||||
|
@FXML
|
||||||
|
private Button buttonRight;
|
||||||
|
@FXML
|
||||||
|
private Button buttonUp;
|
||||||
|
@FXML
|
||||||
|
private Button buttonDown;
|
||||||
|
private final double rootPadding = 10.0;
|
||||||
|
private DrawingArmoredCar _armoredCar;
|
||||||
|
private SetMixedArmoredCarsGeneric<EntityArmoredCar, IDrawingAdditionalElement> _setMixedArmoredCars;
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
public void initialize()
|
||||||
|
{
|
||||||
|
_setMixedArmoredCars = new SetMixedArmoredCarsGeneric<>(10, EntityArmoredCar.class, IDrawingAdditionalElement.class);
|
||||||
|
|
||||||
|
for (int i = 0; i < 10; i++)
|
||||||
|
{
|
||||||
|
_setMixedArmoredCars.AddArmoredCar(CreateRandomArmoredCar());
|
||||||
|
_setMixedArmoredCars.AddAdditionalElement(CreateRandomAdditionalElement());
|
||||||
|
}
|
||||||
|
|
||||||
|
buttonCreate.setTranslateX(rootPadding);
|
||||||
|
|
||||||
|
root.widthProperty().addListener((obs, oldVal, newVal) ->
|
||||||
|
{
|
||||||
|
UpdateGUI();
|
||||||
|
if (_armoredCar != null)
|
||||||
|
{
|
||||||
|
_armoredCar.ChangeBorders((int) canvas.getWidth(), (int) canvas.getHeight());
|
||||||
|
}
|
||||||
|
Draw();
|
||||||
|
});
|
||||||
|
root.heightProperty().addListener((obs, oldVal, newVal) ->
|
||||||
|
{
|
||||||
|
UpdateGUI();
|
||||||
|
if (_armoredCar != null)
|
||||||
|
{
|
||||||
|
_armoredCar.ChangeBorders((int) canvas.getWidth(), (int) canvas.getHeight());
|
||||||
|
}
|
||||||
|
Draw();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public EntityArmoredCar CreateRandomArmoredCar()
|
||||||
|
{
|
||||||
|
Random rnd = new Random();
|
||||||
|
return new EntityArmoredCar(rnd.nextInt(200) + 100, rnd.nextInt(1000) + 1000,
|
||||||
|
Color.rgb(rnd.nextInt(256), rnd.nextInt(256), rnd.nextInt(256)));
|
||||||
|
}
|
||||||
|
|
||||||
|
public IDrawingAdditionalElement CreateRandomAdditionalElement()
|
||||||
|
{
|
||||||
|
Random rnd = new Random();
|
||||||
|
int trackRollersType = rnd.nextInt(0, 3);
|
||||||
|
int numOfTrackRollers = rnd.nextInt(4, 7);
|
||||||
|
IDrawingAdditionalElement additionalElement;
|
||||||
|
switch (trackRollersType)
|
||||||
|
{
|
||||||
|
case 1 ->
|
||||||
|
additionalElement = new DrawingOvalOrnamentRollers(Color.rgb(rnd.nextInt(256), rnd.nextInt(256), rnd.nextInt(256)));
|
||||||
|
case 2 ->
|
||||||
|
additionalElement = new DrawingRectangleOrnamentRollers(Color.rgb(rnd.nextInt(256), rnd.nextInt(256), rnd.nextInt(256)));
|
||||||
|
default ->
|
||||||
|
additionalElement = new DrawingRollers(Color.rgb(rnd.nextInt(256), rnd.nextInt(256), rnd.nextInt(256)));
|
||||||
|
}
|
||||||
|
additionalElement.SetNumberRollers(numOfTrackRollers);
|
||||||
|
|
||||||
|
return additionalElement;
|
||||||
|
}
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
void ButtonCreate_Click()
|
||||||
|
{
|
||||||
|
_armoredCar = _setMixedArmoredCars.GetRandomArmoredCar();
|
||||||
|
SetData();
|
||||||
|
Draw();
|
||||||
|
}
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
void ButtonMove_Click(ActionEvent event)
|
||||||
|
{
|
||||||
|
if (_armoredCar == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
String buttonName = ((Button)event.getSource()).getId();
|
||||||
|
switch (buttonName)
|
||||||
|
{
|
||||||
|
case "buttonUp" -> _armoredCar.MoveTransport(Direction.Up);
|
||||||
|
case "buttonDown" -> _armoredCar.MoveTransport(Direction.Down);
|
||||||
|
case "buttonLeft" -> _armoredCar.MoveTransport(Direction.Left);
|
||||||
|
case "buttonRight" -> _armoredCar.MoveTransport(Direction.Right);
|
||||||
|
}
|
||||||
|
Draw();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void UpdateGUI()
|
||||||
|
{
|
||||||
|
double rootWidth = root.getWidth();
|
||||||
|
double rootHeight = root.getHeight();
|
||||||
|
|
||||||
|
double flowPaneHeight = flowPane.getHeight();
|
||||||
|
double buttonCreateHeight = buttonCreate.getHeight();
|
||||||
|
|
||||||
|
canvas.setWidth(rootWidth);
|
||||||
|
flowPane.setPrefWidth(rootWidth);
|
||||||
|
canvas.setHeight(rootHeight - flowPaneHeight);
|
||||||
|
flowPane.setTranslateY(rootHeight - flowPaneHeight);
|
||||||
|
|
||||||
|
buttonCreate.setTranslateY(rootHeight - flowPaneHeight - buttonCreateHeight - rootPadding);
|
||||||
|
|
||||||
|
int buttonMoveSize = 30;
|
||||||
|
int distanceBetweenButtons = 5;
|
||||||
|
buttonUp.setTranslateY(rootHeight - flowPaneHeight - buttonMoveSize * 2.0 - rootPadding -
|
||||||
|
distanceBetweenButtons);
|
||||||
|
buttonUp.setTranslateX(rootWidth - rootPadding - buttonMoveSize * 2.0 - distanceBetweenButtons);
|
||||||
|
|
||||||
|
buttonDown.setTranslateY(rootHeight - flowPaneHeight - buttonMoveSize - rootPadding);
|
||||||
|
buttonDown.setTranslateX(rootWidth- rootPadding - buttonMoveSize * 2.0 - distanceBetweenButtons);
|
||||||
|
|
||||||
|
buttonLeft.setTranslateY(rootHeight - flowPaneHeight - buttonMoveSize - rootPadding);
|
||||||
|
buttonLeft.setTranslateX(rootWidth - rootPadding - buttonMoveSize * 3.0 -
|
||||||
|
distanceBetweenButtons * 2.0);
|
||||||
|
|
||||||
|
buttonRight.setTranslateY(rootHeight - flowPaneHeight - buttonMoveSize - rootPadding);
|
||||||
|
buttonRight.setTranslateX(rootWidth - rootPadding - buttonMoveSize);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Draw()
|
||||||
|
{
|
||||||
|
GraphicsContext gc = canvas.getGraphicsContext2D();
|
||||||
|
gc.clearRect(0.0, 0.0, canvas.getWidth(), canvas.getHeight());
|
||||||
|
|
||||||
|
if (_armoredCar != null)
|
||||||
|
{
|
||||||
|
_armoredCar.DrawTransport(gc);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void SetData()
|
||||||
|
{
|
||||||
|
Random rnd = new Random();
|
||||||
|
_armoredCar.SetPosition(rnd.nextInt(90) + 10, rnd.nextInt(90),
|
||||||
|
(int) canvas.getWidth(), (int) canvas.getHeight());
|
||||||
|
labelSpeedValue.setText(Integer.toString(_armoredCar.GetArmoredCar().GetSpeed()));
|
||||||
|
labelWeightValue.setText(Double.toString(_armoredCar.GetArmoredCar().GetWeight()));
|
||||||
|
labelBodyColorValue.setText(_armoredCar.GetArmoredCar().GetBodyColor().toString());
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,49 @@
|
|||||||
|
package com.example.antiaircraftgun;
|
||||||
|
|
||||||
|
import javafx.scene.canvas.GraphicsContext;
|
||||||
|
import javafx.scene.paint.Color;
|
||||||
|
|
||||||
|
public class DesertMap extends AbstractMap{
|
||||||
|
protected void DrawBarrierPart(GraphicsContext gc, int i, int j)
|
||||||
|
{
|
||||||
|
gc.setFill(Color.BLACK);
|
||||||
|
gc.fillRect(i * _size_x, j * _size_y, _size_x + 0.5, _size_y + 0.5);
|
||||||
|
}
|
||||||
|
protected void DrawRoadPart(GraphicsContext gc, int i, int j)
|
||||||
|
{
|
||||||
|
gc.setFill(Color.YELLOW);
|
||||||
|
gc.fillRect(i * _size_x, j * _size_y, _size_x + 0.5, _size_y + 0.5);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void GenerateMap()
|
||||||
|
{
|
||||||
|
_map = new int[100][100];
|
||||||
|
_size_x = (float)_width / _map.length;
|
||||||
|
_size_y = (float)_height / _map[0].length;
|
||||||
|
int counter = 0;
|
||||||
|
for (int i = 0; i < _map.length; ++i)
|
||||||
|
{
|
||||||
|
for (int j = 0; j < _map[0].length; ++j)
|
||||||
|
{
|
||||||
|
_map[i][j] = _freeRoad;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
while (counter < 10)
|
||||||
|
{
|
||||||
|
int x = _random.nextInt(0, 90);
|
||||||
|
int y = _random.nextInt(0, 90);
|
||||||
|
int length = _random.nextInt(5, 10);
|
||||||
|
if(counter < 5){
|
||||||
|
for (int i = 0; i < length; i++) {
|
||||||
|
_map[x][y + i] = _barrier;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
for (int i = 0; i < length; i++) {
|
||||||
|
_map[x + i][y] = _barrier;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
counter++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,30 @@
|
|||||||
|
package com.example.antiaircraftgun;
|
||||||
|
|
||||||
|
public enum Direction {
|
||||||
|
None,
|
||||||
|
Up,
|
||||||
|
Down,
|
||||||
|
Left,
|
||||||
|
Right;
|
||||||
|
|
||||||
|
public static Direction FromInteger(int intValue)
|
||||||
|
{
|
||||||
|
switch(intValue)
|
||||||
|
{
|
||||||
|
case 0:
|
||||||
|
return None;
|
||||||
|
case 1:
|
||||||
|
return Up;
|
||||||
|
case 2:
|
||||||
|
return Down;
|
||||||
|
case 3:
|
||||||
|
return Left;
|
||||||
|
case 4:
|
||||||
|
return Right;
|
||||||
|
default:
|
||||||
|
System.out.println("Error: incorrect value!");
|
||||||
|
return Up;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,60 @@
|
|||||||
|
package com.example.antiaircraftgun;
|
||||||
|
|
||||||
|
import javafx.scene.canvas.GraphicsContext;
|
||||||
|
import javafx.scene.paint.Color;
|
||||||
|
|
||||||
|
public class DrawingAntiAircraftGun extends DrawingArmoredCar{
|
||||||
|
public DrawingAntiAircraftGun(int speed, float weight, Color bodyColor, Color dopColor, boolean gun, boolean radar)
|
||||||
|
{
|
||||||
|
super(speed, weight, bodyColor, 110, 75);
|
||||||
|
SetArmoredVehicle(new EntityAntiAircraftGun(speed, weight, bodyColor, dopColor, gun, radar));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void DrawTransport(GraphicsContext gc)
|
||||||
|
{
|
||||||
|
if (!(GetArmoredCar() instanceof EntityAntiAircraftGun antiAircraftGun))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
_startPosY += 35;
|
||||||
|
super.DrawTransport(gc);
|
||||||
|
_startPosY -= 35;
|
||||||
|
|
||||||
|
gc.setStroke(Color.BLACK);
|
||||||
|
|
||||||
|
if (antiAircraftGun.GetGun())
|
||||||
|
{
|
||||||
|
gc.setFill(antiAircraftGun.GetDopColor());
|
||||||
|
gc.fillRect(_startPosX + 35, _startPosY + 20, 25, 15);
|
||||||
|
gc.fillRect(_startPosX + 60, _startPosY + 25, 50, 5);
|
||||||
|
gc.fillRect(_startPosX + 60, _startPosY + 30, 20, 5);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (antiAircraftGun.GetRadar())
|
||||||
|
{
|
||||||
|
double[] radarX =
|
||||||
|
{
|
||||||
|
_startPosX + 32,
|
||||||
|
_startPosX + 32,
|
||||||
|
_startPosX + 22,
|
||||||
|
_startPosX + 10,
|
||||||
|
};
|
||||||
|
|
||||||
|
double[] radarY =
|
||||||
|
{
|
||||||
|
_startPosY + 3,
|
||||||
|
_startPosY + 15,
|
||||||
|
_startPosY + 25,
|
||||||
|
_startPosY + 25,
|
||||||
|
};
|
||||||
|
gc.setStroke(antiAircraftGun.GetDopColor());
|
||||||
|
gc.setFill(antiAircraftGun.GetDopColor());
|
||||||
|
gc.strokeLine(_startPosX + 27, _startPosY + 35, _startPosX + 27, _startPosY + 20);
|
||||||
|
gc.fillPolygon(radarX, radarY, 4);
|
||||||
|
gc.strokeLine(_startPosX + 20, _startPosY + 15, _startPosX + 15, _startPosY + 10);
|
||||||
|
gc.fillOval(_startPosX + 10, _startPosY + 5, 10, 10);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,156 @@
|
|||||||
|
package com.example.antiaircraftgun;
|
||||||
|
|
||||||
|
import javafx.scene.canvas.GraphicsContext;
|
||||||
|
import javafx.scene.paint.Color;
|
||||||
|
|
||||||
|
public class DrawingArmoredCar
|
||||||
|
{
|
||||||
|
private EntityArmoredCar _armoredCar;
|
||||||
|
private IDrawingAdditionalElement _drawingRollers;
|
||||||
|
protected float _startPosX;
|
||||||
|
protected float _startPosY;
|
||||||
|
private Integer _pictureWidth;
|
||||||
|
private Integer _pictureHeight;
|
||||||
|
private int _armoredCarWidth = 90;
|
||||||
|
private int _armoredCarHeight = 40;
|
||||||
|
|
||||||
|
public EntityArmoredCar GetArmoredCar()
|
||||||
|
{
|
||||||
|
return _armoredCar;
|
||||||
|
}
|
||||||
|
protected void SetArmoredVehicle(EntityArmoredCar armoredCar)
|
||||||
|
{
|
||||||
|
_armoredCar = armoredCar;
|
||||||
|
}
|
||||||
|
public IDrawingAdditionalElement GetDrawingRollers()
|
||||||
|
{
|
||||||
|
return _drawingRollers;
|
||||||
|
}
|
||||||
|
public void SetDrawingRollers(IDrawingAdditionalElement drawingRollers)
|
||||||
|
{
|
||||||
|
_drawingRollers = drawingRollers;
|
||||||
|
}
|
||||||
|
public DrawingArmoredCar(int speed, float weight, Color bodyColor)
|
||||||
|
{
|
||||||
|
_armoredCar = new EntityArmoredCar(speed, weight, bodyColor);
|
||||||
|
_drawingRollers = new DrawingRollers(bodyColor);
|
||||||
|
}
|
||||||
|
protected DrawingArmoredCar(int speed, float weight, Color bodyColor, int armoredCarWidth, int armoredCarHeight)
|
||||||
|
{
|
||||||
|
this(speed, weight, bodyColor);
|
||||||
|
_armoredCarHeight = armoredCarHeight;
|
||||||
|
_armoredCarWidth = armoredCarWidth;
|
||||||
|
}
|
||||||
|
public DrawingArmoredCar(EntityArmoredCar armoredCar, IDrawingAdditionalElement additionalElement)
|
||||||
|
{
|
||||||
|
_armoredCar = armoredCar;
|
||||||
|
_drawingRollers = additionalElement;
|
||||||
|
}
|
||||||
|
public void SetPosition(int x, int y, int width, int height)
|
||||||
|
{
|
||||||
|
if (x < 0 || y < 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (x + _armoredCarWidth > width || y + _armoredCarHeight > height) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
_startPosX = x;
|
||||||
|
_startPosY = y;
|
||||||
|
|
||||||
|
_pictureWidth = width;
|
||||||
|
_pictureHeight = height;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void MoveTransport(Direction direction)
|
||||||
|
{
|
||||||
|
if (_pictureWidth == null || _pictureHeight == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (direction) {
|
||||||
|
case Up:
|
||||||
|
if (_startPosY - _armoredCar.GetStep() > 0) {
|
||||||
|
_startPosY -= _armoredCar.GetStep();
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case Down:
|
||||||
|
if (_startPosY + _armoredCarHeight + _armoredCar.GetStep() < _pictureHeight) {
|
||||||
|
_startPosY += _armoredCar.GetStep();
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case Left:
|
||||||
|
if (_startPosX - _armoredCar.GetStep() > 0) {
|
||||||
|
_startPosX -= _armoredCar.GetStep();
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case Right:
|
||||||
|
if (_startPosX + _armoredCarWidth + _armoredCar.GetStep() < _pictureWidth) {
|
||||||
|
_startPosX += _armoredCar.GetStep();
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void DrawTransport(GraphicsContext gc)
|
||||||
|
{
|
||||||
|
if (_startPosX < 0 || _startPosY < 0 || _pictureWidth == null || _pictureHeight == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Гусеницы
|
||||||
|
gc.setFill(Color.GRAY);
|
||||||
|
gc.fillRect(_startPosX + 10, _startPosY + 20, 70, 20);
|
||||||
|
gc.fillOval(_startPosX, _startPosY + 20, 20, 20);
|
||||||
|
gc.fillOval(_startPosX + 70, _startPosY + 20, 20, 20);
|
||||||
|
_drawingRollers.DrawRollers(gc, _startPosX, _startPosY);
|
||||||
|
|
||||||
|
// Броня
|
||||||
|
gc.setStroke(Color.BLACK);
|
||||||
|
gc.setLineWidth(2);
|
||||||
|
gc.setFill(_armoredCar.GetBodyColor());
|
||||||
|
gc.fillRect(_startPosX + 25, _startPosY, 40, 10);
|
||||||
|
gc.fillRect(_startPosX + 5, _startPosY + 10, 80, 10);
|
||||||
|
gc.strokeRect(_startPosX + 25, _startPosY, 40, 10);
|
||||||
|
gc.strokeRect(_startPosX + 5, _startPosY + 10, 80, 10);
|
||||||
|
gc.fillOval(_startPosX + 27, _startPosY + 16, 8, 8);
|
||||||
|
gc.fillOval(_startPosX + 40, _startPosY + 16, 8, 8);
|
||||||
|
gc.fillOval(_startPosX + 53, _startPosY + 16, 8, 8);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void ChangeBorders(int width, int height)
|
||||||
|
{
|
||||||
|
_pictureWidth = width;
|
||||||
|
_pictureHeight = height;
|
||||||
|
|
||||||
|
if (_pictureWidth <= _armoredCarWidth || _pictureHeight <= _armoredCarHeight) {
|
||||||
|
_pictureWidth = null;
|
||||||
|
_pictureHeight = null;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_startPosX + _armoredCarWidth > _pictureWidth) {
|
||||||
|
_startPosX = _pictureWidth - _armoredCarWidth;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_startPosY + _armoredCarHeight > _pictureHeight) {
|
||||||
|
_startPosY = _pictureHeight - _armoredCarHeight;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public float[] GetCurrentPosition()
|
||||||
|
{
|
||||||
|
float[] position = new float[4];
|
||||||
|
position[0] = _startPosX;
|
||||||
|
position[1] = _startPosY;
|
||||||
|
position[2] = _startPosX + _armoredCarWidth;
|
||||||
|
position[3] = _startPosY + _armoredCarHeight;
|
||||||
|
return position;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,48 @@
|
|||||||
|
package com.example.antiaircraftgun;
|
||||||
|
|
||||||
|
import javafx.scene.canvas.GraphicsContext;
|
||||||
|
|
||||||
|
public class DrawingObjectArmoredCar implements IDrawingObject{
|
||||||
|
private DrawingArmoredCar _armoredCar = null;
|
||||||
|
|
||||||
|
public DrawingObjectArmoredCar(DrawingArmoredCar armoredCar)
|
||||||
|
{
|
||||||
|
_armoredCar = armoredCar;
|
||||||
|
}
|
||||||
|
|
||||||
|
public float GetStep()
|
||||||
|
{
|
||||||
|
if (_armoredCar != null && _armoredCar.GetArmoredCar() != null)
|
||||||
|
{
|
||||||
|
return _armoredCar.GetArmoredCar().GetStep();
|
||||||
|
}
|
||||||
|
return 0F;
|
||||||
|
}
|
||||||
|
|
||||||
|
public float[] GetCurrentPosition()
|
||||||
|
{
|
||||||
|
if (_armoredCar != null)
|
||||||
|
{
|
||||||
|
return _armoredCar.GetCurrentPosition();
|
||||||
|
}
|
||||||
|
return new float[4];
|
||||||
|
}
|
||||||
|
|
||||||
|
public void MoveObject(Direction direction)
|
||||||
|
{
|
||||||
|
_armoredCar.MoveTransport(direction);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SetObject(int x, int y, int width, int height)
|
||||||
|
{
|
||||||
|
_armoredCar.SetPosition(x, y, width, height);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void DrawingObject(GraphicsContext gc)
|
||||||
|
{
|
||||||
|
if (_armoredCar != null)
|
||||||
|
{
|
||||||
|
_armoredCar.DrawTransport(gc);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,61 @@
|
|||||||
|
package com.example.antiaircraftgun;
|
||||||
|
|
||||||
|
import javafx.scene.canvas.GraphicsContext;
|
||||||
|
import javafx.scene.paint.Color;
|
||||||
|
|
||||||
|
public class DrawingOvalOrnamentRollers implements IDrawingAdditionalElement{
|
||||||
|
private Color _rollersColor;
|
||||||
|
private NumberRollers _numOfRollers;
|
||||||
|
|
||||||
|
public void SetNumberRollers(int numberOfRollers)
|
||||||
|
{
|
||||||
|
_numOfRollers = NumberRollers.FromInteger(numberOfRollers);
|
||||||
|
}
|
||||||
|
|
||||||
|
public DrawingOvalOrnamentRollers(Color trackRollersColor)
|
||||||
|
{
|
||||||
|
_rollersColor = trackRollersColor;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void DrawRollers(GraphicsContext gc, float startPosX, float startPosY)
|
||||||
|
{
|
||||||
|
if (_rollersColor == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
gc.setFill(_rollersColor);
|
||||||
|
gc.fillOval(startPosX +1, startPosY + 21, 18, 18);
|
||||||
|
gc.fillOval(startPosX + 69, startPosY + 21, 18, 18);
|
||||||
|
gc.fillOval(startPosX + 19, startPosY + 30, 11, 11);
|
||||||
|
gc.fillOval(startPosX + 58, startPosY + 30, 11, 11);
|
||||||
|
|
||||||
|
// Орнамент
|
||||||
|
gc.strokeOval(startPosX + 5, startPosY + 25, 10, 10);
|
||||||
|
gc.strokeOval(startPosX + 73, startPosY + 25, 10, 10);
|
||||||
|
gc.strokeOval(startPosX + 22, startPosY + 33, 5, 5);
|
||||||
|
gc.strokeOval(startPosX + 61, startPosY + 33, 5, 5);
|
||||||
|
|
||||||
|
switch (_numOfRollers)
|
||||||
|
{
|
||||||
|
case Four:
|
||||||
|
break;
|
||||||
|
|
||||||
|
case Five:
|
||||||
|
gc.setFill(_rollersColor);
|
||||||
|
gc.fillOval(startPosX + 45, startPosY + 30, 11, 11);
|
||||||
|
// Орнамент
|
||||||
|
gc.strokeOval(startPosX + 48, startPosY + 33, 5, 5);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case Six:
|
||||||
|
gc.setFill(_rollersColor);
|
||||||
|
gc.fillOval(startPosX + 45, startPosY + 30, 11, 11);
|
||||||
|
gc.fillOval(startPosX + 32, startPosY + 30, 11, 11);
|
||||||
|
// Орнамент
|
||||||
|
gc.strokeOval(startPosX + 48, startPosY + 33, 5, 5);
|
||||||
|
gc.strokeOval(startPosX + 35, startPosY + 33, 5, 5);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,62 @@
|
|||||||
|
package com.example.antiaircraftgun;
|
||||||
|
|
||||||
|
import javafx.scene.canvas.GraphicsContext;
|
||||||
|
import javafx.scene.paint.Color;
|
||||||
|
|
||||||
|
public class DrawingRectangleOrnamentRollers implements IDrawingAdditionalElement{
|
||||||
|
private Color _rollersColor;
|
||||||
|
private NumberRollers _numOfRollers;
|
||||||
|
|
||||||
|
public void SetNumberRollers(int numberOfRollers)
|
||||||
|
{
|
||||||
|
_numOfRollers = NumberRollers.FromInteger(numberOfRollers);
|
||||||
|
}
|
||||||
|
|
||||||
|
public DrawingRectangleOrnamentRollers(Color trackRollersColor)
|
||||||
|
{
|
||||||
|
_rollersColor = trackRollersColor;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void DrawRollers(GraphicsContext gc, float startPosX, float startPosY)
|
||||||
|
{
|
||||||
|
if (_rollersColor == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
gc.setFill(_rollersColor);
|
||||||
|
gc.fillOval(startPosX +1, startPosY + 21, 18, 18);
|
||||||
|
gc.fillOval(startPosX + 69, startPosY + 21, 18, 18);
|
||||||
|
gc.fillOval(startPosX + 19, startPosY + 30, 11, 11);
|
||||||
|
gc.fillOval(startPosX + 58, startPosY + 30, 11, 11);
|
||||||
|
|
||||||
|
// Орнамент
|
||||||
|
gc.strokeRect(startPosX + 5, startPosY + 25, 10, 10);
|
||||||
|
gc.strokeRect(startPosX + 73, startPosY + 25, 10, 10);
|
||||||
|
gc.strokeRect(startPosX + 22, startPosY + 33, 5, 5);
|
||||||
|
gc.strokeRect(startPosX + 61, startPosY + 33, 5, 5);
|
||||||
|
gc.strokeRect(startPosX + 9, startPosY + 28, 3, 3);
|
||||||
|
gc.strokeRect(startPosX + 77, startPosY + 28, 3, 3);
|
||||||
|
|
||||||
|
switch (_numOfRollers)
|
||||||
|
{
|
||||||
|
case Four:
|
||||||
|
break;
|
||||||
|
|
||||||
|
case Five:
|
||||||
|
gc.setFill(_rollersColor);
|
||||||
|
gc.fillOval(startPosX + 45, startPosY + 30, 11, 11);
|
||||||
|
// Орнамент
|
||||||
|
gc.strokeRect(startPosX + 48, startPosY + 33, 5, 5);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case Six:
|
||||||
|
gc.setFill(_rollersColor);
|
||||||
|
gc.fillOval(startPosX + 45, startPosY + 30, 11, 11);
|
||||||
|
gc.fillOval(startPosX + 32, startPosY + 30, 11, 11);
|
||||||
|
// Орнамент
|
||||||
|
gc.strokeRect(startPosX + 48, startPosY + 33, 5, 5);
|
||||||
|
gc.strokeRect(startPosX + 35, startPosY + 33, 5, 5);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,58 @@
|
|||||||
|
package com.example.antiaircraftgun;
|
||||||
|
|
||||||
|
import javafx.scene.canvas.GraphicsContext;
|
||||||
|
import javafx.scene.paint.Color;
|
||||||
|
|
||||||
|
public class DrawingRollers implements IDrawingAdditionalElement{
|
||||||
|
private Color _RollersColor;
|
||||||
|
private NumberRollers _numRollers;
|
||||||
|
public void SetNumberRollers(int numberRollers)
|
||||||
|
{
|
||||||
|
_numRollers = NumberRollers.FromInteger(numberRollers);
|
||||||
|
}
|
||||||
|
public DrawingRollers(Color rollersColor)
|
||||||
|
{
|
||||||
|
_RollersColor = rollersColor;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void DrawRollers(GraphicsContext gc, float startPosX, float startPosY) {
|
||||||
|
if (_RollersColor == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
gc.setFill(_RollersColor);
|
||||||
|
|
||||||
|
switch (_numRollers) {
|
||||||
|
case Four:
|
||||||
|
DrawRoller1(gc, startPosX, startPosY);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case Five:
|
||||||
|
DrawRoller1(gc, startPosX, startPosY);
|
||||||
|
DrawRoller2(gc, startPosX, startPosY);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case Six:
|
||||||
|
DrawRoller1(gc, startPosX, startPosY);
|
||||||
|
DrawRoller2(gc, startPosX, startPosY);
|
||||||
|
DrawRoller3(gc, startPosX, startPosY);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
void DrawRoller1(GraphicsContext gc, float startPosX, float startPosY) {
|
||||||
|
gc.setFill(_RollersColor);
|
||||||
|
gc.fillOval(startPosX +1, startPosY + 21, 18, 18);
|
||||||
|
gc.fillOval(startPosX + 69, startPosY + 21, 18, 18);
|
||||||
|
gc.fillOval(startPosX + 19, startPosY + 30, 11, 11);
|
||||||
|
gc.fillOval(startPosX + 58, startPosY + 30, 11, 11);
|
||||||
|
}
|
||||||
|
void DrawRoller2(GraphicsContext gc, float startPosX, float startPosY) {
|
||||||
|
gc.setFill(_RollersColor);
|
||||||
|
gc.fillOval(startPosX + 45, startPosY + 30, 11, 11);
|
||||||
|
}
|
||||||
|
void DrawRoller3(GraphicsContext gc, float startPosX, float startPosY) {
|
||||||
|
gc.setFill(_RollersColor);
|
||||||
|
gc.fillOval(startPosX + 32, startPosY + 30, 11, 11);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,32 @@
|
|||||||
|
package com.example.antiaircraftgun;
|
||||||
|
|
||||||
|
import javafx.scene.paint.Color;
|
||||||
|
|
||||||
|
public class EntityAntiAircraftGun extends EntityArmoredCar{
|
||||||
|
private final Color _dopColor;
|
||||||
|
private final boolean _gun;
|
||||||
|
private final boolean _radar;
|
||||||
|
|
||||||
|
public Color GetDopColor()
|
||||||
|
{
|
||||||
|
return _dopColor;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean GetGun()
|
||||||
|
{
|
||||||
|
return _gun;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean GetRadar()
|
||||||
|
{
|
||||||
|
return _radar;
|
||||||
|
}
|
||||||
|
|
||||||
|
public EntityAntiAircraftGun(int speed, float weight, Color bodyColor, Color dopColor, boolean gun, boolean radar)
|
||||||
|
{
|
||||||
|
super(speed, weight, bodyColor);
|
||||||
|
_dopColor = dopColor;
|
||||||
|
_gun = gun;
|
||||||
|
_radar = radar;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,38 @@
|
|||||||
|
package com.example.antiaircraftgun;
|
||||||
|
|
||||||
|
import javafx.scene.paint.Color;
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
|
public class EntityArmoredCar
|
||||||
|
{
|
||||||
|
private final int _speed;
|
||||||
|
private final float _weight;
|
||||||
|
private final Color _bodyColor;
|
||||||
|
public int GetSpeed()
|
||||||
|
{
|
||||||
|
return _speed;
|
||||||
|
}
|
||||||
|
|
||||||
|
public float GetWeight()
|
||||||
|
{
|
||||||
|
return _weight;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Color GetBodyColor()
|
||||||
|
{
|
||||||
|
return _bodyColor;
|
||||||
|
}
|
||||||
|
|
||||||
|
public float GetStep()
|
||||||
|
{
|
||||||
|
return _speed * 100 / _weight;
|
||||||
|
}
|
||||||
|
|
||||||
|
public EntityArmoredCar(int speed, float weight, Color bodyColor)
|
||||||
|
{
|
||||||
|
Random random = new Random();
|
||||||
|
_speed = speed <= 0 ? random.nextInt(100) + 50 : speed;
|
||||||
|
_weight = weight <= 0 ? random.nextInt(30) + 40 : weight;
|
||||||
|
_bodyColor = bodyColor;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,84 @@
|
|||||||
|
package com.example.antiaircraftgun;
|
||||||
|
|
||||||
|
import javafx.application.Application;
|
||||||
|
import javafx.fxml.FXMLLoader;
|
||||||
|
import javafx.scene.Scene;
|
||||||
|
import javafx.scene.canvas.Canvas;
|
||||||
|
import javafx.scene.control.Button;
|
||||||
|
import javafx.scene.layout.FlowPane;
|
||||||
|
import javafx.scene.layout.Pane;
|
||||||
|
import javafx.stage.Stage;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
public class FormArmoredCar extends Application
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public void start(Stage stage) throws IOException
|
||||||
|
{
|
||||||
|
FXMLLoader fxmlLoader = new FXMLLoader(FormArmoredCar.class.getResource("form-armored-vehicle-view.fxml"));
|
||||||
|
|
||||||
|
Scene scene = new Scene(fxmlLoader.load(), 600, 400);
|
||||||
|
stage.setTitle("AntiAircraftGun");
|
||||||
|
|
||||||
|
stage.setScene(scene);
|
||||||
|
FirstUpdateGUI(scene);
|
||||||
|
|
||||||
|
stage.show();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void FirstUpdateGUI(Scene scene)
|
||||||
|
{
|
||||||
|
Pane root = (Pane)scene.lookup("#root");
|
||||||
|
Canvas canvas = (Canvas)scene.lookup("#canvas");
|
||||||
|
Button buttonCreate = (Button)scene.lookup("#buttonCreate");
|
||||||
|
Button buttonCreateModif = (Button)scene.lookup("#buttonCreateModif");
|
||||||
|
Button buttonUp = (Button)scene.lookup("#buttonUp");
|
||||||
|
Button buttonLeft = (Button)scene.lookup("#buttonLeft");
|
||||||
|
Button buttonRight = (Button)scene.lookup("#buttonRight");
|
||||||
|
Button buttonDown = (Button)scene.lookup("#buttonDown");
|
||||||
|
Button buttonSelectArmoredCar = (Button)scene.lookup("#buttonSelectArmoredCar");
|
||||||
|
FlowPane flowPane = (FlowPane)scene.lookup("#flowPane");
|
||||||
|
|
||||||
|
root.applyCss();
|
||||||
|
root.layout();
|
||||||
|
|
||||||
|
double flowPaneHeight = flowPane.getHeight();
|
||||||
|
double buttonCreateHeight = buttonCreate.getHeight();
|
||||||
|
double buttonCreateWidth = buttonCreate.getWidth();
|
||||||
|
double rootWidth = root.getWidth();
|
||||||
|
double rootHeight = root.getHeight();
|
||||||
|
double rootPadding = 10.0;
|
||||||
|
double distanceBetweenButtons = 5.0;
|
||||||
|
double buttonMoveSize = 30.0;
|
||||||
|
|
||||||
|
canvas.setWidth(rootWidth);
|
||||||
|
flowPane.setPrefWidth(rootWidth);
|
||||||
|
canvas.setHeight(rootHeight - flowPaneHeight);
|
||||||
|
flowPane.setTranslateY(rootHeight - flowPaneHeight);
|
||||||
|
buttonCreateModif.setTranslateX(rootPadding + buttonCreateWidth + distanceBetweenButtons);
|
||||||
|
buttonCreate.setTranslateY(rootHeight - flowPaneHeight - buttonCreateHeight - rootPadding);
|
||||||
|
buttonCreateModif.setTranslateY(rootHeight - flowPaneHeight - buttonCreateHeight - rootPadding);
|
||||||
|
|
||||||
|
buttonUp.setTranslateY(rootHeight - flowPaneHeight - buttonMoveSize * 2.0 - rootPadding -
|
||||||
|
distanceBetweenButtons);
|
||||||
|
buttonUp.setTranslateX(rootWidth - rootPadding - buttonMoveSize * 2.0 - distanceBetweenButtons);
|
||||||
|
|
||||||
|
buttonDown.setTranslateY(rootHeight - flowPaneHeight - buttonMoveSize - rootPadding);
|
||||||
|
buttonDown.setTranslateX(rootWidth- rootPadding - buttonMoveSize * 2.0 - distanceBetweenButtons);
|
||||||
|
|
||||||
|
buttonLeft.setTranslateY(rootHeight - flowPaneHeight - buttonMoveSize - rootPadding);
|
||||||
|
buttonLeft.setTranslateX(rootWidth - rootPadding - buttonMoveSize * 3.0 - distanceBetweenButtons * 2.0);
|
||||||
|
|
||||||
|
buttonRight.setTranslateY(rootHeight - flowPaneHeight - buttonMoveSize - rootPadding);
|
||||||
|
buttonRight.setTranslateX(rootWidth - rootPadding - buttonMoveSize);
|
||||||
|
|
||||||
|
buttonSelectArmoredCar.setTranslateY(rootHeight - flowPaneHeight - buttonCreateHeight - rootPadding);
|
||||||
|
buttonSelectArmoredCar.setTranslateX(rootWidth - rootPadding - buttonMoveSize * 3.0 -
|
||||||
|
distanceBetweenButtons * 3.0 - buttonSelectArmoredCar.getWidth());
|
||||||
|
}
|
||||||
|
public static void main(String[] args)
|
||||||
|
{
|
||||||
|
launch();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,113 @@
|
|||||||
|
package com.example.antiaircraftgun;
|
||||||
|
|
||||||
|
import javafx.application.Application;
|
||||||
|
import javafx.fxml.FXMLLoader;
|
||||||
|
import javafx.scene.Scene;
|
||||||
|
import javafx.scene.canvas.Canvas;
|
||||||
|
import javafx.scene.control.*;
|
||||||
|
import javafx.scene.layout.Pane;
|
||||||
|
import javafx.stage.Stage;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
public class FormMapWithSetArmoredCars extends Application
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public void start(Stage stage) throws IOException
|
||||||
|
{
|
||||||
|
FXMLLoader fxmlLoader = new FXMLLoader(FormArmoredCar.class.getResource("form-map-with-set-armored-vehicles-view.fxml"));
|
||||||
|
Scene scene = new Scene(fxmlLoader.load(), 600, 400);
|
||||||
|
|
||||||
|
FirstUpdateGUI(scene);
|
||||||
|
|
||||||
|
stage.setTitle("Map with a set of objects");
|
||||||
|
stage.setScene(scene);
|
||||||
|
|
||||||
|
stage.show();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void FirstUpdateGUI(Scene scene)
|
||||||
|
{
|
||||||
|
Pane root = (Pane)scene.lookup("#root");
|
||||||
|
Canvas canvas = (Canvas)scene.lookup("#canvas");
|
||||||
|
Pane paneRight = (Pane)scene.lookup("#paneRight");
|
||||||
|
Label labelTools = (Label)scene.lookup("#labelTools");
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
ComboBox<String> comboBoxSelectorMap = (ComboBox<String>)scene.lookup("#comboBoxSelectorMap");
|
||||||
|
Button buttonAddArmoredCar = (Button)scene.lookup("#buttonAddArmoredCar");
|
||||||
|
TextField textFieldPosition = (TextField)scene.lookup("#textFieldPosition");
|
||||||
|
Button buttonRemoveArmoredCar = (Button)scene.lookup("#buttonRemoveArmoredCar");
|
||||||
|
Button buttonShowStorage = (Button)scene.lookup("#buttonShowStorage");
|
||||||
|
Button buttonShowOnMap = (Button)scene.lookup("#buttonShowOnMap");
|
||||||
|
Button buttonUp = (Button)scene.lookup("#buttonUp");
|
||||||
|
Button buttonLeft = (Button)scene.lookup("#buttonLeft");
|
||||||
|
Button buttonRight = (Button)scene.lookup("#buttonRight");
|
||||||
|
Button buttonDown = (Button)scene.lookup("#buttonDown");
|
||||||
|
|
||||||
|
root.applyCss();
|
||||||
|
root.layout();
|
||||||
|
|
||||||
|
double paneRightPadding = 5.0;
|
||||||
|
double rootWidth = root.getWidth();
|
||||||
|
double rootHeight = root.getHeight();
|
||||||
|
double standardWidth = buttonRemoveArmoredCar.getWidth();
|
||||||
|
double standardHeight = buttonRemoveArmoredCar.getHeight();
|
||||||
|
double paneRightWidth = standardWidth + paneRightPadding * 2;
|
||||||
|
|
||||||
|
canvas.setWidth(rootWidth - paneRightWidth);
|
||||||
|
canvas.setHeight(rootHeight);
|
||||||
|
paneRight.setPrefWidth(paneRightWidth);
|
||||||
|
paneRight.setPrefHeight(rootHeight);
|
||||||
|
paneRight.setTranslateX(rootWidth - paneRightWidth);
|
||||||
|
|
||||||
|
double topMargin = labelTools.getHeight();
|
||||||
|
|
||||||
|
comboBoxSelectorMap.setTranslateX(paneRightPadding);
|
||||||
|
comboBoxSelectorMap.setTranslateY(topMargin);
|
||||||
|
topMargin += standardHeight + paneRightPadding * 3.0;
|
||||||
|
|
||||||
|
buttonAddArmoredCar.setPrefWidth(standardWidth);
|
||||||
|
buttonAddArmoredCar.setTranslateX(paneRightPadding);
|
||||||
|
buttonAddArmoredCar.setTranslateY(topMargin);
|
||||||
|
topMargin += standardHeight + paneRightPadding;
|
||||||
|
|
||||||
|
textFieldPosition.setPrefWidth(standardWidth);
|
||||||
|
textFieldPosition.setTranslateX(paneRightPadding);
|
||||||
|
textFieldPosition.setTranslateY(topMargin);
|
||||||
|
topMargin += standardHeight + paneRightPadding;
|
||||||
|
|
||||||
|
buttonRemoveArmoredCar.setTranslateX(paneRightPadding);
|
||||||
|
buttonRemoveArmoredCar.setTranslateY(topMargin);
|
||||||
|
topMargin += standardHeight + paneRightPadding * 3.0;
|
||||||
|
|
||||||
|
buttonShowStorage.setPrefWidth(standardWidth);
|
||||||
|
buttonShowStorage.setTranslateX(paneRightPadding);
|
||||||
|
buttonShowStorage.setTranslateY(topMargin);
|
||||||
|
topMargin += standardHeight + paneRightPadding;
|
||||||
|
|
||||||
|
buttonShowOnMap.setPrefWidth(standardWidth);
|
||||||
|
buttonShowOnMap.setTranslateX(paneRightPadding);
|
||||||
|
buttonShowOnMap.setTranslateY(topMargin);
|
||||||
|
|
||||||
|
int _distanceBetweenMoveButtons = 5;
|
||||||
|
double moveButtonsSize = 30.0;
|
||||||
|
double moveButtonsXMargin = (paneRightWidth - moveButtonsSize * 3.0 - _distanceBetweenMoveButtons * 2.0) / 2.0;
|
||||||
|
|
||||||
|
buttonUp.setTranslateY(rootHeight - moveButtonsSize * 2.0 - _distanceBetweenMoveButtons - paneRightPadding);
|
||||||
|
buttonUp.setTranslateX(rootWidth - moveButtonsSize * 2.0 - moveButtonsXMargin - _distanceBetweenMoveButtons);
|
||||||
|
|
||||||
|
buttonDown.setTranslateY(rootHeight - moveButtonsSize - paneRightPadding);
|
||||||
|
buttonDown.setTranslateX(rootWidth - moveButtonsSize * 2.0 - moveButtonsXMargin - _distanceBetweenMoveButtons);
|
||||||
|
|
||||||
|
buttonLeft.setTranslateY(rootHeight - moveButtonsSize - paneRightPadding);
|
||||||
|
buttonLeft.setTranslateX(rootWidth - moveButtonsSize * 3.0 - moveButtonsXMargin - _distanceBetweenMoveButtons * 2.0);
|
||||||
|
|
||||||
|
buttonRight.setTranslateY(rootHeight - moveButtonsSize - paneRightPadding);
|
||||||
|
buttonRight.setTranslateX(rootWidth - moveButtonsSize - moveButtonsXMargin);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(String[] args)
|
||||||
|
{
|
||||||
|
launch();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,72 @@
|
|||||||
|
package com.example.antiaircraftgun;
|
||||||
|
|
||||||
|
import javafx.application.Application;
|
||||||
|
import javafx.fxml.FXMLLoader;
|
||||||
|
import javafx.scene.Scene;
|
||||||
|
import javafx.scene.canvas.Canvas;
|
||||||
|
import javafx.scene.control.Button;
|
||||||
|
import javafx.scene.layout.FlowPane;
|
||||||
|
import javafx.scene.layout.Pane;
|
||||||
|
import javafx.stage.Stage;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
public class FormSetMixedArmoredCars extends Application{
|
||||||
|
@Override
|
||||||
|
public void start(Stage stage) throws IOException
|
||||||
|
{
|
||||||
|
FXMLLoader fxmlLoader = new FXMLLoader(FormSetMixedArmoredCars.class.getResource("form-set-mixed-armored-vehicles-view.fxml"));
|
||||||
|
Scene scene = new Scene(fxmlLoader.load(), 600, 400);
|
||||||
|
|
||||||
|
stage.setTitle("Set mixed armored cars");
|
||||||
|
stage.setScene(scene);
|
||||||
|
|
||||||
|
FirstUpdateGUI(scene);
|
||||||
|
stage.show();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void FirstUpdateGUI(Scene scene)
|
||||||
|
{
|
||||||
|
Pane root = (Pane)scene.lookup("#root");
|
||||||
|
Canvas canvas = (Canvas)scene.lookup("#canvas");
|
||||||
|
Button buttonCreate = (Button)scene.lookup("#buttonCreate");
|
||||||
|
Button buttonUp = (Button)scene.lookup("#buttonUp");
|
||||||
|
Button buttonLeft = (Button)scene.lookup("#buttonLeft");
|
||||||
|
Button buttonRight = (Button)scene.lookup("#buttonRight");
|
||||||
|
Button buttonDown = (Button)scene.lookup("#buttonDown");
|
||||||
|
FlowPane flowPane = (FlowPane)scene.lookup("#flowPane");
|
||||||
|
|
||||||
|
root.applyCss();
|
||||||
|
root.layout();
|
||||||
|
|
||||||
|
double flowPaneHeight = flowPane.getHeight();
|
||||||
|
double buttonCreateHeight = buttonCreate.getHeight();
|
||||||
|
double rootWidth = root.getWidth();
|
||||||
|
double rootHeight = root.getHeight();
|
||||||
|
double rootPadding = 10.0;
|
||||||
|
double distanceBetweenButtons = 5.0;
|
||||||
|
double buttonMoveSize = 30.0;
|
||||||
|
|
||||||
|
canvas.setWidth(rootWidth);
|
||||||
|
flowPane.setPrefWidth(rootWidth);
|
||||||
|
canvas.setHeight(rootHeight - flowPaneHeight);
|
||||||
|
flowPane.setTranslateY(rootHeight - flowPaneHeight);
|
||||||
|
|
||||||
|
buttonCreate.setTranslateY(rootHeight - flowPaneHeight - rootPadding - buttonCreateHeight);
|
||||||
|
|
||||||
|
buttonUp.setTranslateY(rootHeight - flowPaneHeight - buttonMoveSize * 2.0 - rootPadding -
|
||||||
|
distanceBetweenButtons);
|
||||||
|
buttonUp.setTranslateX(rootWidth - rootPadding - buttonMoveSize * 2.0 - distanceBetweenButtons);
|
||||||
|
|
||||||
|
buttonDown.setTranslateY(rootHeight - flowPaneHeight - buttonMoveSize - rootPadding);
|
||||||
|
buttonDown.setTranslateX(rootWidth- rootPadding - buttonMoveSize * 2.0 - distanceBetweenButtons);
|
||||||
|
|
||||||
|
buttonLeft.setTranslateY(rootHeight - flowPaneHeight - buttonMoveSize - rootPadding);
|
||||||
|
buttonLeft.setTranslateX(rootWidth - rootPadding - buttonMoveSize * 3.0 - distanceBetweenButtons * 2.0);
|
||||||
|
|
||||||
|
buttonRight.setTranslateY(rootHeight - flowPaneHeight - buttonMoveSize - rootPadding);
|
||||||
|
buttonRight.setTranslateX(rootWidth - rootPadding - buttonMoveSize);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(String[] args) { launch(); }
|
||||||
|
}
|
@ -1,23 +0,0 @@
|
|||||||
package com.example.antiaircraftgun;
|
|
||||||
|
|
||||||
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.antiaircraftgun;
|
|
||||||
|
|
||||||
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,8 @@
|
|||||||
|
package com.example.antiaircraftgun;
|
||||||
|
|
||||||
|
import javafx.scene.canvas.GraphicsContext;
|
||||||
|
|
||||||
|
public interface IDrawingAdditionalElement {
|
||||||
|
public void SetNumberRollers(int numberOfRollers);
|
||||||
|
public void DrawRollers(GraphicsContext gc, float startPosX, float startPosY);
|
||||||
|
}
|
@ -0,0 +1,11 @@
|
|||||||
|
package com.example.antiaircraftgun;
|
||||||
|
|
||||||
|
import javafx.scene.canvas.GraphicsContext;
|
||||||
|
|
||||||
|
public interface IDrawingObject {
|
||||||
|
public float GetStep();
|
||||||
|
public void SetObject(int x, int y, int width, int height);
|
||||||
|
public void MoveObject(Direction direction);
|
||||||
|
public void DrawingObject(GraphicsContext gc);
|
||||||
|
public float[] GetCurrentPosition();
|
||||||
|
}
|
@ -0,0 +1,126 @@
|
|||||||
|
package com.example.antiaircraftgun;
|
||||||
|
|
||||||
|
import javafx.scene.canvas.GraphicsContext;
|
||||||
|
import javafx.scene.paint.Color;
|
||||||
|
|
||||||
|
public class MapWithSetArmoredCarsGeneric<T extends IDrawingObject, U extends AbstractMap>
|
||||||
|
{
|
||||||
|
private final int _pictureWidth;
|
||||||
|
private final int _pictureHeight;
|
||||||
|
private final int _placeSizeWidth = 150;
|
||||||
|
private final int _placeSizeHeight = 90;
|
||||||
|
private final SetArmoredCarsGeneric<T> _setArmoredCars;
|
||||||
|
private GraphicsContext _graphicsContext = null;
|
||||||
|
private final U _map;
|
||||||
|
|
||||||
|
public MapWithSetArmoredCarsGeneric(int picWidth, int picHeight, U map, Class<T> objectT, GraphicsContext gc)
|
||||||
|
{
|
||||||
|
int width = picWidth / _placeSizeWidth;
|
||||||
|
int height = picHeight / _placeSizeHeight;
|
||||||
|
_setArmoredCars = new SetArmoredCarsGeneric<T>(width * height, objectT);
|
||||||
|
_pictureWidth = picWidth;
|
||||||
|
_pictureHeight = picHeight;
|
||||||
|
_map = map;
|
||||||
|
_graphicsContext = gc;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int Add(T armoredCar)
|
||||||
|
{
|
||||||
|
return _setArmoredCars.Insert(armoredCar);
|
||||||
|
}
|
||||||
|
|
||||||
|
public T Delete(int position)
|
||||||
|
{
|
||||||
|
return _setArmoredCars.Remove(position);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void ShowOnMap()
|
||||||
|
{
|
||||||
|
Shaking();
|
||||||
|
for (int i = 0; i < _setArmoredCars.GetCount(); i++)
|
||||||
|
{
|
||||||
|
var armoredCar = _setArmoredCars.Get(i);
|
||||||
|
if (armoredCar != null)
|
||||||
|
{
|
||||||
|
_map.CreateMap(_pictureWidth, _pictureHeight, armoredCar, _graphicsContext);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void ShowSet()
|
||||||
|
{
|
||||||
|
DrawBackground();
|
||||||
|
DrawArmoredCar();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void MoveObject(Direction direction)
|
||||||
|
{
|
||||||
|
if (_map != null)
|
||||||
|
{
|
||||||
|
_map.MoveObject(direction);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Shaking()
|
||||||
|
{
|
||||||
|
int j = _setArmoredCars.GetCount() - 1;
|
||||||
|
for (int i = 0; i < _setArmoredCars.GetCount(); i++)
|
||||||
|
{
|
||||||
|
if (_setArmoredCars.Get(i) == null)
|
||||||
|
{
|
||||||
|
for (; j > i; j--)
|
||||||
|
{
|
||||||
|
var car = _setArmoredCars.Get(j);
|
||||||
|
if (car != null)
|
||||||
|
{
|
||||||
|
_setArmoredCars.Insert(car, i);
|
||||||
|
_setArmoredCars.Remove(j);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (j <= i)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void DrawBackground()
|
||||||
|
{
|
||||||
|
_graphicsContext.setFill(Color.GREEN);
|
||||||
|
_graphicsContext.fillRect(0, 0, _pictureWidth, _pictureHeight);
|
||||||
|
|
||||||
|
_graphicsContext.setFill(Color.LIGHTGRAY);
|
||||||
|
|
||||||
|
for (int i = 0; i < _pictureWidth / _placeSizeWidth; i++)
|
||||||
|
{
|
||||||
|
for (int j = 0; j < _pictureHeight / _placeSizeHeight; j++)
|
||||||
|
{
|
||||||
|
_graphicsContext.fillRect(i * _placeSizeWidth + _placeSizeWidth / 10, j * _placeSizeHeight + _placeSizeHeight / 10, _placeSizeWidth * 8 / 10, _placeSizeHeight * 8 / 10);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void DrawArmoredCar()
|
||||||
|
{
|
||||||
|
int xPositionInStorage = _placeSizeWidth / 10;
|
||||||
|
int yPositionInStorage = _placeSizeHeight / 10;
|
||||||
|
|
||||||
|
for (int i = 0; i < _setArmoredCars.GetCount(); i++)
|
||||||
|
{
|
||||||
|
if (_setArmoredCars.Get(i) != null)
|
||||||
|
{
|
||||||
|
_setArmoredCars.Get(i).SetObject(xPositionInStorage, yPositionInStorage, _pictureWidth, _pictureHeight);
|
||||||
|
_setArmoredCars.Get(i).DrawingObject(_graphicsContext);
|
||||||
|
xPositionInStorage += _placeSizeWidth;
|
||||||
|
}
|
||||||
|
if (xPositionInStorage > _pictureWidth - _placeSizeWidth)
|
||||||
|
{
|
||||||
|
xPositionInStorage = _placeSizeWidth / 10;
|
||||||
|
yPositionInStorage += _placeSizeHeight;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,27 @@
|
|||||||
|
package com.example.antiaircraftgun;
|
||||||
|
|
||||||
|
public enum NumberRollers
|
||||||
|
{
|
||||||
|
Four,
|
||||||
|
Five,
|
||||||
|
Six;
|
||||||
|
|
||||||
|
public static NumberRollers FromInteger(int intValue)
|
||||||
|
{
|
||||||
|
switch(intValue)
|
||||||
|
{
|
||||||
|
case 4:
|
||||||
|
return Four;
|
||||||
|
|
||||||
|
case 5:
|
||||||
|
return Five;
|
||||||
|
|
||||||
|
case 6:
|
||||||
|
return Six;
|
||||||
|
|
||||||
|
default:
|
||||||
|
System.out.println("Error: incorrect value!");
|
||||||
|
return Four;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,87 @@
|
|||||||
|
package com.example.antiaircraftgun;
|
||||||
|
|
||||||
|
import java.lang.reflect.Array;
|
||||||
|
|
||||||
|
public class SetArmoredCarsGeneric<T>
|
||||||
|
{
|
||||||
|
private final T[] _places;
|
||||||
|
public int GetCount()
|
||||||
|
{
|
||||||
|
return _places.length;
|
||||||
|
}
|
||||||
|
|
||||||
|
public SetArmoredCarsGeneric(int count, Class<T> objectT)
|
||||||
|
{
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
final T[] places = (T[])Array.newInstance(objectT, count);
|
||||||
|
_places = places;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int Insert(T armoredCar)
|
||||||
|
{
|
||||||
|
return Insert(armoredCar, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int Insert(T armoredCar, int position)
|
||||||
|
{
|
||||||
|
if (position < 0 || position > _places.length)
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
int emptyCellIndex = -1;
|
||||||
|
if (_places[position] != null)
|
||||||
|
{
|
||||||
|
for (int i = position + 1; i < GetCount(); i++)
|
||||||
|
{
|
||||||
|
if (_places[i] == null)
|
||||||
|
{
|
||||||
|
emptyCellIndex = i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (emptyCellIndex != -1)
|
||||||
|
{
|
||||||
|
for (int i = emptyCellIndex; i > position; i--)
|
||||||
|
{
|
||||||
|
_places[i] = _places[i - 1];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_places[position] = armoredCar;
|
||||||
|
return position;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (emptyCellIndex == -1)
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_places[position] = armoredCar;
|
||||||
|
return position;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public T Remove(int position)
|
||||||
|
{
|
||||||
|
if (position >= GetCount() || position < 0)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
T removedObject = _places[position];
|
||||||
|
_places[position] = null;
|
||||||
|
return removedObject;
|
||||||
|
}
|
||||||
|
|
||||||
|
public T Get(int position)
|
||||||
|
{
|
||||||
|
if (position >= GetCount() || position < 0)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return _places[position];
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,68 @@
|
|||||||
|
package com.example.antiaircraftgun;
|
||||||
|
|
||||||
|
import java.lang.reflect.Array;
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
|
public class SetMixedArmoredCarsGeneric<T extends EntityArmoredCar, U extends IDrawingAdditionalElement>
|
||||||
|
{
|
||||||
|
private final T[] _armoredCars;
|
||||||
|
private final U[] _additionalElements;
|
||||||
|
private final int _maxCount;
|
||||||
|
private int _armoredCarsCount;
|
||||||
|
private int _additionalElementsCount;
|
||||||
|
|
||||||
|
public SetMixedArmoredCarsGeneric(int maxCount, Class<T> objectT, Class<U> objectU)
|
||||||
|
{
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
final T[] armoredCars = (T[]) Array.newInstance(objectT, maxCount);
|
||||||
|
_armoredCars = armoredCars;
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
final U[] additionalElements = (U[]) Array.newInstance(objectU, maxCount);
|
||||||
|
_additionalElements = additionalElements;
|
||||||
|
_maxCount = maxCount;
|
||||||
|
_armoredCarsCount = 0;
|
||||||
|
_additionalElementsCount = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean AddArmoredCar(T armoredCar)
|
||||||
|
{
|
||||||
|
if (_armoredCarsCount == _maxCount)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_armoredCars[_armoredCarsCount] = armoredCar;
|
||||||
|
_armoredCarsCount++;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean AddAdditionalElement(U additionalElement)
|
||||||
|
{
|
||||||
|
if (_additionalElementsCount == _maxCount)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_additionalElements[_additionalElementsCount] = additionalElement;
|
||||||
|
_additionalElementsCount++;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public DrawingArmoredCar GetRandomArmoredCar()
|
||||||
|
{
|
||||||
|
if (_armoredCarsCount == 0 || _additionalElementsCount == 0)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
Random random = new Random();
|
||||||
|
T randomArmoredCar = _armoredCars[random.nextInt(0, _armoredCarsCount)];
|
||||||
|
U randomAdditionalElement = _additionalElements[random.nextInt(0, _additionalElementsCount)];
|
||||||
|
|
||||||
|
return new DrawingArmoredCar(randomArmoredCar, randomAdditionalElement);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,42 @@
|
|||||||
|
package com.example.antiaircraftgun;
|
||||||
|
|
||||||
|
import javafx.scene.canvas.GraphicsContext;
|
||||||
|
import javafx.scene.paint.Color;
|
||||||
|
|
||||||
|
public class SimpleMap extends AbstractMap {
|
||||||
|
protected void DrawBarrierPart(GraphicsContext gc, int i, int j)
|
||||||
|
{
|
||||||
|
gc.setFill(Color.BLACK);
|
||||||
|
gc.fillRect(i * _size_x, j * _size_y, i * (_size_x + 1), j * (_size_y + 1));
|
||||||
|
}
|
||||||
|
protected void DrawRoadPart(GraphicsContext gc, int i, int j)
|
||||||
|
{
|
||||||
|
gc.setFill(Color.LIGHTGRAY);
|
||||||
|
gc.fillRect(i * _size_x, j * _size_y, i * (_size_x + 1), j * (_size_y + 1));
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void GenerateMap()
|
||||||
|
{
|
||||||
|
_map = new int[100][100];
|
||||||
|
_size_x = (float)_width / _map.length;
|
||||||
|
_size_y = (float)_height / _map[0].length;
|
||||||
|
int counter = 0;
|
||||||
|
for (int i = 0; i < _map.length; ++i)
|
||||||
|
{
|
||||||
|
for (int j = 0; j < _map[0].length; ++j)
|
||||||
|
{
|
||||||
|
_map[i][j] = _freeRoad;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
while (counter < 50)
|
||||||
|
{
|
||||||
|
int x = _random.nextInt(0, 100);
|
||||||
|
int y = _random.nextInt(0, 100);
|
||||||
|
if (_map[x][y] == _freeRoad)
|
||||||
|
{
|
||||||
|
_map[x][y] = _barrier;
|
||||||
|
counter++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,42 @@
|
|||||||
|
package com.example.antiaircraftgun;
|
||||||
|
|
||||||
|
import javafx.scene.canvas.GraphicsContext;
|
||||||
|
import javafx.scene.paint.Color;
|
||||||
|
|
||||||
|
public class TrainingGroundMap extends AbstractMap{
|
||||||
|
protected void DrawBarrierPart(GraphicsContext gc, int i, int j)
|
||||||
|
{
|
||||||
|
gc.setFill(Color.BLACK);
|
||||||
|
gc.fillRect(i * _size_x, j * _size_y, i * (_size_x + 1), j * (_size_y + 1));
|
||||||
|
}
|
||||||
|
protected void DrawRoadPart(GraphicsContext gc, int i, int j)
|
||||||
|
{
|
||||||
|
gc.setFill(Color.LIGHTGREEN);
|
||||||
|
gc.fillRect(i * _size_x, j * _size_y, i * (_size_x + 1), j * (_size_y + 1));
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void GenerateMap()
|
||||||
|
{
|
||||||
|
_map = new int[100][100];
|
||||||
|
_size_x = (float)_width / _map.length;
|
||||||
|
_size_y = (float)_height / _map[0].length;
|
||||||
|
int counter = 0;
|
||||||
|
for (int i = 0; i < _map.length; ++i)
|
||||||
|
{
|
||||||
|
for (int j = 0; j < _map[0].length; ++j)
|
||||||
|
{
|
||||||
|
_map[i][j] = _freeRoad;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
while (counter < 25)
|
||||||
|
{
|
||||||
|
int x = _random.nextInt(0, 100);
|
||||||
|
int y = _random.nextInt(0, 100);
|
||||||
|
if (_map[x][y] == _freeRoad)
|
||||||
|
{
|
||||||
|
_map[x][y] = _barrier;
|
||||||
|
counter++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
BIN
AntiAircraftGun/src/main/resources/arrowDown.png
Normal file
BIN
AntiAircraftGun/src/main/resources/arrowDown.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 245 B |
BIN
AntiAircraftGun/src/main/resources/arrowLeft.png
Normal file
BIN
AntiAircraftGun/src/main/resources/arrowLeft.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 257 B |
BIN
AntiAircraftGun/src/main/resources/arrowRight.png
Normal file
BIN
AntiAircraftGun/src/main/resources/arrowRight.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 254 B |
BIN
AntiAircraftGun/src/main/resources/arrowUp.png
Normal file
BIN
AntiAircraftGun/src/main/resources/arrowUp.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 234 B |
@ -0,0 +1,101 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
|
||||||
|
<?import javafx.scene.layout.Pane?>
|
||||||
|
|
||||||
|
<?import javafx.scene.canvas.Canvas?>
|
||||||
|
<?import javafx.scene.layout.FlowPane?>
|
||||||
|
<?import javafx.scene.control.Label?>
|
||||||
|
<?import javafx.scene.control.ComboBox?>
|
||||||
|
<?import javafx.collections.FXCollections?>
|
||||||
|
<?import java.lang.String?>
|
||||||
|
<?import javafx.scene.control.Button?>
|
||||||
|
<?import javafx.scene.image.ImageView?>
|
||||||
|
<?import javafx.scene.image.Image?>
|
||||||
|
<?import javafx.scene.control.ColorPicker?>
|
||||||
|
<Pane xmlns:fx="http://javafx.com/fxml" fx:id="root" fx:controller="com.example.antiaircraftgun.ControllerArmoredCar">
|
||||||
|
<Canvas fx:id="canvas">
|
||||||
|
</Canvas>
|
||||||
|
<FlowPane fx:id="flowPane" style="-fx-background-color: #31374c;">
|
||||||
|
<Label style="-fx-text-fill: #b8becc; -fx-padding: 5 5 5 5;">
|
||||||
|
Speed:
|
||||||
|
</Label>
|
||||||
|
<Label fx:id="labelSpeedValue" style="-fx-text-fill: #ffffff; -fx-padding: 5 5 5 0; -fx-font-weight: bold;">
|
||||||
|
-
|
||||||
|
</Label>
|
||||||
|
<Label style="-fx-text-fill: #b8becc; -fx-padding: 5 5 5 5;">
|
||||||
|
Weight:
|
||||||
|
</Label>
|
||||||
|
<Label fx:id="labelWeightValue" style="-fx-text-fill: #ffffff; -fx-padding: 5 5 5 0; -fx-font-weight: bold;">
|
||||||
|
-
|
||||||
|
</Label>
|
||||||
|
<Label style="-fx-text-fill: #b8becc; -fx-padding: 5 5 5 5;">
|
||||||
|
Color:
|
||||||
|
</Label>
|
||||||
|
<ColorPicker fx:id="bodyColorPicker" onAction="#BodyColorPicker_Changed"/>
|
||||||
|
<Label style="-fx-text-fill: #b8becc; -fx-padding: 5 5 5 5;">
|
||||||
|
DopColor:
|
||||||
|
</Label>
|
||||||
|
<ColorPicker fx:id="dopColorPicker" onAction="#DopColorPicker_Changed"/>
|
||||||
|
<Label style="-fx-text-fill: #b8becc; -fx-padding: 5 5 5 5;">
|
||||||
|
Rollers:
|
||||||
|
</Label>
|
||||||
|
<ComboBox fx:id="comboBoxNumOfRollers" value="5" onAction="#ComboBoxNumOfRollers_Changed">
|
||||||
|
<items>
|
||||||
|
<FXCollections fx:factory="observableArrayList">
|
||||||
|
<String fx:value="4"/>
|
||||||
|
<String fx:value="5"/>
|
||||||
|
<String fx:value="6"/>
|
||||||
|
</FXCollections>
|
||||||
|
</items>
|
||||||
|
</ComboBox>
|
||||||
|
<Label style="-fx-text-fill: #b8becc; -fx-padding: 5 5 5 5;">
|
||||||
|
Ornament:
|
||||||
|
</Label>
|
||||||
|
<ComboBox fx:id="comboBoxOrnamentType" value="None" onAction="#ComboBoxOrnamentType_Changed">
|
||||||
|
<items>
|
||||||
|
<FXCollections fx:factory="observableArrayList">
|
||||||
|
<String fx:value="None"/>
|
||||||
|
<String fx:value="Rectangle"/>
|
||||||
|
<String fx:value="Oval"/>
|
||||||
|
</FXCollections>
|
||||||
|
</items>
|
||||||
|
</ComboBox>
|
||||||
|
</FlowPane>
|
||||||
|
<Button fx:id="buttonCreate" onAction="#ButtonCreate_Click">
|
||||||
|
Create
|
||||||
|
</Button>
|
||||||
|
<Button fx:id="buttonCreateModif" onAction="#ButtonCreateModif_Click">
|
||||||
|
Modification
|
||||||
|
</Button>
|
||||||
|
<Button fx:id="buttonLeft" minWidth="30" minHeight="30" onAction="#ButtonMove_Click">
|
||||||
|
<graphic>
|
||||||
|
<ImageView fitHeight="14.0" fitWidth="14.0" pickOnBounds="true" preserveRatio="true">
|
||||||
|
<Image url="@/arrowLeft.png"/>
|
||||||
|
</ImageView>
|
||||||
|
</graphic>
|
||||||
|
</Button>
|
||||||
|
<Button fx:id="buttonRight" minWidth="30" minHeight="30" onAction="#ButtonMove_Click">
|
||||||
|
<graphic>
|
||||||
|
<ImageView fitHeight="14.0" fitWidth="14.0" pickOnBounds="true" preserveRatio="true">
|
||||||
|
<Image url="@/arrowRight.png"/>
|
||||||
|
</ImageView>
|
||||||
|
</graphic>
|
||||||
|
</Button>
|
||||||
|
<Button fx:id="buttonUp" minWidth="30" minHeight="30" onAction="#ButtonMove_Click">
|
||||||
|
<graphic>
|
||||||
|
<ImageView fitHeight="14.0" fitWidth="14.0" pickOnBounds="true" preserveRatio="true">
|
||||||
|
<Image url="@/arrowUp.png"/>
|
||||||
|
</ImageView>
|
||||||
|
</graphic>
|
||||||
|
</Button>
|
||||||
|
<Button fx:id="buttonDown" minWidth="30" minHeight="30" onAction="#ButtonMove_Click">
|
||||||
|
<graphic>
|
||||||
|
<ImageView fitHeight="14.0" fitWidth="14.0" pickOnBounds="true" preserveRatio="true">
|
||||||
|
<Image url="@/arrowDown.png"/>
|
||||||
|
</ImageView>
|
||||||
|
</graphic>
|
||||||
|
</Button>
|
||||||
|
<Button fx:id="buttonSelectArmoredCar">
|
||||||
|
Select
|
||||||
|
</Button>
|
||||||
|
</Pane>
|
@ -0,0 +1,72 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
|
||||||
|
<?import javafx.scene.layout.Pane?>
|
||||||
|
<?import javafx.scene.canvas.Canvas?>
|
||||||
|
|
||||||
|
<?import javafx.scene.control.Label?>
|
||||||
|
<?import javafx.scene.control.ComboBox?>
|
||||||
|
<?import javafx.collections.FXCollections?>
|
||||||
|
<?import java.lang.String?>
|
||||||
|
<?import javafx.scene.control.Button?>
|
||||||
|
<?import javafx.scene.control.TextField?>
|
||||||
|
<?import javafx.scene.image.ImageView?>
|
||||||
|
<?import javafx.scene.image.Image?>
|
||||||
|
<Pane xmlns:fx="http://javafx.com/fxml" fx:id="root" fx:controller="com.example.antiaircraftgun.ControllerMapWithSetArmoredCars">
|
||||||
|
<Canvas fx:id="canvas">
|
||||||
|
</Canvas>
|
||||||
|
<Pane fx:id="paneRight" style="-fx-background-color: #31374c;">
|
||||||
|
<Label fx:id="labelTools" style="-fx-text-fill: #b8becc; -fx-padding: 5 5 5 5; -fx-font-weight: bold;">
|
||||||
|
Tools
|
||||||
|
</Label>
|
||||||
|
<ComboBox fx:id="comboBoxSelectorMap" value="Simple map" onAction="#ComboBoxSelectorMap_Changed">
|
||||||
|
<items>
|
||||||
|
<FXCollections fx:factory="observableArrayList">
|
||||||
|
<String fx:value="Simple map"/>
|
||||||
|
<String fx:value="Training ground map"/>
|
||||||
|
<String fx:value="Desert map"/>
|
||||||
|
</FXCollections>
|
||||||
|
</items>
|
||||||
|
</ComboBox>
|
||||||
|
<Button fx:id="buttonAddArmoredCar" onAction="#ButtonAddArmoredCar_Click">
|
||||||
|
Add armored vehicle
|
||||||
|
</Button>
|
||||||
|
<TextField fx:id="textFieldPosition" />
|
||||||
|
<Button fx:id="buttonRemoveArmoredCar" onAction="#ButtonRemoveArmoredCar_Click">
|
||||||
|
Remove armored vehicle
|
||||||
|
</Button>
|
||||||
|
<Button fx:id="buttonShowStorage" onAction="#ButtonShowStorage_Click">
|
||||||
|
Show storage
|
||||||
|
</Button>
|
||||||
|
<Button fx:id="buttonShowOnMap" onAction="#ButtonShowOnMap_Click">
|
||||||
|
Show on map
|
||||||
|
</Button>
|
||||||
|
</Pane>
|
||||||
|
<Button fx:id="buttonLeft" minWidth="30" minHeight="30" onAction="#ButtonMove_Click">
|
||||||
|
<graphic>
|
||||||
|
<ImageView fitHeight="14.0" fitWidth="14.0" pickOnBounds="true" preserveRatio="true">
|
||||||
|
<Image url="@/arrowLeft.png"/>
|
||||||
|
</ImageView>
|
||||||
|
</graphic>
|
||||||
|
</Button>
|
||||||
|
<Button fx:id="buttonRight" minWidth="30" minHeight="30" onAction="#ButtonMove_Click">
|
||||||
|
<graphic>
|
||||||
|
<ImageView fitHeight="14.0" fitWidth="14.0" pickOnBounds="true" preserveRatio="true">
|
||||||
|
<Image url="@/arrowRight.png"/>
|
||||||
|
</ImageView>
|
||||||
|
</graphic>
|
||||||
|
</Button>
|
||||||
|
<Button fx:id="buttonUp" minWidth="30" minHeight="30" onAction="#ButtonMove_Click">
|
||||||
|
<graphic>
|
||||||
|
<ImageView fitHeight="14.0" fitWidth="14.0" pickOnBounds="true" preserveRatio="true">
|
||||||
|
<Image url="@/arrowUp.png"/>
|
||||||
|
</ImageView>
|
||||||
|
</graphic>
|
||||||
|
</Button>
|
||||||
|
<Button fx:id="buttonDown" minWidth="30" minHeight="30" onAction="#ButtonMove_Click">
|
||||||
|
<graphic>
|
||||||
|
<ImageView fitHeight="14.0" fitWidth="14.0" pickOnBounds="true" preserveRatio="true">
|
||||||
|
<Image url="@/arrowDown.png"/>
|
||||||
|
</ImageView>
|
||||||
|
</graphic>
|
||||||
|
</Button>
|
||||||
|
</Pane>
|
@ -0,0 +1,65 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
|
||||||
|
<?import javafx.scene.layout.Pane?>
|
||||||
|
|
||||||
|
<?import javafx.scene.canvas.Canvas?>
|
||||||
|
<?import javafx.scene.layout.FlowPane?>
|
||||||
|
<?import javafx.scene.control.Label?>
|
||||||
|
<?import javafx.scene.control.Button?>
|
||||||
|
<?import javafx.scene.image.ImageView?>
|
||||||
|
<?import javafx.scene.image.Image?>
|
||||||
|
<Pane xmlns:fx="http://javafx.com/fxml" fx:id="root" fx:controller="com.example.antiaircraftgun.ControllerSetMixedArmoredCars">
|
||||||
|
<Canvas fx:id="canvas">
|
||||||
|
</Canvas>
|
||||||
|
<FlowPane fx:id="flowPane" style="-fx-background-color: #31374c;">
|
||||||
|
<Label style="-fx-text-fill: #b8becc; -fx-padding: 5 5 5 5;">
|
||||||
|
Speed:
|
||||||
|
</Label>
|
||||||
|
<Label fx:id="labelSpeedValue" style="-fx-text-fill: #ffffff; -fx-padding: 5 5 5 0; -fx-font-weight: bold;">
|
||||||
|
-
|
||||||
|
</Label>
|
||||||
|
<Label style="-fx-text-fill: #b8becc; -fx-padding: 5 5 5 5;">
|
||||||
|
Weight:
|
||||||
|
</Label>
|
||||||
|
<Label fx:id="labelWeightValue" style="-fx-text-fill: #ffffff; -fx-padding: 5 5 5 0; -fx-font-weight: bold;">
|
||||||
|
-
|
||||||
|
</Label>
|
||||||
|
<Label style="-fx-text-fill: #b8becc; -fx-padding: 5 5 5 5;">
|
||||||
|
Color:
|
||||||
|
</Label>
|
||||||
|
<Label fx:id="labelBodyColorValue" style="-fx-text-fill: #ffffff; -fx-padding: 5 5 5 0; -fx-font-weight: bold;">
|
||||||
|
-
|
||||||
|
</Label>
|
||||||
|
</FlowPane>
|
||||||
|
<Button fx:id="buttonCreate" onAction="#ButtonCreate_Click">
|
||||||
|
Create
|
||||||
|
</Button>
|
||||||
|
<Button fx:id="buttonLeft" minWidth="30" minHeight="30" onAction="#ButtonMove_Click">
|
||||||
|
<graphic>
|
||||||
|
<ImageView fitHeight="14.0" fitWidth="14.0" pickOnBounds="true" preserveRatio="true">
|
||||||
|
<Image url="@/arrowLeft.png"/>
|
||||||
|
</ImageView>
|
||||||
|
</graphic>
|
||||||
|
</Button>
|
||||||
|
<Button fx:id="buttonRight" minWidth="30" minHeight="30" onAction="#ButtonMove_Click">
|
||||||
|
<graphic>
|
||||||
|
<ImageView fitHeight="14.0" fitWidth="14.0" pickOnBounds="true" preserveRatio="true">
|
||||||
|
<Image url="@/arrowRight.png"/>
|
||||||
|
</ImageView>
|
||||||
|
</graphic>
|
||||||
|
</Button>
|
||||||
|
<Button fx:id="buttonUp" minWidth="30" minHeight="30" onAction="#ButtonMove_Click">
|
||||||
|
<graphic>
|
||||||
|
<ImageView fitHeight="14.0" fitWidth="14.0" pickOnBounds="true" preserveRatio="true">
|
||||||
|
<Image url="@/arrowUp.png"/>
|
||||||
|
</ImageView>
|
||||||
|
</graphic>
|
||||||
|
</Button>
|
||||||
|
<Button fx:id="buttonDown" minWidth="30" minHeight="30" onAction="#ButtonMove_Click">
|
||||||
|
<graphic>
|
||||||
|
<ImageView fitHeight="14.0" fitWidth="14.0" pickOnBounds="true" preserveRatio="true">
|
||||||
|
<Image url="@/arrowDown.png"/>
|
||||||
|
</ImageView>
|
||||||
|
</graphic>
|
||||||
|
</Button>
|
||||||
|
</Pane>
|
Loading…
Reference in New Issue
Block a user