Compare commits
21 Commits
Author | SHA1 | Date | |
---|---|---|---|
807990537b | |||
ceee7cf028 | |||
65e66e99be | |||
81e02f1e3c | |||
fd6d48d3f1 | |||
c960ca3f0d | |||
4918afa089 | |||
e4074db762 | |||
8d447ae26d | |||
101e7291a0 | |||
fad7731fa2 | |||
5ee42860b1 | |||
ccfa42bf48 | |||
7640caf855 | |||
3e1f894eb1 | |||
576f76a841 | |||
cb0819b008 | |||
e839721bae | |||
6636194584 | |||
9648850f1d | |||
7a5f91114c |
47
.gitignore
vendored
47
.gitignore
vendored
@ -1,26 +1,29 @@
|
||||
# ---> Java
|
||||
# Compiled class file
|
||||
*.class
|
||||
### IntelliJ IDEA ###
|
||||
out/
|
||||
!**/src/main/**/out/
|
||||
!**/src/test/**/out/
|
||||
|
||||
# Log file
|
||||
*.log
|
||||
### Eclipse ###
|
||||
.apt_generated
|
||||
.classpath
|
||||
.factorypath
|
||||
.project
|
||||
.settings
|
||||
.springBeans
|
||||
.sts4-cache
|
||||
bin/
|
||||
!**/src/main/**/bin/
|
||||
!**/src/test/**/bin/
|
||||
|
||||
# BlueJ files
|
||||
*.ctxt
|
||||
### NetBeans ###
|
||||
/nbproject/private/
|
||||
/nbbuild/
|
||||
/dist/
|
||||
/nbdist/
|
||||
/.nb-gradle/
|
||||
|
||||
# Mobile Tools for Java (J2ME)
|
||||
.mtj.tmp/
|
||||
|
||||
# Package Files #
|
||||
*.jar
|
||||
*.war
|
||||
*.nar
|
||||
*.ear
|
||||
*.zip
|
||||
*.tar.gz
|
||||
*.rar
|
||||
|
||||
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
|
||||
hs_err_pid*
|
||||
replay_pid*
|
||||
### VS Code ###
|
||||
.vscode/
|
||||
|
||||
### Mac OS ###
|
||||
.DS_Store
|
3
.idea/.gitignore
vendored
Normal file
3
.idea/.gitignore
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
11
.idea/PIbd_23_Kislitsa_E.D_AirFighter_Hard.iml
Normal file
11
.idea/PIbd_23_Kislitsa_E.D_AirFighter_Hard.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>
|
5
.idea/misc.xml
Normal file
5
.idea/misc.xml
Normal file
@ -0,0 +1,5 @@
|
||||
<project version="4">
|
||||
<component name="ProjectRootManager" version="2" project-jdk-name="19" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/out" />
|
||||
</component>
|
||||
</project>
|
8
.idea/modules.xml
Normal file
8
.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$/.idea/PIbd_23_Kislitsa_E.D_AirFighter_Hard.iml" filepath="$PROJECT_DIR$/.idea/PIbd_23_Kislitsa_E.D_AirFighter_Hard.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
124
.idea/uiDesigner.xml
Normal file
124
.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>
|
6
.idea/vcs.xml
Normal file
6
.idea/vcs.xml
Normal file
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
BIN
DownButton.png
Normal file
BIN
DownButton.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 532 B |
BIN
LeftButton.png
Normal file
BIN
LeftButton.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 740 B |
BIN
RightButton.png
Normal file
BIN
RightButton.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 843 B |
BIN
UpButton.png
Normal file
BIN
UpButton.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.0 KiB |
8
src/DirectionType.java
Normal file
8
src/DirectionType.java
Normal file
@ -0,0 +1,8 @@
|
||||
package src;
|
||||
public enum DirectionType {
|
||||
Up,
|
||||
Down,
|
||||
Left,
|
||||
Right
|
||||
|
||||
}
|
82
src/DrawningObjects/DrawningAirFighter.java
Normal file
82
src/DrawningObjects/DrawningAirFighter.java
Normal file
@ -0,0 +1,82 @@
|
||||
package src.DrawningObjects;
|
||||
import src.Entities.EntityAirplane;
|
||||
import src.Entities.EntityAirFighter;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
public class DrawningAirFighter extends DrawningAirplane {
|
||||
public DrawningAirFighter(int speed, double weight, Color bodyColor, Color additionalColor,
|
||||
boolean dopwings, boolean rackets, int width, int height) {
|
||||
super(speed, weight, bodyColor, width, height);
|
||||
if (EntityAirplane != null) {
|
||||
EntityAirplane = new EntityAirFighter(speed, weight, bodyColor, additionalColor, dopwings, rackets);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void DrawAirplane(Graphics2D g2d) {
|
||||
if (!(EntityAirplane instanceof EntityAirFighter)) {
|
||||
return;
|
||||
}
|
||||
super.DrawAirplane(g2d);
|
||||
EntityAirFighter _airplaneAirFighter = (EntityAirFighter) EntityAirplane;
|
||||
if (_airplaneAirFighter.Racket()) {
|
||||
g2d.setColor(Color.GRAY);
|
||||
g2d.fillRect(_startPosX + 70, _startPosY - 15, 10, 10);
|
||||
g2d.setColor(Color.BLACK);
|
||||
g2d.drawRect(_startPosX + 70, _startPosY - 15, 10, 10);
|
||||
int[] xPointsArrNoseRacket = {_startPosX + 70, _startPosX + 70, _startPosX + 60};
|
||||
int[] yPointsArrNoseRacket = {_startPosY - 5, _startPosY - 15, _startPosY - 10};
|
||||
|
||||
g2d.setColor(Color.RED);
|
||||
g2d.fillPolygon(xPointsArrNoseRacket, yPointsArrNoseRacket, xPointsArrNoseRacket.length);
|
||||
g2d.setColor(Color.BLACK);
|
||||
g2d.drawPolygon(xPointsArrNoseRacket, yPointsArrNoseRacket, xPointsArrNoseRacket.length);
|
||||
g2d.setColor(Color.GRAY);
|
||||
g2d.fillRect(_startPosX + 70, _startPosY - 40, 10, 10);
|
||||
g2d.setColor(Color.BLACK);
|
||||
g2d.drawRect(_startPosX + 70, _startPosY - 40, 10, 10);
|
||||
int[] xPoints2ArrNoseRacket = {_startPosX + 70, _startPosX + 70, _startPosX + 60};
|
||||
int[] yPoints2ArrNoseRacket = {_startPosY - 30, _startPosY - 40, _startPosY - 35};
|
||||
g2d.setColor(Color.RED);
|
||||
g2d.fillPolygon(xPoints2ArrNoseRacket, yPoints2ArrNoseRacket, xPoints2ArrNoseRacket.length);
|
||||
g2d.setColor(Color.BLACK);
|
||||
g2d.drawPolygon(xPoints2ArrNoseRacket, yPoints2ArrNoseRacket, xPoints2ArrNoseRacket.length);
|
||||
|
||||
g2d.setColor(Color.GRAY);
|
||||
g2d.fillRect(_startPosX + 70, _startPosY + 59, 10, 10);
|
||||
g2d.setColor(Color.BLACK);
|
||||
g2d.drawRect(_startPosX + 70, _startPosY + 59, 10, 10);
|
||||
int[] xPoints3ArrNoseRacket = {_startPosX + 70, _startPosX + 70, _startPosX + 60};
|
||||
int[] yPoints3ArrNoseRacket = {_startPosY + 59, _startPosY + 69, _startPosY + 64};
|
||||
g2d.setColor(Color.RED);
|
||||
g2d.fillPolygon(xPoints3ArrNoseRacket, yPoints3ArrNoseRacket, xPoints3ArrNoseRacket.length);
|
||||
g2d.setColor(Color.BLACK);
|
||||
g2d.drawPolygon(xPoints3ArrNoseRacket, yPoints3ArrNoseRacket, xPoints3ArrNoseRacket.length);
|
||||
|
||||
g2d.setColor(Color.GRAY);
|
||||
g2d.fillRect(_startPosX + 70, _startPosY + 34, 10, 10);
|
||||
g2d.setColor(Color.BLACK);
|
||||
g2d.drawRect(_startPosX + 70, _startPosY + 34, 10, 10);
|
||||
int[] xPoints4ArrNoseRacket = {_startPosX + 70, _startPosX + 70, _startPosX + 60};
|
||||
int[] yPoints4ArrNoseRacket = {_startPosY + 34, _startPosY + 44, _startPosY + 39};
|
||||
g2d.setColor(Color.RED);
|
||||
g2d.fillPolygon(xPoints4ArrNoseRacket, yPoints4ArrNoseRacket, xPoints4ArrNoseRacket.length);
|
||||
g2d.setColor(Color.BLACK);
|
||||
g2d.drawPolygon(xPoints4ArrNoseRacket, yPoints4ArrNoseRacket, xPoints4ArrNoseRacket.length);
|
||||
|
||||
}
|
||||
if (_airplaneAirFighter.DopWing()) {
|
||||
g2d.setColor(_airplaneAirFighter.AdditionalColor());
|
||||
int[] xPointsrightdopwing = {_startPosX + 30, _startPosX + 30, _startPosX + 35, _startPosX + 45};
|
||||
int[] yPointsrightdopwing = {_startPosY + 4, _startPosY - 34, _startPosY - 34, _startPosY + 4};
|
||||
g2d.fillPolygon(xPointsrightdopwing, yPointsrightdopwing, xPointsrightdopwing.length);
|
||||
|
||||
int[] xPointsleftdopwing = {_startPosX + 30,_startPosX + 30,_startPosX+35,_startPosX+45};
|
||||
int[] yPointsleftdopwing = {_startPosY + 24,_startPosY + 59,_startPosY + 59,_startPosY + 24};
|
||||
g2d.fillPolygon(xPointsleftdopwing,yPointsleftdopwing,xPointsleftdopwing.length);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
177
src/DrawningObjects/DrawningAirplane.java
Normal file
177
src/DrawningObjects/DrawningAirplane.java
Normal file
@ -0,0 +1,177 @@
|
||||
package src.DrawningObjects;
|
||||
|
||||
import java.awt.*;
|
||||
import java.util.Random;
|
||||
import src.DirectionType;
|
||||
import src.MovementStrategy.DrawningObjectAirplane;
|
||||
import src.MovementStrategy.IMoveableObject;
|
||||
import src.Entities.EntityAirplane;
|
||||
public class DrawningAirplane {
|
||||
|
||||
protected EntityAirplane EntityAirplane;
|
||||
public int _pictureWidth;
|
||||
public int _pictureHeight;
|
||||
protected int _startPosX = 0;
|
||||
protected int _startPosY = 0;
|
||||
private int _airplaneWidth = 160;
|
||||
private int _airplaneHeight = 160;
|
||||
private int _airplanekorpusHeight = 90;
|
||||
protected IDraw DrawningEngines;
|
||||
|
||||
public EntityAirplane EntityAirplane(){
|
||||
return EntityAirplane;
|
||||
}
|
||||
public DrawningAirplane(int speed, double weight, Color bodyColor, int width, int height){
|
||||
if(width <= _airplaneWidth || height <= _airplaneHeight)
|
||||
return;
|
||||
_startPosY=70;
|
||||
_startPosX = 0;
|
||||
_pictureWidth = width;
|
||||
_pictureHeight = height;
|
||||
EntityAirplane = new EntityAirplane(speed, weight, bodyColor);
|
||||
DrawningEngines = new DrawningEngines(_airplaneWidth, _airplaneHeight,_startPosX,_startPosY);
|
||||
Random rand = new Random();
|
||||
int variant = rand.nextInt(0,3);
|
||||
if(variant ==0){
|
||||
DrawningEngines = new DrawningEngines(_airplaneWidth, _airplaneHeight,_startPosX,_startPosY);
|
||||
} else{
|
||||
if(variant ==1){
|
||||
DrawningEngines = new DrawningEnginesQuad(_airplaneWidth, _airplaneHeight,_startPosX,_startPosY);
|
||||
|
||||
}
|
||||
else if(variant==2) {
|
||||
DrawningEngines = new DrawningEnginesOval(_airplaneWidth, _airplaneHeight, _startPosX, _startPosY);
|
||||
}
|
||||
}
|
||||
DrawningEngines.ChangeEnginesNumb(rand.nextInt(1, 5));
|
||||
}
|
||||
|
||||
public void SetPosition(int x, int y){
|
||||
if(EntityAirplane == null)
|
||||
return;
|
||||
_startPosX = x;
|
||||
_startPosY = y;
|
||||
DrawningEngines.ChangeX(_startPosX);
|
||||
DrawningEngines.ChangeY(_startPosY);
|
||||
if (x + _airplaneWidth >= _pictureWidth || y + _airplaneHeight >= _pictureHeight) {
|
||||
_startPosX = 0;
|
||||
_startPosY = 70;
|
||||
}
|
||||
}
|
||||
public int GetPosX(){return _startPosX;}
|
||||
public int GetPosY(){return _startPosY;}
|
||||
public int GetWidth(){return _airplaneWidth;}
|
||||
public int GetHeight(){return _airplaneHeight;}
|
||||
public boolean CanMove(DirectionType direction)
|
||||
{
|
||||
if (EntityAirplane == null)
|
||||
return false;
|
||||
boolean can = false;
|
||||
switch (direction)
|
||||
{
|
||||
case Left:
|
||||
can = _startPosX - EntityAirplane.Step() >= 0;
|
||||
break;
|
||||
case Right:
|
||||
can = _startPosX + EntityAirplane.Step() + _airplaneWidth< _pictureWidth;
|
||||
break;
|
||||
case Down:
|
||||
can = _startPosY + EntityAirplane.Step() + _airplanekorpusHeight < _pictureHeight;
|
||||
break;
|
||||
case Up:
|
||||
can = _startPosY - EntityAirplane.Step() - _airplaneHeight >= 0;
|
||||
break;
|
||||
};
|
||||
return can;
|
||||
}
|
||||
public IMoveableObject GetMoveableObject(){
|
||||
return new DrawningObjectAirplane(this);
|
||||
}
|
||||
public void MoveTransport(DirectionType direction){
|
||||
if (!CanMove(direction) || EntityAirplane == null)
|
||||
return;
|
||||
switch (direction)
|
||||
{
|
||||
case Left:
|
||||
if (_startPosX - EntityAirplane.Step() >= 0)
|
||||
_startPosX -= (int)EntityAirplane.Step();
|
||||
else
|
||||
_startPosX = 0;
|
||||
break;
|
||||
case Up:
|
||||
if (_startPosY - EntityAirplane.Step() - _airplaneHeight >= 0)
|
||||
_startPosY -= (int)EntityAirplane.Step();
|
||||
else
|
||||
_startPosY = 0;
|
||||
break;
|
||||
case Right:
|
||||
if (_startPosX + EntityAirplane.Step() + _airplaneWidth < _pictureWidth)
|
||||
_startPosX += (int)EntityAirplane.Step();
|
||||
else
|
||||
_startPosX = _pictureWidth - _airplaneWidth;
|
||||
break;
|
||||
case Down:
|
||||
if (_startPosY + EntityAirplane.Step() + _airplaneHeight < _pictureHeight)
|
||||
_startPosY += (int)EntityAirplane.Step();
|
||||
else
|
||||
_startPosY = _pictureHeight - _airplaneHeight;
|
||||
break;
|
||||
}
|
||||
DrawningEngines.ChangeX(_startPosX);
|
||||
DrawningEngines.ChangeY(_startPosY);
|
||||
}
|
||||
public void DrawAirplane(Graphics2D g2d){
|
||||
|
||||
if (EntityAirplane == null)
|
||||
return;
|
||||
DrawningEngines.DrawEngines(g2d);
|
||||
//тело самолёта
|
||||
g2d.setColor(EntityAirplane.BodyColor());
|
||||
g2d.fillRect(_startPosX + 20,_startPosY +4,140,20);
|
||||
g2d.setColor(Color.BLACK);
|
||||
g2d.drawRect(_startPosX + 20,_startPosY +4,140,20);
|
||||
//Нос самолёта
|
||||
int[] xPointsArrNose = {_startPosX + 20,_startPosX + 20,_startPosX-3};
|
||||
int[] yPointsArrNose = {_startPosY + 4,_startPosY + 24,_startPosY + 12};
|
||||
g2d.setColor(Color.BLACK);
|
||||
g2d.fillPolygon(xPointsArrNose, yPointsArrNose, xPointsArrNose.length);
|
||||
g2d.setColor(Color.BLACK);
|
||||
g2d.drawPolygon(xPointsArrNose, yPointsArrNose, xPointsArrNose.length);
|
||||
|
||||
// Правое крыло
|
||||
int[] xPointsArrRightWing = {_startPosX + 80,_startPosX+80,_startPosX+85,_startPosX + 100};
|
||||
int[] yPointsArrRightWing = { _startPosY + 4,_startPosY - 66,_startPosY - 66, _startPosY + 4 };
|
||||
g2d.setColor(EntityAirplane.BodyColor());
|
||||
g2d.fillPolygon(xPointsArrRightWing, yPointsArrRightWing, xPointsArrRightWing.length);
|
||||
g2d.setColor(Color.BLACK);
|
||||
g2d.drawPolygon(xPointsArrRightWing, yPointsArrRightWing, xPointsArrRightWing.length);
|
||||
|
||||
// Левое крыло
|
||||
int[] xPointsArrLeftWing = {_startPosX + 80,_startPosX + 100,_startPosX+85,_startPosX+80};
|
||||
int[] yPointsArrLeftWing = {_startPosY + 24,_startPosY + 24,_startPosY + 94,_startPosY + 94};
|
||||
g2d.setColor(EntityAirplane.BodyColor());
|
||||
g2d.fillPolygon(xPointsArrLeftWing, yPointsArrLeftWing, xPointsArrLeftWing.length);
|
||||
g2d.setColor(Color.BLACK);
|
||||
g2d.drawPolygon(xPointsArrLeftWing, yPointsArrLeftWing, xPointsArrLeftWing.length);
|
||||
|
||||
// Правое задние крыло
|
||||
int[] xPointsArrRightBackWing={_startPosX + 140,_startPosX + 160,_startPosX+160,_startPosX+140};
|
||||
int[] yPointsArrRightBackWing={ _startPosY + 4,_startPosY + 4,_startPosY - 22,_startPosY -4};
|
||||
g2d.setColor(EntityAirplane.BodyColor());
|
||||
g2d.fillPolygon(xPointsArrRightBackWing, yPointsArrRightBackWing, xPointsArrRightBackWing.length);
|
||||
g2d.setColor(Color.BLACK);
|
||||
g2d.drawPolygon(xPointsArrRightBackWing, yPointsArrRightBackWing, xPointsArrRightBackWing.length);
|
||||
// Заднее левое крыло
|
||||
int[] xPointsArrLeftBackWing= {_startPosX + 140,_startPosX + 160,_startPosX+160,_startPosX+140};
|
||||
int[] yPointsArrLeftBackWing= {_startPosY + 24,_startPosY + 24,_startPosY + 50,_startPosY + 32};
|
||||
g2d.setColor(EntityAirplane.BodyColor());
|
||||
g2d.fillPolygon(xPointsArrLeftBackWing, yPointsArrLeftBackWing, xPointsArrLeftBackWing.length);
|
||||
g2d.setColor(Color.BLACK);
|
||||
g2d.drawPolygon(xPointsArrLeftBackWing, yPointsArrLeftBackWing, xPointsArrLeftBackWing.length);
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
54
src/DrawningObjects/DrawningEngines.java
Normal file
54
src/DrawningObjects/DrawningEngines.java
Normal file
@ -0,0 +1,54 @@
|
||||
package src.DrawningObjects;
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import src.NumberType;
|
||||
|
||||
public class DrawningEngines implements IDraw {
|
||||
|
||||
private NumberType EngineNumb;
|
||||
private int Width, Height;
|
||||
private Color EngineColor;
|
||||
public int CurX, CurY;
|
||||
public DrawningEngines(int width, int height,int curX, int curY){
|
||||
Width = width;
|
||||
Height = height;
|
||||
CurX = curX;
|
||||
CurY = curY;
|
||||
EngineColor = Color.BLACK;
|
||||
}
|
||||
public void ChangeX(int x){
|
||||
CurX = x;
|
||||
}
|
||||
public void ChangeY(int y){
|
||||
CurY = y;
|
||||
}
|
||||
public void ChangeEnginesNumb(int x){
|
||||
if(x <= 1)
|
||||
EngineNumb = NumberType.Two;
|
||||
if(x == 2)
|
||||
EngineNumb = NumberType.Four;
|
||||
if(x >= 3)
|
||||
EngineNumb = NumberType.Six;
|
||||
}
|
||||
public NumberType EngineNumb(){
|
||||
return EngineNumb;
|
||||
}
|
||||
public void DrawEngines(Graphics2D g2d){
|
||||
g2d.setColor(EngineColor);
|
||||
g2d.fillOval(CurX + 92,CurY - 15,25,10 );
|
||||
g2d.fillOval(CurX + 92,CurY + 34,25,10 );
|
||||
|
||||
if (EngineNumb == NumberType.Four || EngineNumb == NumberType.Six)
|
||||
{
|
||||
g2d.fillOval(CurX + 86,CurY - 40,25,10 );
|
||||
|
||||
g2d.fillOval(CurX + 86,CurY +59,25,10 );
|
||||
}
|
||||
|
||||
if (EngineNumb == NumberType.Six)
|
||||
{
|
||||
g2d.fillOval(CurX + 128,CurY -7,25,10 );
|
||||
g2d.fillOval(CurX + 128,CurY +25,25,10 );
|
||||
}
|
||||
}
|
||||
}
|
52
src/DrawningObjects/DrawningEnginesOval.java
Normal file
52
src/DrawningObjects/DrawningEnginesOval.java
Normal file
@ -0,0 +1,52 @@
|
||||
package src.DrawningObjects;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
public class DrawningEnginesOval implements IDraw{
|
||||
private src.NumberType EngineNumb;
|
||||
private int Width, Height;
|
||||
private Color EngineColor;
|
||||
public int CurX, CurY;
|
||||
public DrawningEnginesOval(int width, int height,int curX, int curY){
|
||||
Width = width;
|
||||
Height = height;
|
||||
CurX = curX;
|
||||
CurY = curY;
|
||||
EngineColor = Color.BLACK;
|
||||
}
|
||||
public void ChangeX(int x){
|
||||
CurX = x;
|
||||
}
|
||||
public void ChangeY(int y){
|
||||
CurY = y;
|
||||
}
|
||||
public void ChangeEnginesNumb(int x){
|
||||
if(x <= 1)
|
||||
EngineNumb = src.NumberType.Two;
|
||||
if(x == 2)
|
||||
EngineNumb = src.NumberType.Four;
|
||||
if(x >= 3)
|
||||
EngineNumb = src.NumberType.Six;
|
||||
}
|
||||
public src.NumberType EngineNumb(){
|
||||
return EngineNumb;
|
||||
}
|
||||
public void DrawEngines(Graphics2D g2d){
|
||||
g2d.setColor(EngineColor);
|
||||
g2d.drawOval(CurX + 92,CurY - 15,25,10 );
|
||||
g2d.drawOval(CurX + 92,CurY + 34,25,10 );
|
||||
|
||||
if (EngineNumb == src.NumberType.Four || EngineNumb == src.NumberType.Six)
|
||||
{
|
||||
g2d.drawOval(CurX + 86,CurY - 40,25,10 );
|
||||
|
||||
g2d.drawOval(CurX + 86,CurY +59,25,10 );
|
||||
}
|
||||
|
||||
if (EngineNumb == src.NumberType.Six)
|
||||
{
|
||||
g2d.drawOval(CurX + 128,CurY -7,25,10 );
|
||||
g2d.drawOval(CurX + 128,CurY +25,25,10 );
|
||||
}
|
||||
}
|
||||
}
|
55
src/DrawningObjects/DrawningEnginesQuad.java
Normal file
55
src/DrawningObjects/DrawningEnginesQuad.java
Normal file
@ -0,0 +1,55 @@
|
||||
package src.DrawningObjects;
|
||||
|
||||
import src.NumberType;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
|
||||
public class DrawningEnginesQuad implements IDraw {
|
||||
private src.NumberType EngineNumb;
|
||||
private int Width, Height;
|
||||
private Color EngineColor;
|
||||
public int CurX, CurY;
|
||||
public DrawningEnginesQuad(int width, int height, int curX, int curY){
|
||||
Width = width;
|
||||
Height = height;
|
||||
CurX = curX;
|
||||
CurY = curY;
|
||||
EngineColor = Color.BLACK;
|
||||
}
|
||||
public void ChangeX(int x){
|
||||
CurX = x;
|
||||
}
|
||||
public void ChangeY(int y){
|
||||
CurY = y;
|
||||
}
|
||||
public void ChangeEnginesNumb(int x){
|
||||
if(x <= 1)
|
||||
EngineNumb = src.NumberType.Two;
|
||||
if(x == 2)
|
||||
EngineNumb = src.NumberType.Four;
|
||||
if(x >= 3)
|
||||
EngineNumb = src.NumberType.Six;
|
||||
}
|
||||
public src.NumberType EngineNumb(){
|
||||
return EngineNumb;
|
||||
}
|
||||
public void DrawEngines(Graphics2D g2d){
|
||||
g2d.setColor(EngineColor);
|
||||
g2d.fillRect(CurX + 92,CurY - 15,25,10 );
|
||||
g2d.fillRect(CurX + 92,CurY + 34,25,10 );
|
||||
|
||||
if (EngineNumb == src.NumberType.Four || EngineNumb == src.NumberType.Six)
|
||||
{
|
||||
g2d.fillRect(CurX + 86,CurY - 40,25,10 );
|
||||
|
||||
g2d.fillRect(CurX + 86,CurY +59,25,10 );
|
||||
}
|
||||
|
||||
if (EngineNumb == src.NumberType.Six)
|
||||
{
|
||||
g2d.fillRect(CurX + 128,CurY -7,25,10 );
|
||||
g2d.fillRect(CurX + 128,CurY +25,25,10 );
|
||||
}
|
||||
}
|
||||
}
|
9
src/DrawningObjects/IDraw.java
Normal file
9
src/DrawningObjects/IDraw.java
Normal file
@ -0,0 +1,9 @@
|
||||
package src.DrawningObjects;
|
||||
import src.NumberType;
|
||||
import java.awt.*;
|
||||
public interface IDraw {
|
||||
public void ChangeEnginesNumb(int x);
|
||||
public void DrawEngines(Graphics2D g2d);
|
||||
public void ChangeX(int x);
|
||||
public void ChangeY(int y);
|
||||
}
|
24
src/Entities/EntityAirFighter.java
Normal file
24
src/Entities/EntityAirFighter.java
Normal file
@ -0,0 +1,24 @@
|
||||
package src.Entities;
|
||||
import java.awt.*;
|
||||
|
||||
public class EntityAirFighter extends EntityAirplane {
|
||||
private Color BodyColor;
|
||||
private Color AdditionalColor;
|
||||
private boolean DopWing;
|
||||
private boolean Racket;
|
||||
public Color AdditionalColor(){return AdditionalColor;}
|
||||
public Color BodyColor(){
|
||||
return BodyColor;
|
||||
}
|
||||
public boolean Racket(){return Racket;}
|
||||
public boolean DopWing(){return DopWing;}
|
||||
public EntityAirFighter(int speed, double weight, Color bodyColor, Color additionalColor,
|
||||
boolean racket, boolean dopwing){
|
||||
super(speed, weight, bodyColor);
|
||||
|
||||
BodyColor = bodyColor;
|
||||
AdditionalColor=additionalColor;
|
||||
Racket = racket;
|
||||
DopWing= dopwing;
|
||||
}
|
||||
}
|
26
src/Entities/EntityAirplane.java
Normal file
26
src/Entities/EntityAirplane.java
Normal file
@ -0,0 +1,26 @@
|
||||
package src.Entities;
|
||||
import java.awt.*;
|
||||
|
||||
public class EntityAirplane {
|
||||
private int Speed;
|
||||
private double Weight, Step;
|
||||
private Color BodyColor;
|
||||
public int Speed(){
|
||||
return Speed;
|
||||
}
|
||||
public double Weight(){
|
||||
return Weight;
|
||||
}
|
||||
public double Step(){
|
||||
return Step;
|
||||
}
|
||||
public Color BodyColor(){
|
||||
return BodyColor;
|
||||
}
|
||||
public EntityAirplane(int speed, double weight, Color bodyColor){
|
||||
Speed = speed;
|
||||
Weight = weight;
|
||||
Step = (double)Speed * 100 / Weight;
|
||||
BodyColor = bodyColor;
|
||||
}
|
||||
}
|
230
src/FormAirFighter.java
Normal file
230
src/FormAirFighter.java
Normal file
@ -0,0 +1,230 @@
|
||||
package src;
|
||||
|
||||
import src.DrawningObjects.DrawningAirplane;
|
||||
|
||||
import src.MovementStrategy.*;
|
||||
import src.DrawningObjects.DrawningAirFighter;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.util.Random;
|
||||
|
||||
public class FormAirFighter {
|
||||
private DrawningAirplane DrawningAirplane;
|
||||
private AbstractStrategy _abstractStrategy;
|
||||
|
||||
public JButton buttonSelect;
|
||||
|
||||
public JFrame AirplaneFrame;
|
||||
Canvas canv;
|
||||
static int pictureBoxWidth = 902;
|
||||
static int pictureBoxHeight = 453;
|
||||
public Color ChooseColor(JFrame AirplaneFrame){
|
||||
JColorChooser dialog = new JColorChooser();
|
||||
Color res = JColorChooser.showDialog(AirplaneFrame, "Выберите цвет", Color.WHITE);
|
||||
return res;
|
||||
}
|
||||
|
||||
public DrawningAirplane SelectedAirplane(){
|
||||
return DrawningAirplane;
|
||||
}
|
||||
public void Draw(){
|
||||
if(DrawningAirplane == null)
|
||||
return;
|
||||
canv.repaint();
|
||||
}
|
||||
public void ChangeAirplane(DrawningAirplane newAirplane){
|
||||
newAirplane.SetPosition(0,70);
|
||||
DrawningAirplane = newAirplane;
|
||||
canv.DrawningAirplane = DrawningAirplane;
|
||||
|
||||
}
|
||||
public FormAirFighter(){
|
||||
AirplaneFrame =new JFrame ();
|
||||
JButton buttonCreate = new JButton("Создать");
|
||||
JButton buttonCreateAirFighter = new JButton("Создать боевой самлоёт");
|
||||
JButton buttonStep = new JButton("Шаг");
|
||||
buttonSelect = new JButton ("Выбрать");
|
||||
JComboBox comboBoxStrategy = new JComboBox(
|
||||
new String[]{
|
||||
"Довести до центра",
|
||||
"Довести до края",
|
||||
});
|
||||
JButton UpButton = new JButton();
|
||||
UpButton.setIcon(new ImageIcon("UpButton.jpg"));
|
||||
JButton DownButton = new JButton();
|
||||
DownButton.setIcon(new ImageIcon("DownButton.jpg"));
|
||||
JButton LeftButton = new JButton();
|
||||
LeftButton.setIcon(new ImageIcon("LeftButton.jpg"));
|
||||
JButton RightButton = new JButton();
|
||||
RightButton.setIcon(new ImageIcon("RightButton.jpg"));
|
||||
buttonStep.addActionListener(
|
||||
new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e){
|
||||
if (DrawningAirplane == 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
|
||||
DrawningObjectAirplane(DrawningAirplane), pictureBoxWidth,
|
||||
pictureBoxHeight);
|
||||
comboBoxStrategy.setEnabled(false);
|
||||
}
|
||||
if (_abstractStrategy == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_abstractStrategy.MakeStep();
|
||||
Draw();
|
||||
if (_abstractStrategy.GetStatus() == Status.Finish)
|
||||
{
|
||||
comboBoxStrategy.setEnabled(true);
|
||||
_abstractStrategy = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
buttonCreate.addActionListener(
|
||||
new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
Random random = new Random();
|
||||
Color color = new Color(random.nextInt(0, 256), random.nextInt(0, 256), random.nextInt(0, 256));
|
||||
Color choosen = ChooseColor(AirplaneFrame);
|
||||
if(choosen != null){
|
||||
color = choosen;
|
||||
}
|
||||
DrawningAirplane = new DrawningAirplane(random.nextInt(100, 300), random.nextDouble(1000, 3000),
|
||||
color,
|
||||
pictureBoxWidth, pictureBoxHeight);
|
||||
canv.DrawningAirplane = DrawningAirplane;
|
||||
comboBoxStrategy.enable(true);
|
||||
Draw();
|
||||
}
|
||||
}
|
||||
);
|
||||
buttonCreateAirFighter.addActionListener(
|
||||
new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e){
|
||||
Random random = new Random();
|
||||
Color color = new Color(random.nextInt(0, 256), random.nextInt(0, 256), random.nextInt(0, 256));
|
||||
Color additionalColor = new Color(random.nextInt(0, 256), random.nextInt(0, 256), random.nextInt(0, 256));
|
||||
Color choosen = ChooseColor(AirplaneFrame);
|
||||
if(choosen != null){
|
||||
color = choosen;
|
||||
}
|
||||
choosen = ChooseColor(AirplaneFrame);
|
||||
if(choosen != null){
|
||||
additionalColor = choosen;
|
||||
}
|
||||
DrawningAirplane = new DrawningAirFighter(random.nextInt(100, 300), random.nextDouble(1000, 3000),
|
||||
color,
|
||||
additionalColor,
|
||||
random.nextBoolean(), random.nextBoolean(),
|
||||
pictureBoxWidth, pictureBoxHeight);
|
||||
canv.DrawningAirplane = DrawningAirplane;
|
||||
comboBoxStrategy.enable(true);
|
||||
Draw();
|
||||
}
|
||||
}
|
||||
);
|
||||
RightButton.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
if(DrawningAirplane.EntityAirplane() == null) {
|
||||
return;
|
||||
}
|
||||
DrawningAirplane.MoveTransport(DirectionType.Right);
|
||||
Draw();
|
||||
}
|
||||
});
|
||||
LeftButton.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
if(DrawningAirplane.EntityAirplane() == null)
|
||||
return;
|
||||
DrawningAirplane.MoveTransport(DirectionType.Left);
|
||||
Draw();
|
||||
}
|
||||
});
|
||||
UpButton.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
if(DrawningAirplane.EntityAirplane() == null)
|
||||
return;
|
||||
DrawningAirplane.MoveTransport(DirectionType.Up);
|
||||
Draw();
|
||||
}
|
||||
});
|
||||
DownButton.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
if(DrawningAirplane.EntityAirplane() == null)
|
||||
return;
|
||||
DrawningAirplane.MoveTransport(DirectionType.Down);
|
||||
Draw();
|
||||
}
|
||||
});
|
||||
|
||||
AirplaneFrame.setSize (900, 500);
|
||||
AirplaneFrame.setDefaultCloseOperation (JFrame.DISPOSE_ON_CLOSE);
|
||||
AirplaneFrame.setLayout(null);
|
||||
canv = new Canvas();
|
||||
canv.setSize(pictureBoxWidth, pictureBoxHeight);
|
||||
buttonSelect.setBounds(383,401, 180, 40);
|
||||
buttonCreate.setBounds(198, 401, 180, 40);
|
||||
buttonCreateAirFighter.setBounds(12, 401, 180, 40);
|
||||
RightButton.setBounds(840,411,30,30);
|
||||
LeftButton.setBounds(768,411,30,30);
|
||||
UpButton.setBounds(804,375,30,30);
|
||||
DownButton.setBounds(804,411,30,30);
|
||||
comboBoxStrategy.setBounds(719,12,151,28);
|
||||
buttonStep.setBounds(768, 46, 94, 29);
|
||||
AirplaneFrame.add(canv);
|
||||
AirplaneFrame.add(buttonCreate);
|
||||
AirplaneFrame.add(buttonCreateAirFighter);
|
||||
AirplaneFrame.add(UpButton);
|
||||
AirplaneFrame.add(DownButton);
|
||||
AirplaneFrame.add(LeftButton);
|
||||
AirplaneFrame.add(RightButton);
|
||||
AirplaneFrame.add(comboBoxStrategy);
|
||||
AirplaneFrame.add(buttonStep);
|
||||
AirplaneFrame.add(buttonSelect);
|
||||
AirplaneFrame.setVisible(true);
|
||||
}
|
||||
}
|
||||
class Canvas extends JComponent{
|
||||
public DrawningAirplane DrawningAirplane;
|
||||
public Canvas(){
|
||||
}
|
||||
public void paintComponent (Graphics g){
|
||||
if (DrawningAirplane == null){
|
||||
return;
|
||||
}
|
||||
super.paintComponents (g) ;
|
||||
Graphics2D g2d = (Graphics2D)g;
|
||||
DrawningAirplane.DrawAirplane(g2d);
|
||||
super.repaint();
|
||||
}
|
||||
}
|
||||
|
207
src/FormAirFighterCollection.java
Normal file
207
src/FormAirFighterCollection.java
Normal file
@ -0,0 +1,207 @@
|
||||
package src;
|
||||
|
||||
import src.DrawningObjects.DrawningAirplane;
|
||||
import src.Generics.AirplaneGenericCollection;
|
||||
import src.FormAirFighter;
|
||||
import src.Generics.AirplaneGenericStorage;
|
||||
import src.Generics.AirplaneTrashCollection;
|
||||
import src.MovementStrategy.DrawningObjectAirplane;
|
||||
import src.MovementStrategy.IMoveableObject;
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.util.List;
|
||||
|
||||
public class FormAirFighterCollection {
|
||||
private final AirplaneGenericStorage _storage;
|
||||
|
||||
private JList<String> listBoxStorages;
|
||||
private DefaultListModel<String> listBoxModel;
|
||||
private int pictureBoxWidth = 902;
|
||||
private int pictureBoxHeight = 453;
|
||||
|
||||
CollectionCanvas canv;
|
||||
|
||||
void Draw(){
|
||||
if(canv == null)
|
||||
return;
|
||||
canv.repaint();
|
||||
}
|
||||
private void ReloadObjects(){
|
||||
int index = listBoxStorages.getSelectedIndex();
|
||||
listBoxModel.clear();
|
||||
List<String> keys = _storage.Keys();
|
||||
for(int i = 0; i < keys.size(); i++){
|
||||
listBoxModel.addElement(keys.get(i));
|
||||
}
|
||||
if(listBoxModel.size() > 0 && (index == -1 || index >= listBoxModel.size()))
|
||||
listBoxStorages.setSelectedIndex(0);
|
||||
else if(listBoxModel.size() > 0)
|
||||
listBoxStorages.setSelectedIndex(index);
|
||||
}
|
||||
public FormAirFighterCollection(){
|
||||
AirplaneTrashCollection<DrawningAirplane> _trashCollection = new AirplaneTrashCollection<>();
|
||||
JButton callTrashButton = new JButton("мусор");
|
||||
_storage = new AirplaneGenericStorage(pictureBoxWidth, pictureBoxHeight);
|
||||
JScrollPane scrollPane = new JScrollPane();
|
||||
canv = new CollectionCanvas();
|
||||
JPanel toolBox = new JPanel();
|
||||
JTextField storageName = new JTextField();
|
||||
JButton addStorageButton = new JButton("Добавить набор");
|
||||
listBoxModel = new DefaultListModel<>();
|
||||
listBoxStorages= new JList<>(listBoxModel);
|
||||
scrollPane.setViewportView(listBoxStorages);
|
||||
JButton delStorageButton = new JButton("Удалить набор");
|
||||
toolBox.setBounds(623,12, 227, 80);
|
||||
JFrame collectionFrame = new JFrame();
|
||||
collectionFrame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
|
||||
collectionFrame.setSize(880,497);
|
||||
toolBox.setBounds(666, 12, 127, 426);
|
||||
canv.setBounds(12,12,pictureBoxWidth,pictureBoxHeight);
|
||||
JButton addButton = new JButton("Добавить");
|
||||
JButton removeButton = new JButton("Удалить");
|
||||
JButton refreshButton = new JButton("Обновить");
|
||||
JTextField airplaneNumb = new JTextField();
|
||||
GridLayout lay = new GridLayout(9,1);
|
||||
toolBox.add(storageName);
|
||||
toolBox.add(addStorageButton);
|
||||
toolBox.add(scrollPane);
|
||||
toolBox.add(delStorageButton);
|
||||
toolBox.setLayout(lay);
|
||||
toolBox.add(addButton);
|
||||
toolBox.add(airplaneNumb);
|
||||
toolBox.add(removeButton);
|
||||
toolBox.add(refreshButton);
|
||||
toolBox.add(callTrashButton);
|
||||
collectionFrame.add(toolBox);
|
||||
collectionFrame.add(canv);
|
||||
collectionFrame.setVisible(true);
|
||||
canv._storage = _storage;
|
||||
canv.listBoxStorages = listBoxStorages;
|
||||
|
||||
addStorageButton.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
if(storageName.getText() == null)
|
||||
return;
|
||||
_storage.AddSet(storageName.getText());
|
||||
ReloadObjects();
|
||||
}
|
||||
});
|
||||
|
||||
delStorageButton.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
if(listBoxStorages.getSelectedIndex() == -1) {
|
||||
return;
|
||||
}
|
||||
_storage.DelSet(listBoxStorages.getSelectedValue());
|
||||
ReloadObjects();
|
||||
}
|
||||
});
|
||||
|
||||
callTrashButton.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
if(_trashCollection.GetSize() == 0)
|
||||
return;
|
||||
FormAirFighter form = new FormAirFighter();
|
||||
form.ChangeAirplane(_trashCollection.Pop());
|
||||
|
||||
}
|
||||
});
|
||||
addButton.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
if(listBoxStorages.getSelectedIndex() == -1) {
|
||||
return;
|
||||
}
|
||||
AirplaneGenericCollection<DrawningAirplane, DrawningObjectAirplane> _airplanes = _storage.Get(listBoxStorages.getSelectedValue());
|
||||
|
||||
FormAirFighter form = new FormAirFighter();
|
||||
form.buttonSelect.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
if (_airplanes.Insert(form.SelectedAirplane()))
|
||||
{
|
||||
JOptionPane.showMessageDialog(null, "Объект добавлен", "Информация", JOptionPane.INFORMATION_MESSAGE);
|
||||
form.SelectedAirplane()._pictureWidth = pictureBoxWidth;
|
||||
form.SelectedAirplane()._pictureHeight = pictureBoxHeight;
|
||||
Draw();
|
||||
}
|
||||
else
|
||||
{
|
||||
JOptionPane.showMessageDialog(null, "Не удалось добавить объект", "Информация", JOptionPane.INFORMATION_MESSAGE);
|
||||
}
|
||||
|
||||
form.AirplaneFrame.dispose();
|
||||
Draw();
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
removeButton.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
if(listBoxStorages.getSelectedIndex() == -1) {
|
||||
return;
|
||||
}
|
||||
AirplaneGenericCollection<DrawningAirplane, DrawningObjectAirplane> _airplanes = _storage.Get(listBoxStorages.getSelectedValue());
|
||||
if(_airplanes == null) {
|
||||
return;
|
||||
}
|
||||
String tmp = airplaneNumb.getText();
|
||||
int numb;
|
||||
|
||||
try{
|
||||
numb = Integer.parseInt(tmp);
|
||||
}
|
||||
catch(Exception ex){
|
||||
JOptionPane.showMessageDialog(null, "Введите число", "Информация", JOptionPane.INFORMATION_MESSAGE);
|
||||
return;
|
||||
}
|
||||
DrawningAirplane curAirplane = _airplanes.Get(numb);
|
||||
_trashCollection.Push(curAirplane);
|
||||
_airplanes.Remove(numb);
|
||||
_airplanes.ShowAirplanes();
|
||||
JOptionPane.showMessageDialog(null, "Объект удален", "Информация", JOptionPane.INFORMATION_MESSAGE);
|
||||
Draw();
|
||||
}
|
||||
});
|
||||
|
||||
refreshButton.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
if(listBoxStorages.getSelectedIndex() == -1) {
|
||||
return;
|
||||
}
|
||||
AirplaneGenericCollection<DrawningAirplane, DrawningObjectAirplane> _airplanes = _storage.Get(listBoxStorages.getSelectedValue());
|
||||
if(_airplanes == null) {
|
||||
return;
|
||||
}
|
||||
_airplanes.ShowAirplanes();
|
||||
|
||||
Draw();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
class CollectionCanvas extends JComponent {
|
||||
public AirplaneGenericStorage _storage;
|
||||
public JList<String> listBoxStorages;
|
||||
|
||||
public CollectionCanvas(){
|
||||
}
|
||||
@Override
|
||||
public void paintComponent (Graphics g){
|
||||
if (listBoxStorages == null || listBoxStorages.getSelectedIndex() == -1){
|
||||
return;
|
||||
}
|
||||
super.paintComponents (g) ;
|
||||
Graphics2D g2d = (Graphics2D)g;
|
||||
g2d.drawImage(_storage.Get(listBoxStorages.getSelectedValue()).ShowAirplanes(), 0, 0, this);
|
||||
super.repaint();
|
||||
}
|
||||
}
|
91
src/Generics/AirplaneGenericCollection.java
Normal file
91
src/Generics/AirplaneGenericCollection.java
Normal file
@ -0,0 +1,91 @@
|
||||
package src.Generics;
|
||||
|
||||
import src.DrawningObjects.DrawningAirplane;
|
||||
import src.MovementStrategy.IMoveableObject;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.image.BufferedImage;
|
||||
|
||||
public class AirplaneGenericCollection<T extends DrawningAirplane, U extends IMoveableObject> {
|
||||
private final int _pictureWidth;
|
||||
|
||||
private final int _pictureHeight;
|
||||
|
||||
private final int _placeSizeWidth = 166;
|
||||
|
||||
private final int _placeSizeHeight = 160;
|
||||
|
||||
private final SetGeneric<T> _collection;
|
||||
|
||||
public AirplaneGenericCollection(int picWidth, int picHeight){
|
||||
int width = picWidth / _placeSizeWidth;
|
||||
int height = picHeight / _placeSizeHeight;
|
||||
_pictureWidth = picWidth-202;
|
||||
_pictureHeight = picHeight;
|
||||
_collection = new SetGeneric<T>(width * height);
|
||||
}
|
||||
|
||||
public int Size(){
|
||||
return _collection.Count;
|
||||
}
|
||||
public boolean Insert(T obj){
|
||||
if (obj == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return _collection.Insert(obj);
|
||||
}
|
||||
|
||||
public boolean Remove(int position){
|
||||
return _collection.Remove(position);
|
||||
}
|
||||
public U GetU(int pos){
|
||||
T ans = _collection.Get(pos);
|
||||
if(ans == null)
|
||||
return null;
|
||||
return (U)ans.GetMoveableObject();
|
||||
}
|
||||
public T Get(int position){
|
||||
if(position < 0 || position >= _collection.Count)
|
||||
return null;
|
||||
return _collection.Get(position);
|
||||
}
|
||||
private void DrawBackground(Graphics g)
|
||||
{
|
||||
g.setColor(Color.BLACK);
|
||||
for (int i = 0; i < _pictureWidth / _placeSizeWidth; i++)
|
||||
{
|
||||
for (int j = 0; j < _pictureHeight / _placeSizeHeight +
|
||||
1; ++j)
|
||||
{
|
||||
g.drawLine(i * _placeSizeWidth, j *
|
||||
_placeSizeHeight, i * _placeSizeWidth + _placeSizeWidth / 2, j *
|
||||
_placeSizeHeight);
|
||||
}
|
||||
g.drawLine(i * _placeSizeWidth, 0, i *
|
||||
_placeSizeWidth, _pictureHeight / _placeSizeHeight * _placeSizeHeight);
|
||||
}
|
||||
}
|
||||
|
||||
private void DrawObjects(Graphics g)
|
||||
{
|
||||
for (int i = 0; i < _collection.Count; i++)
|
||||
{
|
||||
DrawningAirplane airplane = _collection.Get(i);
|
||||
if (airplane != null)
|
||||
{
|
||||
int inRow = _pictureWidth / _placeSizeWidth;
|
||||
airplane.SetPosition(_pictureWidth - _placeSizeWidth - (i % inRow * _placeSizeWidth) - _placeSizeWidth /10 * 2 , _pictureHeight - _pictureHeight % _placeSizeHeight - (i / inRow + 1) * _placeSizeHeight + (_placeSizeHeight - _placeSizeHeight * 170 / 1000) / 2);
|
||||
airplane.DrawAirplane((Graphics2D) g);
|
||||
}
|
||||
}
|
||||
}
|
||||
public BufferedImage ShowAirplanes()
|
||||
{
|
||||
BufferedImage bmp = new BufferedImage(_pictureWidth, _pictureHeight, BufferedImage.TYPE_4BYTE_ABGR);
|
||||
Graphics gr = bmp.createGraphics();
|
||||
DrawBackground(gr);
|
||||
DrawObjects(gr);
|
||||
return bmp;
|
||||
}
|
||||
}
|
49
src/Generics/AirplaneGenericStorage.java
Normal file
49
src/Generics/AirplaneGenericStorage.java
Normal file
@ -0,0 +1,49 @@
|
||||
package src.Generics;
|
||||
|
||||
import src.DrawningObjects.DrawningAirplane;
|
||||
import src.MovementStrategy.DrawningObjectAirplane;
|
||||
|
||||
import java.util.Dictionary;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Queue;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class AirplaneGenericStorage {
|
||||
final HashMap<String, AirplaneGenericCollection<DrawningAirplane, DrawningObjectAirplane>> _airplaneStorages;
|
||||
public List<String> Keys(){
|
||||
if(_airplaneStorages == null)
|
||||
return null;
|
||||
return _airplaneStorages.keySet().stream().collect(Collectors.toList());
|
||||
}
|
||||
private final int _pictureWidth;
|
||||
private final int _pictureHeight;
|
||||
|
||||
public AirplaneGenericStorage(int pictureWidth, int pictureHeight){
|
||||
_airplaneStorages = new HashMap<>();
|
||||
_pictureWidth = pictureWidth;
|
||||
_pictureHeight = pictureHeight;
|
||||
}
|
||||
|
||||
public void AddSet(String name){
|
||||
if(_airplaneStorages.containsKey(name))
|
||||
return;
|
||||
_airplaneStorages.put(name, new AirplaneGenericCollection<>(_pictureWidth, _pictureHeight));
|
||||
}
|
||||
|
||||
public void DelSet(String name){
|
||||
if(!_airplaneStorages.containsKey(name))
|
||||
return;
|
||||
_airplaneStorages.remove(name);
|
||||
}
|
||||
|
||||
public AirplaneGenericCollection<DrawningAirplane, DrawningObjectAirplane> Get(String name){
|
||||
if(!_airplaneStorages.containsKey(name))
|
||||
return null;
|
||||
return _airplaneStorages.get(name);
|
||||
}
|
||||
|
||||
public DrawningAirplane Get(String collectionName, int position){
|
||||
return _airplaneStorages.get(collectionName).Get(position);
|
||||
}
|
||||
}
|
26
src/Generics/AirplaneTrashCollection.java
Normal file
26
src/Generics/AirplaneTrashCollection.java
Normal file
@ -0,0 +1,26 @@
|
||||
package src.Generics;
|
||||
|
||||
import src.DrawningObjects.DrawningAirplane;
|
||||
|
||||
import java.util.ArrayDeque;
|
||||
import java.util.Queue;
|
||||
|
||||
public class AirplaneTrashCollection <T extends DrawningAirplane> {
|
||||
Queue <T> _queue;
|
||||
|
||||
public AirplaneTrashCollection(){
|
||||
_queue = new ArrayDeque<>();
|
||||
}
|
||||
|
||||
public void Push(T airplane){
|
||||
_queue.add(airplane);
|
||||
}
|
||||
|
||||
public int GetSize(){
|
||||
return _queue.size();
|
||||
}
|
||||
|
||||
public T Pop(){
|
||||
return _queue.remove();
|
||||
}
|
||||
}
|
62
src/Generics/HardGeneric.java
Normal file
62
src/Generics/HardGeneric.java
Normal file
@ -0,0 +1,62 @@
|
||||
package src.Generics;
|
||||
|
||||
import src.DrawningObjects.DrawningAirplane;
|
||||
import src.DrawningObjects.IDraw;
|
||||
import src.Entities.EntityAirplane;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
public class HardGeneric <T extends EntityAirplane,U extends IDraw>{
|
||||
T[] arrFirst;
|
||||
U[] arrSecond;
|
||||
|
||||
private int curSz;
|
||||
private int CountFirst;
|
||||
private int CountSecond;
|
||||
|
||||
private int pictureBoxWidth;
|
||||
|
||||
private int pictureBoxHeight;
|
||||
|
||||
public HardGeneric(int countFirst, int countSecond, int width, int height){
|
||||
curSz = 0;
|
||||
CountFirst = countFirst;
|
||||
CountSecond = countSecond;
|
||||
arrFirst = (T[]) new EntityAirplane[CountFirst];
|
||||
arrSecond = (U[]) new IDraw[CountSecond];
|
||||
pictureBoxHeight = height;
|
||||
pictureBoxWidth = width;
|
||||
}
|
||||
|
||||
public int InsertFirst(T entityAirplane){
|
||||
if(arrFirst[CountFirst-1] != null)
|
||||
return -1;
|
||||
for(int i = curSz -1; i>= 0; i--) {
|
||||
arrFirst[i + 1] = arrFirst[i];
|
||||
arrSecond[i + 1] = arrSecond[i];
|
||||
}
|
||||
curSz++;
|
||||
arrFirst[0] = entityAirplane;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
public int InsertSecond(U inter){
|
||||
if(arrSecond[CountSecond-1] != null)
|
||||
return -1;
|
||||
arrSecond[0] = inter;
|
||||
return 0;
|
||||
}
|
||||
|
||||
public DrawningAirplane MakeObject(){
|
||||
Random rand = new Random();
|
||||
int indFirst = rand.nextInt(0, curSz);
|
||||
int indSecond = rand.nextInt(0,curSz);
|
||||
EntityAirplane entity = arrFirst[indFirst];
|
||||
IDraw inter = arrSecond[indSecond];
|
||||
DrawningAirplane airplane = new DrawningAirplane(entity.Speed(), entity.Weight(), entity.BodyColor(),
|
||||
pictureBoxWidth, pictureBoxHeight);
|
||||
return airplane;
|
||||
}
|
||||
}
|
||||
|
52
src/Generics/SetGeneric.java
Normal file
52
src/Generics/SetGeneric.java
Normal file
@ -0,0 +1,52 @@
|
||||
package src.Generics;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
public class SetGeneric <T extends Object>{
|
||||
private final List<T> _places;
|
||||
|
||||
public int Count;
|
||||
private final int _maxCount;
|
||||
public SetGeneric(int count){
|
||||
_maxCount = count;
|
||||
_places = new ArrayList<>();
|
||||
}
|
||||
|
||||
public boolean Insert(T monorail){
|
||||
if(_places.size() == _maxCount)
|
||||
return false;
|
||||
Insert(monorail, 0);
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean Insert(T monorail, int position){
|
||||
if (!(position >= 0 && position <= _places.size() && _places.size() < _maxCount))
|
||||
return false;
|
||||
_places.add(position, monorail);
|
||||
Count++;
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean Remove(int position){
|
||||
if(!(position >= 0 && position < _places.size()))
|
||||
return false;
|
||||
_places.remove(position);
|
||||
Count--;
|
||||
return true;
|
||||
}
|
||||
|
||||
public T Get(int position){
|
||||
if(!(position >= 0 && position < Count))
|
||||
return null;
|
||||
return (T)_places.get(position);
|
||||
}
|
||||
|
||||
public ArrayList<T> GetMonorails(int maxMonorails){
|
||||
ArrayList<T> toRet = new ArrayList<>();
|
||||
for(int i = 0; i < _places.size(); i++){
|
||||
toRet.add(_places.get(i));
|
||||
if(i == maxMonorails)
|
||||
return toRet;
|
||||
}
|
||||
return toRet;
|
||||
}
|
||||
}
|
75
src/HardForm.java
Normal file
75
src/HardForm.java
Normal file
@ -0,0 +1,75 @@
|
||||
package src;
|
||||
|
||||
import src.DrawningObjects.DrawningAirplane;
|
||||
import src.DrawningObjects.DrawningEngines;
|
||||
import src.DrawningObjects.IDraw;
|
||||
import src.Entities.EntityAirplane;
|
||||
import src.Generics.HardGeneric;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.text.html.parser.Entity;
|
||||
import java.awt.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.util.Random;
|
||||
|
||||
public class HardForm {
|
||||
private Canvas canv;
|
||||
|
||||
private int pictureBoxWidth;
|
||||
private int pictureBoxHeight;
|
||||
|
||||
private EntityAirplane makeEntity(){
|
||||
Random rand = new Random();
|
||||
return new EntityAirplane(rand.nextInt(100, 300), rand.nextDouble(1000,3000),
|
||||
Color.getHSBColor(rand.nextInt(0, 301), rand.nextInt(0, 301), rand.nextInt(0, 301)));
|
||||
}
|
||||
void Draw(){
|
||||
if(canv == null)
|
||||
return;
|
||||
canv.repaint();
|
||||
}
|
||||
private IDraw makeIDraw(EntityAirplane entity){
|
||||
Random rand = new Random();
|
||||
return new DrawningEngines(pictureBoxWidth, pictureBoxHeight, 0, 0);
|
||||
}
|
||||
public HardForm(){
|
||||
Random rand = new Random();
|
||||
int sz = rand.nextInt(1, 10);
|
||||
|
||||
JFrame HardFrame = new JFrame();
|
||||
HardFrame.setSize(700, 400);
|
||||
HardFrame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
|
||||
canv = new Canvas();
|
||||
canv.setBounds(0,0,pictureBoxWidth,pictureBoxHeight);
|
||||
JButton makeObject = new JButton("Создать");
|
||||
makeObject.setBounds(0, 0, 100, 40);
|
||||
canv.add(makeObject);
|
||||
HardFrame.setContentPane(canv);
|
||||
HardFrame.setVisible(true);
|
||||
pictureBoxHeight = canv.getHeight();
|
||||
pictureBoxWidth = canv.getWidth();
|
||||
HardGeneric<EntityAirplane, IDraw> toDraw= new HardGeneric<>(sz,
|
||||
sz, pictureBoxWidth, pictureBoxHeight);
|
||||
for(int i = 0; i < sz; i++){
|
||||
EntityAirplane ent = makeEntity();
|
||||
toDraw.InsertFirst(ent);
|
||||
toDraw.InsertSecond(makeIDraw(ent));
|
||||
}
|
||||
makeObject.addActionListener(
|
||||
new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
DrawningAirplane DrawningAirplane = toDraw.MakeObject();
|
||||
DrawningAirplane.SetPosition(pictureBoxWidth / 2 - DrawningAirplane.GetWidth()/2,
|
||||
pictureBoxHeight / 2 - DrawningAirplane.GetHeight()/2);
|
||||
canv.DrawningAirplane = DrawningAirplane;
|
||||
Draw();
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
20
src/Main.java
Normal file
20
src/Main.java
Normal file
@ -0,0 +1,20 @@
|
||||
package src;
|
||||
import src.DrawningObjects.DrawningAirFighter;
|
||||
import src.FormAirFighterCollection;
|
||||
import src.DrawningObjects.DrawningAirplane;
|
||||
import src.MovementStrategy.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.Random;
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.swing.*;
|
||||
|
||||
public class Main {
|
||||
public static void main(String[] args) throws IOException {
|
||||
FormAirFighterCollection form = new FormAirFighterCollection();
|
||||
}
|
||||
}
|
69
src/MovementStrategy/AbstractStrategy.java
Normal file
69
src/MovementStrategy/AbstractStrategy.java
Normal file
@ -0,0 +1,69 @@
|
||||
package src.MovementStrategy;
|
||||
import src.DirectionType;
|
||||
|
||||
public abstract class AbstractStrategy {
|
||||
private IMoveableObject _moveableObject;
|
||||
private Status _state = Status.NotInit;
|
||||
private int FieldWidth;
|
||||
protected int FieldWidth(){return FieldWidth;}
|
||||
private int FieldHeight;
|
||||
protected int FieldHeight(){return 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(DirectionType.Left);}
|
||||
protected boolean MoveRight() {return MoveTo(DirectionType.Right);}
|
||||
protected boolean MoveUp() {return MoveTo(DirectionType.Up);}
|
||||
protected boolean MoveDown() {return MoveTo(DirectionType.Down);}
|
||||
protected ObjectParameters GetObjectParameters(){
|
||||
if(_moveableObject != null)
|
||||
return _moveableObject.GetObjectParameters();
|
||||
else return null;
|
||||
}
|
||||
protected Integer GetStep()
|
||||
{
|
||||
if (_state != Status.InProgress)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return _moveableObject.GetStep();
|
||||
}
|
||||
protected abstract void MoveToTarget();
|
||||
protected abstract boolean IsTargetDestination();
|
||||
private boolean MoveTo(DirectionType directionType) {
|
||||
if (_state != Status.InProgress)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (_moveableObject.CheckCanMove(directionType))
|
||||
{
|
||||
_moveableObject.MoveObject(directionType);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
31
src/MovementStrategy/DrawningObjectAirplane.java
Normal file
31
src/MovementStrategy/DrawningObjectAirplane.java
Normal file
@ -0,0 +1,31 @@
|
||||
package src.MovementStrategy;
|
||||
import src.DirectionType;
|
||||
import src.DrawningObjects.DrawningAirplane;
|
||||
|
||||
public class DrawningObjectAirplane implements IMoveableObject{
|
||||
private final DrawningAirplane _drawningAirplane;
|
||||
public DrawningObjectAirplane(DrawningAirplane drawningAirplane){
|
||||
_drawningAirplane = drawningAirplane;
|
||||
}
|
||||
public ObjectParameters GetObjectParameters(){
|
||||
if(_drawningAirplane == null || _drawningAirplane.EntityAirplane() == null)
|
||||
return null;
|
||||
return new ObjectParameters(_drawningAirplane.GetPosX(), _drawningAirplane.GetPosY(),
|
||||
_drawningAirplane.GetWidth(), _drawningAirplane.GetHeight());
|
||||
}
|
||||
public int GetStep(){
|
||||
if(_drawningAirplane.EntityAirplane() == null)
|
||||
return 0;
|
||||
return (int)_drawningAirplane.EntityAirplane().Step();
|
||||
}
|
||||
public boolean CheckCanMove(DirectionType direction){
|
||||
if(_drawningAirplane == null)
|
||||
return false;
|
||||
return _drawningAirplane.CanMove(direction);
|
||||
}
|
||||
public void MoveObject(DirectionType direction){
|
||||
if(_drawningAirplane == null)
|
||||
return;
|
||||
_drawningAirplane.MoveTransport(direction);
|
||||
}
|
||||
}
|
10
src/MovementStrategy/IMoveableObject.java
Normal file
10
src/MovementStrategy/IMoveableObject.java
Normal file
@ -0,0 +1,10 @@
|
||||
package src.MovementStrategy;
|
||||
|
||||
import src.DirectionType;
|
||||
|
||||
public interface IMoveableObject {
|
||||
public ObjectParameters GetObjectParameters();
|
||||
public int GetStep();
|
||||
boolean CheckCanMove(DirectionType direction);
|
||||
void MoveObject(DirectionType direction);
|
||||
}
|
36
src/MovementStrategy/MoveToBorder.java
Normal file
36
src/MovementStrategy/MoveToBorder.java
Normal file
@ -0,0 +1,36 @@
|
||||
package src.MovementStrategy;
|
||||
|
||||
public class MoveToBorder extends AbstractStrategy {
|
||||
@Override
|
||||
protected boolean IsTargetDestination() {
|
||||
var objParams = GetObjectParameters();
|
||||
if (objParams == null) {
|
||||
return false;
|
||||
}
|
||||
int a = FieldWidth();
|
||||
int b = FieldHeight();
|
||||
int q = GetStep();
|
||||
return objParams.RightBorder <= FieldWidth() && objParams.RightBorder + GetStep() >= FieldWidth() &&
|
||||
objParams.DownBorder <= FieldHeight() && objParams.DownBorder + GetStep() >= FieldHeight();
|
||||
}
|
||||
@Override
|
||||
protected void MoveToTarget() {
|
||||
var objParams = GetObjectParameters();
|
||||
if (objParams == null) {
|
||||
return;
|
||||
}
|
||||
var diffX = objParams.RightBorder - FieldWidth();
|
||||
if (Math.abs(diffX) >= GetStep()) {
|
||||
if (diffX < 0) {
|
||||
MoveRight();
|
||||
}
|
||||
}
|
||||
var diffY = objParams.DownBorder - FieldHeight();
|
||||
if (Math.abs(diffY) >= GetStep()) {
|
||||
if (diffY < 0) {
|
||||
MoveDown();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
52
src/MovementStrategy/MoveToCenter.java
Normal file
52
src/MovementStrategy/MoveToCenter.java
Normal file
@ -0,0 +1,52 @@
|
||||
package src.MovementStrategy;
|
||||
|
||||
public class MoveToCenter extends AbstractStrategy{
|
||||
@Override
|
||||
protected boolean IsTargetDestination(){
|
||||
var objParams = GetObjectParameters();
|
||||
if(objParams == null)
|
||||
return false;
|
||||
return ((objParams.ObjectMiddleHorizontal <= FieldWidth() / 2 &&
|
||||
objParams.ObjectMiddleHorizontal + GetStep() >= FieldWidth() / 2)
|
||||
||(objParams.ObjectMiddleHorizontal >= FieldWidth() / 2 &&
|
||||
objParams.ObjectMiddleHorizontal - GetStep() <= FieldWidth() / 2)) &&
|
||||
|
||||
((objParams.ObjectMiddleVertical <= FieldHeight() / 2 &&
|
||||
objParams.ObjectMiddleVertical + GetStep() >= FieldHeight() / 2) ||
|
||||
(objParams.ObjectMiddleVertical >= FieldHeight() / 2 &&
|
||||
objParams.ObjectMiddleVertical - GetStep() <= FieldHeight() / 2));
|
||||
}
|
||||
@Override
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
27
src/MovementStrategy/ObjectParameters.java
Normal file
27
src/MovementStrategy/ObjectParameters.java
Normal file
@ -0,0 +1,27 @@
|
||||
package src.MovementStrategy;
|
||||
|
||||
public class ObjectParameters {
|
||||
private final int _x;
|
||||
private final int _y;
|
||||
private final int _width;
|
||||
private final int _height;
|
||||
public int LeftBorder;
|
||||
public int TopBorder;
|
||||
public int RightBorder;
|
||||
public int DownBorder;
|
||||
public int ObjectMiddleHorizontal;
|
||||
public int ObjectMiddleVertical;
|
||||
public ObjectParameters(int x, int y, int width, int height)
|
||||
{
|
||||
_x = x;
|
||||
_y = y;
|
||||
_width = width;
|
||||
_height = height;
|
||||
LeftBorder = _x;
|
||||
TopBorder = _y;
|
||||
RightBorder = _x + width;
|
||||
DownBorder = _y + _height * 125 / 1000 + (_height-_height * 125 / 1000)/2 ;
|
||||
ObjectMiddleHorizontal = _x + _width / 2;
|
||||
ObjectMiddleVertical = _y +(_height - _height * 125 / 1000) / 2 / 2;
|
||||
}
|
||||
}
|
7
src/MovementStrategy/Status.java
Normal file
7
src/MovementStrategy/Status.java
Normal file
@ -0,0 +1,7 @@
|
||||
package src.MovementStrategy;
|
||||
|
||||
public enum Status {
|
||||
NotInit,
|
||||
InProgress,
|
||||
Finish
|
||||
}
|
6
src/NumberType.java
Normal file
6
src/NumberType.java
Normal file
@ -0,0 +1,6 @@
|
||||
package src;
|
||||
public enum NumberType {
|
||||
Two,
|
||||
Four,
|
||||
Six
|
||||
}
|
2
src/README.md
Normal file
2
src/README.md
Normal file
@ -0,0 +1,2 @@
|
||||
# PIbd-23-Kislitsa E.D.-AirFighter-Hard
|
||||
|
Loading…
Reference in New Issue
Block a user