Compare commits

...

8 Commits

Author SHA1 Message Date
xiaoshengjie 611c25dbdb dd
2 years ago
xiaoshengjie 866a485d38 忽略不关注文件夹
2 years ago
xiaoshengjie 9e116a4e90 责任链+sate
2 years ago
xiaoshengjie 77222b80fc c
2 years ago
xiaoshengjie 28c33f858a 删除日志
2 years ago
xiaoshengjie 10d5726d64 GameModel使用单例模式
2 years ago
xiaoshengjie b563018987 责任链+调停者+新增墙体
2 years ago
xiaoshengjie 0de31db767 责任链+调停者
2 years ago

@ -6,3 +6,5 @@
/dataSources.local.xml
# Editor-based HTTP Client requests
/httpRequests/
/.idea
/target

@ -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,30 +0,0 @@
t java:S115"ZRename this constant name to match the regular expression '^[A-Z][A-Z0-9]*(_[A-Z0-9]+)*$'.(«¶ó•ûÿÿÿÿ
t java:S115"ZRename this constant name to match the regular expression '^[A-Z][A-Z0-9]*(_[A-Z0-9]+)*$'.(“ƒÎ³øÿÿÿÿ
<
java:S1170"!Make this final field static too.(ñ‹œÞþÿÿÿÿ
Q java:S125"<This block of commented-out lines of code should be removed.(“‰<E2809C>÷
Q java:S125"<This block of commented-out lines of code should be removed.(ÝŠÐò
V java:S125"<This block of commented-out lines of code should be removed.(¥·ïãøÿÿÿÿ
Q java:S125"<This block of commented-out lines of code should be removed.(„üº¨
V java:S125'"<This block of commented-out lines of code should be removed.(äüø©øÿÿÿÿ
Q java:S125+"<This block of commented-out lines of code should be removed.(ã…éã
V java:S125-"<This block of commented-out lines of code should be removed.(ñ¥ùšøÿÿÿÿ
Q java:S125:"<This block of commented-out lines of code should be removed.(½·¥¯
V java:S125C"<This block of commented-out lines of code should be removed.(׈¼Œûÿÿÿÿ
Q java:S125S"<This block of commented-out lines of code should be removed.(ÛûÏÝ
Q java:S125g"<This block of commented-out lines of code should be removed.(óÆ<C3B3>Ò
T java:S106"9Replace this use of System.out or System.err by a logger.(‡³›ªøÿÿÿÿ
C
java:S1602²",Remove useless curly braces around statement(¥—ýð
W java:S125É"<This block of commented-out lines of code should be removed.(¿ÿÅ<C3BF>ýÿÿÿÿ
\
java:S1128"ARemove this unused import 'com.study.tank.strategy.FireStrategy'.(·ôÞ<C3B4>úÿÿÿÿ
b
java:S1128"LRemove this unused import 'com.study.tank.strategy.Imp.DefaultFireStrategy'.(ÿŸ‰Û
h
java:S1128"MRemove this unused import 'com.study.tank.strategy.Imp.GoodTankFireStrategy'.(±ÿ<C2B1>¯ýÿÿÿÿ
j
java:S1104"OMake dir a static final constant or non-public and provide accessors if needed.(³Ó‚ªüÿÿÿÿ
k
java:S1104"UMake tankFrame a static final constant or non-public and provide accessors if needed.(¼¹’’

@ -0,0 +1,11 @@
w
java:S2234"ZParameters to collider have the same names but not the same order as the method arguments.(¼˜‹Ï8õôäíÁ0
P
java:S2209"5Change this instance-reference to a static reference.(ÅùÝ¥ýÿÿÿÿ
P
java:S2209"5Change this instance-reference to a static reference.(ÅùÝ¥ýÿÿÿÿ
P
java:S2209""5Change this instance-reference to a static reference.(˜ÏÓ¦üÿÿÿÿ
P
java:S2209""5Change this instance-reference to a static reference.(˜ÏÓ¦üÿÿÿÿ

@ -1,2 +0,0 @@
t java:S120"ZRename this package name to match the regular expression '^[a-z_]+(\.[a-z_][a-z0-9_]*)*$'.(„Ùæšþÿÿÿÿ

@ -1,5 +0,0 @@
\
java:S1610 ":Convert the abstract class "BaseBullet" into an interface.(õʘÙüÿÿÿÿ8­<38>Þ•Á0
M
java:S1128"0Remove this unused import 'com.study.tank.Tank'.(—Þƒä8™¤Þ—Á0

@ -0,0 +1,3 @@
j
java:S1104 "UMake rectangle a static final constant or non-public and provide accessors if needed.(ÁÛ¯?

@ -1,3 +0,0 @@
V
java:S1610 ";Convert the abstract class "GameFactory" into an interface.(ÙæÒƒþÿÿÿÿ

@ -1,11 +0,0 @@
o java:S115 "ZRename this constant name to match the regular expression '^[A-Z][A-Z0-9]*(_[A-Z0-9]+)*$'.(´µ†£
t java:S115"ZRename this constant name to match the regular expression '^[A-Z][A-Z0-9]*(_[A-Z0-9]+)*$'.( §Ûàüÿÿÿÿ
<
java:S1170"!Make this final field static too.(Í¥ä›ùÿÿÿÿ
:
java:S1659"Declare "y" on a separate line.(±šß¯ùÿÿÿÿ
B
java:S1602%",Remove useless curly braces around statement(¥—ýð
Q java:S1254"<This block of commented-out lines of code should be removed.(óÆ<C3B3>Ò
V java:S125a"<This block of commented-out lines of code should be removed.(«åÀ™øÿÿÿÿ

@ -0,0 +1,3 @@
u
java:S2234"ZParameters to collider have the same names but not the same order as the method arguments.(Øåå¶ýÿÿÿÿ

@ -1,13 +0,0 @@
r java:S116)"XRename this field "dataLine_info" to match the regular expression '^[a-z][a-zA-Z0-9]*$'.(¨ô˜„ûÿÿÿÿ
Q java:S125"<This block of commented-out lines of code should be removed.(…£¾ô
V java:S1254"<This block of commented-out lines of code should be removed.(βº‰ùÿÿÿÿ
J
java:S1117>"5Rename "b" which hides the field declared at line 15.(š„ñ_
Q java:S125B"<This block of commented-out lines of code should be removed.(…£¾ô
Q java:S125G"<This block of commented-out lines of code should be removed.(Œîܺ
] java:S125["<This block of commented-out lines of code should be removed.(»ž<C2BB>•ûÿÿÿÿ¸Õ˜Á0
Z
java:S1128 "=Remove this unused import 'javax.sound.sampled.FloatControl'.(ÍÊÍÅ8ÆèΘÁ0
=
java:S2189""Add an end condition to this loop.(˜ïˆžÿÿÿÿÿ

@ -1,9 +0,0 @@
t java:S115"ZRename this constant name to match the regular expression '^[A-Z][A-Z0-9]*(_[A-Z0-9]+)*$'.(µöëæøÿÿÿÿ
t java:S115"ZRename this constant name to match the regular expression '^[A-Z][A-Z0-9]*(_[A-Z0-9]+)*$'.(àê°—þÿÿÿÿ
:
java:S1659"Declare "y" on a separate line.(±šß¯ùÿÿÿÿ
V java:S125#"<This block of commented-out lines of code should be removed.(Ûµ€çüÿÿÿÿ
Q java:S125'"<This block of commented-out lines of code should be removed.(Ò¸ô×
>
java:S1604"(Make this anonymous inner class a lambda(Éãî

@ -1,40 +0,0 @@
t java:S115"ZRename this constant name to match the regular expression '^[A-Z][A-Z0-9]*(_[A-Z0-9]+)*$'.(«¶ó•ûÿÿÿÿ
t java:S115"ZRename this constant name to match the regular expression '^[A-Z][A-Z0-9]*(_[A-Z0-9]+)*$'.(“ƒÎ³øÿÿÿÿ
K
java:S2387")"x" is the name of a field in "BaseTank".(±šß¯ùÿÿÿÿ8÷Š™˜Á0
K
java:S2387")"y" is the name of a field in "BaseTank".(±šß¯ùÿÿÿÿ8øŠ™˜Á0
O
java:S2387"-"group" is the name of a field in "BaseTank".(<28>ãîçúÿÿÿÿ8ùŠ™˜Á0
<
java:S1170"!Make this final field static too.(ñ‹œÞþÿÿÿÿ
:
java:S1659"Declare "y" on a separate line.(±šß¯ùÿÿÿÿ
W
java:S1161":Add the "@Override" annotation above this method signature(´Ç½ ˜Á0
\
java:S1161!":Add the "@Override" annotation above this method signature(ÛöϬúÿÿÿÿ8„˜Á0
] java:S125&"<This block of commented-out lines of code should be removed.(äüø©øÿÿÿÿ8¶ûŠ˜Á0
X java:S125*"<This block of commented-out lines of code should be removed.(ã…éã8½ÁŠ˜Á0
V java:S125/"<This block of commented-out lines of code should be removed.(<28>㪳ýÿÿÿÿ
> java:S1084")Either remove or fill this block of code.(<28>”ý¾
W
java:S1161B":Add the "@Override" annotation above this method signature(Äêñð8‰˜Á0
Q java:S1259"<This block of commented-out lines of code should be removed.(½·¥¯
\
java:S1161F":Add the "@Override" annotation above this method signature(<28>°¿´üÿÿÿÿ˜Á0
\
java:S1161R":Add the "@Override" annotation above this method signature(ôѽþüÿÿÿÿ˜Á0
\
java:S1161V":Add the "@Override" annotation above this method signature(‰§¸Êþÿÿÿÿ8˜Á0
S java:S106h"9Replace this use of System.out or System.err by a logger.(ɳëñýÿÿÿÿ
W java:S125 "<This block of commented-out lines of code should be removed.(¿ÿÅ<C3BF>ýÿÿÿÿ
Q
java:S2209¡"5Change this instance-reference to a static reference.(ÐÇÕ§ÿÿÿÿÿ
Q
java:S2209¢"5Change this instance-reference to a static reference.(¬öלùÿÿÿÿ
j
java:S1104"OMake dir a static final constant or non-public and provide accessors if needed.(³Ó‚ªüÿÿÿÿ
k
java:S1104"UMake tankFrame a static final constant or non-public and provide accessors if needed.(¼¹’’

@ -1,5 +0,0 @@
V
java:S1610 ";Convert the abstract class "BaseExplode" into an interface.(âå·ëøÿÿÿÿ
P
java:S1128"5Remove this unused import 'com.study.tank.TankFrame'.(ÒþÒšüÿÿÿÿ

@ -0,0 +1,3 @@
W
java:S1128"5Remove this unused import 'com.study.tank.GameModel'.(<28>ÈòÀÿÿÿÿÿ8‡ÁîíÁ0

@ -1,3 +0,0 @@
J
java:S2699 "-Add at least one assertion to this test case.(Ýü²ó͘Á0

@ -1,15 +0,0 @@
:
java:S1659"Declare "y" on a separate line.(‰«¥’üÿÿÿÿ
T
java:S5993-"9Change the visibility of this constructor to "protected".(Òœóêýÿÿÿÿ
J
java:S1128"/Remove this unused import 'com.study.tank.Dir'.(Š£Â¹ùÿÿÿÿ
P
java:S1128"5Remove this unused import 'com.study.tank.TankFrame'.(ÒþÒšüÿÿÿÿ
s
java:S1104"QMake group a static final constant or non-public and provide accessors if needed.(˜ÖüÝûÿÿÿÿ8‰‡˜Á0
o
java:S1104"MMake x a static final constant or non-public and provide accessors if needed.(‰«¥’üÿÿÿÿ8¥¢‡˜Á0
o
java:S1104"MMake y a static final constant or non-public and provide accessors if needed.(‰«¥’üÿÿÿÿ8¥¢‡˜Á0

@ -1,9 +0,0 @@
o java:S115"ZRename this constant name to match the regular expression '^[A-Z][A-Z0-9]*(_[A-Z0-9]+)*$'.(´µ†£
t java:S115"ZRename this constant name to match the regular expression '^[A-Z][A-Z0-9]*(_[A-Z0-9]+)*$'.( §Ûàüÿÿÿÿ
<
java:S1170"!Make this final field static too.(Í¥ä›ùÿÿÿÿ
:
java:S1659"Declare "y" on a separate line.(±šß¯ùÿÿÿÿ
B
java:S1602&",Remove useless curly braces around statement(¥—ýð

@ -0,0 +1,12 @@
Q java:S125"<This block of commented-out lines of code should be removed.(¸äˆ
P
java:S2209"5Change this instance-reference to a static reference.(¯œÿ§ùÿÿÿÿ
P
java:S2209"5Change this instance-reference to a static reference.(¯œÿ§ùÿÿÿÿ
J
java:S2209"5Change this instance-reference to a static reference.(ЙÉq
J
java:S2209"5Change this instance-reference to a static reference.(ЙÉq
B
java:S1128"%Remove this unused import 'java.awt'.(ï´µ©8<>¿îíÁ0

@ -1,8 +0,0 @@
t java:S115 "ZRename this constant name to match the regular expression '^[A-Z][A-Z0-9]*(_[A-Z0-9]+)*$'.(µöëæøÿÿÿÿ
t java:S115"ZRename this constant name to match the regular expression '^[A-Z][A-Z0-9]*(_[A-Z0-9]+)*$'.(àê°—þÿÿÿÿ
:
java:S1659"Declare "y" on a separate line.(±šß¯ùÿÿÿÿ
X java:S125 "<This block of commented-out lines of code should be removed.(óÆ<C3B3>Ò8…Ï<E280A6>Á0
>
java:S1604"(Make this anonymous inner class a lambda(Éãî

@ -1,28 +0,0 @@
7 java:S131_""Add a default case to this switch.(°Ó<C2B0>÷
S java:S106t"9Replace this use of System.out or System.err by a logger.(¢ƒÀ™ÿÿÿÿÿ
7 java:S131u""Add a default case to this switch.(°Ó<C2B0>÷
^
java:S1126Š"BReplace this if-then-else statement by a single method invocation.(Ò¦ºÚûÿÿÿÿ
t
java:S2293"YReplace the type specification in this constructor call with the diamond operator ("<>").(­´³•úÿÿÿÿ
t
java:S2293"YReplace the type specification in this constructor call with the diamond operator ("<>").(¡ã˜Ôúÿÿÿÿ
o
java:S2293"YReplace the type specification in this constructor call with the diamond operator ("<>").(‹†²É

java:S1319"eThe type of "tanks" should be an interface such as "List" rather than the implementation "ArrayList".(­´³•úÿÿÿÿ8éÙ±Á0

java:S1319"gThe type of "bullets" should be an interface such as "List" rather than the implementation "ArrayList".(¡ã˜Ôúÿÿÿÿ¸³Á0

java:S1319"hThe type of "explodes" should be an interface such as "List" rather than the implementation "ArrayList".(‹†²É¸³Á0
s
java:S1104"QMake tanks a static final constant or non-public and provide accessors if needed.(­´³•úÿÿÿÿ¸³Á0
t
java:S1104"RMake myTank a static final constant or non-public and provide accessors if needed.(Ÿ«é‚üÿÿÿÿ¸³Á0
u
java:S1104"SMake bullets a static final constant or non-public and provide accessors if needed.(¡ã˜Ôúÿÿÿÿ¸³Á0
q
java:S1104"TMake explodes a static final constant or non-public and provide accessors if needed.(‹†²É8êÙ±Á0
p
java:S1104"NMake gf a static final constant or non-public and provide accessors if needed.(ÓÊ´<C38A>ÿÿÿÿÿ¸³Á0

@ -1,63 +0,0 @@
a
java:S1659"FDeclare "goodTankR" and all following declarations on a separate line.(ôǬ÷ÿÿÿÿÿ
`
java:S1659"EDeclare "badTankR" and all following declarations on a separate line.(<28>ß ýÿÿÿÿ
Z
java:S1659"DDeclare "bulletR" and all following declarations on a separate line.(¼ùÌð
8
java:S2386"Make this member "protected".(·ô®—øÿÿÿÿ
\
java:S1118":Add a private constructor to hide the implicit public one.(ϦÂïùÿÿÿÿ8ŠÉÊ•Á0
p
java:S1104"UMake goodTankL a static final constant or non-public and provide accessors if needed.(ôǬ÷ÿÿÿÿÿ
p
java:S1104"UMake goodTankR a static final constant or non-public and provide accessors if needed.(ôǬ÷ÿÿÿÿÿ
p
java:S1104"UMake goodTankU a static final constant or non-public and provide accessors if needed.(ôǬ÷ÿÿÿÿÿ
p
java:S1104"UMake goodTankD a static final constant or non-public and provide accessors if needed.(ôǬ÷ÿÿÿÿÿ
o
java:S1104"TMake badTankL a static final constant or non-public and provide accessors if needed.(<28>ß ýÿÿÿÿ
o
java:S1104"TMake badTankR a static final constant or non-public and provide accessors if needed.(<28>ß ýÿÿÿÿ
o
java:S1104"TMake badTankU a static final constant or non-public and provide accessors if needed.(<28>ß ýÿÿÿÿ
o
java:S1104"TMake badTankD a static final constant or non-public and provide accessors if needed.(<28>ß ýÿÿÿÿ
i
java:S1104"SMake bulletL a static final constant or non-public and provide accessors if needed.(¼ùÌð
i
java:S1104"SMake bulletR a static final constant or non-public and provide accessors if needed.(¼ùÌð
i
java:S1104"SMake bulletU a static final constant or non-public and provide accessors if needed.(¼ùÌð
i
java:S1104"SMake bulletD a static final constant or non-public and provide accessors if needed.(¼ùÌð
o
java:S1104"TMake explodes a static final constant or non-public and provide accessors if needed.(·ô®—øÿÿÿÿ
J
java:S1444"/Make this "public static goodTankL" field final(ôǬ÷ÿÿÿÿÿ
J
java:S1444"/Make this "public static goodTankR" field final(ôǬ÷ÿÿÿÿÿ
J
java:S1444"/Make this "public static goodTankU" field final(ôǬ÷ÿÿÿÿÿ
J
java:S1444"/Make this "public static goodTankD" field final(ôǬ÷ÿÿÿÿÿ
I
java:S1444".Make this "public static badTankL" field final(<28>ß ýÿÿÿÿ
I
java:S1444".Make this "public static badTankR" field final(<28>ß ýÿÿÿÿ
I
java:S1444".Make this "public static badTankU" field final(<28>ß ýÿÿÿÿ
I
java:S1444".Make this "public static badTankD" field final(<28>ß ýÿÿÿÿ
C
java:S1444"-Make this "public static bulletL" field final(¼ùÌð
C
java:S1444"-Make this "public static bulletR" field final(¼ùÌð
C
java:S1444"-Make this "public static bulletU" field final(¼ùÌð
C
java:S1444"-Make this "public static bulletD" field final(¼ùÌð
I
java:S1444".Make this "public static explodes" field final(·ô®—øÿÿÿÿ

@ -0,0 +1,5 @@
|
java:S2234"ZParameters to collider have the same names but not the same order as the method arguments.(Øåå¶ýÿÿÿÿ8í³éíÁ0
O
java:S3516 "9Refactor this method to not always return the same value.(ÈâØà

@ -1,6 +0,0 @@
K
java:S2209"5Change this instance-reference to a static reference.(õ”Ž‚
P
java:S2209"5Change this instance-reference to a static reference.(€›ººýÿÿÿÿ
t java:S120"ZRename this package name to match the regular expression '^[a-z_]+(\.[a-z_][a-z0-9_]*)*$'.(„Ùæšþÿÿÿÿ

@ -1,5 +0,0 @@
I
java:S1602",Remove useless curly braces around statement(¥—ýð8¼ª»ðÀ0
D
java:S2189""Add an end condition to this loop.(˜ïˆžÿÿÿÿÿ8<>ܹðÀ0

@ -1,47 +0,0 @@
>
study-tank.iml,6\9\69fcf7cf0cb84aa5f9c25dd41d8b89bcf868840a
]
-src/main/java/com/study/tank/PropertyMgr.java,f\a\fa22466dc106d781e88480a5609428c6ed1e96c2
]
-src/main/java/com/study/tank/ImageManger.java,e\3\e33fa438c138d070344c0d8500f75aa75f823e55
7
pom.xml,4\4\442292b8a7efeabbe4cc176709b833b1792140ec
Y
)src/main/java/com/study/tank/Explode.java,a\7\a7a9714ccccb1e9cd6c18c07b50adb6fb63efde1
e
5src/main/java/com/study/tank/factory/RectExplode.java,6\9\69e5f1fcaeb728725015172c220b41d4f2f3235c
e
5src/main/java/com/study/tank/factory/GameFactory.java,4\0\40f02948eb790c7986e5ecd2216cd56c8d1316c0
g
7src/main/java/com/study/tank/strategy/FireStrategy.java,e\2\e2f699d7ece4648d65d8f55bbb53b4c1a97a0134
e
5src/main/java/com/study/tank/factory/BaseExplode.java,7\3\739d9cb13e6b2724f1a0fbbf0a0a279d33a10ff3
d
4src/main/java/com/study/tank/factory/BaseBullet.java,2\9\2995ce511c59d5daf350eb58870c6c2ad9774f9c
e
5src/main/java/com/study/tank/factory/RoundBullet.java,4\a\4a5d2311ad0ce6ee7cbe87839280d9b76f3a4b04
X
(src/main/java/com/study/tank/Bullet.java,9\e\9e5a3f4cb2d4a5a75750157065729f2eb8cc0a07
b
2src/main/java/com/study/tank/factory/BaseTank.java,9\d\9d993a8181111dcdfd4f4d45ff6e01eca290e383
a
1src/main/java/com/study/tank/factory/WarTank.java,7\0\70f82ce88ac6b54afd6eed03fe6951084561b5c5
e
5src/main/java/com/study/tank/factory/RectFactory.java,4\6\469cb43b51ba7e207f3767d69d0e3deded4e3c93
V
&src/main/java/com/study/tank/Tank.java,0\8\081d67b31c95c91f6926f605dfc94fdd2bada262
Z
*src/main/java/com/study/tank/TestMain.java,f\0\f05c3638610e0ce274846e174c61431121775426
h
8src/main/java/com/study/tank/factory/DefaultFactory.java,8\a\8a8f68332c66aa57898f0442651ad801e856c9d1
s
Csrc/main/java/com/study/tank/strategy/Imp/GoodTankFireStrategy.java,1\6\1652b301de6e1dadaab20f1f8c9dcf053f3cd3a7
r
Bsrc/main/java/com/study/tank/strategy/Imp/DefaultFireStrategy.java,e\b\ebd48d685c9a0a6dded8bb1c6d2c75c717c9c10d
W
'src/main/java/com/study/tank/Audio.java,5\b\5bd8e55a95e8e3ef2459b7d56ee9a74443b8f788
[
+src/test/java/com/study/tank/ImageTest.java,9\7\97cf6348e49d166ce567c6eb53c9d085ee3b786c
[
+src/main/java/com/study/tank/TankFrame.java,c\d\cd8bb0d273a44e56af2c725281536ed379107cc0

@ -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>

@ -10,15 +10,16 @@ import java.awt.*;
* @Auther: xiaoshengjie
* @Date: 2022/10/22/11:16
*/
public class Bullet extends BaseBullet {
public class Bullet extends GameObject {
public static final int bWidth = ImageManger.bulletL.getWidth();
public static final int bHeight = ImageManger.bulletL.getHeight();
private int x, y;
// public int x, y;
private Dir dir = Dir.DOWN;
private final int speed = 10;
private boolean living = true;
TankFrame tf = null;
private Group group = Group.BAD;
//TankFrame tf = null;
public Group group = Group.BAD;
public Rectangle rectangle = new Rectangle();
public Group getGroup() {
return group;
@ -28,21 +29,25 @@ public class Bullet extends BaseBullet {
this.group = group;
}
public Bullet(int x, int y, Dir dir, Group group, TankFrame tankFrame) {
public Bullet(int x, int y, Dir dir, Group group) {
super();
this.x = x;
this.y = y;
this.dir = dir;
this.tf = tankFrame;
this.group = group;
tankFrame.bullets.add(this);
this.rectangle.x = x;
this.rectangle.y = y;
this.rectangle.width = bWidth;
this.rectangle.height = bHeight;
new Thread(() -> {
new Audio("audio/tank_fire.wav");
}).start();
GameModel.INSTANCE.add(this);
}
public void paint(Graphics g) {
if (!living) tf.bullets.remove(this);
if (!living) GameModel.INSTANCE.remove(this);
switch (dir) {
case DOWN:
g.drawImage(ImageManger.bulletD, x, y, null);
@ -78,6 +83,8 @@ public class Bullet extends BaseBullet {
y += speed;
break;
}
rectangle.x = x;
rectangle.y = y;
if (x < 0 || y < 0 || x > TankFrame.GAME_WIDTH || y > TankFrame.GAME_HEIGHT) {
living = false;
}
@ -86,15 +93,15 @@ public class Bullet extends BaseBullet {
/**
*
*/
public void collideWithTank(BaseTank tank) {
public void collideWithTank(Tank tank) {
if (this.group == tank.getGroup()) return;
Rectangle rect1 = new Rectangle(this.x, this.y, bWidth, bHeight);
Rectangle rect2 = new Rectangle(tank.getX(), tank.getY(), Tank.tankWidth, Tank.tankHeight);
Rectangle rect2 = new Rectangle(tank.x, tank.y, Tank.tankWidth, Tank.tankHeight);
//碰撞矩形
if (rect1.intersects(rect2)) {
tank.die();
this.die();
tf.explodes.add(tf.gf.createExplode(this.x + bWidth / 2 - Explode.bWidth / 2, this.y + bWidth - Explode.bHeight / 2, tf));
new Explode(this.x + bWidth / 2 - Explode.bWidth / 2, this.y + bWidth - Explode.bHeight / 2);
}
}

@ -9,39 +9,30 @@ import java.awt.*;
* @Auther: xiaoshengjie
* @Date: 2022/10/22/11:16
*/
public class Explode extends BaseExplode {
public class Explode extends GameObject {
public static final int bWidth = ImageManger.explodes[0].getWidth();
public static final int bHeight = ImageManger.explodes[0].getHeight();
private int x, y;
TankFrame tf = null;
private int step = 0;
public Explode(int x, int y, TankFrame tankFrame) {
public Explode(int x, int y) {
this.x = x;
this.y = y;
this.tf = tankFrame;
new Thread(new Runnable() {
public void run() {
new Audio("audio/explode.wav").play();
}
}).start();
GameModel.INSTANCE.add(this);
}
// public void paint(Graphics g) {
// g.drawImage(ImageManger.explodes[step++], x, y, null);
// if (step >= ImageManger.explodes.length) {
// tf.explodes.remove(this);
// }
// }
@Override
public void paint(Graphics g) {
g.drawImage(ImageManger.explodes[step++], x, y, null);
if (step >= ImageManger.explodes.length) {
tf.explodes.remove(this);
GameModel.INSTANCE.remove(this);
}
}
}

@ -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);
}

@ -2,75 +2,50 @@ package com.study.tank;
import com.study.tank.factory.BaseTank;
import com.study.tank.strategy.FireStrategy;
import com.study.tank.strategy.Imp.DefaultFireStrategy;
import com.study.tank.strategy.Imp.GoodTankFireStrategy;
//import com.study.tank.strategy.Imp.DefaultFireStrategy;
//import com.study.tank.strategy.Imp.GoodTankFireStrategy;
import java.awt.*;
import java.util.Random;
import java.util.UUID;
/**
* @Description:
* @Auther: xiaoshengjie
* @Date: 2022/10/22/10:08
*/
public class Tank extends BaseTank {
public class Tank extends GameObject {
public static final int tankWidth = ImageManger.goodTankU.getWidth();
public static final int tankHeight = ImageManger.goodTankU.getHeight();
private boolean moving = true;
// private int x, y;
private boolean living = true;
public Dir dir = Dir.DOWN;
private final int speed = 4;
public TankFrame tankFrame = null;
private final int speed = 5;
//public TankFrame tankFrame = null;
private Random random = new Random();
//Group group = Group.BAD;
// FireStrategy fs;
// public Group getGroup() {
// return group;
// }
//
// public void setGroup(Group group) {
// this.group = group;
// }
public Tank(int x, int y, Dir dir, Group group, TankFrame tankFrame) {
// this.x = x;
// this.y = y;
super(x, y, group);
public Group group = Group.BAD;
public Rectangle rectangle = new Rectangle();
int oldX, oldY;
public String uuid;
public Tank(int x, int y, Dir dir, Group group) {
super();
this.x = x;
this.y = y;
this.dir = dir;
//this.group = group;
this.tankFrame = tankFrame;
// 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();
// } 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;
// }
this.group = group;
this.oldY = y;
this.oldX = x;
this.uuid = UUID.randomUUID().toString();
rectangle.x = x;
rectangle.y = y;
rectangle.width = Tank.tankWidth;
rectangle.height = Tank.tankHeight;
GameModel.INSTANCE.add(this);
}
public Dir getDir() {
return dir;
@ -80,14 +55,6 @@ public class Tank extends BaseTank {
return speed;
}
// public void setX(int x) {
// this.x = x;
// }
//
// public void setY(int y) {
// this.y = y;
// }
public boolean isMoving() {
return moving;
}
@ -100,37 +67,18 @@ public class Tank extends BaseTank {
this.dir = dir;
}
// public void paint(Graphics g) {
// System.out.println("tank paint");
// if (!living) {
// tankFrame.tanks.remove(this);
// moving = false;
// return;
// }
// switch (this.dir) {
// case DOWN:
// g.drawImage(this.group == Group.GOOD ? ImageManger.goodTankD : ImageManger.badTankD, this.x, this.y, null);
// break;
// case UP:
// g.drawImage(this.group == Group.GOOD ? ImageManger.goodTankU : ImageManger.badTankU, this.x, this.y, null);
// break;
// case RIGHT:
// g.drawImage(this.group == Group.GOOD ? ImageManger.goodTankR : ImageManger.badTankR, this.x, this.y, null);
// break;
// case LEFT:
// g.drawImage(this.group == Group.GOOD ? ImageManger.goodTankL : ImageManger.badTankL, this.x, this.y, null);
// break;
// }
// move();
// }
public Group getGroup() {
return group;
}
public void setGroup(Group group) {
this.group = group;
}
@Override
public void paint(Graphics g) {
System.out.println("tank paint");
if (!living) {
tankFrame.tanks.remove(this);
moving = false;
GameModel.INSTANCE.remove(this);
return;
}
switch (this.dir) {
@ -151,9 +99,12 @@ public class Tank extends BaseTank {
}
public void move() {
if (!living) return;
if (!this.moving) return;
switch (dir) {
if (!this.moving) {
return;
}
oldX = this.x;
oldY = this.y;
switch (this.dir) {
case LEFT:
x -= speed;
break;
@ -179,13 +130,15 @@ public class Tank extends BaseTank {
new Audio("audio/tank_move.wav").play();
}).start();
}
rectangle.x = x;
rectangle.y = y;
}
private void boundsCheck() {
if (this.x < 0) x = TankFrame.GAME_WIDTH - Tank.tankWidth;
if (this.y < 28) y = TankFrame.GAME_HEIGHT - Tank.tankHeight;
if (this.x > TankFrame.GAME_WIDTH - tankWidth) x = 0;
if (this.y > TankFrame.GAME_HEIGHT - tankHeight) y = 28;
if (x < 0) x = TankFrame.GAME_WIDTH - Tank.tankWidth;
if (y < 28) y = TankFrame.GAME_HEIGHT - Tank.tankHeight;
if (x > TankFrame.GAME_WIDTH - tankWidth) x = 0;
if (y > TankFrame.GAME_HEIGHT - tankHeight) y = 28;
}
//0.4几率的随机方向
@ -199,30 +152,37 @@ public class Tank extends BaseTank {
*/
public void fire() {
//fs.fire(this);
int bx = this.getX() + Tank.tankWidth / 2 - ImageManger.bulletD.getWidth() / 2;
int by = this.getY() + Tank.tankHeight / 2 - ImageManger.bulletD.getHeight() / 2;
switch (this.dir) {
int bx = x + Tank.tankWidth / 2 - ImageManger.bulletD.getWidth() / 2;
int by = y + Tank.tankHeight / 2 - ImageManger.bulletD.getHeight() / 2;
switch (dir) {
case DOWN:
new Bullet(bx, by + 6, this.dir, this.getGroup(), this.tankFrame);
new Bullet(bx, by - 6, this.dir, this.getGroup(), this.tankFrame);
new Bullet(bx, by + 6, this.dir, this.getGroup());
new Bullet(bx, by - 6, this.dir, this.getGroup());
break;
case UP:
new Bullet(bx + 1, by + 6, this.dir, this.getGroup(), this.tankFrame);
new Bullet(bx + 1, by - 6, this.dir, this.getGroup(), this.tankFrame);
new Bullet(bx + 1, by + 6, this.dir, this.getGroup());
new Bullet(bx + 1, by - 6, this.dir, this.getGroup());
break;
case LEFT:
new Bullet(bx + 6, by, this.dir, this.getGroup(), this.tankFrame);
new Bullet(bx - 6, by, this.dir, this.getGroup(), this.tankFrame);
new Bullet(bx + 6, by, this.dir, this.getGroup());
new Bullet(bx - 6, by, this.dir, this.getGroup());
break;
case RIGHT:
new Bullet(bx + 6, by + 1, this.dir, this.getGroup(), this.tankFrame);
new Bullet(bx - 6, by + 1, this.dir, this.getGroup(), this.tankFrame);
new Bullet(bx + 6, by + 1, this.dir, this.getGroup());
new Bullet(bx - 6, by + 1, this.dir, this.getGroup());
break;
}
}
public void stop() {
this.moving = false;
}
public void goBack() {
x = oldX;
y = oldY;
}
@Override
public void die() {
this.living = false;
}

@ -17,11 +17,8 @@ import java.util.ArrayList;
public class TankFrame extends Frame {
public static final int GAME_WIDTH = Integer.parseInt((String) PropertyMgr.get("gameWidth"));
public static final int GAME_HEIGHT = Integer.parseInt((String) PropertyMgr.get("gameHeight"));
public ArrayList<BaseTank> tanks = new ArrayList<BaseTank>();
public Tank myTank = new Tank(150, 150, Dir.DOWN, Group.GOOD, this);
public ArrayList<BaseBullet> bullets = new ArrayList<BaseBullet>();
public ArrayList<BaseExplode> explodes = new ArrayList<BaseExplode>();
public GameFactory gf = new DefaultFactory();
// GameModel gameModel = new GameModel();
// public GameFactory gf = new DefaultFactory();
public TankFrame() {
//设置窗口大小
@ -58,26 +55,7 @@ public class TankFrame extends Frame {
@Override
public void paint(Graphics g) {
Color c = g.getColor();
g.setColor(Color.BLUE);
g.drawString("子弹的数量:" + bullets.size(), 5, 40);
g.drawString("敌人的数量:" + tanks.size(), 5, 60);
g.setColor(c);
myTank.paint(g);
for (int i = 0; i < tanks.size(); i++) {
tanks.get(i).paint(g);
}
for (int i = 0; i < bullets.size(); i++) {
bullets.get(i).paint(g);
}
for (int i = 0; i < bullets.size(); i++) {
for (int j = 0; j < tanks.size(); j++) {
bullets.get(i).collideWithTank(tanks.get(j));
}
}
for (int i = 0; i < explodes.size(); i++) {
explodes.get(i).paint(g);
}
GameModel.INSTANCE.paint(g);
}
/**
@ -113,7 +91,6 @@ public class TankFrame extends Frame {
public void keyReleased(KeyEvent e) {
super.keyReleased(e);
int key = e.getKeyCode();
System.out.println("弹起:" + key);
switch (key) {
case KeyEvent.VK_A:
bL = false;
@ -128,7 +105,13 @@ public class TankFrame extends Frame {
bD = false;
break;
case KeyEvent.VK_SPACE:
myTank.fire();
GameModel.INSTANCE.myTank.fire();
break;
case KeyEvent.VK_U:
GameModel.INSTANCE.save();
break;
case KeyEvent.VK_P:
GameModel.INSTANCE.load();
break;
}
setDirMethod();
@ -136,14 +119,14 @@ public class TankFrame extends Frame {
public void setDirMethod() {
if (!bD && !bU && !bR && !bL) {
myTank.setMoving(false);
GameModel.INSTANCE.myTank.setMoving(false);
} else {
myTank.setMoving(true);
GameModel.INSTANCE.myTank.setMoving(true);
}
if (bL) myTank.setDir(Dir.LEFT);
if (bR) myTank.setDir(Dir.RIGHT);
if (bU) myTank.setDir(Dir.UP);
if (bD) myTank.setDir(Dir.DOWN);
if (bL) GameModel.INSTANCE.myTank.setDir(Dir.LEFT);
if (bR) GameModel.INSTANCE.myTank.setDir(Dir.RIGHT);
if (bU) GameModel.INSTANCE.myTank.setDir(Dir.UP);
if (bD) GameModel.INSTANCE.myTank.setDir(Dir.DOWN);
}
}

@ -8,14 +8,7 @@ package com.study.tank;
public class TestMain {
public static void main(String[] args) throws InterruptedException {
TankFrame tf = new TankFrame();
//初始化敌人坦克
int initCountTank = Integer.parseInt((String) PropertyMgr.get("initTankCount"));
for (int i = 0; i < initCountTank; i++) {
tf.tanks.add(tf.gf.createTank(80 + i * 100, 50, Dir.DOWN, Group.BAD, tf));
}
new Thread(() -> {
new Audio("audio/war1.wav").loop();
}).start();

@ -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,26 @@
package com.study.tank.command;
/**
* @author xsj
* @date 2022/11/1 10:09
*/
public class CopyCommand extends Command {
Content c;
private final int index = 1;
public CopyCommand(Content c) {
this.c = c;
}
@Override
void doIt() {
c.msg = c.msg + c.msg;
System.out.println("copy新数据操作后" + c.msg);
}
@Override
void unDo() {
c.msg = c.msg.substring(0, c.msg.length() / 2);
System.out.println("取消copy新数据操作后" + c.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;
import com.study.tank.*;
/**
* @author xsj
* @date 2022/10/26 13:13
*/
public class DefaultFactory extends GameFactory {
@Override
public BaseTank createTank(int x, int y, Dir dir, Group group, TankFrame tankFrame) {
return new Tank(x, y, dir, group, tankFrame);
}
@Override
public BaseBullet createBullet(int x, int y, Dir dir, Group group, TankFrame tankFrame) {
return new Bullet(x,y,dir,group,tankFrame);
}
@Override
public BaseExplode createExplode(int x, int y, TankFrame tankFrame) {
return new Explode(x, y, tankFrame);
}
}
//package com.study.tank.factory;
//
//import com.study.tank.*;
//
///**
// * @author xsj
// * @date 2022/10/26 13:13
// */
//public class DefaultFactory extends GameFactory {
//
// @Override
// public BaseTank createTank(int x, int y, Dir dir, Group group, TankFrame tankFrame) {
// return new Tank(x, y, dir, group, tankFrame);
// }
//
// @Override
// public BaseBullet createBullet(int x, int y, Dir dir, Group group, TankFrame tankFrame) {
// return new Bullet(x,y,dir,group,tankFrame);
// }
//
// @Override
// public BaseExplode createExplode(int x, int y, TankFrame tankFrame) {
// return new Explode(x, y, tankFrame);
// }
//}

@ -1,46 +1,46 @@
package com.study.tank.factory;
import com.study.tank.Audio;
import com.study.tank.ImageManger;
import com.study.tank.TankFrame;
import java.awt.*;
/**
* @author xsj
* @date 2022/10/26 13:37
*/
public class RectExplode extends BaseExplode {
public static final int bWidth = ImageManger.explodes[0].getWidth();
public static final int bHeight = ImageManger.explodes[0].getHeight();
private int x, y;
TankFrame tf = null;
private int step = 0;
public RectExplode(int x, int y, TankFrame tankFrame) {
this.x = x;
this.y = y;
this.tf = tankFrame;
new Thread(new Runnable() {
public void run() {
new Audio("audio/explode.wav").play();
}
}).start();
}
@Override
public void paint(Graphics g) {
// g.drawImage(ImageManger.explodes[step++], x, y, null);
Color c = g.getColor();
g.setColor(Color.red);
g.fillRect(x, y, 10 * step, 10 * step);
// if (step >= ImageManger.explodes.length) {
// tf.explodes.remove(this);
//package com.study.tank.factory;
//
//import com.study.tank.Audio;
//import com.study.tank.ImageManger;
//import com.study.tank.TankFrame;
//
//import java.awt.*;
//
///**
// * @author xsj
// * @date 2022/10/26 13:37
// */
//public class RectExplode extends BaseExplode {
// public static final int bWidth = ImageManger.explodes[0].getWidth();
// public static final int bHeight = ImageManger.explodes[0].getHeight();
// private int x, y;
// TankFrame tf = null;
// private int step = 0;
//
//
// public RectExplode(int x, int y, TankFrame tankFrame) {
// this.x = x;
// this.y = y;
// this.tf = tankFrame;
//
// new Thread(new Runnable() {
// public void run() {
// new Audio("audio/explode.wav").play();
// }
step++;
if (step > 5) tf.explodes.remove(this);
g.setColor(c);
}
}
// }).start();
// }
//
// @Override
// public void paint(Graphics g) {
//// g.drawImage(ImageManger.explodes[step++], x, y, null);
// Color c = g.getColor();
// g.setColor(Color.red);
// g.fillRect(x, y, 10 * step, 10 * step);
//// if (step >= ImageManger.explodes.length) {
//// tf.explodes.remove(this);
//// }
// step++;
// if (step > 5) tf.explodes.remove(this);
// g.setColor(c);
// }
//}

@ -1,25 +1,25 @@
package com.study.tank.factory;
import com.study.tank.*;
/**
* @author xsj
* @date 2022/10/26 13:36
*/
public class RectFactory extends GameFactory {
@Override
public BaseTank createTank(int x, int y, Dir dir, Group group, TankFrame tankFrame) {
return new WarTank(x, y, dir, group, tankFrame);
}
@Override
public BaseBullet createBullet(int x, int y, Dir dir, Group group, TankFrame tankFrame) {
return new RoundBullet(x, y, dir, group, tankFrame);
}
@Override
public BaseExplode createExplode(int x, int y, TankFrame tankFrame) {
return new RectExplode(x, y, tankFrame);
}
}
//package com.study.tank.factory;
//
//import com.study.tank.*;
//
///**
// * @author xsj
// * @date 2022/10/26 13:36
// */
//public class RectFactory extends GameFactory {
//
// @Override
// public BaseTank createTank(int x, int y, Dir dir, Group group, TankFrame tankFrame) {
// return new WarTank(x, y, dir, group, tankFrame);
// }
//
// @Override
// public BaseBullet createBullet(int x, int y, Dir dir, Group group, TankFrame tankFrame) {
// return new RoundBullet(x, y, dir, group, tankFrame);
// }
//
// @Override
// public BaseExplode createExplode(int x, int y, TankFrame tankFrame) {
// return new RectExplode(x, y, tankFrame);
// }
//}

@ -1,100 +1,112 @@
package com.study.tank.factory;
import com.study.tank.*;
import java.awt.*;
/**
* @Description:
* @Auther: xiaoshengjie
* @Date: 2022/10/22/11:16
*/
public class RoundBullet extends BaseBullet {
public static final int bWidth = ImageManger.bulletL.getWidth();
public static final int bHeight = ImageManger.bulletL.getHeight();
private int x, y;
private Dir dir = Dir.DOWN;
private final int speed = 10;
private boolean living = true;
TankFrame tf = null;
private Group group = Group.BAD;
public Group getGroup() {
return group;
}
public void setGroup(Group group) {
this.group = group;
}
public RoundBullet(int x, int y, Dir dir, Group group, TankFrame tankFrame) {
this.x = x;
this.y = y;
this.dir = dir;
this.tf = tankFrame;
this.group = group;
tankFrame.bullets.add(this);
new Thread(() -> {
new Audio("audio/tank_fire.wav");
}).start();
}
@Override
public void paint(Graphics g) {
if (!living) tf.bullets.remove(this);
Color c = g.getColor();
g.setColor(Color.RED);
g.fillOval(x, y, 20, 20);
g.setColor(c);
move();
}
//package com.study.tank.factory;
//
//import com.study.tank.*;
//
//import java.awt.*;
//
///**
// * @Description:
// * @Auther: xiaoshengjie
// * @Date: 2022/10/22/上午11:16
// */
//public class RoundBullet extends BaseBullet {
// public static final int bWidth = ImageManger.bulletL.getWidth();
// public static final int bHeight = ImageManger.bulletL.getHeight();
// private int x, y;
// private Dir dir = Dir.DOWN;
// private final int speed = 10;
// private boolean living = true;
// TankFrame tf = null;
// private Group group = Group.BAD;
//
// public Group getGroup() {
// return group;
// }
//
// public void setGroup(Group group) {
// this.group = group;
// }
//
// public RoundBullet(int x, int y, Dir dir, Group group, TankFrame tankFrame) {
// this.x = x;
// this.y = y;
// this.dir = dir;
// this.tf = tankFrame;
// this.group = group;
// tankFrame.bullets.add(this);
// new Thread(() -> {
// new Audio("audio/tank_fire.wav");
// }).start();
// }
//
// @Override
// public void paint(Graphics g) {
// if (!living) tf.bullets.remove(this);
// Color c = g.getColor();
// g.setColor(Color.RED);
// g.fillOval(x, y, 20, 20);
// g.setColor(c);
// move();
// }
//
//// public void paint(Graphics g) {
//// if (!living) tf.bullets.remove(this);
//// switch (dir) {
//// case DOWN:
//// g.drawImage(ImageManger.bulletD, x, y, null);
//// break;
//// case UP:
//// g.drawImage(ImageManger.bulletU, x, y, null);
//// break;
//// case RIGHT:
//// g.drawImage(ImageManger.bulletR, x, y, null);
//// break;
//// case LEFT:
//// g.drawImage(ImageManger.bulletL, x, y, null);
//// break;
//// }
//// move();
//// }
//
// /**
// * 移动
// */
// public void move() {
// switch (dir) {
// case DOWN:
// g.drawImage(ImageManger.bulletD, x, y, null);
// break;
// case UP:
// g.drawImage(ImageManger.bulletU, x, y, null);
// case LEFT:
// x -= speed;
// break;
// case RIGHT:
// g.drawImage(ImageManger.bulletR, x, y, null);
// x += speed;
// break;
// case LEFT:
// g.drawImage(ImageManger.bulletL, x, y, null);
// case UP:
// y -= speed;
// break;
// case DOWN:
// y += speed;
// break;
// }
// move();
// if (x < 0 || y < 0 || x > TankFrame.GAME_WIDTH || y > TankFrame.GAME_HEIGHT) {
// living = false;
// }
/**
*
*/
public void move() {
switch (dir) {
case LEFT:
x -= speed;
break;
case RIGHT:
x += speed;
break;
case UP:
y -= speed;
break;
case DOWN:
y += speed;
break;
}
if (x < 0 || y < 0 || x > TankFrame.GAME_WIDTH || y > TankFrame.GAME_HEIGHT) {
living = false;
}
}
/**
*
*/
// public void collideWithTank(Tank tank) {
// }
//
// /**
// * 碰撞
// */
//// public void collideWithTank(Tank tank) {
//// if (this.group == tank.getGroup()) return;
//// Rectangle rect1 = new Rectangle(this.x, this.y, bWidth, bHeight);
//// Rectangle rect2 = new Rectangle(tank.getX(), tank.getY(), Tank.tankWidth, Tank.tankHeight);
//// //碰撞矩形
//// if (rect1.intersects(rect2)) {
//// tank.die();
//// this.die();
//// tf.explodes.add(tf.gf.createExplode(this.x + bWidth / 2 - Explode.bWidth / 2, this.y + bWidth - Explode.bHeight / 2, tf));
//// }
//// }
// @Override
// public void collideWithTank(BaseTank tank) {
// if (this.group == tank.getGroup()) return;
// Rectangle rect1 = new Rectangle(this.x, this.y, bWidth, bHeight);
// Rectangle rect2 = new Rectangle(tank.getX(), tank.getY(), Tank.tankWidth, Tank.tankHeight);
@ -105,21 +117,9 @@ public class RoundBullet extends BaseBullet {
// tf.explodes.add(tf.gf.createExplode(this.x + bWidth / 2 - Explode.bWidth / 2, this.y + bWidth - Explode.bHeight / 2, tf));
// }
// }
@Override
public void collideWithTank(BaseTank tank) {
if (this.group == tank.getGroup()) return;
Rectangle rect1 = new Rectangle(this.x, this.y, bWidth, bHeight);
Rectangle rect2 = new Rectangle(tank.getX(), tank.getY(), Tank.tankWidth, Tank.tankHeight);
//碰撞矩形
if (rect1.intersects(rect2)) {
tank.die();
this.die();
tf.explodes.add(tf.gf.createExplode(this.x + bWidth / 2 - Explode.bWidth / 2, this.y + bWidth - Explode.bHeight / 2, tf));
}
}
public void die() {
this.living = false;
}
}
//
// public void die() {
// this.living = false;
// }
//
//}

@ -1,170 +1,170 @@
package com.study.tank.factory;
import com.study.tank.*;
import com.study.tank.strategy.FireStrategy;
import com.study.tank.strategy.Imp.DefaultFireStrategy;
import java.awt.*;
import java.util.Random;
/**
* @Description:
* @Auther: xiaoshengjie
* @Date: 2022/10/22/10:08
*/
public class WarTank extends BaseTank {
public static final int tankWidth = ImageManger.goodTankU.getWidth();
public static final int tankHeight = ImageManger.goodTankU.getHeight();
private boolean moving = true;
private int x, y;
private boolean living = true;
public Dir dir = Dir.DOWN;
private final int speed = 4;
public TankFrame tankFrame = null;
private Random random = new Random();
Group group = Group.BAD;
FireStrategy fs;
public Group getGroup() {
return 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;
//package com.study.tank.factory;
//
//import com.study.tank.*;
//import com.study.tank.strategy.FireStrategy;
//import com.study.tank.strategy.Imp.DefaultFireStrategy;
//
//import java.awt.*;
//import java.util.Random;
//
///**
// * @Description:
// * @Auther: xiaoshengjie
// * @Date: 2022/10/22/上午10:08
// */
//public class WarTank extends BaseTank {
// public static final int tankWidth = ImageManger.goodTankU.getWidth();
// public static final int tankHeight = ImageManger.goodTankU.getHeight();
// private boolean moving = true;
// private int x, y;
// private boolean living = true;
// public Dir dir = Dir.DOWN;
// private final int speed = 4;
// public TankFrame tankFrame = null;
// private Random random = new Random();
// Group group = Group.BAD;
//
// FireStrategy fs;
//
// public Group getGroup() {
// return group;
// }
//
// public void setGroup(Group group) {
// this.group = group;
this.tankFrame = tankFrame;
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();
} else {
fs = new DefaultFireStrategy();
}
} catch (Exception e) {
}
}
// public Tank(int x, int y, Dir dir, Group group, boolean moving, TankFrame tankFrame) {
// }
//
// 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.tankFrame = tankFrame;
// 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();
// } 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;
// }
//
// public void setY(int 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.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;
}
public void setY(int 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;
}
@Override
public void paint(Graphics g) {
System.out.println("war paint");
if (!living) {
tankFrame.tanks.remove(this);
moving = false;
return;
}
Color c = g.getColor();
g.setColor(group == Group.GOOD ? Color.BLUE : Color.YELLOW);
g.fillRect(x, y, 40, 40);
g.setColor(c);
move();
}
public void move() {
if (!living) return;
if (!this.moving) return;
switch (dir) {
case LEFT:
x -= speed;
break;
case RIGHT:
x += speed;
break;
case UP:
y -= speed;
break;
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;
}
}
// }
//
// @Override
// public void paint(Graphics g) {
// System.out.println("war paint");
// if (!living) {
// tankFrame.tanks.remove(this);
// moving = false;
// return;
// }
// Color c = g.getColor();
// g.setColor(group == Group.GOOD ? Color.BLUE : Color.YELLOW);
// g.fillRect(x, y, 40, 40);
// g.setColor(c);
// move();
// }
//
// public void move() {
// if (!living) return;
// if (!this.moving) return;
// switch (dir) {
// case LEFT:
// x -= speed;
// break;
// case RIGHT:
// x += speed;
// break;
// case UP:
// y -= speed;
// break;
// 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-------");
}
}

@ -0,0 +1,28 @@
package com.study.tank.sate;
/**
* @author xsj
* @date 2022/11/1 16:04
*/
public class RunCarSate extends CarSate {
@Override
void open() {
System.out.println("run状态不能open-----------");
}
@Override
void closed() {
System.out.println("run状态不能closed-----------");
}
@Override
void running() {
System.out.println("run状态不需要继续running-----------");
}
@Override
void stop() {
System.out.println("run状态可以stop-----------");
}
}

@ -0,0 +1,28 @@
package com.study.tank.sate;
/**
* @author xsj
* @date 2022/11/1 16:06
*/
public class StopCarSate extends CarSate {
@Override
void open() {
System.out.println("stop状态可以open-------");
}
@Override
void closed() {
System.out.println("stop状态不可以closed-------");
}
@Override
void running() {
System.out.println("stop状态可以running-------");
}
@Override
void stop() {
System.out.println("stop状态不需要stop-------");
}
}

@ -1,20 +1,20 @@
package com.study.tank.strategy.Imp;
import com.study.tank.Bullet;
import com.study.tank.ImageManger;
import com.study.tank.Tank;
import com.study.tank.strategy.FireStrategy;
/**
* @author xsj
* @date 2022/10/25 10:30
*/
public class DefaultFireStrategy implements FireStrategy {
@Override
public void fire(Tank tank) {
int bx = tank.getX() + tank.tankWidth / 2 - ImageManger.bulletD.getWidth() / 2 + 2;
int by = tank.getY() + tank.tankHeight / 2 - ImageManger.bulletD.getHeight() / 2 + 2;
new Bullet(bx, by, tank.dir, tank.getGroup(), tank.tankFrame);
}
}
//package com.study.tank.strategy.Imp;
//
//import com.study.tank.Bullet;
//import com.study.tank.ImageManger;
//import com.study.tank.Tank;
//import com.study.tank.strategy.FireStrategy;
//
///**
// * @author xsj
// * @date 2022/10/25 10:30
// */
//public class DefaultFireStrategy implements FireStrategy {
//
// @Override
// public void fire(Tank tank) {
// int bx = tank.getX() + tank.tankWidth / 2 - ImageManger.bulletD.getWidth() / 2 + 2;
// int by = tank.getY() + tank.tankHeight / 2 - ImageManger.bulletD.getHeight() / 2 + 2;
// new Bullet(bx, by, tank.dir, tank.getGroup(), tank.tankFrame);
// }
//}

@ -1,39 +1,39 @@
package com.study.tank.strategy.Imp;
import com.study.tank.Bullet;
import com.study.tank.ImageManger;
import com.study.tank.Tank;
import com.study.tank.strategy.FireStrategy;
/**
* @author xsj
* @date 2022/10/25 13:28
*/
public class GoodTankFireStrategy implements FireStrategy {
@Override
public void fire(Tank tank) {
int bx = tank.getX() + Tank.tankWidth / 2 - ImageManger.bulletD.getWidth() / 2;
int by = tank.getY() + Tank.tankHeight / 2 - ImageManger.bulletD.getHeight() / 2;
switch (tank.dir) {
case DOWN:
new Bullet(bx, by + 6, tank.dir, tank.getGroup(), tank.tankFrame);
new Bullet(bx, by - 6, tank.dir, tank.getGroup(), tank.tankFrame);
break;
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);
break;
case LEFT:
new Bullet(bx + 6, by, tank.dir, tank.getGroup(), tank.tankFrame);
new Bullet(bx - 6, by, tank.dir, tank.getGroup(), tank.tankFrame);
break;
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);
break;
}
}
}
//package com.study.tank.strategy.Imp;
//
//import com.study.tank.Bullet;
//import com.study.tank.ImageManger;
//import com.study.tank.Tank;
//import com.study.tank.strategy.FireStrategy;
//
///**
// * @author xsj
// * @date 2022/10/25 13:28
// */
//public class GoodTankFireStrategy implements FireStrategy {
//
// @Override
// public void fire(Tank tank) {
// int bx = tank.getX() + Tank.tankWidth / 2 - ImageManger.bulletD.getWidth() / 2;
// int by = tank.getY() + Tank.tankHeight / 2 - ImageManger.bulletD.getHeight() / 2;
// switch (tank.dir) {
// case DOWN:
// new Bullet(bx, by + 6, tank.dir, tank.getGroup(), tank.tankFrame);
// new Bullet(bx, by - 6, tank.dir, tank.getGroup(), tank.tankFrame);
// break;
// 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);
// break;
// case LEFT:
// new Bullet(bx + 6, by, tank.dir, tank.getGroup(), tank.tankFrame);
// new Bullet(bx - 6, by, tank.dir, tank.getGroup(), tank.tankFrame);
// break;
// 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);
// break;
//
// }
//
// }
//}

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…
Cancel
Save