Compare commits
10 Commits
Author | SHA1 | Date | |
---|---|---|---|
785a3bbfc0 | |||
bac51aa40c | |||
a3c081c02a | |||
41dc8a4325 | |||
9bb10333ef | |||
e8a6638e15 | |||
3c072a98a3 | |||
4c828eed80 | |||
37b37b1fa1 | |||
fb10dd3a4a |
29
Tank/.gitignore
vendored
Normal file
29
Tank/.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
|
8
Tank/.idea/.gitignore
vendored
Normal file
8
Tank/.idea/.gitignore
vendored
Normal file
@ -0,0 +1,8 @@
|
||||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
||||
# Editor-based HTTP Client requests
|
||||
/httpRequests/
|
||||
# Datasource local storage ignored files
|
||||
/dataSources/
|
||||
/dataSources.local.xml
|
6
Tank/.idea/misc.xml
Normal file
6
Tank/.idea/misc.xml
Normal file
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_20" default="true" project-jdk-name="19" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/out" />
|
||||
</component>
|
||||
</project>
|
8
Tank/.idea/modules.xml
Normal file
8
Tank/.idea/modules.xml
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$/Tank.iml" filepath="$PROJECT_DIR$/Tank.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
124
Tank/.idea/uiDesigner.xml
Normal file
124
Tank/.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>
|
BIN
Tank/Resources/KeyDown.png
Normal file
BIN
Tank/Resources/KeyDown.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.4 KiB |
BIN
Tank/Resources/KeyLeft.png
Normal file
BIN
Tank/Resources/KeyLeft.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.2 KiB |
BIN
Tank/Resources/KeyRight.png
Normal file
BIN
Tank/Resources/KeyRight.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.3 KiB |
BIN
Tank/Resources/KeyUp.png
Normal file
BIN
Tank/Resources/KeyUp.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.2 KiB |
11
Tank/Tank.iml
Normal file
11
Tank/Tank.iml
Normal file
@ -0,0 +1,11 @@
|
||||
<?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$/src" isTestSource="false" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
93
Tank/src/AbstractStrategy.java
Normal file
93
Tank/src/AbstractStrategy.java
Normal file
@ -0,0 +1,93 @@
|
||||
public abstract class AbstractStrategy {
|
||||
// Перемещаемый объект
|
||||
private IMoveableObject _moveableObject;
|
||||
|
||||
// Статус перемещения
|
||||
private Status _state = Status.NotInit;
|
||||
|
||||
// Ширина поля
|
||||
protected int FieldWidth;
|
||||
|
||||
// Высота поля
|
||||
protected int FieldHeight;
|
||||
|
||||
// Статус перемещения
|
||||
public Status GetStatus() {
|
||||
return _state;
|
||||
}
|
||||
|
||||
// Установка данных
|
||||
public void SetData(IMoveableObject moveableObject, int width, int height) {
|
||||
if (moveableObject == null) {
|
||||
_state = Status.NotInit;
|
||||
return;
|
||||
}
|
||||
_state = Status.InProgress;
|
||||
_moveableObject = moveableObject;
|
||||
FieldWidth = width;
|
||||
FieldHeight = height;
|
||||
}
|
||||
|
||||
// Шаг перемещения
|
||||
public void MakeStep() {
|
||||
if (_state != Status.InProgress) {
|
||||
return;
|
||||
}
|
||||
if (IsTargetDestination()) {
|
||||
_state = Status.Finish;
|
||||
return;
|
||||
}
|
||||
MoveToTarget();
|
||||
}
|
||||
|
||||
// Перемещение влево
|
||||
protected boolean MoveLeft() {
|
||||
return MoveTo(Direction.Left);
|
||||
}
|
||||
|
||||
// Перемещение вправо
|
||||
protected boolean MoveRight() {
|
||||
return MoveTo(Direction.Right);
|
||||
}
|
||||
|
||||
// Перемещение вверх
|
||||
protected boolean MoveUp() {
|
||||
return MoveTo(Direction.Up);
|
||||
}
|
||||
|
||||
// Перемещение вниз
|
||||
protected boolean MoveDown() {
|
||||
return MoveTo(Direction.Down);
|
||||
}
|
||||
|
||||
// Параметры объекта
|
||||
protected ObjectParameters GetObjectParameters() {
|
||||
return _moveableObject.GetObjectPosition();
|
||||
}
|
||||
|
||||
// Шаг объекта
|
||||
protected int GetStep() {
|
||||
if (_state != Status.InProgress) {
|
||||
return 0;
|
||||
}
|
||||
return _moveableObject.GetStep();
|
||||
}
|
||||
|
||||
// Перемещение к цели
|
||||
protected abstract void MoveToTarget();
|
||||
|
||||
// Достигнута ли цель
|
||||
protected abstract boolean IsTargetDestination();
|
||||
|
||||
// Попытка перемещения в требуемом направлении
|
||||
private boolean MoveTo(Direction Direction) {
|
||||
if (_state != Status.InProgress) {
|
||||
return false;
|
||||
}
|
||||
if (_moveableObject.CheckCanMove(Direction)) {
|
||||
_moveableObject.MoveObject(Direction);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
13
Tank/src/CountWheels.java
Normal file
13
Tank/src/CountWheels.java
Normal file
@ -0,0 +1,13 @@
|
||||
public enum CountWheels {
|
||||
Two(2),
|
||||
Three(3),
|
||||
Four(4),
|
||||
Five(5);
|
||||
private final int Value;
|
||||
CountWheels(int Count){
|
||||
Value = Count;
|
||||
}
|
||||
public int getCountWheels(){
|
||||
return Value;
|
||||
}
|
||||
}
|
6
Tank/src/Direction.java
Normal file
6
Tank/src/Direction.java
Normal file
@ -0,0 +1,6 @@
|
||||
public enum Direction {
|
||||
Up,
|
||||
Left,
|
||||
Down,
|
||||
Right
|
||||
}
|
107
Tank/src/DrawingArmoVehicle.java
Normal file
107
Tank/src/DrawingArmoVehicle.java
Normal file
@ -0,0 +1,107 @@
|
||||
import java.awt.*;
|
||||
import java.util.Random;
|
||||
|
||||
public class DrawingArmoVehicle {
|
||||
protected IOrnamentForm OrnamentsForm;
|
||||
public EntityArmoVehicle ArmoVehicle;
|
||||
protected int _pictureWidth;
|
||||
protected int _pictureHeight;
|
||||
protected int _startPosX;
|
||||
protected int _startPosY;
|
||||
protected int _TankWidth = 160;
|
||||
protected int _TankHeight = 55;
|
||||
|
||||
public DrawingArmoVehicle(int speed, double weight, Color bodyColor, int _numWheel, int width, int height) {
|
||||
_pictureWidth = width;
|
||||
_pictureHeight = height;
|
||||
if (_pictureHeight < _TankHeight || _pictureWidth < _TankWidth)
|
||||
return;
|
||||
ArmoVehicle = new EntityArmoVehicle(speed, weight, bodyColor, _numWheel);
|
||||
|
||||
Random random = new Random();
|
||||
switch(random.nextInt(0, 3)) {
|
||||
case 0:
|
||||
OrnamentsForm = new DrawingWheelsCombination();
|
||||
break;
|
||||
case 1:
|
||||
OrnamentsForm = new DrawingStarOrnament();
|
||||
break;
|
||||
case 2:
|
||||
OrnamentsForm = new DrawingSuspensionOrnament();
|
||||
break;
|
||||
default:
|
||||
OrnamentsForm = new DrawingWheelsCombination();
|
||||
break;
|
||||
}
|
||||
OrnamentsForm.setDigit(_numWheel);
|
||||
}
|
||||
|
||||
public void SetPosition(int x, int y) {
|
||||
_startPosX = Math.min(x, _pictureWidth - _TankWidth);
|
||||
_startPosY = Math.min(y, _pictureHeight - _TankHeight);
|
||||
}
|
||||
|
||||
public int GetPosX (){ return _startPosX; }
|
||||
public int GetPosY (){ return _startPosY; }
|
||||
public int GetWidth (){ return _TankWidth; }
|
||||
public int GetHeight (){ return _TankHeight; }
|
||||
|
||||
public boolean CanMove(Direction direction) {
|
||||
if (ArmoVehicle == null) {
|
||||
return false;
|
||||
}
|
||||
switch (direction) {
|
||||
case Left:
|
||||
return _startPosX - ArmoVehicle.Step > 0;
|
||||
case Right:
|
||||
return _startPosX + _TankWidth + ArmoVehicle.Step < _pictureWidth;
|
||||
case Up:
|
||||
return _startPosY - ArmoVehicle.Step > 0;
|
||||
case Down:
|
||||
return _startPosY + _TankHeight + ArmoVehicle.Step < _pictureHeight;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public void MoveTransport(Direction direction) {
|
||||
if (!CanMove(direction) || ArmoVehicle == null) {
|
||||
return;
|
||||
}
|
||||
switch (direction) {
|
||||
//влево
|
||||
case Left:
|
||||
_startPosX -= (int)ArmoVehicle.Step;
|
||||
break;
|
||||
//вверх
|
||||
case Up:
|
||||
_startPosY -= (int)ArmoVehicle.Step;
|
||||
break;
|
||||
// вправо
|
||||
case Right:
|
||||
_startPosX += (int)ArmoVehicle.Step;
|
||||
break;
|
||||
//вниз
|
||||
case Down:
|
||||
_startPosY += (int)ArmoVehicle.Step;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void DrawTransport(Graphics2D g) {
|
||||
if (ArmoVehicle == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
// body
|
||||
g.setColor(ArmoVehicle.BodyColor);
|
||||
int[] xPoints = {_startPosX + 5, _startPosX + 140, _startPosX + 130,_startPosX + 12};
|
||||
int[] yPoints = {_startPosY + 30, _startPosY + 30, _startPosY + 42, _startPosY + 42};
|
||||
int nPoints = xPoints.length;
|
||||
g.drawPolygon(xPoints,yPoints,nPoints);
|
||||
g.fillPolygon(xPoints,yPoints,nPoints);
|
||||
|
||||
//wheels
|
||||
OrnamentsForm.Draw(g, _startPosX, _startPosY);
|
||||
}
|
||||
}
|
17
Tank/src/DrawingObjectTank.java
Normal file
17
Tank/src/DrawingObjectTank.java
Normal file
@ -0,0 +1,17 @@
|
||||
public class DrawingObjectTank implements IMoveableObject {
|
||||
private DrawingArmoVehicle _drawingArmoVehicle = null;
|
||||
public DrawingObjectTank(DrawingArmoVehicle drawingTank)
|
||||
{
|
||||
_drawingArmoVehicle = drawingTank;
|
||||
}
|
||||
public ObjectParameters GetObjectPosition() {
|
||||
if (_drawingArmoVehicle == null || _drawingArmoVehicle.ArmoVehicle == null) {
|
||||
return null;
|
||||
}
|
||||
return new ObjectParameters(_drawingArmoVehicle.GetPosX(),_drawingArmoVehicle.GetPosY(),
|
||||
_drawingArmoVehicle.GetWidth(), _drawingArmoVehicle.GetHeight());
|
||||
}
|
||||
public int GetStep(){ return (int)_drawingArmoVehicle.ArmoVehicle.Step; }
|
||||
public boolean CheckCanMove(Direction direction) { return _drawingArmoVehicle.CanMove(direction);}
|
||||
public void MoveObject(Direction direction) { _drawingArmoVehicle.MoveTransport(direction); }
|
||||
}
|
85
Tank/src/DrawingStarOrnament.java
Normal file
85
Tank/src/DrawingStarOrnament.java
Normal file
@ -0,0 +1,85 @@
|
||||
import java.awt.*;
|
||||
|
||||
public class DrawingStarOrnament implements IOrnamentForm {
|
||||
private CountWheels wheels;
|
||||
private Color StarColor;
|
||||
public CountWheels getNumWheel() {
|
||||
return wheels;
|
||||
}
|
||||
|
||||
public void setDigit(int number) {
|
||||
switch(number){
|
||||
case 2:
|
||||
wheels = CountWheels.Two;
|
||||
break;
|
||||
case 3:
|
||||
wheels = CountWheels.Three;
|
||||
break;
|
||||
case 4:
|
||||
wheels = CountWheels.Four;
|
||||
break;
|
||||
default:
|
||||
wheels = CountWheels.Two;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void CaterpillarStar(Graphics g, int _startPosX, int _startPosY) {
|
||||
StarColor = Color.RED;
|
||||
g.setColor(StarColor);
|
||||
int xPontsStar[] = {_startPosX + 15, _startPosX + 18, _startPosX + 21, _startPosX + 18, _startPosX + 19, _startPosX + 16, _startPosX + 12, _startPosX + 12, _startPosX + 11, _startPosX + 15, _startPosX + 16};
|
||||
int yPontsStar[] = {_startPosY + 35, _startPosY + 38, _startPosY + 38, _startPosY + 42, _startPosY + 45, _startPosY + 42, _startPosY + 45, _startPosY + 41, _startPosY + 38, _startPosY + 38, _startPosY + 35};
|
||||
g.drawPolygon(xPontsStar, yPontsStar, xPontsStar.length);
|
||||
g.fillPolygon(xPontsStar, yPontsStar, xPontsStar.length);
|
||||
}
|
||||
|
||||
public void DrawWheels(Graphics g, int _startPosX, int _startPosY){
|
||||
g.setColor(Color.BLACK);
|
||||
g.fillOval(10 + _startPosX, 42 + _startPosY, 20, 20);
|
||||
}
|
||||
public void Draw(Graphics g, int _startPosX, int _startPosY) {
|
||||
if (wheels == CountWheels.Two){
|
||||
DrawWheels(g,_startPosX, _startPosY);
|
||||
DrawWheels(g,_startPosX + 100, _startPosY);
|
||||
|
||||
CaterpillarStar(g,_startPosX + 5, _startPosY + 12);
|
||||
CaterpillarStar(g,_startPosX + 105, _startPosY + 12);
|
||||
}
|
||||
|
||||
if (wheels == CountWheels.Three) {
|
||||
DrawWheels(g,_startPosX, _startPosY);
|
||||
DrawWheels(g,_startPosX + 50, _startPosY);
|
||||
DrawWheels(g,_startPosX + 100, _startPosY);
|
||||
|
||||
CaterpillarStar(g,_startPosX + 5, _startPosY + 12);
|
||||
CaterpillarStar(g,_startPosX + 55, _startPosY + 12);
|
||||
CaterpillarStar(g,_startPosX + 105, _startPosY + 12);
|
||||
}
|
||||
|
||||
if (wheels == CountWheels.Four) {
|
||||
DrawWheels(g,_startPosX, _startPosY);
|
||||
DrawWheels(g,_startPosX + 25, _startPosY);
|
||||
DrawWheels(g,_startPosX + 50, _startPosY);
|
||||
DrawWheels(g,_startPosX + 100, _startPosY);
|
||||
|
||||
CaterpillarStar(g,_startPosX + 5, _startPosY + 12);
|
||||
CaterpillarStar(g,_startPosX + 30, _startPosY + 12);
|
||||
CaterpillarStar(g,_startPosX + 55, _startPosY + 12);
|
||||
CaterpillarStar(g,_startPosX + 105, _startPosY + 12);
|
||||
}
|
||||
|
||||
if(wheels == CountWheels.Five) {
|
||||
DrawWheels(g,_startPosX, _startPosY);
|
||||
DrawWheels(g,_startPosX + 25, _startPosY);
|
||||
DrawWheels(g,_startPosX + 50, _startPosY);
|
||||
DrawWheels(g,_startPosX + 75, _startPosY);
|
||||
DrawWheels(g,_startPosX + 100, _startPosY);
|
||||
|
||||
CaterpillarStar(g,_startPosX + 5, _startPosY + 12);
|
||||
CaterpillarStar(g,_startPosX + 30, _startPosY + 12);
|
||||
CaterpillarStar(g,_startPosX + 55, _startPosY + 12);
|
||||
CaterpillarStar(g,_startPosX + 80, _startPosY + 12);
|
||||
CaterpillarStar(g,_startPosX + 105, _startPosY + 12);
|
||||
}
|
||||
}
|
||||
}
|
70
Tank/src/DrawingSuspensionOrnament.java
Normal file
70
Tank/src/DrawingSuspensionOrnament.java
Normal file
@ -0,0 +1,70 @@
|
||||
import java.awt.*;
|
||||
|
||||
public class DrawingSuspensionOrnament implements IOrnamentForm {
|
||||
private CountWheels wheels;
|
||||
private Color SuspensionColor;
|
||||
public CountWheels getNumWheel() {
|
||||
return wheels;
|
||||
}
|
||||
|
||||
public void setDigit(int number) {
|
||||
switch(number){
|
||||
case 2:
|
||||
wheels = CountWheels.Two;
|
||||
break;
|
||||
case 3:
|
||||
wheels = CountWheels.Three;
|
||||
break;
|
||||
case 4:
|
||||
wheels = CountWheels.Four;
|
||||
break;
|
||||
default:
|
||||
wheels = CountWheels.Two;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void DrawWheels(Graphics g, int _startPosX, int _startPosY) {
|
||||
g.setColor(Color.BLACK);
|
||||
g.fillOval(10 + _startPosX, 42 + _startPosY, 20, 20);
|
||||
}
|
||||
|
||||
public void DrawSuspension(Graphics g, int _startPosX, int _startPosY) {
|
||||
SuspensionColor = Color.BLUE;
|
||||
g.setColor(SuspensionColor);
|
||||
g.fillRect(_startPosX + 27, _startPosY + 50, 10, 3);
|
||||
}
|
||||
|
||||
public void Draw(Graphics g, int _startPosX, int _startPosY) {
|
||||
if (wheels == CountWheels.Two) {
|
||||
DrawWheels(g,_startPosX, _startPosY);
|
||||
DrawWheels(g,_startPosX + 100, _startPosY);
|
||||
|
||||
DrawSuspension(g, _startPosX, _startPosY);
|
||||
DrawSuspension(g,_startPosX + 73, _startPosY);
|
||||
}
|
||||
|
||||
if (wheels == CountWheels.Three) {
|
||||
DrawWheels(g,_startPosX, _startPosY);
|
||||
DrawWheels(g,_startPosX + 50, _startPosY);
|
||||
DrawWheels(g,_startPosX + 100, _startPosY);
|
||||
|
||||
DrawSuspension(g, _startPosX, _startPosY);
|
||||
DrawSuspension(g,_startPosX + 24, _startPosY);
|
||||
DrawSuspension(g,_startPosX + 73, _startPosY);
|
||||
}
|
||||
|
||||
if (wheels == CountWheels.Four) {
|
||||
DrawWheels(g,_startPosX, _startPosY);
|
||||
DrawWheels(g,_startPosX + 25, _startPosY);
|
||||
DrawWheels(g,_startPosX + 50, _startPosY);
|
||||
DrawWheels(g,_startPosX + 75, _startPosY);
|
||||
DrawWheels(g,_startPosX + 100, _startPosY);
|
||||
|
||||
DrawSuspension(g, _startPosX, _startPosY);
|
||||
DrawSuspension(g,_startPosX + 24, _startPosY);
|
||||
DrawSuspension(g,_startPosX + 53, _startPosY);
|
||||
DrawSuspension(g,_startPosX + 73, _startPosY);
|
||||
}
|
||||
}
|
||||
}
|
62
Tank/src/DrawingTank.java
Normal file
62
Tank/src/DrawingTank.java
Normal file
@ -0,0 +1,62 @@
|
||||
import java.awt.*;
|
||||
|
||||
public class DrawingTank extends DrawingArmoVehicle {
|
||||
protected IOrnamentForm OrnamentsForm;
|
||||
private boolean OrnamentAdd;
|
||||
|
||||
public DrawingTank(int speed, double weight, Color bodyColor, int _numWheel, Color additionalColor, boolean bodyKit, boolean caterpillar, boolean tower, int width, int height, boolean ornamentAdd) {
|
||||
super(speed, weight, bodyColor, _numWheel, width, height);
|
||||
ArmoVehicle = new EntityTank(speed, weight, bodyColor, _numWheel, additionalColor, bodyKit, caterpillar, tower);
|
||||
_TankWidth = ((EntityTank)ArmoVehicle).BodyKit ? 169 : 83;
|
||||
|
||||
this.OrnamentAdd = ornamentAdd;
|
||||
}
|
||||
|
||||
// Установка позиции
|
||||
public void SetPosition(int x, int y) {
|
||||
_startPosX = Math.min(x, _pictureWidth-_TankWidth);
|
||||
_startPosY = Math.min(y, _pictureHeight-_TankHeight);
|
||||
}
|
||||
|
||||
private boolean setOrnamentAdd() { return OrnamentAdd; }
|
||||
|
||||
// Прорисовка объекта
|
||||
public void DrawTransport(Graphics2D g) {
|
||||
if (ArmoVehicle == null) {
|
||||
return;
|
||||
}
|
||||
super.DrawTransport(g);
|
||||
|
||||
if (((EntityTank) ArmoVehicle).BodyKit) {
|
||||
g.setColor(((EntityTank) ArmoVehicle).AdditionalColor);
|
||||
int[] xPointsBody = {_startPosX + 52, _startPosX + 52, _startPosX + 40, _startPosX + 15,_startPosX + 15, _startPosX + 60,_startPosX + 90,_startPosX + 120,_startPosX + 100,_startPosX + 95, _startPosX + 90};
|
||||
int[] yPointsBody = {_startPosY + 30, _startPosY + 27, _startPosY + 23, _startPosY + 18,_startPosY + 15, _startPosY + 11,_startPosY + 11,_startPosY + 20,_startPosY + 25,_startPosY + 27,_startPosY + 30};
|
||||
int nPointsBody = xPointsBody.length;
|
||||
|
||||
g.drawPolygon(xPointsBody,yPointsBody,nPointsBody);
|
||||
g.fillPolygon(xPointsBody,yPointsBody,nPointsBody);
|
||||
}
|
||||
|
||||
if (((EntityTank) ArmoVehicle).Caterpillar) {
|
||||
Color Gray = new Color(128, 128, 128);
|
||||
g.setColor(Gray);
|
||||
g.drawOval(_startPosX + 10, _startPosY + 30, 120, 30);
|
||||
}
|
||||
|
||||
if (((EntityTank) ArmoVehicle).Tower) {
|
||||
g.setColor(Color.DARK_GRAY);
|
||||
// Орудие
|
||||
g.drawRect(_startPosX + 112, _startPosY + 17, 60, 5);
|
||||
g.fillRect(_startPosX + 112, _startPosY + 17, 60, 5);
|
||||
|
||||
// Зенитное орудие
|
||||
int[] xPointsGun = {_startPosX + 45, _startPosX + 45, _startPosX + 41, _startPosX + 41, _startPosX + 42, _startPosX + 41, _startPosX + 44,_startPosX + 50 ,_startPosX + 52,_startPosX + 53, _startPosX + 58};
|
||||
int[] yPointsGun = {_startPosY + 12, _startPosY + 10, _startPosY + 8, _startPosY + 7, _startPosY + 5, _startPosY + 4,_startPosY + 3,_startPosY + 3,_startPosY + 5,_startPosY + 7,_startPosY + 10};
|
||||
int nPointsGun = xPointsGun.length;
|
||||
|
||||
g.fillRect(_startPosX + 50, _startPosY + 5, 20, 2);
|
||||
g.drawPolygon(xPointsGun,yPointsGun,nPointsGun);
|
||||
g.fillPolygon(xPointsGun,yPointsGun,nPointsGun);
|
||||
}
|
||||
}
|
||||
}
|
109
Tank/src/DrawingWheelsCombination.java
Normal file
109
Tank/src/DrawingWheelsCombination.java
Normal file
@ -0,0 +1,109 @@
|
||||
import java.awt.*;
|
||||
|
||||
public class DrawingWheelsCombination implements IOrnamentForm {
|
||||
private CountWheels wheels;
|
||||
private Color CombinationColor;
|
||||
public CountWheels getNumWheel() {
|
||||
return wheels;
|
||||
}
|
||||
|
||||
public void setDigit(int number) {
|
||||
switch(number) {
|
||||
case 2:
|
||||
wheels = CountWheels.Two;
|
||||
break;
|
||||
case 3:
|
||||
wheels = CountWheels.Three;
|
||||
break;
|
||||
case 4:
|
||||
wheels = CountWheels.Four;
|
||||
break;
|
||||
default:
|
||||
wheels = CountWheels.Two;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void CaterpillarStar(Graphics g, int _startPosX, int _startPosY) {
|
||||
CombinationColor = Color.RED;
|
||||
g.setColor(CombinationColor);
|
||||
int xPontsStar[] = {_startPosX + 15, _startPosX + 18, _startPosX + 21, _startPosX + 18, _startPosX + 19, _startPosX + 16, _startPosX + 12, _startPosX + 13, _startPosX + 12, _startPosX + 15, _startPosX + 16};
|
||||
int yPontsStar[] = {_startPosY + 35, _startPosY + 38, _startPosY + 38, _startPosY + 42, _startPosY + 45, _startPosY + 42, _startPosY + 45, _startPosY + 41, _startPosY + 38, _startPosY + 38, _startPosY + 35};
|
||||
g.drawPolygon(xPontsStar, yPontsStar, xPontsStar.length);
|
||||
g.fillPolygon(xPontsStar, yPontsStar, xPontsStar.length);
|
||||
}
|
||||
|
||||
public void DrawSuspension(Graphics g, int _startPosX, int _startPosY) {
|
||||
CombinationColor = Color.BLUE;
|
||||
g.setColor(CombinationColor);
|
||||
g.fillRect(_startPosX + 27, _startPosY + 50, 10, 3);
|
||||
}
|
||||
|
||||
public void DrawWheels(Graphics g, int _startPosX, int _startPosY){
|
||||
g.setColor(Color.BLACK);
|
||||
g.fillOval(10 + _startPosX, 42 + _startPosY, 20, 20);
|
||||
}
|
||||
|
||||
public void Draw(Graphics g, int _startPosX, int _startPosY) {
|
||||
if (wheels == CountWheels.Two){
|
||||
DrawWheels(g,_startPosX, _startPosY);
|
||||
DrawWheels(g,_startPosX + 100, _startPosY);
|
||||
|
||||
DrawSuspension(g, _startPosX, _startPosY);
|
||||
DrawSuspension(g,_startPosX + 73, _startPosY);
|
||||
|
||||
CaterpillarStar(g,_startPosX + 5, _startPosY + 12);
|
||||
CaterpillarStar(g,_startPosX + 105, _startPosY + 12);
|
||||
|
||||
}
|
||||
if (wheels == CountWheels.Three) {
|
||||
DrawWheels(g,_startPosX, _startPosY);
|
||||
DrawWheels(g,_startPosX + 50, _startPosY);
|
||||
DrawWheels(g,_startPosX + 100, _startPosY);
|
||||
|
||||
DrawSuspension(g, _startPosX, _startPosY);
|
||||
DrawSuspension(g,_startPosX + 24, _startPosY);
|
||||
DrawSuspension(g,_startPosX + 73, _startPosY);
|
||||
|
||||
CaterpillarStar(g,_startPosX + 5, _startPosY + 12);
|
||||
CaterpillarStar(g,_startPosX + 55, _startPosY + 12);
|
||||
CaterpillarStar(g,_startPosX + 105, _startPosY + 12);
|
||||
}
|
||||
|
||||
if (wheels == CountWheels.Four) {
|
||||
DrawWheels(g,_startPosX, _startPosY);
|
||||
DrawWheels(g,_startPosX + 25, _startPosY);
|
||||
DrawWheels(g,_startPosX + 50, _startPosY);
|
||||
DrawWheels(g,_startPosX + 100, _startPosY);
|
||||
|
||||
DrawSuspension(g, _startPosX, _startPosY);
|
||||
DrawSuspension(g,_startPosX + 24, _startPosY);
|
||||
DrawSuspension(g,_startPosX + 53, _startPosY);
|
||||
DrawSuspension(g,_startPosX + 73, _startPosY);
|
||||
|
||||
CaterpillarStar(g,_startPosX + 5, _startPosY + 12);
|
||||
CaterpillarStar(g,_startPosX + 30, _startPosY + 12);
|
||||
CaterpillarStar(g,_startPosX + 55, _startPosY + 12);
|
||||
CaterpillarStar(g,_startPosX + 105, _startPosY + 12);
|
||||
|
||||
}
|
||||
if(wheels == CountWheels.Five) {
|
||||
DrawWheels(g,_startPosX, _startPosY);
|
||||
DrawWheels(g,_startPosX + 25, _startPosY);
|
||||
DrawWheels(g,_startPosX + 50, _startPosY);
|
||||
DrawWheels(g,_startPosX + 75, _startPosY);
|
||||
DrawWheels(g,_startPosX + 100, _startPosY);
|
||||
|
||||
DrawSuspension(g, _startPosX, _startPosY);
|
||||
DrawSuspension(g,_startPosX + 24, _startPosY);
|
||||
DrawSuspension(g,_startPosX + 53, _startPosY);
|
||||
DrawSuspension(g,_startPosX + 73, _startPosY);
|
||||
|
||||
CaterpillarStar(g,_startPosX + 5, _startPosY + 12);
|
||||
CaterpillarStar(g,_startPosX + 30, _startPosY + 12);
|
||||
CaterpillarStar(g,_startPosX + 55, _startPosY + 12);
|
||||
CaterpillarStar(g,_startPosX + 80, _startPosY + 12);
|
||||
CaterpillarStar(g,_startPosX + 105, _startPosY + 12);
|
||||
}
|
||||
}
|
||||
}
|
17
Tank/src/EntityArmoVehicle.java
Normal file
17
Tank/src/EntityArmoVehicle.java
Normal file
@ -0,0 +1,17 @@
|
||||
import java.awt.*;
|
||||
|
||||
public class EntityArmoVehicle {
|
||||
public int Speed;
|
||||
public double Weight;
|
||||
public Color BodyColor;
|
||||
public double Step;
|
||||
public int numWheel;
|
||||
|
||||
public EntityArmoVehicle(int speed, double weight, Color bodyColor, int _numWheel) {
|
||||
Speed = speed;
|
||||
Weight = weight;
|
||||
BodyColor = bodyColor;
|
||||
numWheel = _numWheel;
|
||||
Step = (double) Speed * 200 / Weight;
|
||||
}
|
||||
}
|
19
Tank/src/EntityTank.java
Normal file
19
Tank/src/EntityTank.java
Normal file
@ -0,0 +1,19 @@
|
||||
import java.awt.*;
|
||||
|
||||
public class EntityTank extends EntityArmoVehicle {
|
||||
public Color AdditionalColor;
|
||||
public boolean BodyKit;
|
||||
public boolean Caterpillar;
|
||||
public boolean Tower;
|
||||
|
||||
public EntityTank(int speed, double weight, Color bodyColor, int _numWheel, Color additionalColor, boolean bodyKit, boolean caterpillar, boolean tower) {
|
||||
super(speed, weight, bodyColor, _numWheel);
|
||||
AdditionalColor = additionalColor;
|
||||
BodyKit = bodyKit;
|
||||
Caterpillar = caterpillar;
|
||||
Tower = tower;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
198
Tank/src/FormTank.java
Normal file
198
Tank/src/FormTank.java
Normal file
@ -0,0 +1,198 @@
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.util.Random;
|
||||
|
||||
public class FormTank {
|
||||
private DrawingArmoVehicle _drawingArmoVehicle;
|
||||
private AbstractStrategy abstractStrategy;
|
||||
Canvas canv;
|
||||
static int pictureBoxWidth = 980;
|
||||
static int pictureBoxHeight = 560;
|
||||
|
||||
public void Draw() {
|
||||
canv.repaint();
|
||||
}
|
||||
|
||||
public FormTank() {
|
||||
JFrame Frame = new JFrame("Tank");
|
||||
JButton buttonCreateArmoVehicle = new JButton("Создать Бронемашину");
|
||||
JButton buttonCreateTank = new JButton("Создать Танк");
|
||||
JButton buttonStrategysStep = new JButton("Шаг");
|
||||
JComboBox ComboBoxStrategy = new JComboBox(new String[]{"к центру", "к краю формочки"});
|
||||
|
||||
Icon iconUp = new ImageIcon("Tank//Resources//KeyUp.png");
|
||||
JButton up = new JButton(iconUp);
|
||||
up.setName("up");
|
||||
|
||||
Icon iconDown = new ImageIcon("Tank//Resources//KeyDown.png");
|
||||
JButton down = new JButton(iconDown);
|
||||
down.setName("down");
|
||||
|
||||
Icon iconRight = new ImageIcon("Tank//Resources//KeyRight.png");
|
||||
JButton right = new JButton(iconRight);
|
||||
right.setName("right");
|
||||
|
||||
Icon iconLeft = new ImageIcon("Tank//Resources//KeyLeft.png");
|
||||
JButton left = new JButton(iconLeft);
|
||||
left.setName("left");
|
||||
|
||||
buttonStrategysStep.addActionListener(
|
||||
new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
if (_drawingArmoVehicle == null) {
|
||||
return;
|
||||
}
|
||||
if (ComboBoxStrategy.isEnabled()) {
|
||||
switch (ComboBoxStrategy.getSelectedIndex()) {
|
||||
case 0:
|
||||
abstractStrategy = new MoveToCenter();
|
||||
break;
|
||||
case 1:
|
||||
abstractStrategy = new MoveToBorder();
|
||||
break;
|
||||
default:
|
||||
abstractStrategy = null;
|
||||
break;
|
||||
}
|
||||
|
||||
if (abstractStrategy == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
abstractStrategy.SetData(new
|
||||
DrawingObjectTank(_drawingArmoVehicle), pictureBoxWidth, pictureBoxHeight);
|
||||
ComboBoxStrategy.setEnabled(false);
|
||||
}
|
||||
if (abstractStrategy == null) {
|
||||
return;
|
||||
}
|
||||
abstractStrategy.MakeStep();
|
||||
Draw();
|
||||
if (abstractStrategy.GetStatus() == Status.Finish) {
|
||||
ComboBoxStrategy.setEnabled(true);
|
||||
abstractStrategy = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
buttonCreateTank.addActionListener(
|
||||
new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
Random random = new Random();
|
||||
_drawingArmoVehicle = new DrawingTank(
|
||||
random.nextInt(100, 300),
|
||||
random.nextInt(1000, 3000),
|
||||
new Color(random.nextInt(0, 256), random.nextInt(0, 256), random.nextInt(0, 256)),
|
||||
random.nextInt(2, 6),
|
||||
new Color(random.nextInt(0, 256), random.nextInt(0, 256), random.nextInt(0, 256)),
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
pictureBoxWidth,
|
||||
pictureBoxHeight,
|
||||
true
|
||||
);
|
||||
_drawingArmoVehicle.SetPosition(random.nextInt(10, 100), random.nextInt(10, 100));
|
||||
canv._drawingArmoVehicle = _drawingArmoVehicle;
|
||||
Draw();
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
buttonCreateArmoVehicle.addActionListener(
|
||||
new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
Random random = new Random();
|
||||
_drawingArmoVehicle = new DrawingArmoVehicle(
|
||||
random.nextInt(100, 300),
|
||||
random.nextInt(1000, 3000),
|
||||
new Color(random.nextInt(0, 256), random.nextInt(0, 256), random.nextInt(0, 256)),
|
||||
random.nextInt(2, 5),
|
||||
1000,
|
||||
560);
|
||||
_drawingArmoVehicle.SetPosition(random.nextInt(10, 100), random.nextInt(10, 100));
|
||||
canv._drawingArmoVehicle = _drawingArmoVehicle;
|
||||
Draw();
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
ActionListener actioListener = new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
if (_drawingArmoVehicle == null) {
|
||||
return;
|
||||
}
|
||||
switch (((JButton) (e.getSource())).getName()) {
|
||||
case "up":
|
||||
_drawingArmoVehicle.MoveTransport(Direction.Up);
|
||||
break;
|
||||
case "down":
|
||||
_drawingArmoVehicle.MoveTransport(Direction.Down);
|
||||
break;
|
||||
case "left":
|
||||
_drawingArmoVehicle.MoveTransport(Direction.Left);
|
||||
break;
|
||||
case "right":
|
||||
_drawingArmoVehicle.MoveTransport(Direction.Right);
|
||||
break;
|
||||
}
|
||||
Draw();
|
||||
}
|
||||
};
|
||||
|
||||
up.addActionListener(actioListener);
|
||||
down.addActionListener(actioListener);
|
||||
left.addActionListener(actioListener);
|
||||
right.addActionListener(actioListener);
|
||||
|
||||
Frame.setSize(1000, 600);
|
||||
Frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
Frame.setLayout(null);
|
||||
canv = new Canvas();
|
||||
canv.setBounds(0, 0, pictureBoxWidth, pictureBoxHeight);
|
||||
|
||||
buttonCreateArmoVehicle.setBounds(5, 500, 170, 40);
|
||||
buttonCreateTank.setBounds(185, 500, 170, 40);
|
||||
|
||||
up.setBounds(900, 480, 40, 40);
|
||||
down.setBounds(900, 520, 40, 40);
|
||||
left.setBounds(860, 520, 40, 40);
|
||||
right.setBounds(940, 520, 40, 40);
|
||||
|
||||
ComboBoxStrategy.setBounds(pictureBoxWidth - 150, 20, 150, 20);
|
||||
buttonStrategysStep.setBounds(pictureBoxWidth - 150, 45, 150, 20);
|
||||
|
||||
Frame.add(canv);
|
||||
Frame.add(buttonCreateArmoVehicle);
|
||||
Frame.add(buttonCreateTank);
|
||||
Frame.add(up);
|
||||
Frame.add(down);
|
||||
Frame.add(left);
|
||||
Frame.add(right);
|
||||
|
||||
Frame.add(ComboBoxStrategy);
|
||||
Frame.add(buttonStrategysStep);
|
||||
|
||||
Frame.setVisible(true);
|
||||
}
|
||||
}
|
||||
|
||||
class Canvas extends JComponent {
|
||||
public DrawingArmoVehicle _drawingArmoVehicle;
|
||||
|
||||
public Canvas() {
|
||||
}
|
||||
|
||||
public void paintComponent(Graphics g) {
|
||||
if (_drawingArmoVehicle == null) {
|
||||
return;
|
||||
}
|
||||
super.paintComponents(g);
|
||||
Graphics2D g2d = (Graphics2D) g;
|
||||
_drawingArmoVehicle.DrawTransport(g2d);
|
||||
super.repaint();
|
||||
}
|
||||
}
|
13
Tank/src/IMoveableObject.java
Normal file
13
Tank/src/IMoveableObject.java
Normal file
@ -0,0 +1,13 @@
|
||||
public interface IMoveableObject {
|
||||
// Получение координаты X объекта
|
||||
ObjectParameters GetObjectPosition();
|
||||
|
||||
// Шаг объекта
|
||||
int GetStep();
|
||||
|
||||
// Проверка, можно ли переместиться по нужному направлению
|
||||
boolean CheckCanMove(Direction direction);
|
||||
|
||||
/// Изменение направления пермещения объекта
|
||||
void MoveObject(Direction direction);
|
||||
}
|
7
Tank/src/IOrnamentForm.java
Normal file
7
Tank/src/IOrnamentForm.java
Normal file
@ -0,0 +1,7 @@
|
||||
import java.awt.*;
|
||||
|
||||
public interface IOrnamentForm {
|
||||
public CountWheels getNumWheel();
|
||||
void setDigit(int number);
|
||||
void Draw(Graphics g, int _startPosX, int _startPosY);
|
||||
}
|
5
Tank/src/Main.java
Normal file
5
Tank/src/Main.java
Normal file
@ -0,0 +1,5 @@
|
||||
public class Main {
|
||||
public static void main(String[] args) {
|
||||
new FormTank();
|
||||
}
|
||||
}
|
36
Tank/src/MoveToBorder.java
Normal file
36
Tank/src/MoveToBorder.java
Normal file
@ -0,0 +1,36 @@
|
||||
public class MoveToBorder extends AbstractStrategy{
|
||||
protected boolean IsTargetDestination() {
|
||||
var objParams = GetObjectParameters();
|
||||
if (objParams == null) {
|
||||
return false;
|
||||
}
|
||||
return objParams.RightBorder() <= FieldWidth &&
|
||||
objParams.RightBorder() + GetStep() >= FieldWidth &&
|
||||
objParams.DownBorder() <= FieldHeight &&
|
||||
objParams.DownBorder() + GetStep() >= FieldHeight;
|
||||
}
|
||||
protected void MoveToTarget() {
|
||||
var objParams = GetObjectParameters();
|
||||
if (objParams == null) {
|
||||
return;
|
||||
}
|
||||
var diffX = objParams.RightBorder() - FieldWidth;
|
||||
if (Math.abs(diffX) > GetStep()) {
|
||||
if (diffX > 0) {
|
||||
MoveLeft();
|
||||
}
|
||||
else {
|
||||
MoveRight();
|
||||
}
|
||||
}
|
||||
var diffY = objParams.DownBorder() - FieldHeight;
|
||||
if (Math.abs(diffY) > GetStep()) {
|
||||
if (diffY > 0) {
|
||||
MoveUp();
|
||||
}
|
||||
else {
|
||||
MoveDown();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
35
Tank/src/MoveToCenter.java
Normal file
35
Tank/src/MoveToCenter.java
Normal file
@ -0,0 +1,35 @@
|
||||
public class MoveToCenter extends AbstractStrategy {
|
||||
protected boolean IsTargetDestination() {
|
||||
var objParams = GetObjectParameters();
|
||||
if (objParams == null) {
|
||||
return false;
|
||||
}
|
||||
return
|
||||
Math.abs(objParams.ObjectMiddleHorizontal() - FieldWidth / 2) <= GetStep()
|
||||
&&
|
||||
Math.abs(objParams.ObjectMiddleVertical() - FieldHeight / 2) <= GetStep();
|
||||
}
|
||||
|
||||
protected void MoveToTarget() {
|
||||
var objParams = GetObjectParameters();
|
||||
if (objParams == null) {
|
||||
return;
|
||||
}
|
||||
var diffX = objParams.ObjectMiddleHorizontal() - FieldWidth / 2;
|
||||
if (Math.abs(diffX) > GetStep()) {
|
||||
if (diffX > 0) {
|
||||
MoveLeft();
|
||||
} else {
|
||||
MoveRight();
|
||||
}
|
||||
}
|
||||
var diffY = objParams.ObjectMiddleVertical() - FieldHeight / 2;
|
||||
if (Math.abs(diffY) > GetStep()) {
|
||||
if (diffY > 0) {
|
||||
MoveUp();
|
||||
} else {
|
||||
MoveDown();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
44
Tank/src/ObjectParameters.java
Normal file
44
Tank/src/ObjectParameters.java
Normal file
@ -0,0 +1,44 @@
|
||||
public class ObjectParameters {
|
||||
private int _x;
|
||||
private int _y;
|
||||
private int _width;
|
||||
private int _height;
|
||||
|
||||
// Левая граница
|
||||
public int LeftBorder() {
|
||||
return _x;
|
||||
}
|
||||
|
||||
// Верхняя граница
|
||||
public int TopBorder() {
|
||||
return _y;
|
||||
}
|
||||
|
||||
// Правая граница
|
||||
public int RightBorder() {
|
||||
return _x + _width;
|
||||
}
|
||||
|
||||
// Нижняя граница
|
||||
public int DownBorder() {
|
||||
return _y + _height;
|
||||
}
|
||||
|
||||
// Середина объекта
|
||||
public int ObjectMiddleHorizontal() {
|
||||
return _x + _width / 2;
|
||||
}
|
||||
|
||||
// Середина объекта
|
||||
public int ObjectMiddleVertical() {
|
||||
return _y + _height / 2;
|
||||
}
|
||||
|
||||
// Конструктор
|
||||
public ObjectParameters(int x, int y, int width, int height) {
|
||||
_x = x;
|
||||
_y = y;
|
||||
_width = width;
|
||||
_height = height;
|
||||
}
|
||||
}
|
5
Tank/src/Status.java
Normal file
5
Tank/src/Status.java
Normal file
@ -0,0 +1,5 @@
|
||||
public enum Status {
|
||||
NotInit,
|
||||
InProgress,
|
||||
Finish
|
||||
}
|
Loading…
Reference in New Issue
Block a user