labWork01
This commit is contained in:
parent
1e6c192183
commit
202784cb0a
29
SelfPropelledArtilleryUnit_Hard/.gitignore
vendored
Normal file
29
SelfPropelledArtilleryUnit_Hard/.gitignore
vendored
Normal file
@ -0,0 +1,29 @@
|
||||
### IntelliJ IDEA ###
|
||||
out/
|
||||
!**/src/main/**/out/
|
||||
!**/src/test/**/out/
|
||||
|
||||
### Eclipse ###
|
||||
.apt_generated
|
||||
.classpath
|
||||
.factorypath
|
||||
.project
|
||||
.settings
|
||||
.springBeans
|
||||
.sts4-cache
|
||||
bin/
|
||||
!**/src/main/**/bin/
|
||||
!**/src/test/**/bin/
|
||||
|
||||
### NetBeans ###
|
||||
/nbproject/private/
|
||||
/nbbuild/
|
||||
/dist/
|
||||
/nbdist/
|
||||
/.nb-gradle/
|
||||
|
||||
### VS Code ###
|
||||
.vscode/
|
||||
|
||||
### Mac OS ###
|
||||
.DS_Store
|
3
SelfPropelledArtilleryUnit_Hard/.idea/.gitignore
generated
vendored
Normal file
3
SelfPropelledArtilleryUnit_Hard/.idea/.gitignore
generated
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
6
SelfPropelledArtilleryUnit_Hard/.idea/misc.xml
generated
Normal file
6
SelfPropelledArtilleryUnit_Hard/.idea/misc.xml
generated
Normal file
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_17" default="true" project-jdk-name="17" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/out" />
|
||||
</component>
|
||||
</project>
|
8
SelfPropelledArtilleryUnit_Hard/.idea/modules.xml
generated
Normal file
8
SelfPropelledArtilleryUnit_Hard/.idea/modules.xml
generated
Normal file
@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/SelfPropelledArtilleryUnit_Hard.iml" filepath="$PROJECT_DIR$/SelfPropelledArtilleryUnit_Hard.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
124
SelfPropelledArtilleryUnit_Hard/.idea/uiDesigner.xml
generated
Normal file
124
SelfPropelledArtilleryUnit_Hard/.idea/uiDesigner.xml
generated
Normal file
@ -0,0 +1,124 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="Palette2">
|
||||
<group name="Swing">
|
||||
<item class="com.intellij.uiDesigner.HSpacer" tooltip-text="Horizontal Spacer" icon="/com/intellij/uiDesigner/icons/hspacer.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="1" hsize-policy="6" anchor="0" fill="1" />
|
||||
</item>
|
||||
<item class="com.intellij.uiDesigner.VSpacer" tooltip-text="Vertical Spacer" icon="/com/intellij/uiDesigner/icons/vspacer.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="6" hsize-policy="1" anchor="0" fill="2" />
|
||||
</item>
|
||||
<item class="javax.swing.JPanel" icon="/com/intellij/uiDesigner/icons/panel.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3" />
|
||||
</item>
|
||||
<item class="javax.swing.JScrollPane" icon="/com/intellij/uiDesigner/icons/scrollPane.svg" removable="false" auto-create-binding="false" can-attach-label="true">
|
||||
<default-constraints vsize-policy="7" hsize-policy="7" anchor="0" fill="3" />
|
||||
</item>
|
||||
<item class="javax.swing.JButton" icon="/com/intellij/uiDesigner/icons/button.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="3" anchor="0" fill="1" />
|
||||
<initial-values>
|
||||
<property name="text" value="Button" />
|
||||
</initial-values>
|
||||
</item>
|
||||
<item class="javax.swing.JRadioButton" icon="/com/intellij/uiDesigner/icons/radioButton.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
|
||||
<initial-values>
|
||||
<property name="text" value="RadioButton" />
|
||||
</initial-values>
|
||||
</item>
|
||||
<item class="javax.swing.JCheckBox" icon="/com/intellij/uiDesigner/icons/checkBox.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
|
||||
<initial-values>
|
||||
<property name="text" value="CheckBox" />
|
||||
</initial-values>
|
||||
</item>
|
||||
<item class="javax.swing.JLabel" icon="/com/intellij/uiDesigner/icons/label.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="0" anchor="8" fill="0" />
|
||||
<initial-values>
|
||||
<property name="text" value="Label" />
|
||||
</initial-values>
|
||||
</item>
|
||||
<item class="javax.swing.JTextField" icon="/com/intellij/uiDesigner/icons/textField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
|
||||
<preferred-size width="150" height="-1" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JPasswordField" icon="/com/intellij/uiDesigner/icons/passwordField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
|
||||
<preferred-size width="150" height="-1" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JFormattedTextField" icon="/com/intellij/uiDesigner/icons/formattedTextField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
|
||||
<preferred-size width="150" height="-1" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JTextArea" icon="/com/intellij/uiDesigner/icons/textArea.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||
<preferred-size width="150" height="50" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JTextPane" icon="/com/intellij/uiDesigner/icons/textPane.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||
<preferred-size width="150" height="50" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JEditorPane" icon="/com/intellij/uiDesigner/icons/editorPane.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||
<preferred-size width="150" height="50" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JComboBox" icon="/com/intellij/uiDesigner/icons/comboBox.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="0" hsize-policy="2" anchor="8" fill="1" />
|
||||
</item>
|
||||
<item class="javax.swing.JTable" icon="/com/intellij/uiDesigner/icons/table.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||
<preferred-size width="150" height="50" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JList" icon="/com/intellij/uiDesigner/icons/list.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="6" hsize-policy="2" anchor="0" fill="3">
|
||||
<preferred-size width="150" height="50" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JTree" icon="/com/intellij/uiDesigner/icons/tree.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||
<preferred-size width="150" height="50" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JTabbedPane" icon="/com/intellij/uiDesigner/icons/tabbedPane.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
|
||||
<preferred-size width="200" height="200" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JSplitPane" icon="/com/intellij/uiDesigner/icons/splitPane.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
|
||||
<preferred-size width="200" height="200" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JSpinner" icon="/com/intellij/uiDesigner/icons/spinner.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
|
||||
</item>
|
||||
<item class="javax.swing.JSlider" icon="/com/intellij/uiDesigner/icons/slider.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
|
||||
</item>
|
||||
<item class="javax.swing.JSeparator" icon="/com/intellij/uiDesigner/icons/separator.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3" />
|
||||
</item>
|
||||
<item class="javax.swing.JProgressBar" icon="/com/intellij/uiDesigner/icons/progressbar.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1" />
|
||||
</item>
|
||||
<item class="javax.swing.JToolBar" icon="/com/intellij/uiDesigner/icons/toolbar.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1">
|
||||
<preferred-size width="-1" height="20" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JToolBar$Separator" icon="/com/intellij/uiDesigner/icons/toolbarSeparator.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="0" anchor="0" fill="1" />
|
||||
</item>
|
||||
<item class="javax.swing.JScrollBar" icon="/com/intellij/uiDesigner/icons/scrollbar.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="6" hsize-policy="0" anchor="0" fill="2" />
|
||||
</item>
|
||||
</group>
|
||||
</component>
|
||||
</project>
|
BIN
SelfPropelledArtilleryUnit_Hard/Resources/30px_arrow_down.png
Normal file
BIN
SelfPropelledArtilleryUnit_Hard/Resources/30px_arrow_down.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 244 B |
BIN
SelfPropelledArtilleryUnit_Hard/Resources/30px_arrow_left.png
Normal file
BIN
SelfPropelledArtilleryUnit_Hard/Resources/30px_arrow_left.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 249 B |
BIN
SelfPropelledArtilleryUnit_Hard/Resources/30px_arrow_right.png
Normal file
BIN
SelfPropelledArtilleryUnit_Hard/Resources/30px_arrow_right.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 254 B |
BIN
SelfPropelledArtilleryUnit_Hard/Resources/30px_arrow_up.png
Normal file
BIN
SelfPropelledArtilleryUnit_Hard/Resources/30px_arrow_up.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 257 B |
@ -0,0 +1,12 @@
|
||||
<?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$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/Resources" type="java-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
14
SelfPropelledArtilleryUnit_Hard/src/CrawlerRollersCount.java
Normal file
14
SelfPropelledArtilleryUnit_Hard/src/CrawlerRollersCount.java
Normal file
@ -0,0 +1,14 @@
|
||||
public enum CrawlerRollersCount {
|
||||
Four(4),
|
||||
Five(5),
|
||||
Six(6);
|
||||
|
||||
private int numOfRollers;
|
||||
CrawlerRollersCount(int numOfRollers){
|
||||
this.numOfRollers = numOfRollers;
|
||||
}
|
||||
public int getNumOfRollers(){
|
||||
return numOfRollers;
|
||||
}
|
||||
}
|
||||
|
6
SelfPropelledArtilleryUnit_Hard/src/DirectionType.java
Normal file
6
SelfPropelledArtilleryUnit_Hard/src/DirectionType.java
Normal file
@ -0,0 +1,6 @@
|
||||
public enum DirectionType {
|
||||
Up,
|
||||
Down,
|
||||
Left,
|
||||
Right
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
import java.awt.*;
|
||||
|
||||
public class DrawingCrawlerRollers {
|
||||
private CrawlerRollersCount rollersCount;
|
||||
public void setCrawlerRollersCount(int numOfRoller){
|
||||
for (CrawlerRollersCount numofenum : CrawlerRollersCount.values()){
|
||||
if (numofenum.getNumOfRollers() == numOfRoller){
|
||||
rollersCount = numofenum;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public CrawlerRollersCount getCrawlerRollersCount(){
|
||||
return rollersCount;
|
||||
}
|
||||
public void DrawRollers(Graphics g, int x, int y, int width, int height, Color bodyColor){
|
||||
g.setColor(bodyColor);
|
||||
g.fillOval(x, y, width, height);
|
||||
g.setColor(Color.BLACK);
|
||||
g.drawOval(x, y, width, height);
|
||||
g.setColor(bodyColor);
|
||||
}
|
||||
}
|
@ -0,0 +1,183 @@
|
||||
import java.awt.*;
|
||||
import java.util.Random;
|
||||
|
||||
public class DrawingSelfPropelledArtilleryUnit {
|
||||
private EntitySelfPropelledArtilleryUnit entitySelfPropelledArtilleryUnit;
|
||||
public DrawingCrawlerRollers drawingCrawlerRollers = null;
|
||||
private Integer pictureWidth;
|
||||
private Integer pictureHeight;
|
||||
private Integer _startPosX;
|
||||
private Integer _startPosY;
|
||||
private final int drawingSelfPropelledArtilleryUnitWidth = 100;
|
||||
private final int drawingSelfPropelledArtilleryUnitHeight = 50;
|
||||
private final int drawingKeelHeight = 35;
|
||||
private DrawingCrawlerRollers _drawingCrawlerRollers;
|
||||
public EntitySelfPropelledArtilleryUnit EntitySelfPropelledArtilleryUnit() {
|
||||
return entitySelfPropelledArtilleryUnit;
|
||||
}
|
||||
public void Init(int speed, double weight, Color bodyColor, Color additionalColor, boolean turretCannon, boolean launchBattery) {
|
||||
entitySelfPropelledArtilleryUnit = new EntitySelfPropelledArtilleryUnit();
|
||||
entitySelfPropelledArtilleryUnit.Init(speed, weight, bodyColor, additionalColor, turretCannon, launchBattery);
|
||||
pictureHeight = null;
|
||||
pictureWidth = null;
|
||||
_startPosX = null;
|
||||
_startPosY = null;
|
||||
drawingCrawlerRollers = new DrawingCrawlerRollers();
|
||||
Random random = new Random();
|
||||
int rand = random.nextInt(3,7);
|
||||
drawingCrawlerRollers.setCrawlerRollersCount(rand);
|
||||
}
|
||||
|
||||
public void setPictureSize(int width, int height) {
|
||||
pictureWidth = width;
|
||||
pictureHeight = height;
|
||||
}
|
||||
|
||||
public void setPosition(int x, int y) {
|
||||
if (pictureHeight == null || pictureWidth == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (x < 0) {
|
||||
x = 0;
|
||||
} else if (x - drawingSelfPropelledArtilleryUnitWidth >= pictureWidth) {
|
||||
x = pictureWidth - drawingSelfPropelledArtilleryUnitWidth - drawingSelfPropelledArtilleryUnitWidth;
|
||||
}
|
||||
|
||||
if (y - drawingKeelHeight < 0) {
|
||||
y = drawingKeelHeight;
|
||||
} else if (y - drawingSelfPropelledArtilleryUnitHeight >= pictureHeight) {
|
||||
y = pictureHeight - drawingSelfPropelledArtilleryUnitHeight - drawingSelfPropelledArtilleryUnitHeight;
|
||||
}
|
||||
|
||||
_startPosY = y;
|
||||
_startPosX = x;
|
||||
}
|
||||
|
||||
public boolean moveTransport(DirectionType direction) {
|
||||
if (entitySelfPropelledArtilleryUnit == null || _startPosX == null || _startPosY == null || pictureWidth == null || pictureHeight == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return switch (direction) {
|
||||
case Left -> {
|
||||
if (_startPosX - entitySelfPropelledArtilleryUnit.getStep() >= 0) {
|
||||
_startPosX -= (int) entitySelfPropelledArtilleryUnit.getStep();
|
||||
}
|
||||
yield true;
|
||||
}
|
||||
case Up -> {
|
||||
if (_startPosY - drawingKeelHeight - entitySelfPropelledArtilleryUnit.getStep() >= 0) {
|
||||
_startPosY -= (int) entitySelfPropelledArtilleryUnit.getStep();
|
||||
}
|
||||
yield true;
|
||||
}
|
||||
case Right -> {
|
||||
if (_startPosX + entitySelfPropelledArtilleryUnit.getStep() <= pictureWidth - drawingSelfPropelledArtilleryUnitWidth) {
|
||||
_startPosX += (int) entitySelfPropelledArtilleryUnit.getStep();
|
||||
}
|
||||
yield true;
|
||||
}
|
||||
case Down -> {
|
||||
if (_startPosY + entitySelfPropelledArtilleryUnit.getStep() <= pictureHeight - drawingSelfPropelledArtilleryUnitHeight + drawingKeelHeight) {
|
||||
_startPosY += (int) entitySelfPropelledArtilleryUnit.getStep();
|
||||
}
|
||||
yield true;
|
||||
}
|
||||
default -> false;
|
||||
};
|
||||
}
|
||||
|
||||
public void drawTransport(Graphics g) {
|
||||
if (entitySelfPropelledArtilleryUnit == null || _startPosX == null || _startPosY == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
Graphics2D g2d = (Graphics2D) g;
|
||||
g2d.setColor(Color.BLACK);
|
||||
g.drawOval(_startPosX + 0, _startPosY + 75, 30, 30);
|
||||
g.drawOval(_startPosX + 90, _startPosY + 75, 30, 30);
|
||||
g.drawRect(_startPosX + 15, _startPosY + 75, 90, 30);
|
||||
|
||||
//границы ЦВЕТ
|
||||
g.fillRect(_startPosX + 25, _startPosY + 40, 35, 30);//башня
|
||||
g.fillOval(_startPosX + 0, _startPosY + 75, 30, 30);
|
||||
g.fillOval(_startPosX + 90, _startPosY + 75, 30, 30);
|
||||
g.fillRect(_startPosX + 15, _startPosY + 75, 90, 30);
|
||||
|
||||
// границы арт. установки
|
||||
g.drawRect(_startPosX + 25, _startPosY + 40, 35, 30);
|
||||
g.drawRect(_startPosX + 0, _startPosY + 65, 120, 13);
|
||||
|
||||
// верхние катки ОТРИСОВКА
|
||||
g.drawOval(_startPosX + 30, _startPosY + 70, 20, 20);
|
||||
g.drawOval(_startPosX + 50, _startPosY + 70, 20, 20);
|
||||
g.drawOval(_startPosX + 70, _startPosY + 70, 20, 20);
|
||||
|
||||
//нижние катки ОТРИСОВКА
|
||||
g.drawOval(_startPosX + 30, _startPosY + 90, 15, 15);
|
||||
g.drawOval(_startPosX + 45, _startPosY + 90, 15, 15);
|
||||
g.drawOval(_startPosX + 60, _startPosY + 90, 15, 15);
|
||||
g.drawOval(_startPosX + 75, _startPosY + 90, 15, 15);
|
||||
|
||||
g.fillOval(_startPosX + 3, _startPosY + 78, 24, 24);
|
||||
g.fillOval(_startPosX + 93, _startPosY + 78, 24, 24);
|
||||
|
||||
int x = _startPosX;
|
||||
if (drawingCrawlerRollers.getCrawlerRollersCount() != null){
|
||||
switch (drawingCrawlerRollers.getCrawlerRollersCount()){
|
||||
case Four:
|
||||
drawingCrawlerRollers.DrawRollers(g,x + 15, _startPosY + 90, 15, 15, entitySelfPropelledArtilleryUnit.getBodyColor());
|
||||
break;
|
||||
case Five:
|
||||
drawingCrawlerRollers.DrawRollers(g,x + 15, _startPosY + 90, 15, 15, entitySelfPropelledArtilleryUnit.getBodyColor());
|
||||
drawingCrawlerRollers.DrawRollers(g,x + 90, _startPosY + 90, 15, 15, entitySelfPropelledArtilleryUnit.getBodyColor());
|
||||
break;
|
||||
case Six:
|
||||
drawingCrawlerRollers.DrawRollers(g,x + 15, _startPosY + 90, 15, 15, entitySelfPropelledArtilleryUnit.getBodyColor());
|
||||
drawingCrawlerRollers.DrawRollers(g,x + 90, _startPosY + 90, 15, 15, entitySelfPropelledArtilleryUnit.getBodyColor());
|
||||
drawingCrawlerRollers.DrawRollers(g,x + 90, _startPosY + 90, 15, 15, entitySelfPropelledArtilleryUnit.getBodyColor());
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
g2d.setColor(entitySelfPropelledArtilleryUnit.getBodyColor());
|
||||
// верхние катки ЦВЕТ
|
||||
g.fillOval(_startPosX + 30, _startPosY + 70, 20, 20);
|
||||
g.fillOval(_startPosX + 50, _startPosY + 70, 20, 20);
|
||||
g.fillOval(_startPosX + 70, _startPosY + 70, 20, 20);
|
||||
|
||||
//нижние катки ЦВЕТ
|
||||
g.fillOval(_startPosX + 30, _startPosY + 90, 15, 15);
|
||||
g.fillOval(_startPosX + 45, _startPosY + 90, 15, 15);
|
||||
g.fillOval(_startPosX + 60, _startPosY + 90, 15, 15);
|
||||
g.fillOval(_startPosX + 75, _startPosY + 90, 15, 15);
|
||||
|
||||
//Большие катки ОТРИСОВКА
|
||||
g.drawOval(_startPosX + 3, _startPosY + 78, 24, 24);
|
||||
g.drawOval(_startPosX + 93, _startPosY + 78, 24, 24);
|
||||
|
||||
g.fillRect(_startPosX + 0, _startPosY + 65, 120, 13);
|
||||
|
||||
|
||||
// Орудийная башня
|
||||
if (entitySelfPropelledArtilleryUnit.getTurretCannon()) {
|
||||
g.fillOval(_startPosX + 26, _startPosY + 35, 50, 30);
|
||||
g.fillRect(_startPosX + 25, _startPosY + 36, 20, 29);
|
||||
g.fillRect(_startPosX + 60, _startPosY + 45, 60, 5);
|
||||
g.fillOval(_startPosX + 113, _startPosY + 42, 20, 10);
|
||||
}
|
||||
g.setColor(Color.RED);
|
||||
// Пусковая батарея
|
||||
if (entitySelfPropelledArtilleryUnit.getLaunchBattery()) {
|
||||
g.fillRect(_startPosX + 0, _startPosY + 45, 20, 20);
|
||||
int[] xPoints = {_startPosX + 0, _startPosX + 0, _startPosX + 20, _startPosX + 20, _startPosX + 0};
|
||||
int[] yPoints = {_startPosY + 15, _startPosY + 65, _startPosY + 65, _startPosY + 45, _startPosY + 15};
|
||||
g.fillPolygon(xPoints, yPoints, 5);
|
||||
g.fillOval(_startPosX + 0, _startPosY + 5, 10, 30);
|
||||
g.fillRect(_startPosX + 10, _startPosY + 15, 20, 5);
|
||||
g.fillRect(_startPosX + 10, _startPosY + 25, 15, 5);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,48 @@
|
||||
import java.awt.*;
|
||||
|
||||
public class EntitySelfPropelledArtilleryUnit {
|
||||
private int Speed;
|
||||
public int getSpeed() {
|
||||
return Speed;
|
||||
}
|
||||
|
||||
private double Weight;
|
||||
|
||||
public double getWeight() {
|
||||
return Weight;
|
||||
}
|
||||
|
||||
private Color BodyColor;
|
||||
public Color getBodyColor() {
|
||||
return BodyColor;
|
||||
}
|
||||
|
||||
private Color AdditionalColor;
|
||||
public Color getAdditionalColor() {
|
||||
return AdditionalColor;
|
||||
}
|
||||
|
||||
private double Step;
|
||||
public double getStep() {
|
||||
return (double)Speed * 100 / Weight;
|
||||
}
|
||||
|
||||
private boolean TurretCannon;
|
||||
public boolean getTurretCannon() {
|
||||
return TurretCannon;
|
||||
}
|
||||
|
||||
private boolean LaunchBattery;
|
||||
public boolean getLaunchBattery() {
|
||||
return LaunchBattery;
|
||||
}
|
||||
|
||||
public void Init(int speed, double weight, Color bodyColor, Color additionalColor, boolean turretCannon, boolean launchBattery) {
|
||||
Speed = speed;
|
||||
Weight = weight;
|
||||
BodyColor = bodyColor;
|
||||
AdditionalColor = additionalColor;
|
||||
TurretCannon = turretCannon;
|
||||
LaunchBattery = launchBattery;
|
||||
}
|
||||
}
|
@ -0,0 +1,93 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="FormSelfPropelledArtilleryUnit">
|
||||
<grid id="27dc6" binding="PanelWrapper" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<constraints>
|
||||
<xy x="20" y="20" width="815" height="552"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<grid id="bc0ec" binding="PictureBox" layout-manager="GridLayoutManager" row-count="3" column-count="5" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<constraints>
|
||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<component id="3e40e" class="javax.swing.JButton" binding="buttonCreate">
|
||||
<constraints>
|
||||
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="Создать"/>
|
||||
</properties>
|
||||
</component>
|
||||
<hspacer id="46156">
|
||||
<constraints>
|
||||
<grid row="2" column="1" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
</hspacer>
|
||||
<vspacer id="1c39c">
|
||||
<constraints>
|
||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
</vspacer>
|
||||
<component id="ed753" class="javax.swing.JButton" binding="buttonRight">
|
||||
<constraints>
|
||||
<grid row="2" column="4" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="2" indent="0" use-parent-layout="false">
|
||||
<minimum-size width="30" height="30"/>
|
||||
<preferred-size width="30" height="30"/>
|
||||
<maximum-size width="30" height="30"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties>
|
||||
<icon value="30px_arrow_right.png"/>
|
||||
<text value=""/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="2fa29" class="javax.swing.JButton" binding="buttonDown">
|
||||
<constraints>
|
||||
<grid row="2" column="3" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false">
|
||||
<minimum-size width="30" height="30"/>
|
||||
<preferred-size width="30" height="30"/>
|
||||
<maximum-size width="30" height="30"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties>
|
||||
<icon value="30px_arrow_down.png"/>
|
||||
<text value=""/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="853ee" class="javax.swing.JButton" binding="buttonLeft">
|
||||
<constraints>
|
||||
<grid row="2" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="2" indent="0" use-parent-layout="false">
|
||||
<minimum-size width="30" height="30"/>
|
||||
<preferred-size width="30" height="30"/>
|
||||
<maximum-size width="30" height="30"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties>
|
||||
<icon value="30px_arrow_left.png"/>
|
||||
<text value=""/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="5a172" class="javax.swing.JButton" binding="buttonUp">
|
||||
<constraints>
|
||||
<grid row="1" column="3" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="2" indent="0" use-parent-layout="false">
|
||||
<minimum-size width="30" height="30"/>
|
||||
<preferred-size width="30" height="30"/>
|
||||
<maximum-size width="30" height="30"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties>
|
||||
<icon value="30px_arrow_up.png"/>
|
||||
<text value=""/>
|
||||
</properties>
|
||||
</component>
|
||||
</children>
|
||||
</grid>
|
||||
</children>
|
||||
</grid>
|
||||
</form>
|
@ -0,0 +1,107 @@
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
public class FormSelfPropelledArtilleryUnit {
|
||||
protected DrawingSelfPropelledArtilleryUnit _drawningSeaplane = new DrawingSelfPropelledArtilleryUnit();
|
||||
JPanel PanelWrapper;
|
||||
private JPanel PictureBox;
|
||||
private JButton buttonCreate;
|
||||
private JButton buttonRight;
|
||||
private JButton buttonLeft;
|
||||
private JButton buttonDown;
|
||||
private JButton buttonUp;
|
||||
|
||||
private List<JComponent> controls;
|
||||
public FormSelfPropelledArtilleryUnit() {
|
||||
buttonUp.setName("buttonUp");
|
||||
buttonDown.setName("buttonDown");
|
||||
buttonLeft.setName("buttonLeft");
|
||||
buttonRight.setName("buttonRight");
|
||||
|
||||
InitializeControlsRepaintList();
|
||||
|
||||
buttonCreate.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
_drawningSeaplane = new DrawingSelfPropelledArtilleryUnit();
|
||||
Random random = new Random();
|
||||
_drawningSeaplane.Init(random.nextInt(30, 100),
|
||||
random.nextInt(100, 500),
|
||||
new Color(random.nextInt(256), random.nextInt(256), random.nextInt(256)),
|
||||
new Color(random.nextInt(256), random.nextInt(256), random.nextInt(256)),
|
||||
random.nextBoolean(), random.nextBoolean() );
|
||||
_drawningSeaplane.setPictureSize(PictureBox.getWidth(), PictureBox.getHeight());
|
||||
_drawningSeaplane.setPosition(random.nextInt(35, 100),
|
||||
random.nextInt(35, 100));
|
||||
Draw();
|
||||
|
||||
}
|
||||
});
|
||||
ActionListener buttonMoveClickedListener = new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
String buttonName = ((JButton) e.getSource()).getName();
|
||||
boolean result = false;
|
||||
|
||||
switch (buttonName) {
|
||||
case "buttonUp": {
|
||||
result = _drawningSeaplane.moveTransport(DirectionType.Up);
|
||||
}
|
||||
break;
|
||||
case "buttonDown": {
|
||||
result = _drawningSeaplane.moveTransport(DirectionType.Down);
|
||||
}
|
||||
break;
|
||||
case "buttonLeft": {
|
||||
result = _drawningSeaplane.moveTransport(DirectionType.Left);
|
||||
}
|
||||
break;
|
||||
case "buttonRight": {
|
||||
result = _drawningSeaplane.moveTransport(DirectionType.Right);
|
||||
}
|
||||
break;
|
||||
|
||||
};
|
||||
|
||||
if (result) {
|
||||
Draw();
|
||||
};
|
||||
};
|
||||
};
|
||||
buttonRight.addActionListener(buttonMoveClickedListener);
|
||||
buttonDown.addActionListener(buttonMoveClickedListener);
|
||||
buttonLeft.addActionListener(buttonMoveClickedListener);
|
||||
buttonUp.addActionListener(buttonMoveClickedListener);
|
||||
|
||||
}
|
||||
private void Draw() {
|
||||
if (_drawningSeaplane.EntitySelfPropelledArtilleryUnit() == null) {
|
||||
return;
|
||||
}
|
||||
Graphics g = PictureBox.getGraphics();
|
||||
g.setColor(PictureBox.getBackground());
|
||||
g.fillRect(0,0, PictureBox.getWidth(), PictureBox.getHeight());
|
||||
_drawningSeaplane.drawTransport(g);
|
||||
|
||||
RepaintControls();
|
||||
}
|
||||
private void RepaintControls() {
|
||||
for (JComponent control : controls) {
|
||||
control.repaint();
|
||||
}
|
||||
}
|
||||
|
||||
private void InitializeControlsRepaintList() {
|
||||
controls = new LinkedList<>();
|
||||
controls.add(buttonCreate);
|
||||
controls.add(buttonUp);
|
||||
controls.add(buttonDown);
|
||||
controls.add(buttonLeft);
|
||||
controls.add(buttonRight);
|
||||
}
|
||||
}
|
14
SelfPropelledArtilleryUnit_Hard/src/Main.java
Normal file
14
SelfPropelledArtilleryUnit_Hard/src/Main.java
Normal file
@ -0,0 +1,14 @@
|
||||
import javax.swing.*;
|
||||
|
||||
public class Main {
|
||||
public static void main(String[] args) {
|
||||
JFrame.setDefaultLookAndFeelDecorated(false);
|
||||
JFrame frame = new JFrame("FormSeaplane");
|
||||
frame.setContentPane(new FormSelfPropelledArtilleryUnit().PanelWrapper);
|
||||
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
frame.setLocation(500, 200);
|
||||
frame.pack();
|
||||
frame.setSize(1000, 500);
|
||||
frame.setVisible(true);
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user