Compare commits
8 Commits
Author | SHA1 | Date |
---|---|---|
xiaoshengjie | 611c25dbdb | 2 years ago |
xiaoshengjie | 866a485d38 | 2 years ago |
xiaoshengjie | 9e116a4e90 | 2 years ago |
xiaoshengjie | 77222b80fc | 2 years ago |
xiaoshengjie | 28c33f858a | 2 years ago |
xiaoshengjie | 10d5726d64 | 2 years ago |
xiaoshengjie | b563018987 | 2 years ago |
xiaoshengjie | 0de31db767 | 2 years ago |
@ -1,16 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project version="4">
|
|
||||||
<component name="CompilerConfiguration">
|
|
||||||
<annotationProcessing>
|
|
||||||
<profile name="Maven default annotation processors profile" enabled="true">
|
|
||||||
<sourceOutputDir name="target/generated-sources/annotations" />
|
|
||||||
<sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
|
|
||||||
<outputRelativeToContentRoot value="true" />
|
|
||||||
<module name="study-tank" />
|
|
||||||
</profile>
|
|
||||||
</annotationProcessing>
|
|
||||||
<bytecodeTargetLevel>
|
|
||||||
<module name="study-tank" target="1.8" />
|
|
||||||
</bytecodeTargetLevel>
|
|
||||||
</component>
|
|
||||||
</project>
|
|
@ -1,25 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project version="4">
|
|
||||||
<component name="RemoteRepositoriesConfiguration">
|
|
||||||
<remote-repository>
|
|
||||||
<option name="id" value="central" />
|
|
||||||
<option name="name" value="Central Repository" />
|
|
||||||
<option name="url" value="https://maven.aliyun.com/repository/public" />
|
|
||||||
</remote-repository>
|
|
||||||
<remote-repository>
|
|
||||||
<option name="id" value="central" />
|
|
||||||
<option name="name" value="Central Repository" />
|
|
||||||
<option name="url" value="https://repo.maven.apache.org/maven2" />
|
|
||||||
</remote-repository>
|
|
||||||
<remote-repository>
|
|
||||||
<option name="id" value="central" />
|
|
||||||
<option name="name" value="Maven Central repository" />
|
|
||||||
<option name="url" value="https://repo1.maven.org/maven2" />
|
|
||||||
</remote-repository>
|
|
||||||
<remote-repository>
|
|
||||||
<option name="id" value="jboss.community" />
|
|
||||||
<option name="name" value="JBoss Community repository" />
|
|
||||||
<option name="url" value="https://repository.jboss.org/nexus/content/repositories/public/" />
|
|
||||||
</remote-repository>
|
|
||||||
</component>
|
|
||||||
</project>
|
|
@ -1,13 +0,0 @@
|
|||||||
<component name="libraryTable">
|
|
||||||
<library name="Maven: junit:junit:4.12">
|
|
||||||
<CLASSES>
|
|
||||||
<root url="jar://$PROJECT_DIR$/../../ProgramFile/maven-repository/junit/junit/4.12/junit-4.12.jar!/" />
|
|
||||||
</CLASSES>
|
|
||||||
<JAVADOC>
|
|
||||||
<root url="jar://$PROJECT_DIR$/../../ProgramFile/maven-repository/junit/junit/4.12/junit-4.12-javadoc.jar!/" />
|
|
||||||
</JAVADOC>
|
|
||||||
<SOURCES>
|
|
||||||
<root url="jar://$PROJECT_DIR$/../../ProgramFile/maven-repository/junit/junit/4.12/junit-4.12-sources.jar!/" />
|
|
||||||
</SOURCES>
|
|
||||||
</library>
|
|
||||||
</component>
|
|
@ -1,13 +0,0 @@
|
|||||||
<component name="libraryTable">
|
|
||||||
<library name="Maven: org.hamcrest:hamcrest-core:1.3">
|
|
||||||
<CLASSES>
|
|
||||||
<root url="jar://$PROJECT_DIR$/../../ProgramFile/maven-repository/org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3.jar!/" />
|
|
||||||
</CLASSES>
|
|
||||||
<JAVADOC>
|
|
||||||
<root url="jar://$PROJECT_DIR$/../../ProgramFile/maven-repository/org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3-javadoc.jar!/" />
|
|
||||||
</JAVADOC>
|
|
||||||
<SOURCES>
|
|
||||||
<root url="jar://$PROJECT_DIR$/../../ProgramFile/maven-repository/org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3-sources.jar!/" />
|
|
||||||
</SOURCES>
|
|
||||||
</library>
|
|
||||||
</component>
|
|
@ -1,13 +0,0 @@
|
|||||||
<component name="libraryTable">
|
|
||||||
<library name="Maven: org.springframework:spring-aop:5.3.23">
|
|
||||||
<CLASSES>
|
|
||||||
<root url="jar://$PROJECT_DIR$/../../ProgramFile/maven-repository/org/springframework/spring-aop/5.3.23/spring-aop-5.3.23.jar!/" />
|
|
||||||
</CLASSES>
|
|
||||||
<JAVADOC>
|
|
||||||
<root url="jar://$PROJECT_DIR$/../../ProgramFile/maven-repository/org/springframework/spring-aop/5.3.23/spring-aop-5.3.23-javadoc.jar!/" />
|
|
||||||
</JAVADOC>
|
|
||||||
<SOURCES>
|
|
||||||
<root url="jar://$PROJECT_DIR$/../../ProgramFile/maven-repository/org/springframework/spring-aop/5.3.23/spring-aop-5.3.23-sources.jar!/" />
|
|
||||||
</SOURCES>
|
|
||||||
</library>
|
|
||||||
</component>
|
|
@ -1,13 +0,0 @@
|
|||||||
<component name="libraryTable">
|
|
||||||
<library name="Maven: org.springframework:spring-beans:5.3.23">
|
|
||||||
<CLASSES>
|
|
||||||
<root url="jar://$PROJECT_DIR$/../../ProgramFile/maven-repository/org/springframework/spring-beans/5.3.23/spring-beans-5.3.23.jar!/" />
|
|
||||||
</CLASSES>
|
|
||||||
<JAVADOC>
|
|
||||||
<root url="jar://$PROJECT_DIR$/../../ProgramFile/maven-repository/org/springframework/spring-beans/5.3.23/spring-beans-5.3.23-javadoc.jar!/" />
|
|
||||||
</JAVADOC>
|
|
||||||
<SOURCES>
|
|
||||||
<root url="jar://$PROJECT_DIR$/../../ProgramFile/maven-repository/org/springframework/spring-beans/5.3.23/spring-beans-5.3.23-sources.jar!/" />
|
|
||||||
</SOURCES>
|
|
||||||
</library>
|
|
||||||
</component>
|
|
@ -1,13 +0,0 @@
|
|||||||
<component name="libraryTable">
|
|
||||||
<library name="Maven: org.springframework:spring-context:5.3.23">
|
|
||||||
<CLASSES>
|
|
||||||
<root url="jar://$PROJECT_DIR$/../../ProgramFile/maven-repository/org/springframework/spring-context/5.3.23/spring-context-5.3.23.jar!/" />
|
|
||||||
</CLASSES>
|
|
||||||
<JAVADOC>
|
|
||||||
<root url="jar://$PROJECT_DIR$/../../ProgramFile/maven-repository/org/springframework/spring-context/5.3.23/spring-context-5.3.23-javadoc.jar!/" />
|
|
||||||
</JAVADOC>
|
|
||||||
<SOURCES>
|
|
||||||
<root url="jar://$PROJECT_DIR$/../../ProgramFile/maven-repository/org/springframework/spring-context/5.3.23/spring-context-5.3.23-sources.jar!/" />
|
|
||||||
</SOURCES>
|
|
||||||
</library>
|
|
||||||
</component>
|
|
@ -1,13 +0,0 @@
|
|||||||
<component name="libraryTable">
|
|
||||||
<library name="Maven: org.springframework:spring-core:5.3.23">
|
|
||||||
<CLASSES>
|
|
||||||
<root url="jar://$PROJECT_DIR$/../../ProgramFile/maven-repository/org/springframework/spring-core/5.3.23/spring-core-5.3.23.jar!/" />
|
|
||||||
</CLASSES>
|
|
||||||
<JAVADOC>
|
|
||||||
<root url="jar://$PROJECT_DIR$/../../ProgramFile/maven-repository/org/springframework/spring-core/5.3.23/spring-core-5.3.23-javadoc.jar!/" />
|
|
||||||
</JAVADOC>
|
|
||||||
<SOURCES>
|
|
||||||
<root url="jar://$PROJECT_DIR$/../../ProgramFile/maven-repository/org/springframework/spring-core/5.3.23/spring-core-5.3.23-sources.jar!/" />
|
|
||||||
</SOURCES>
|
|
||||||
</library>
|
|
||||||
</component>
|
|
@ -1,13 +0,0 @@
|
|||||||
<component name="libraryTable">
|
|
||||||
<library name="Maven: org.springframework:spring-expression:5.3.23">
|
|
||||||
<CLASSES>
|
|
||||||
<root url="jar://$PROJECT_DIR$/../../ProgramFile/maven-repository/org/springframework/spring-expression/5.3.23/spring-expression-5.3.23.jar!/" />
|
|
||||||
</CLASSES>
|
|
||||||
<JAVADOC>
|
|
||||||
<root url="jar://$PROJECT_DIR$/../../ProgramFile/maven-repository/org/springframework/spring-expression/5.3.23/spring-expression-5.3.23-javadoc.jar!/" />
|
|
||||||
</JAVADOC>
|
|
||||||
<SOURCES>
|
|
||||||
<root url="jar://$PROJECT_DIR$/../../ProgramFile/maven-repository/org/springframework/spring-expression/5.3.23/spring-expression-5.3.23-sources.jar!/" />
|
|
||||||
</SOURCES>
|
|
||||||
</library>
|
|
||||||
</component>
|
|
@ -1,13 +0,0 @@
|
|||||||
<component name="libraryTable">
|
|
||||||
<library name="Maven: org.springframework:spring-jcl:5.3.23">
|
|
||||||
<CLASSES>
|
|
||||||
<root url="jar://$PROJECT_DIR$/../../ProgramFile/maven-repository/org/springframework/spring-jcl/5.3.23/spring-jcl-5.3.23.jar!/" />
|
|
||||||
</CLASSES>
|
|
||||||
<JAVADOC>
|
|
||||||
<root url="jar://$PROJECT_DIR$/../../ProgramFile/maven-repository/org/springframework/spring-jcl/5.3.23/spring-jcl-5.3.23-javadoc.jar!/" />
|
|
||||||
</JAVADOC>
|
|
||||||
<SOURCES>
|
|
||||||
<root url="jar://$PROJECT_DIR$/../../ProgramFile/maven-repository/org/springframework/spring-jcl/5.3.23/spring-jcl-5.3.23-sources.jar!/" />
|
|
||||||
</SOURCES>
|
|
||||||
</library>
|
|
||||||
</component>
|
|
@ -1,11 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project version="4">
|
|
||||||
<component name="MavenProjectsManager">
|
|
||||||
<option name="originalFiles">
|
|
||||||
<list>
|
|
||||||
<option value="$PROJECT_DIR$/pom.xml" />
|
|
||||||
</list>
|
|
||||||
</option>
|
|
||||||
</component>
|
|
||||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" project-jdk-name="1.8" project-jdk-type="JavaSDK" />
|
|
||||||
</project>
|
|
@ -1,8 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project version="4">
|
|
||||||
<component name="ProjectModuleManager">
|
|
||||||
<modules>
|
|
||||||
<module fileurl="file://$PROJECT_DIR$/study-tank.iml" filepath="$PROJECT_DIR$/study-tank.iml" />
|
|
||||||
</modules>
|
|
||||||
</component>
|
|
||||||
</project>
|
|
@ -1,124 +0,0 @@
|
|||||||
<?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.png" 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.png" 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.png" 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.png" 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.png" 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.png" 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.png" 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.png" 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.png" 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.png" 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.png" 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.png" 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.png" 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.png" 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.png" 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.png" 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.png" 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.png" 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.png" 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.png" 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.png" 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.png" 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.png" 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.png" 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.png" 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.png" 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.png" removable="false" auto-create-binding="true" can-attach-label="false">
|
|
||||||
<default-constraints vsize-policy="6" hsize-policy="0" anchor="0" fill="2" />
|
|
||||||
</item>
|
|
||||||
</group>
|
|
||||||
</component>
|
|
||||||
</project>
|
|
@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="VcsDirectoryMappings">
|
||||||
|
<mapping directory="" vcs="Git" />
|
||||||
|
</component>
|
||||||
|
</project>
|
@ -0,0 +1,115 @@
|
|||||||
|
package com.study.tank;
|
||||||
|
|
||||||
|
import com.study.tank.cor.BulletAndTankCollider;
|
||||||
|
import com.study.tank.cor.Collider;
|
||||||
|
import com.study.tank.cor.ColliderChain;
|
||||||
|
import com.study.tank.cor.TankTankCollider;
|
||||||
|
import com.study.tank.factory.BaseTank;
|
||||||
|
|
||||||
|
import java.awt.*;
|
||||||
|
import java.io.*;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author xsj
|
||||||
|
* @date 2022/10/27 14:30
|
||||||
|
*/
|
||||||
|
public class GameModel implements Serializable {
|
||||||
|
public static GameModel INSTANCE = new GameModel();
|
||||||
|
|
||||||
|
static {
|
||||||
|
INSTANCE.init();
|
||||||
|
}
|
||||||
|
|
||||||
|
Tank myTank;
|
||||||
|
List<GameObject> gameModelList = new ArrayList<>();
|
||||||
|
ColliderChain chain = new ColliderChain();
|
||||||
|
|
||||||
|
public GameModel() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public void init() {
|
||||||
|
myTank = new Tank(150, 150, Dir.DOWN, Group.GOOD);
|
||||||
|
//初始化敌人坦克
|
||||||
|
int initCountTank = Integer.parseInt((String) PropertyMgr.get("initTankCount"));
|
||||||
|
for (int i = 0; i < initCountTank; i++) {
|
||||||
|
new Tank(80 + i * 100, 50, Dir.DOWN, Group.BAD);
|
||||||
|
}
|
||||||
|
new Wall(200, 200, 50, 100);
|
||||||
|
new Wall(500, 200, 100, 200);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void add(GameObject object) {
|
||||||
|
this.gameModelList.add(object);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void remove(GameObject object) {
|
||||||
|
this.gameModelList.remove(object);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void paint(Graphics g) {
|
||||||
|
for (int i = 0; i < gameModelList.size(); i++) {
|
||||||
|
gameModelList.get(i).paint(g);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < gameModelList.size(); i++) {
|
||||||
|
for (int j = i + 1; j < gameModelList.size(); j++) {
|
||||||
|
GameObject o1 = gameModelList.get(i);
|
||||||
|
GameObject o2 = gameModelList.get(j);
|
||||||
|
//collider1.collider(o1, o2, this);//
|
||||||
|
//collider2.collider(o1, o2, this);
|
||||||
|
if (chain.collider(o1, o2)) return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 存档
|
||||||
|
*/
|
||||||
|
public void save() {
|
||||||
|
File f = new File("E:/jie/tank.data");
|
||||||
|
ObjectOutputStream oos = null;
|
||||||
|
try {
|
||||||
|
if (!f.exists()){
|
||||||
|
f.getParentFile().mkdir();//创建文件上级目录
|
||||||
|
f.createNewFile();//创建文件
|
||||||
|
}
|
||||||
|
oos = new ObjectOutputStream(new FileOutputStream(f));
|
||||||
|
oos.writeObject(GameModel.INSTANCE);
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
} finally {
|
||||||
|
if (oos != null) {
|
||||||
|
try {
|
||||||
|
oos.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 加载存档节点
|
||||||
|
*/
|
||||||
|
public void load() {
|
||||||
|
File f = new File("E:/jie/tank.data");
|
||||||
|
ObjectInputStream ois = null;
|
||||||
|
try {
|
||||||
|
ois = new ObjectInputStream(new FileInputStream(f));
|
||||||
|
INSTANCE = (GameModel) ois.readObject();
|
||||||
|
} catch (IOException | ClassNotFoundException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
} finally {
|
||||||
|
if (ois != null) {
|
||||||
|
try {
|
||||||
|
ois.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,14 @@
|
|||||||
|
package com.study.tank;
|
||||||
|
|
||||||
|
import java.awt.*;
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author xsj
|
||||||
|
* @date 2022/10/27 14:20
|
||||||
|
*/
|
||||||
|
public abstract class GameObject implements Serializable {
|
||||||
|
public int x, y;
|
||||||
|
|
||||||
|
public abstract void paint(Graphics g);
|
||||||
|
}
|
@ -0,0 +1,30 @@
|
|||||||
|
package com.study.tank;
|
||||||
|
|
||||||
|
import java.awt.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author xsj
|
||||||
|
* @date 2022/10/28 15:37
|
||||||
|
*/
|
||||||
|
public class Wall extends GameObject {
|
||||||
|
int width;
|
||||||
|
int height;
|
||||||
|
public Rectangle rectangle;
|
||||||
|
|
||||||
|
public Wall(int x, int y, int width, int height) {
|
||||||
|
this.x = x;
|
||||||
|
this.y = y;
|
||||||
|
this.width = width;
|
||||||
|
this.height = height;
|
||||||
|
rectangle = new Rectangle(x, y, width, height);
|
||||||
|
GameModel.INSTANCE.add(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void paint(Graphics g) {
|
||||||
|
Color c = g.getColor();
|
||||||
|
g.setColor(Color.GRAY);
|
||||||
|
g.fillRect(this.x, this.y, this.width, this.height);
|
||||||
|
g.setColor(c);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,10 @@
|
|||||||
|
package com.study.tank.command;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author xsj
|
||||||
|
* @date 2022/11/1 10:08
|
||||||
|
*/
|
||||||
|
public abstract class Command {
|
||||||
|
abstract void doIt();
|
||||||
|
abstract void unDo();
|
||||||
|
}
|
@ -0,0 +1,38 @@
|
|||||||
|
package com.study.tank.command;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author xsj
|
||||||
|
* @date 2022/11/1 10:30
|
||||||
|
*/
|
||||||
|
public class CommandChain extends Command {
|
||||||
|
int index = 0;
|
||||||
|
List<Command> commandList = new ArrayList<>();
|
||||||
|
|
||||||
|
public CommandChain() {
|
||||||
|
Content c = new Content();
|
||||||
|
this.add(new InsertCommand(c));
|
||||||
|
this.add(new CopyCommand(c));
|
||||||
|
this.add(new DeleteCommand(c));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void add(Command command) {
|
||||||
|
this.commandList.add(command);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
void doIt() {
|
||||||
|
for (int i = 0; i < commandList.size(); i++) {
|
||||||
|
commandList.get(i).doIt();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
void unDo() {
|
||||||
|
for (int i = commandList.size(); i > 0; i--) {
|
||||||
|
commandList.get(i - 1).unDo();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,13 @@
|
|||||||
|
package com.study.tank.command;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author xsj
|
||||||
|
* @date 2022/11/1 10:29
|
||||||
|
*/
|
||||||
|
public class CommandMain {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
CommandChain chain = new CommandChain();
|
||||||
|
chain.doIt();
|
||||||
|
chain.unDo();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,15 @@
|
|||||||
|
package com.study.tank.command;
|
||||||
|
|
||||||
|
import org.springframework.beans.BeanUtils;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author xsj
|
||||||
|
* @date 2022/11/1 10:17
|
||||||
|
*/
|
||||||
|
public class Content {
|
||||||
|
public String msg = "请操作数据-----";
|
||||||
|
|
||||||
|
public Content() {
|
||||||
|
System.out.println("原始数据:" + msg);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,29 @@
|
|||||||
|
package com.study.tank.command;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author xsj
|
||||||
|
* @date 2022/11/1 10:09
|
||||||
|
*/
|
||||||
|
public class DeleteCommand extends Command {
|
||||||
|
|
||||||
|
Content c;
|
||||||
|
String delete = "";
|
||||||
|
private final int index = 2;
|
||||||
|
|
||||||
|
public DeleteCommand(Content c) {
|
||||||
|
this.c = c;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
void doIt() {
|
||||||
|
delete = c.msg;
|
||||||
|
c.msg = "";
|
||||||
|
System.out.println("删除新数据操作后:" + c.msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
void unDo() {
|
||||||
|
c.msg = delete;
|
||||||
|
System.out.println("取消删除新数据操作后:" + c.msg);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,28 @@
|
|||||||
|
package com.study.tank.command;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author xsj
|
||||||
|
* @date 2022/11/1 10:09
|
||||||
|
*/
|
||||||
|
public class InsertCommand extends Command {
|
||||||
|
|
||||||
|
Content c;
|
||||||
|
String sortString = "baidu.com";
|
||||||
|
private final int index = 0;
|
||||||
|
|
||||||
|
public InsertCommand(Content c) {
|
||||||
|
this.c = c;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
void doIt() {
|
||||||
|
c.msg += sortString;
|
||||||
|
System.out.println("插入新数据操作后:" + c.msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
void unDo() {
|
||||||
|
c.msg = c.msg.substring(0, c.msg.length() - sortString.length());
|
||||||
|
System.out.println("取消插入新数据操作后:"+c.msg);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,40 @@
|
|||||||
|
package com.study.tank.cor;
|
||||||
|
|
||||||
|
import com.study.tank.*;
|
||||||
|
|
||||||
|
import java.awt.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author xsj
|
||||||
|
* @date 2022/10/27 17:13
|
||||||
|
*/
|
||||||
|
public class BulletAndTankCollider implements Collider {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean collider(GameObject o1, GameObject o2) {
|
||||||
|
if (o1 instanceof Bullet && o2 instanceof Tank) {
|
||||||
|
Bullet bullet = (Bullet) o1;
|
||||||
|
Tank tank = (Tank) o2;
|
||||||
|
if (collideWithTank(bullet, tank)) return true;
|
||||||
|
} else if (o1 instanceof Tank && o2 instanceof Bullet) {
|
||||||
|
return collider(o2, o1);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean collideWithTank(Bullet bullet, Tank tank) {
|
||||||
|
if (bullet.group == tank.getGroup()) return false;
|
||||||
|
if (tank.group == Group.GOOD) return false;
|
||||||
|
Rectangle rect1 = new Rectangle(bullet.x, bullet.y, bullet.bWidth, bullet.bHeight);
|
||||||
|
Rectangle rect2 = new Rectangle(tank.x, tank.y, Tank.tankWidth, Tank.tankHeight);
|
||||||
|
//碰撞矩形
|
||||||
|
if (rect1.intersects(rect2)) {
|
||||||
|
tank.die();
|
||||||
|
bullet.die();
|
||||||
|
new Explode(bullet.x + bullet.bWidth / 2 - Explode.bWidth / 2, bullet.y + bullet.bWidth - Explode.bHeight / 2);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,25 @@
|
|||||||
|
package com.study.tank.cor;
|
||||||
|
|
||||||
|
import com.study.tank.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author xsj
|
||||||
|
* @date 2022/10/28 15:56
|
||||||
|
*/
|
||||||
|
public class BulletWallCollider implements Collider {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean collider(GameObject o1, GameObject o2) {
|
||||||
|
if (o1 instanceof Bullet && o2 instanceof Wall) {
|
||||||
|
Bullet bullet = (Bullet) o1;
|
||||||
|
Wall w = (Wall) o2;
|
||||||
|
if (bullet.rectangle.intersects(w.rectangle)) {
|
||||||
|
bullet.die();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
} else if (o2 instanceof Bullet && o1 instanceof Wall) {
|
||||||
|
collider(o2, o1);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,14 @@
|
|||||||
|
package com.study.tank.cor;
|
||||||
|
|
||||||
|
import com.study.tank.GameModel;
|
||||||
|
import com.study.tank.GameObject;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author xsj
|
||||||
|
* @date 2022/10/27 15:39
|
||||||
|
*/
|
||||||
|
public interface Collider extends Serializable {
|
||||||
|
boolean collider(GameObject o1, GameObject o2);
|
||||||
|
}
|
@ -0,0 +1,31 @@
|
|||||||
|
package com.study.tank.cor;
|
||||||
|
|
||||||
|
import com.study.tank.GameModel;
|
||||||
|
import com.study.tank.GameObject;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author xsj
|
||||||
|
* @date 2022/10/28 9:32
|
||||||
|
*/
|
||||||
|
public class ColliderChain implements Collider {
|
||||||
|
List<Collider> colliders = new ArrayList<>();
|
||||||
|
|
||||||
|
public ColliderChain() {
|
||||||
|
colliders.add(new BulletAndTankCollider());
|
||||||
|
colliders.add(new TankTankCollider());
|
||||||
|
colliders.add(new WallTankCollider());
|
||||||
|
colliders.add(new BulletWallCollider());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean collider(GameObject o1, GameObject o2) {
|
||||||
|
for (Collider c : colliders) {
|
||||||
|
if (c.collider(o1, o2)) return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,38 @@
|
|||||||
|
package com.study.tank.cor;
|
||||||
|
|
||||||
|
import com.study.tank.*;
|
||||||
|
|
||||||
|
import java.awt.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author xsj
|
||||||
|
* @date 2022/10/27 17:35
|
||||||
|
*/
|
||||||
|
public class TankTankCollider implements Collider {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean collider(GameObject o1, GameObject o2) {
|
||||||
|
if (o1 instanceof Tank && o2 instanceof Tank) {
|
||||||
|
Tank tank1 = (Tank) o1;
|
||||||
|
Tank tank2 = (Tank) o2;
|
||||||
|
// Rectangle rect1 = new Rectangle(tank1.x, tank1.y, Tank.tankWidth, Tank.tankHeight);
|
||||||
|
// Rectangle rect2 = new Rectangle(tank2.x, tank2.y, Tank.tankWidth, Tank.tankHeight);
|
||||||
|
if (tank1.group == tank2.group) {
|
||||||
|
if (tank1.rectangle.intersects(tank2.rectangle)) {
|
||||||
|
tank1.goBack();
|
||||||
|
tank2.goBack();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
//碰撞矩形
|
||||||
|
if (tank1.rectangle.intersects(tank2.rectangle)) {
|
||||||
|
tank1.die();
|
||||||
|
tank2.die();
|
||||||
|
new Explode(tank1.x + tank1.tankWidth / 2 - Explode.bWidth / 2, tank1.y + tank1.tankHeight / 2 - Explode.bHeight/2);
|
||||||
|
new Explode(tank2.x + tank2.tankWidth / 2 - Explode.bWidth / 2, tank2.y + tank2.tankHeight / 2-Explode.bHeight/2);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,25 @@
|
|||||||
|
package com.study.tank.cor;
|
||||||
|
|
||||||
|
import com.study.tank.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author xsj
|
||||||
|
* @date 2022/10/28 15:43
|
||||||
|
*/
|
||||||
|
public class WallTankCollider implements Collider {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean collider(GameObject o1, GameObject o2) {
|
||||||
|
if (o1 instanceof Tank && o2 instanceof Wall) {
|
||||||
|
Tank tank = (Tank) o1;
|
||||||
|
Wall w = (Wall) o2;
|
||||||
|
if (tank.group == Group.GOOD) return false;
|
||||||
|
if (tank.rectangle.intersects(w.rectangle)) {
|
||||||
|
tank.stop();
|
||||||
|
}
|
||||||
|
} else if (o2 instanceof Tank && o1 instanceof Wall) {
|
||||||
|
collider(o2, o1);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
@ -1,25 +1,25 @@
|
|||||||
package com.study.tank.factory;
|
//package com.study.tank.factory;
|
||||||
|
//
|
||||||
import com.study.tank.*;
|
//import com.study.tank.*;
|
||||||
|
//
|
||||||
/**
|
///**
|
||||||
* @author xsj
|
// * @author xsj
|
||||||
* @date 2022/10/26 13:13
|
// * @date 2022/10/26 13:13
|
||||||
*/
|
// */
|
||||||
public class DefaultFactory extends GameFactory {
|
//public class DefaultFactory extends GameFactory {
|
||||||
|
//
|
||||||
@Override
|
// @Override
|
||||||
public BaseTank createTank(int x, int y, Dir dir, Group group, TankFrame tankFrame) {
|
// public BaseTank createTank(int x, int y, Dir dir, Group group, TankFrame tankFrame) {
|
||||||
return new Tank(x, y, dir, group, tankFrame);
|
// return new Tank(x, y, dir, group, tankFrame);
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
@Override
|
// @Override
|
||||||
public BaseBullet createBullet(int x, int y, Dir dir, Group group, TankFrame tankFrame) {
|
// public BaseBullet createBullet(int x, int y, Dir dir, Group group, TankFrame tankFrame) {
|
||||||
return new Bullet(x,y,dir,group,tankFrame);
|
// return new Bullet(x,y,dir,group,tankFrame);
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
@Override
|
// @Override
|
||||||
public BaseExplode createExplode(int x, int y, TankFrame tankFrame) {
|
// public BaseExplode createExplode(int x, int y, TankFrame tankFrame) {
|
||||||
return new Explode(x, y, tankFrame);
|
// return new Explode(x, y, tankFrame);
|
||||||
}
|
// }
|
||||||
}
|
//}
|
||||||
|
@ -1,25 +1,25 @@
|
|||||||
package com.study.tank.factory;
|
//package com.study.tank.factory;
|
||||||
|
//
|
||||||
import com.study.tank.*;
|
//import com.study.tank.*;
|
||||||
|
//
|
||||||
/**
|
///**
|
||||||
* @author xsj
|
// * @author xsj
|
||||||
* @date 2022/10/26 13:36
|
// * @date 2022/10/26 13:36
|
||||||
*/
|
// */
|
||||||
public class RectFactory extends GameFactory {
|
//public class RectFactory extends GameFactory {
|
||||||
|
//
|
||||||
@Override
|
// @Override
|
||||||
public BaseTank createTank(int x, int y, Dir dir, Group group, TankFrame tankFrame) {
|
// public BaseTank createTank(int x, int y, Dir dir, Group group, TankFrame tankFrame) {
|
||||||
return new WarTank(x, y, dir, group, tankFrame);
|
// return new WarTank(x, y, dir, group, tankFrame);
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
@Override
|
// @Override
|
||||||
public BaseBullet createBullet(int x, int y, Dir dir, Group group, TankFrame tankFrame) {
|
// public BaseBullet createBullet(int x, int y, Dir dir, Group group, TankFrame tankFrame) {
|
||||||
return new RoundBullet(x, y, dir, group, tankFrame);
|
// return new RoundBullet(x, y, dir, group, tankFrame);
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
@Override
|
// @Override
|
||||||
public BaseExplode createExplode(int x, int y, TankFrame tankFrame) {
|
// public BaseExplode createExplode(int x, int y, TankFrame tankFrame) {
|
||||||
return new RectExplode(x, y, tankFrame);
|
// return new RectExplode(x, y, tankFrame);
|
||||||
}
|
// }
|
||||||
}
|
//}
|
||||||
|
@ -1,170 +1,170 @@
|
|||||||
package com.study.tank.factory;
|
//package com.study.tank.factory;
|
||||||
|
//
|
||||||
import com.study.tank.*;
|
//import com.study.tank.*;
|
||||||
import com.study.tank.strategy.FireStrategy;
|
//import com.study.tank.strategy.FireStrategy;
|
||||||
import com.study.tank.strategy.Imp.DefaultFireStrategy;
|
//import com.study.tank.strategy.Imp.DefaultFireStrategy;
|
||||||
|
//
|
||||||
import java.awt.*;
|
//import java.awt.*;
|
||||||
import java.util.Random;
|
//import java.util.Random;
|
||||||
|
//
|
||||||
/**
|
///**
|
||||||
* @Description:
|
// * @Description:
|
||||||
* @Auther: xiaoshengjie
|
// * @Auther: xiaoshengjie
|
||||||
* @Date: 2022/10/22/上午10:08
|
// * @Date: 2022/10/22/上午10:08
|
||||||
*/
|
// */
|
||||||
public class WarTank extends BaseTank {
|
//public class WarTank extends BaseTank {
|
||||||
public static final int tankWidth = ImageManger.goodTankU.getWidth();
|
// public static final int tankWidth = ImageManger.goodTankU.getWidth();
|
||||||
public static final int tankHeight = ImageManger.goodTankU.getHeight();
|
// public static final int tankHeight = ImageManger.goodTankU.getHeight();
|
||||||
private boolean moving = true;
|
// private boolean moving = true;
|
||||||
private int x, y;
|
// private int x, y;
|
||||||
private boolean living = true;
|
// private boolean living = true;
|
||||||
public Dir dir = Dir.DOWN;
|
// public Dir dir = Dir.DOWN;
|
||||||
private final int speed = 4;
|
// private final int speed = 4;
|
||||||
public TankFrame tankFrame = null;
|
// public TankFrame tankFrame = null;
|
||||||
private Random random = new Random();
|
// private Random random = new Random();
|
||||||
Group group = Group.BAD;
|
// Group group = Group.BAD;
|
||||||
|
//
|
||||||
FireStrategy fs;
|
// FireStrategy fs;
|
||||||
|
//
|
||||||
public Group getGroup() {
|
// public Group getGroup() {
|
||||||
return group;
|
// return group;
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
public void setGroup(Group group) {
|
// public void setGroup(Group group) {
|
||||||
this.group = group;
|
|
||||||
}
|
|
||||||
|
|
||||||
public WarTank(int x, int y, Dir dir, Group group, TankFrame tankFrame) {
|
|
||||||
// this.x = x;
|
|
||||||
// this.y = y;
|
|
||||||
super(x, y, group);
|
|
||||||
this.dir = dir;
|
|
||||||
// this.group = group;
|
// this.group = group;
|
||||||
this.tankFrame = tankFrame;
|
// }
|
||||||
try {
|
//
|
||||||
if (this.group == Group.GOOD) {
|
// public WarTank(int x, int y, Dir dir, Group group, TankFrame tankFrame) {
|
||||||
String goodName = (String) PropertyMgr.get("goodFs");
|
//// this.x = x;
|
||||||
//fs = (GoodTankFireStrategy) Class.forName(goodName).newInstance();
|
//// this.y = y;
|
||||||
fs = (FireStrategy) Class.forName(goodName).getDeclaredConstructor().newInstance();
|
// super(x, y, group);
|
||||||
} else {
|
// this.dir = dir;
|
||||||
fs = new DefaultFireStrategy();
|
//// this.group = group;
|
||||||
}
|
// this.tankFrame = tankFrame;
|
||||||
} catch (Exception e) {
|
// try {
|
||||||
|
// if (this.group == Group.GOOD) {
|
||||||
}
|
// String goodName = (String) PropertyMgr.get("goodFs");
|
||||||
}
|
// //fs = (GoodTankFireStrategy) Class.forName(goodName).newInstance();
|
||||||
|
// fs = (FireStrategy) Class.forName(goodName).getDeclaredConstructor().newInstance();
|
||||||
// public Tank(int x, int y, Dir dir, Group group, boolean moving, TankFrame tankFrame) {
|
// } else {
|
||||||
|
// fs = new DefaultFireStrategy();
|
||||||
|
// }
|
||||||
|
// } catch (Exception e) {
|
||||||
|
//
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
//// public Tank(int x, int y, Dir dir, Group group, boolean moving, TankFrame tankFrame) {
|
||||||
|
//// this.x = x;
|
||||||
|
//// this.y = y;
|
||||||
|
//// this.dir = dir;
|
||||||
|
//// this.group = group;
|
||||||
|
//// this.tankFrame = tankFrame;
|
||||||
|
//// this.moving = false;
|
||||||
|
//// }
|
||||||
|
//
|
||||||
|
// public int getX() {
|
||||||
|
// return x;
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// public int getY() {
|
||||||
|
// return y;
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// public Dir getDir() {
|
||||||
|
// return dir;
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// public int getSpeed() {
|
||||||
|
// return speed;
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// public void setX(int x) {
|
||||||
// this.x = x;
|
// this.x = x;
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// public void setY(int y) {
|
||||||
// this.y = y;
|
// this.y = y;
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// public boolean isMoving() {
|
||||||
|
// return moving;
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// public void setMoving(boolean moving) {
|
||||||
|
// this.moving = moving;
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// public void setDir(Dir dir) {
|
||||||
// this.dir = dir;
|
// this.dir = dir;
|
||||||
// this.group = group;
|
// }
|
||||||
// this.tankFrame = tankFrame;
|
//
|
||||||
// this.moving = false;
|
// @Override
|
||||||
// }
|
// public void paint(Graphics g) {
|
||||||
|
// System.out.println("war paint");
|
||||||
public int getX() {
|
// if (!living) {
|
||||||
return x;
|
// tankFrame.tanks.remove(this);
|
||||||
}
|
// moving = false;
|
||||||
|
// return;
|
||||||
public int getY() {
|
// }
|
||||||
return y;
|
// Color c = g.getColor();
|
||||||
}
|
// g.setColor(group == Group.GOOD ? Color.BLUE : Color.YELLOW);
|
||||||
|
// g.fillRect(x, y, 40, 40);
|
||||||
public Dir getDir() {
|
// g.setColor(c);
|
||||||
return dir;
|
// move();
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
public int getSpeed() {
|
// public void move() {
|
||||||
return speed;
|
// if (!living) return;
|
||||||
}
|
// if (!this.moving) return;
|
||||||
|
// switch (dir) {
|
||||||
public void setX(int x) {
|
// case LEFT:
|
||||||
this.x = x;
|
// x -= speed;
|
||||||
}
|
// break;
|
||||||
|
// case RIGHT:
|
||||||
public void setY(int y) {
|
// x += speed;
|
||||||
this.y = y;
|
// break;
|
||||||
}
|
// case UP:
|
||||||
|
// y -= speed;
|
||||||
public boolean isMoving() {
|
// break;
|
||||||
return moving;
|
// case DOWN:
|
||||||
}
|
// y += speed;
|
||||||
|
// break;
|
||||||
public void setMoving(boolean moving) {
|
// }
|
||||||
this.moving = moving;
|
// if (group == Group.BAD && random.nextInt(100) > 95)
|
||||||
}
|
// this.fire();
|
||||||
|
//
|
||||||
public void setDir(Dir dir) {
|
// if (this.group == Group.BAD && random.nextInt(100) > 95)
|
||||||
this.dir = dir;
|
// this.randomDir();
|
||||||
}
|
//
|
||||||
|
// boundsCheck();
|
||||||
@Override
|
// }
|
||||||
public void paint(Graphics g) {
|
//
|
||||||
System.out.println("war paint");
|
// private void boundsCheck() {
|
||||||
if (!living) {
|
// if (this.x < 0) x = TankFrame.GAME_WIDTH - WarTank.tankWidth;
|
||||||
tankFrame.tanks.remove(this);
|
// if (this.y < 28) y = TankFrame.GAME_HEIGHT - WarTank.tankHeight;
|
||||||
moving = false;
|
// if (this.x > TankFrame.GAME_WIDTH - tankWidth) x = 0;
|
||||||
return;
|
// if (this.y > TankFrame.GAME_HEIGHT - tankHeight) y = 28;
|
||||||
}
|
// }
|
||||||
Color c = g.getColor();
|
//
|
||||||
g.setColor(group == Group.GOOD ? Color.BLUE : Color.YELLOW);
|
// //0.4几率的随机方向
|
||||||
g.fillRect(x, y, 40, 40);
|
// private void randomDir() {
|
||||||
g.setColor(c);
|
// if (random.nextInt(100) > 60)
|
||||||
move();
|
// this.dir = Dir.values()[random.nextInt(4)];
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
public void move() {
|
// /**
|
||||||
if (!living) return;
|
// * 开火
|
||||||
if (!this.moving) return;
|
// */
|
||||||
switch (dir) {
|
// public void fire() {
|
||||||
case LEFT:
|
// //fs.fire(this);
|
||||||
x -= speed;
|
// int bx = this.getX() + this.tankWidth / 2 - ImageManger.bulletD.getWidth() / 2 + 2;
|
||||||
break;
|
// int by = this.getY() + this.tankHeight / 2 - ImageManger.bulletD.getHeight() / 2 + 2;
|
||||||
case RIGHT:
|
// new Bullet(bx, by, this.dir, this.getGroup(), this.tankFrame);
|
||||||
x += speed;
|
// }
|
||||||
break;
|
//
|
||||||
case UP:
|
// @Override
|
||||||
y -= speed;
|
// public void die() {
|
||||||
break;
|
// this.living = false;
|
||||||
case DOWN:
|
// }
|
||||||
y += speed;
|
//}
|
||||||
break;
|
|
||||||
}
|
|
||||||
if (group == Group.BAD && random.nextInt(100) > 95)
|
|
||||||
this.fire();
|
|
||||||
|
|
||||||
if (this.group == Group.BAD && random.nextInt(100) > 95)
|
|
||||||
this.randomDir();
|
|
||||||
|
|
||||||
boundsCheck();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void boundsCheck() {
|
|
||||||
if (this.x < 0) x = TankFrame.GAME_WIDTH - WarTank.tankWidth;
|
|
||||||
if (this.y < 28) y = TankFrame.GAME_HEIGHT - WarTank.tankHeight;
|
|
||||||
if (this.x > TankFrame.GAME_WIDTH - tankWidth) x = 0;
|
|
||||||
if (this.y > TankFrame.GAME_HEIGHT - tankHeight) y = 28;
|
|
||||||
}
|
|
||||||
|
|
||||||
//0.4几率的随机方向
|
|
||||||
private void randomDir() {
|
|
||||||
if (random.nextInt(100) > 60)
|
|
||||||
this.dir = Dir.values()[random.nextInt(4)];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 开火
|
|
||||||
*/
|
|
||||||
public void fire() {
|
|
||||||
//fs.fire(this);
|
|
||||||
int bx = this.getX() + this.tankWidth / 2 - ImageManger.bulletD.getWidth() / 2 + 2;
|
|
||||||
int by = this.getY() + this.tankHeight / 2 - ImageManger.bulletD.getHeight() / 2 + 2;
|
|
||||||
new Bullet(bx, by, this.dir, this.getGroup(), this.tankFrame);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void die() {
|
|
||||||
this.living = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@ -0,0 +1,49 @@
|
|||||||
|
package com.study.tank.sate;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author xsj
|
||||||
|
* @date 2022/11/1 15:42
|
||||||
|
*/
|
||||||
|
public class Car {
|
||||||
|
private String name;
|
||||||
|
private CarSatesDict sate;
|
||||||
|
private CarSate carSate;
|
||||||
|
|
||||||
|
public Car(String name,CarSatesDict sate) {
|
||||||
|
this.name = name;
|
||||||
|
this.sate = sate;
|
||||||
|
switch (sate){
|
||||||
|
case OPEN:
|
||||||
|
this.carSate = new OpenSateCar();
|
||||||
|
break;
|
||||||
|
case CLOSED:
|
||||||
|
this.carSate = new ClosedCarSate();
|
||||||
|
break;
|
||||||
|
case RUNNING:
|
||||||
|
this.carSate = new RunCarSate();
|
||||||
|
break;
|
||||||
|
case STOP:
|
||||||
|
this.carSate = new StopCarSate();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void open() {
|
||||||
|
carSate.open();
|
||||||
|
}
|
||||||
|
|
||||||
|
void closed() {
|
||||||
|
carSate.closed();
|
||||||
|
}
|
||||||
|
|
||||||
|
void running() {
|
||||||
|
carSate.running();
|
||||||
|
}
|
||||||
|
|
||||||
|
void stop() {
|
||||||
|
carSate.stop();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,17 @@
|
|||||||
|
package com.study.tank.sate;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author xsj
|
||||||
|
* @date 2022/11/1 15:53
|
||||||
|
*/
|
||||||
|
public class CarMain {
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
Car car = new Car("荣威", CarSatesDict.CLOSED);
|
||||||
|
car.open();
|
||||||
|
car.closed();
|
||||||
|
car.running();
|
||||||
|
car.stop();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,12 @@
|
|||||||
|
package com.study.tank.sate;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author xsj
|
||||||
|
* @date 2022/11/1 15:44
|
||||||
|
*/
|
||||||
|
public abstract class CarSate {
|
||||||
|
abstract void open();
|
||||||
|
abstract void closed();
|
||||||
|
abstract void running();
|
||||||
|
abstract void stop();
|
||||||
|
}
|
@ -0,0 +1,9 @@
|
|||||||
|
package com.study.tank.sate;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author xsj
|
||||||
|
* @date 2022/11/1 15:59
|
||||||
|
*/
|
||||||
|
public enum CarSatesDict {
|
||||||
|
OPEN,CLOSED,RUNNING,STOP
|
||||||
|
}
|
@ -0,0 +1,28 @@
|
|||||||
|
package com.study.tank.sate;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author xsj
|
||||||
|
* @date 2022/11/1 15:49
|
||||||
|
*/
|
||||||
|
public class ClosedCarSate extends CarSate{
|
||||||
|
|
||||||
|
@Override
|
||||||
|
void open() {
|
||||||
|
System.out.println("关门状态,可以开门-------");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
void closed() {
|
||||||
|
System.out.println("关门状态无法closed-------");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
void running() {
|
||||||
|
System.out.println("关门状态,可以running-------");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
void stop() {
|
||||||
|
System.out.println("关门状态,可以stop-------");
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,28 @@
|
|||||||
|
package com.study.tank.sate;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author xsj
|
||||||
|
* @date 2022/11/1 15:47
|
||||||
|
*/
|
||||||
|
public class OpenSateCar extends CarSate{
|
||||||
|
|
||||||
|
@Override
|
||||||
|
void open() {
|
||||||
|
System.out.println("开门状态无法开门-------");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
void closed() {
|
||||||
|
System.out.println("(当前开门)可以调用closed-------");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
void running() {
|
||||||
|
System.out.println("开门状态无法调用running-------");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
void stop() {
|
||||||
|
System.out.println("开门状态无法调用stop-------");
|
||||||
|
}
|
||||||
|
}
|
@ -1,20 +1,20 @@
|
|||||||
package com.study.tank.strategy.Imp;
|
//package com.study.tank.strategy.Imp;
|
||||||
|
//
|
||||||
import com.study.tank.Bullet;
|
//import com.study.tank.Bullet;
|
||||||
import com.study.tank.ImageManger;
|
//import com.study.tank.ImageManger;
|
||||||
import com.study.tank.Tank;
|
//import com.study.tank.Tank;
|
||||||
import com.study.tank.strategy.FireStrategy;
|
//import com.study.tank.strategy.FireStrategy;
|
||||||
|
//
|
||||||
/**
|
///**
|
||||||
* @author xsj
|
// * @author xsj
|
||||||
* @date 2022/10/25 10:30
|
// * @date 2022/10/25 10:30
|
||||||
*/
|
// */
|
||||||
public class DefaultFireStrategy implements FireStrategy {
|
//public class DefaultFireStrategy implements FireStrategy {
|
||||||
|
//
|
||||||
@Override
|
// @Override
|
||||||
public void fire(Tank tank) {
|
// public void fire(Tank tank) {
|
||||||
int bx = tank.getX() + tank.tankWidth / 2 - ImageManger.bulletD.getWidth() / 2 + 2;
|
// int bx = tank.getX() + tank.tankWidth / 2 - ImageManger.bulletD.getWidth() / 2 + 2;
|
||||||
int by = tank.getY() + tank.tankHeight / 2 - ImageManger.bulletD.getHeight() / 2 + 2;
|
// int by = tank.getY() + tank.tankHeight / 2 - ImageManger.bulletD.getHeight() / 2 + 2;
|
||||||
new Bullet(bx, by, tank.dir, tank.getGroup(), tank.tankFrame);
|
// new Bullet(bx, by, tank.dir, tank.getGroup(), tank.tankFrame);
|
||||||
}
|
// }
|
||||||
}
|
//}
|
||||||
|
@ -1,39 +1,39 @@
|
|||||||
package com.study.tank.strategy.Imp;
|
//package com.study.tank.strategy.Imp;
|
||||||
|
//
|
||||||
import com.study.tank.Bullet;
|
//import com.study.tank.Bullet;
|
||||||
import com.study.tank.ImageManger;
|
//import com.study.tank.ImageManger;
|
||||||
import com.study.tank.Tank;
|
//import com.study.tank.Tank;
|
||||||
import com.study.tank.strategy.FireStrategy;
|
//import com.study.tank.strategy.FireStrategy;
|
||||||
|
//
|
||||||
/**
|
///**
|
||||||
* @author xsj
|
// * @author xsj
|
||||||
* @date 2022/10/25 13:28
|
// * @date 2022/10/25 13:28
|
||||||
*/
|
// */
|
||||||
public class GoodTankFireStrategy implements FireStrategy {
|
//public class GoodTankFireStrategy implements FireStrategy {
|
||||||
|
//
|
||||||
@Override
|
// @Override
|
||||||
public void fire(Tank tank) {
|
// public void fire(Tank tank) {
|
||||||
int bx = tank.getX() + Tank.tankWidth / 2 - ImageManger.bulletD.getWidth() / 2;
|
// int bx = tank.getX() + Tank.tankWidth / 2 - ImageManger.bulletD.getWidth() / 2;
|
||||||
int by = tank.getY() + Tank.tankHeight / 2 - ImageManger.bulletD.getHeight() / 2;
|
// int by = tank.getY() + Tank.tankHeight / 2 - ImageManger.bulletD.getHeight() / 2;
|
||||||
switch (tank.dir) {
|
// switch (tank.dir) {
|
||||||
case DOWN:
|
// case DOWN:
|
||||||
new Bullet(bx, by + 6, tank.dir, tank.getGroup(), tank.tankFrame);
|
// new Bullet(bx, by + 6, tank.dir, tank.getGroup(), tank.tankFrame);
|
||||||
new Bullet(bx, by - 6, tank.dir, tank.getGroup(), tank.tankFrame);
|
// new Bullet(bx, by - 6, tank.dir, tank.getGroup(), tank.tankFrame);
|
||||||
break;
|
// break;
|
||||||
case UP:
|
// case UP:
|
||||||
new Bullet(bx + 1, by + 6, tank.dir, tank.getGroup(), tank.tankFrame);
|
// new Bullet(bx + 1, by + 6, tank.dir, tank.getGroup(), tank.tankFrame);
|
||||||
new Bullet(bx + 1, by - 6, tank.dir, tank.getGroup(), tank.tankFrame);
|
// new Bullet(bx + 1, by - 6, tank.dir, tank.getGroup(), tank.tankFrame);
|
||||||
break;
|
// break;
|
||||||
case LEFT:
|
// case LEFT:
|
||||||
new Bullet(bx + 6, by, tank.dir, tank.getGroup(), tank.tankFrame);
|
// new Bullet(bx + 6, by, tank.dir, tank.getGroup(), tank.tankFrame);
|
||||||
new Bullet(bx - 6, by, tank.dir, tank.getGroup(), tank.tankFrame);
|
// new Bullet(bx - 6, by, tank.dir, tank.getGroup(), tank.tankFrame);
|
||||||
break;
|
// break;
|
||||||
case RIGHT:
|
// case RIGHT:
|
||||||
new Bullet(bx + 6, by + 1, tank.dir, tank.getGroup(), tank.tankFrame);
|
// new Bullet(bx + 6, by + 1, tank.dir, tank.getGroup(), tank.tankFrame);
|
||||||
new Bullet(bx - 6, by + 1, tank.dir, tank.getGroup(), tank.tankFrame);
|
// new Bullet(bx - 6, by + 1, tank.dir, tank.getGroup(), tank.tankFrame);
|
||||||
break;
|
// break;
|
||||||
|
//
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
}
|
// }
|
||||||
}
|
//}
|
||||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue