Browse Source
Merge remote-tracking branch 'MeinProg2/master' into main
Merge remote-tracking branch 'MeinProg2/master' into main
Manu
3 years ago
147 changed files with 5017 additions and 0 deletions
-
67ArrayManipulation.java
-
BINGameProject-3/.DS_Store
-
10GameProject-3/.classpath
-
1GameProject-3/.gitignore
-
17GameProject-3/.project
-
15GameProject-3/.settings/org.eclipse.jdt.core.prefs
-
10GameProject-3/Game/.classpath
-
1GameProject-3/Game/.gitignore
-
17GameProject-3/Game/.project
-
14GameProject-3/Game/.settings/org.eclipse.jdt.core.prefs
-
2GameProject-3/Game/src/module-info.java
-
BINGameProject-3/audio/laser.wav
-
BINGameProject-3/audio/shot.wav
-
BINGameProject-3/audio/smash.wav
-
BINGameProject-3/bin/.DS_Store
-
BINGameProject-3/bin/base/.DS_Store
-
BINGameProject-3/bin/base/GameLoop.class
-
BINGameProject-3/bin/base/MultiLevelGame.class
-
BINGameProject-3/bin/collider/CircleCollider.class
-
BINGameProject-3/bin/collider/Collider.class
-
BINGameProject-3/bin/collider/RectCollider.class
-
BINGameProject-3/bin/controller/CollisionAwareEgoController.class
-
BINGameProject-3/bin/controller/EgoController.class
-
BINGameProject-3/bin/controller/EnemyController.class
-
BINGameProject-3/bin/controller/FallingStarController.class
-
BINGameProject-3/bin/controller/LimitedTimeController.class
-
BINGameProject-3/bin/controller/MineController.class
-
BINGameProject-3/bin/controller/ObjectController.class
-
BINGameProject-3/bin/controller/SimpleShotController.class
-
BINGameProject-3/bin/controller/ZickZackController.class
-
BINGameProject-3/bin/controller/package-info.class
-
BINGameProject-3/bin/gameobjects/AnimatedGameobject.class
-
BINGameProject-3/bin/gameobjects/EgoObject.class
-
BINGameProject-3/bin/gameobjects/FallingStar.class
-
BINGameProject-3/bin/gameobjects/GameObject.class
-
BINGameProject-3/bin/gameobjects/RectObject.class
-
BINGameProject-3/bin/gameobjects/TextObject.class
-
30GameProject-3/bin/log4j2.xml
-
BINGameProject-3/bin/playground/.DS_Store
-
BINGameProject-3/bin/playground/Animation.class
-
BINGameProject-3/bin/playground/HighscoreManager.class
-
BINGameProject-3/bin/playground/Level1.class
-
BINGameProject-3/bin/playground/Level2.class
-
BINGameProject-3/bin/playground/Level3.class
-
BINGameProject-3/bin/playground/Level4.class
-
BINGameProject-3/bin/playground/Level5.class
-
BINGameProject-3/bin/playground/Level6.class
-
BINGameProject-3/bin/playground/Level7.class
-
BINGameProject-3/bin/playground/LevelBoss.class
-
BINGameProject-3/bin/playground/LevelHitTwice.class
-
BINGameProject-3/bin/playground/Music$1.class
-
BINGameProject-3/bin/playground/Music.class
-
BINGameProject-3/bin/playground/Playground.class
-
BINGameProject-3/bin/playground/SaveGame.class
-
BINGameProject-3/bin/playground/SpaceInvadersLevel.class
-
BINGameProject-3/bin/playground/SpaceInvadersLevelTest.class
-
BINGameProject-3/bin/rendering/AnimationArtist.class
-
BINGameProject-3/bin/rendering/Artist.class
-
BINGameProject-3/bin/rendering/CircleArtist.class
-
BINGameProject-3/bin/rendering/RectArtist.class
-
BINGameProject-3/bin/rendering/TextArtist.class
-
BINGameProject-3/bin/ui/AboutFrame$1.class
-
BINGameProject-3/bin/ui/AboutFrame.class
-
BINGameProject-3/bin/ui/GamePanel.class
-
BINGameProject-3/bin/ui/GameUI.class
-
1GameProject-3/highscore.txt
-
202GameProject-3/lib/apache-log4j-2.13.3-bin/LICENSE.txt
-
17GameProject-3/lib/apache-log4j-2.13.3-bin/NOTICE.txt
-
60GameProject-3/lib/apache-log4j-2.13.3-bin/RELEASE-NOTES.md
-
BINGameProject-3/lib/apache-log4j-2.13.3-bin/log4j-1.2-api-2.13.3.jar
-
BINGameProject-3/lib/apache-log4j-2.13.3-bin/log4j-api-2.13.3.jar
-
BINGameProject-3/lib/apache-log4j-2.13.3-bin/log4j-core-2.13.3.jar
-
122GameProject-3/log/log4j.log
-
BINGameProject-3/src/.DS_Store
-
BINGameProject-3/src/base/.DS_Store
-
231GameProject-3/src/base/GameLoop.java
-
30GameProject-3/src/base/MultiLevelGame.java
-
88GameProject-3/src/collider/CircleCollider.java
-
127GameProject-3/src/collider/Collider.java
-
127GameProject-3/src/collider/RectCollider.java
-
84GameProject-3/src/controller/CollisionAwareEgoController.java
-
216GameProject-3/src/controller/EgoController.java
-
36GameProject-3/src/controller/EnemyController.java
-
24GameProject-3/src/controller/FallingStarController.java
-
36GameProject-3/src/controller/LimitedTimeController.java
-
47GameProject-3/src/controller/MineController.java
-
110GameProject-3/src/controller/ObjectController.java
-
16GameProject-3/src/controller/SimpleShotController.java
-
32GameProject-3/src/controller/ZickZackController.java
-
11GameProject-3/src/controller/package-info.java
-
42GameProject-3/src/gameobjects/AnimatedGameobject.java
-
34GameProject-3/src/gameobjects/EgoObject.java
-
28GameProject-3/src/gameobjects/FallingStar.java
-
377GameProject-3/src/gameobjects/GameObject.java
-
76GameProject-3/src/gameobjects/RectObject.java
-
70GameProject-3/src/gameobjects/TextObject.java
-
30GameProject-3/src/log4j2.xml
-
BINGameProject-3/src/playground/.DS_Store
-
84GameProject-3/src/playground/Animation.java
-
55GameProject-3/src/playground/HighscoreManager.java
@ -0,0 +1,67 @@ |
|||||
|
package ha01; |
||||
|
|
||||
|
import java.util.Arrays; |
||||
|
|
||||
|
public class ArrayManipulation { |
||||
|
|
||||
|
|
||||
|
public static int[] reverseArray(int[] arr) { |
||||
|
|
||||
|
for (int i = 0; i < arr.length/2; i++) { |
||||
|
int tmp = arr[i]; |
||||
|
arr[i] = arr[arr.length - 1 - i]; |
||||
|
arr[arr.length - 1 - i] = tmp; |
||||
|
} |
||||
|
return arr; |
||||
|
} |
||||
|
|
||||
|
/*Liefert ein neues Array zurück ohne das erste Element*/ |
||||
|
public static int[] removeFirst(int[] arr) { |
||||
|
|
||||
|
int [] arrNeu = {}; |
||||
|
arrNeu = new int[arr.length-1]; |
||||
|
if(arr.length != 0) { |
||||
|
for (int i = 1; i < arr.length; i++) { |
||||
|
arrNeu[i-1] = arr[i]; |
||||
|
} |
||||
|
} |
||||
|
return arrNeu; |
||||
|
} |
||||
|
|
||||
|
/*Erstellt ein neues Array ohne das letzte Element*/ |
||||
|
public static int[] removeLast(int[] arr) { |
||||
|
|
||||
|
int [] arrNeu = {}; |
||||
|
arrNeu = new int[arr.length-1]; |
||||
|
if(arr.length != 0) { |
||||
|
for (int i =0; i < arr.length -1; i++) { |
||||
|
arrNeu[i] = arr[i]; |
||||
|
} |
||||
|
} |
||||
|
return arrNeu; |
||||
|
} |
||||
|
|
||||
|
/*Erstellt ein neues Array wo alle Zahlen quadriert werden*/ |
||||
|
|
||||
|
public static int[] squareEach(int[] arr) { |
||||
|
|
||||
|
int [] arrNeu = {}; |
||||
|
arrNeu = new int[arr.length]; |
||||
|
for (int i=0; i <arr.length; i++) { |
||||
|
arrNeu[i] = arr[i] * arr[i]; |
||||
|
} |
||||
|
return arrNeu; |
||||
|
} |
||||
|
|
||||
|
|
||||
|
|
||||
|
public static void main(String[] args) { |
||||
|
|
||||
|
int[] arr = {1,2,3,4,5}; |
||||
|
int [] arr2 = {}; |
||||
|
System.out.println(Arrays.toString(reverseArray(arr))); |
||||
|
System.out.println(Arrays.toString(removeFirst(arr))); |
||||
|
System.out.println(Arrays.toString(removeLast(arr))); |
||||
|
System.out.println(Arrays.toString(squareEach(arr))); |
||||
|
} |
||||
|
} |
@ -0,0 +1,10 @@ |
|||||
|
<?xml version="1.0" encoding="UTF-8"?> |
||||
|
<classpath> |
||||
|
<classpathentry kind="src" path="src"/> |
||||
|
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/> |
||||
|
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/5"/> |
||||
|
<classpathentry kind="lib" path="lib/apache-log4j-2.13.3-bin/log4j-1.2-api-2.13.3.jar"/> |
||||
|
<classpathentry kind="lib" path="lib/apache-log4j-2.13.3-bin/log4j-api-2.13.3.jar"/> |
||||
|
<classpathentry kind="lib" path="lib/apache-log4j-2.13.3-bin/log4j-core-2.13.3.jar"/> |
||||
|
<classpathentry kind="output" path="bin"/> |
||||
|
</classpath> |
@ -0,0 +1 @@ |
|||||
|
/.metadata/ |
@ -0,0 +1,17 @@ |
|||||
|
<?xml version="1.0" encoding="UTF-8"?> |
||||
|
<projectDescription> |
||||
|
<name>GameProject</name> |
||||
|
<comment></comment> |
||||
|
<projects> |
||||
|
</projects> |
||||
|
<buildSpec> |
||||
|
<buildCommand> |
||||
|
<name>org.eclipse.jdt.core.javabuilder</name> |
||||
|
<arguments> |
||||
|
</arguments> |
||||
|
</buildCommand> |
||||
|
</buildSpec> |
||||
|
<natures> |
||||
|
<nature>org.eclipse.jdt.core.javanature</nature> |
||||
|
</natures> |
||||
|
</projectDescription> |
@ -0,0 +1,15 @@ |
|||||
|
eclipse.preferences.version=1 |
||||
|
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled |
||||
|
org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate |
||||
|
org.eclipse.jdt.core.compiler.codegen.targetPlatform=12 |
||||
|
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve |
||||
|
org.eclipse.jdt.core.compiler.compliance=12 |
||||
|
org.eclipse.jdt.core.compiler.debug.lineNumber=generate |
||||
|
org.eclipse.jdt.core.compiler.debug.localVariable=generate |
||||
|
org.eclipse.jdt.core.compiler.debug.sourceFile=generate |
||||
|
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error |
||||
|
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled |
||||
|
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error |
||||
|
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning |
||||
|
org.eclipse.jdt.core.compiler.release=enabled |
||||
|
org.eclipse.jdt.core.compiler.source=12 |
@ -0,0 +1,10 @@ |
|||||
|
<?xml version="1.0" encoding="UTF-8"?> |
||||
|
<classpath> |
||||
|
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-17"> |
||||
|
<attributes> |
||||
|
<attribute name="module" value="true"/> |
||||
|
</attributes> |
||||
|
</classpathentry> |
||||
|
<classpathentry kind="src" path="src"/> |
||||
|
<classpathentry kind="output" path="bin"/> |
||||
|
</classpath> |
@ -0,0 +1 @@ |
|||||
|
/bin/ |
@ -0,0 +1,17 @@ |
|||||
|
<?xml version="1.0" encoding="UTF-8"?> |
||||
|
<projectDescription> |
||||
|
<name>Game</name> |
||||
|
<comment></comment> |
||||
|
<projects> |
||||
|
</projects> |
||||
|
<buildSpec> |
||||
|
<buildCommand> |
||||
|
<name>org.eclipse.jdt.core.javabuilder</name> |
||||
|
<arguments> |
||||
|
</arguments> |
||||
|
</buildCommand> |
||||
|
</buildSpec> |
||||
|
<natures> |
||||
|
<nature>org.eclipse.jdt.core.javanature</nature> |
||||
|
</natures> |
||||
|
</projectDescription> |
@ -0,0 +1,14 @@ |
|||||
|
eclipse.preferences.version=1 |
||||
|
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled |
||||
|
org.eclipse.jdt.core.compiler.codegen.targetPlatform=17 |
||||
|
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve |
||||
|
org.eclipse.jdt.core.compiler.compliance=17 |
||||
|
org.eclipse.jdt.core.compiler.debug.lineNumber=generate |
||||
|
org.eclipse.jdt.core.compiler.debug.localVariable=generate |
||||
|
org.eclipse.jdt.core.compiler.debug.sourceFile=generate |
||||
|
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error |
||||
|
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled |
||||
|
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error |
||||
|
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning |
||||
|
org.eclipse.jdt.core.compiler.release=enabled |
||||
|
org.eclipse.jdt.core.compiler.source=17 |
@ -0,0 +1,2 @@ |
|||||
|
module Game { |
||||
|
} |
@ -0,0 +1,30 @@ |
|||||
|
<?xml version="1.0" encoding="UTF-8"?> |
||||
|
|
||||
|
<configuration status="OFF"> |
||||
|
<appenders> |
||||
|
|
||||
|
<Console name="Console" target="SYSTEM_OUT"> |
||||
|
<PatternLayout pattern="%d %-5level %logger{36} - %msg%n" /> |
||||
|
</Console> |
||||
|
|
||||
|
<File name="File" fileName="log\log4j.log"> |
||||
|
<PatternLayout pattern="%d %-5level %logger{36} - %msg%n" /> |
||||
|
</File> |
||||
|
|
||||
|
</appenders> |
||||
|
|
||||
|
<loggers> |
||||
|
|
||||
|
<root level="warn"> |
||||
|
<appender-ref ref="Console" /> |
||||
|
<appender-ref ref="File" /> |
||||
|
</root> |
||||
|
|
||||
|
<Logger name="base.GameLoop" level="info"> |
||||
|
</Logger> |
||||
|
|
||||
|
<Logger name="playground" level="info"> |
||||
|
</Logger> |
||||
|
|
||||
|
</loggers> |
||||
|
</configuration> |
@ -0,0 +1 @@ |
|||||
|
7500 |
@ -0,0 +1,202 @@ |
|||||
|
|
||||
|
Apache License |
||||
|
Version 2.0, January 2004 |
||||
|
http://www.apache.org/licenses/ |
||||
|
|
||||
|
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION |
||||
|
|
||||
|
1. Definitions. |
||||
|
|
||||
|
"License" shall mean the terms and conditions for use, reproduction, |
||||
|
and distribution as defined by Sections 1 through 9 of this document. |
||||
|
|
||||
|
"Licensor" shall mean the copyright owner or entity authorized by |
||||
|
the copyright owner that is granting the License. |
||||
|
|
||||
|
"Legal Entity" shall mean the union of the acting entity and all |
||||
|
other entities that control, are controlled by, or are under common |
||||
|
control with that entity. For the purposes of this definition, |
||||
|
"control" means (i) the power, direct or indirect, to cause the |
||||
|
direction or management of such entity, whether by contract or |
||||
|
otherwise, or (ii) ownership of fifty percent (50%) or more of the |
||||
|
outstanding shares, or (iii) beneficial ownership of such entity. |
||||
|
|
||||
|
"You" (or "Your") shall mean an individual or Legal Entity |
||||
|
exercising permissions granted by this License. |
||||
|
|
||||
|
"Source" form shall mean the preferred form for making modifications, |
||||
|
including but not limited to software source code, documentation |
||||
|
source, and configuration files. |
||||
|
|
||||
|
"Object" form shall mean any form resulting from mechanical |
||||
|
transformation or translation of a Source form, including but |
||||
|
not limited to compiled object code, generated documentation, |
||||
|
and conversions to other media types. |
||||
|
|
||||
|
"Work" shall mean the work of authorship, whether in Source or |
||||
|
Object form, made available under the License, as indicated by a |
||||
|
copyright notice that is included in or attached to the work |
||||
|
(an example is provided in the Appendix below). |
||||
|
|
||||
|
"Derivative Works" shall mean any work, whether in Source or Object |
||||
|
form, that is based on (or derived from) the Work and for which the |
||||
|
editorial revisions, annotations, elaborations, or other modifications |
||||
|
represent, as a whole, an original work of authorship. For the purposes |
||||
|
of this License, Derivative Works shall not include works that remain |
||||
|
separable from, or merely link (or bind by name) to the interfaces of, |
||||
|
the Work and Derivative Works thereof. |
||||
|
|
||||
|
"Contribution" shall mean any work of authorship, including |
||||
|
the original version of the Work and any modifications or additions |
||||
|
to that Work or Derivative Works thereof, that is intentionally |
||||
|
submitted to Licensor for inclusion in the Work by the copyright owner |
||||
|
or by an individual or Legal Entity authorized to submit on behalf of |
||||
|
the copyright owner. For the purposes of this definition, "submitted" |
||||
|
means any form of electronic, verbal, or written communication sent |
||||
|
to the Licensor or its representatives, including but not limited to |
||||
|
communication on electronic mailing lists, source code control systems, |
||||
|
and issue tracking systems that are managed by, or on behalf of, the |
||||
|
Licensor for the purpose of discussing and improving the Work, but |
||||
|
excluding communication that is conspicuously marked or otherwise |
||||
|
designated in writing by the copyright owner as "Not a Contribution." |
||||
|
|
||||
|
"Contributor" shall mean Licensor and any individual or Legal Entity |
||||
|
on behalf of whom a Contribution has been received by Licensor and |
||||
|
subsequently incorporated within the Work. |
||||
|
|
||||
|
2. Grant of Copyright License. Subject to the terms and conditions of |
||||
|
this License, each Contributor hereby grants to You a perpetual, |
||||
|
worldwide, non-exclusive, no-charge, royalty-free, irrevocable |
||||
|
copyright license to reproduce, prepare Derivative Works of, |
||||
|
publicly display, publicly perform, sublicense, and distribute the |
||||
|
Work and such Derivative Works in Source or Object form. |
||||
|
|
||||
|
3. Grant of Patent License. Subject to the terms and conditions of |
||||
|
this License, each Contributor hereby grants to You a perpetual, |
||||
|
worldwide, non-exclusive, no-charge, royalty-free, irrevocable |
||||
|
(except as stated in this section) patent license to make, have made, |
||||
|
use, offer to sell, sell, import, and otherwise transfer the Work, |
||||
|
where such license applies only to those patent claims licensable |
||||
|
by such Contributor that are necessarily infringed by their |
||||
|
Contribution(s) alone or by combination of their Contribution(s) |
||||
|
with the Work to which such Contribution(s) was submitted. If You |
||||
|
institute patent litigation against any entity (including a |
||||
|
cross-claim or counterclaim in a lawsuit) alleging that the Work |
||||
|
or a Contribution incorporated within the Work constitutes direct |
||||
|
or contributory patent infringement, then any patent licenses |
||||
|
granted to You under this License for that Work shall terminate |
||||
|
as of the date such litigation is filed. |
||||
|
|
||||
|
4. Redistribution. You may reproduce and distribute copies of the |
||||
|
Work or Derivative Works thereof in any medium, with or without |
||||
|
modifications, and in Source or Object form, provided that You |
||||
|
meet the following conditions: |
||||
|
|
||||
|
(a) You must give any other recipients of the Work or |
||||
|
Derivative Works a copy of this License; and |
||||
|
|
||||
|
(b) You must cause any modified files to carry prominent notices |
||||
|
stating that You changed the files; and |
||||
|
|
||||
|
(c) You must retain, in the Source form of any Derivative Works |
||||
|
that You distribute, all copyright, patent, trademark, and |
||||
|
attribution notices from the Source form of the Work, |
||||
|
excluding those notices that do not pertain to any part of |
||||
|
the Derivative Works; and |
||||
|
|
||||
|
(d) If the Work includes a "NOTICE" text file as part of its |
||||
|
distribution, then any Derivative Works that You distribute must |
||||
|
include a readable copy of the attribution notices contained |
||||
|
within such NOTICE file, excluding those notices that do not |
||||
|
pertain to any part of the Derivative Works, in at least one |
||||
|
of the following places: within a NOTICE text file distributed |
||||
|
as part of the Derivative Works; within the Source form or |
||||
|
documentation, if provided along with the Derivative Works; or, |
||||
|
within a display generated by the Derivative Works, if and |
||||
|
wherever such third-party notices normally appear. The contents |
||||
|
of the NOTICE file are for informational purposes only and |
||||
|
do not modify the License. You may add Your own attribution |
||||
|
notices within Derivative Works that You distribute, alongside |
||||
|
or as an addendum to the NOTICE text from the Work, provided |
||||
|
that such additional attribution notices cannot be construed |
||||
|
as modifying the License. |
||||
|
|
||||
|
You may add Your own copyright statement to Your modifications and |
||||
|
may provide additional or different license terms and conditions |
||||
|
for use, reproduction, or distribution of Your modifications, or |
||||
|
for any such Derivative Works as a whole, provided Your use, |
||||
|
reproduction, and distribution of the Work otherwise complies with |
||||
|
the conditions stated in this License. |
||||
|
|
||||
|
5. Submission of Contributions. Unless You explicitly state otherwise, |
||||
|
any Contribution intentionally submitted for inclusion in the Work |
||||
|
by You to the Licensor shall be under the terms and conditions of |
||||
|
this License, without any additional terms or conditions. |
||||
|
Notwithstanding the above, nothing herein shall supersede or modify |
||||
|
the terms of any separate license agreement you may have executed |
||||
|
with Licensor regarding such Contributions. |
||||
|
|
||||
|
6. Trademarks. This License does not grant permission to use the trade |
||||
|
names, trademarks, service marks, or product names of the Licensor, |
||||
|
except as required for reasonable and customary use in describing the |
||||
|
origin of the Work and reproducing the content of the NOTICE file. |
||||
|
|
||||
|
7. Disclaimer of Warranty. Unless required by applicable law or |
||||
|
agreed to in writing, Licensor provides the Work (and each |
||||
|
Contributor provides its Contributions) on an "AS IS" BASIS, |
||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or |
||||
|
implied, including, without limitation, any warranties or conditions |
||||
|
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A |
||||
|
PARTICULAR PURPOSE. You are solely responsible for determining the |
||||
|
appropriateness of using or redistributing the Work and assume any |
||||
|
risks associated with Your exercise of permissions under this License. |
||||
|
|
||||
|
8. Limitation of Liability. In no event and under no legal theory, |
||||
|
whether in tort (including negligence), contract, or otherwise, |
||||
|
unless required by applicable law (such as deliberate and grossly |
||||
|
negligent acts) or agreed to in writing, shall any Contributor be |
||||
|
liable to You for damages, including any direct, indirect, special, |
||||
|
incidental, or consequential damages of any character arising as a |
||||
|
result of this License or out of the use or inability to use the |
||||
|
Work (including but not limited to damages for loss of goodwill, |
||||
|
work stoppage, computer failure or malfunction, or any and all |
||||
|
other commercial damages or losses), even if such Contributor |
||||
|
has been advised of the possibility of such damages. |
||||
|
|
||||
|
9. Accepting Warranty or Additional Liability. While redistributing |
||||
|
the Work or Derivative Works thereof, You may choose to offer, |
||||
|
and charge a fee for, acceptance of support, warranty, indemnity, |
||||
|
or other liability obligations and/or rights consistent with this |
||||
|
License. However, in accepting such obligations, You may act only |
||||
|
on Your own behalf and on Your sole responsibility, not on behalf |
||||
|
of any other Contributor, and only if You agree to indemnify, |
||||
|
defend, and hold each Contributor harmless for any liability |
||||
|
incurred by, or claims asserted against, such Contributor by reason |
||||
|
of your accepting any such warranty or additional liability. |
||||
|
|
||||
|
END OF TERMS AND CONDITIONS |
||||
|
|
||||
|
APPENDIX: How to apply the Apache License to your work. |
||||
|
|
||||
|
To apply the Apache License to your work, attach the following |
||||
|
boilerplate notice, with the fields enclosed by brackets "[]" |
||||
|
replaced with your own identifying information. (Don't include |
||||
|
the brackets!) The text should be enclosed in the appropriate |
||||
|
comment syntax for the file format. We also recommend that a |
||||
|
file or class name and description of purpose be included on the |
||||
|
same "printed page" as the copyright notice for easier |
||||
|
identification within third-party archives. |
||||
|
|
||||
|
Copyright 1999-2005 The Apache Software Foundation |
||||
|
|
||||
|
Licensed under the Apache License, Version 2.0 (the "License"); |
||||
|
you may not use this file except in compliance with the License. |
||||
|
You may obtain a copy of the License at |
||||
|
|
||||
|
http://www.apache.org/licenses/LICENSE-2.0 |
||||
|
|
||||
|
Unless required by applicable law or agreed to in writing, software |
||||
|
distributed under the License is distributed on an "AS IS" BASIS, |
||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
|
See the License for the specific language governing permissions and |
||||
|
limitations under the License. |
@ -0,0 +1,17 @@ |
|||||
|
Apache Log4j |
||||
|
Copyright 1999-2017 Apache Software Foundation |
||||
|
|
||||
|
This product includes software developed at |
||||
|
The Apache Software Foundation (http://www.apache.org/). |
||||
|
|
||||
|
ResolverUtil.java |
||||
|
Copyright 2005-2006 Tim Fennell |
||||
|
|
||||
|
Dumbster SMTP test server |
||||
|
Copyright 2004 Jason Paul Kitchen |
||||
|
|
||||
|
TypeUtil.java |
||||
|
Copyright 2002-2012 Ramnivas Laddad, Juergen Hoeller, Chris Beams |
||||
|
|
||||
|
picocli (http://picocli.info) |
||||
|
Copyright 2017 Remko Popma |
@ -0,0 +1,60 @@ |
|||||
|
<!--- |
||||
|
Licensed to the Apache Software Foundation (ASF) under one or more |
||||
|
contributor license agreements. See the NOTICE file distributed with |
||||
|
this work for additional information regarding copyright ownership. |
||||
|
The ASF licenses this file to You under the Apache License, Version 2.0 |
||||
|
(the "License"); you may not use this file except in compliance with |
||||
|
the License. You may obtain a copy of the License at |
||||
|
|
||||
|
http://www.apache.org/licenses/LICENSE-2.0 |
||||
|
|
||||
|
Unless required by applicable law or agreed to in writing, software |
||||
|
distributed under the License is distributed on an "AS IS" BASIS, |
||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
|
See the License for the specific language governing permissions and |
||||
|
limitations under the License. |
||||
|
--> |
||||
|
# Apache Log4j 2.13.3 Release Notes |
||||
|
|
||||
|
The Apache Log4j 2 team is pleased to announce the Log4j 2.13.3 release! |
||||
|
|
||||
|
Apache Log4j is a well known framework for logging application behavior. Log4j 2 is an upgrade |
||||
|
to Log4j that provides significant improvements over its predecessor, Log4j 1.x, and provides |
||||
|
many other modern features such as support for Markers, lambda expressions for lazy logging, |
||||
|
property substitution using Lookups, multiple patterns on a PatternLayout and asynchronous |
||||
|
Loggers. Another notable Log4j 2 feature is the ability to be "garbage-free" (avoid allocating |
||||
|
temporary objects) while logging. In addition, Log4j 2 will not lose events while reconfiguring. |
||||
|
|
||||
|
The artifacts may be downloaded from https://logging.apache.org/log4j/2.x/download.html. |
||||
|
|
||||
|
This release contains a fix for bug LOG4J2-2838. |
||||
|
|
||||
|
Due to a break in compatibility in the SLF4J binding, Log4j now ships with two versions of the SLF4J to Log4j adapters. |
||||
|
log4j-slf4j-impl should be used with SLF4J 1.7.x and earlier and log4j-slf4j18-impl should be used with SLF4J 1.8.x and |
||||
|
later. |
||||
|
|
||||
|
Note that the default XML, JSON and YAML formats changed in the 2.11.0 release: they no longer have the "timeMillis" |
||||
|
attribute and instead have an "Instant" element with "epochSecond" and "nanoOfSecond" attributes. If the previous |
||||
|
behavior is desired the "includeTimeMillis" attribute may be set to true on each of the respective Layouts. |
||||
|
|
||||
|
The Log4j 2.13.3 API, as well as many core components, maintains binary compatibility with previous releases. |
||||
|
|
||||
|
## GA Release 2.13.3 |
||||
|
|
||||
|
Changes in this version include: |
||||
|
|
||||
|
|
||||
|
### Fixed Bugs |
||||
|
* [LOG4J2-2838](https://issues.apache.org/jira/browse/LOG4J2-2838): |
||||
|
Fix NullPointerException in ThreadContextDataInjector. |
||||
|
|
||||
|
|
||||
|
--- |
||||
|
|
||||
|
Apache Log4j 2.13.3 requires a minimum of Java 8 to build and run. Log4j 2.3 was the |
||||
|
last release that supported Java 6 and Log4j 2.12.1 is the last release to support Java 7. |
||||
|
|
||||
|
For complete information on Apache Log4j 2, including instructions on how to submit bug |
||||
|
reports, patches, or suggestions for improvement, see the Apache Apache Log4j 2 website: |
||||
|
|
||||
|
https://logging.apache.org/log4j/2.x/ |
@ -0,0 +1,122 @@ |
|||||
|
2022-04-24 23:39:39,870 INFO base.GameLoop - GUI starts |
||||
|
2022-04-24 23:39:49,629 INFO base.GameLoop - GUI NEW |
||||
|
2022-04-24 23:39:49,629 INFO playground.SpaceInvadersLevel - PREPARE |
||||
|
2022-04-24 23:39:49,665 INFO playground.Animation - img added .\video/sweetAlien0.png |
||||
|
2022-04-24 23:39:49,670 INFO playground.Animation - img added .\video/sweetAlien1.png |
||||
|
2022-04-24 23:39:49,671 INFO playground.Animation - img added .\video/sweetAlien2.png |
||||
|
2022-04-24 23:39:49,672 INFO playground.Animation - img added .\video/sweetAlien3.png |
||||
|
2022-04-24 23:39:49,674 INFO playground.Animation - img added .\video/sweetAlien4.png |
||||
|
2022-04-24 23:39:49,676 INFO playground.Animation - img added .\video/sweetAlien5.png |
||||
|
2022-04-24 23:39:49,677 INFO playground.Animation - img added .\video/sweetAlien6.png |
||||
|
2022-04-24 23:39:49,679 INFO playground.Animation - img added .\video/sweetAlien7.png |
||||
|
2022-04-24 23:39:49,683 INFO playground.Animation - img added .\video/heart0.png |
||||
|
2022-04-24 23:39:49,684 INFO playground.Animation - img added .\video/heart1.png |
||||
|
2022-04-24 23:39:49,685 WARN playground.HighscoreManager - WARNING: Highscore file was not found and reset |
||||
|
2022-04-24 23:39:49,686 INFO playground.HighscoreManager - Highscore file was opened and saved score: 0 |
||||
|
2022-04-24 23:39:49,689 INFO playground.SpaceInvadersLevel - HIGHSCORE0 |
||||
|
2022-04-25 00:38:02,074 INFO base.GameLoop - GUI starts |
||||
|
2022-04-25 00:38:06,610 INFO base.GameLoop - GUI NEW |
||||
|
2022-04-25 00:38:06,610 INFO playground.SpaceInvadersLevel - PREPARE |
||||
|
2022-04-25 00:38:06,635 INFO playground.Animation - img added .\video/sweetAlien0.png |
||||
|
2022-04-25 00:38:06,638 INFO playground.Animation - img added .\video/sweetAlien1.png |
||||
|
2022-04-25 00:38:06,639 INFO playground.Animation - img added .\video/sweetAlien2.png |
||||
|
2022-04-25 00:38:06,641 INFO playground.Animation - img added .\video/sweetAlien3.png |
||||
|
2022-04-25 00:38:06,644 INFO playground.Animation - img added .\video/sweetAlien4.png |
||||
|
2022-04-25 00:38:06,646 INFO playground.Animation - img added .\video/sweetAlien5.png |
||||
|
2022-04-25 00:38:06,648 INFO playground.Animation - img added .\video/sweetAlien6.png |
||||
|
2022-04-25 00:38:06,650 INFO playground.Animation - img added .\video/sweetAlien7.png |
||||
|
2022-04-25 00:38:06,655 INFO playground.Animation - img added .\video/heart0.png |
||||
|
2022-04-25 00:38:06,656 INFO playground.Animation - img added .\video/heart1.png |
||||
|
2022-04-25 00:38:06,659 INFO playground.SpaceInvadersLevel - HIGHSCORE0 |
||||
|
2022-04-25 00:38:33,252 INFO base.GameLoop - GUI NEW |
||||
|
2022-04-25 00:38:33,252 INFO playground.SpaceInvadersLevel - PREPARE |
||||
|
2022-04-25 00:38:33,254 INFO playground.SpaceInvadersLevel - HIGHSCORE0 |
||||
|
2022-04-25 00:38:53,472 INFO base.GameLoop - GUI NEW |
||||
|
2022-04-25 00:38:53,472 INFO playground.SpaceInvadersLevel - PREPARE |
||||
|
2022-04-25 00:38:53,473 INFO playground.SpaceInvadersLevel - HIGHSCORE0 |
||||
|
2022-05-04 23:49:21,781 INFO base.GameLoop - GUI starts |
||||
|
2022-05-04 23:49:23,804 INFO base.GameLoop - GUI NEW |
||||
|
2022-05-04 23:49:23,804 INFO playground.SpaceInvadersLevel - PREPARE |
||||
|
2022-05-04 23:49:23,838 INFO playground.Animation - img added .\video/sweetAlien0.png |
||||
|
2022-05-04 23:49:23,842 INFO playground.Animation - img added .\video/sweetAlien1.png |
||||
|
2022-05-04 23:49:23,843 INFO playground.Animation - img added .\video/sweetAlien2.png |
||||
|
2022-05-04 23:49:23,846 INFO playground.Animation - img added .\video/sweetAlien3.png |
||||
|
2022-05-04 23:49:23,848 INFO playground.Animation - img added .\video/sweetAlien4.png |
||||
|
2022-05-04 23:49:23,850 INFO playground.Animation - img added .\video/sweetAlien5.png |
||||
|
2022-05-04 23:49:23,852 INFO playground.Animation - img added .\video/sweetAlien6.png |
||||
|
2022-05-04 23:49:23,853 INFO playground.Animation - img added .\video/sweetAlien7.png |
||||
|
2022-05-04 23:49:23,857 INFO playground.Animation - img added .\video/heart0.png |
||||
|
2022-05-04 23:49:23,859 INFO playground.Animation - img added .\video/heart1.png |
||||
|
2022-05-04 23:49:23,861 INFO playground.SpaceInvadersLevel - HIGHSCORE2700 |
||||
|
2022-05-04 23:50:06,924 INFO base.GameLoop - GUI starts |
||||
|
2022-05-04 23:50:08,516 INFO base.GameLoop - GUI NEW |
||||
|
2022-05-04 23:50:08,517 INFO playground.SpaceInvadersLevel - PREPARE |
||||
|
2022-05-04 23:50:08,541 INFO playground.Animation - img added .\video/sweetAlien0.png |
||||
|
2022-05-04 23:50:08,545 INFO playground.Animation - img added .\video/sweetAlien1.png |
||||
|
2022-05-04 23:50:08,547 INFO playground.Animation - img added .\video/sweetAlien2.png |
||||
|
2022-05-04 23:50:08,549 INFO playground.Animation - img added .\video/sweetAlien3.png |
||||
|
2022-05-04 23:50:08,551 INFO playground.Animation - img added .\video/sweetAlien4.png |
||||
|
2022-05-04 23:50:08,553 INFO playground.Animation - img added .\video/sweetAlien5.png |
||||
|
2022-05-04 23:50:08,554 INFO playground.Animation - img added .\video/sweetAlien6.png |
||||
|
2022-05-04 23:50:08,556 INFO playground.Animation - img added .\video/sweetAlien7.png |
||||
|
2022-05-04 23:50:08,560 INFO playground.Animation - img added .\video/heart0.png |
||||
|
2022-05-04 23:50:08,562 INFO playground.Animation - img added .\video/heart1.png |
||||
|
2022-05-04 23:50:08,564 INFO playground.SpaceInvadersLevel - HIGHSCORE2700 |
||||
|
2022-05-04 23:50:27,571 INFO playground.SpaceInvadersLevel - no enemies left, level done. |
||||
|
2022-05-04 23:50:27,571 INFO playground.SpaceInvadersLevel - PREPARE |
||||
|
2022-05-04 23:50:27,574 INFO playground.Animation - img added .\video/sweetAlien0.png |
||||
|
2022-05-04 23:50:27,576 INFO playground.Animation - img added .\video/sweetAlien1.png |
||||
|
2022-05-04 23:50:27,577 INFO playground.Animation - img added .\video/sweetAlien2.png |
||||
|
2022-05-04 23:50:27,578 INFO playground.Animation - img added .\video/sweetAlien3.png |
||||
|
2022-05-04 23:50:27,579 INFO playground.Animation - img added .\video/sweetAlien4.png |
||||
|
2022-05-04 23:50:27,580 INFO playground.Animation - img added .\video/sweetAlien5.png |
||||
|
2022-05-04 23:50:27,581 INFO playground.Animation - img added .\video/sweetAlien6.png |
||||
|
2022-05-04 23:50:27,583 INFO playground.Animation - img added .\video/sweetAlien7.png |
||||
|
2022-05-04 23:50:27,586 INFO playground.Animation - img added .\video/heart0.png |
||||
|
2022-05-04 23:50:27,587 INFO playground.Animation - img added .\video/heart1.png |
||||
|
2022-05-04 23:50:27,588 INFO playground.SpaceInvadersLevel - HIGHSCORE2700 |
||||
|
2022-05-04 23:51:42,798 INFO base.GameLoop - GUI starts |
||||
|
2022-05-04 23:51:44,444 INFO base.GameLoop - GUI NEW |
||||
|
2022-05-04 23:51:44,444 INFO playground.SpaceInvadersLevel - PREPARE |
||||
|
2022-05-04 23:51:44,473 INFO playground.Animation - img added .\video/sweetAlien0.png |
||||
|
2022-05-04 23:51:44,477 INFO playground.Animation - img added .\video/sweetAlien1.png |
||||
|
2022-05-04 23:51:44,479 INFO playground.Animation - img added .\video/sweetAlien2.png |
||||
|
2022-05-04 23:51:44,481 INFO playground.Animation - img added .\video/sweetAlien3.png |
||||
|
2022-05-04 23:51:44,483 INFO playground.Animation - img added .\video/sweetAlien4.png |
||||
|
2022-05-04 23:51:44,485 INFO playground.Animation - img added .\video/sweetAlien5.png |
||||
|
2022-05-04 23:51:44,487 INFO playground.Animation - img added .\video/sweetAlien6.png |
||||
|
2022-05-04 23:51:44,488 INFO playground.Animation - img added .\video/sweetAlien7.png |
||||
|
2022-05-04 23:51:44,492 INFO playground.Animation - img added .\video/heart0.png |
||||
|
2022-05-04 23:51:44,494 INFO playground.Animation - img added .\video/heart1.png |
||||
|
2022-05-04 23:51:44,497 INFO playground.SpaceInvadersLevel - HIGHSCORE2700 |
||||
|
2022-05-04 23:51:55,712 INFO playground.SpaceInvadersLevel - no enemies left, level done. |
||||
|
2022-05-04 23:51:55,712 INFO playground.SpaceInvadersLevel - PREPARE |
||||
|
2022-05-04 23:51:55,715 INFO playground.Animation - img added .\video/sweetAlien0.png |
||||
|
2022-05-04 23:51:55,717 INFO playground.Animation - img added .\video/sweetAlien1.png |
||||
|
2022-05-04 23:51:55,718 INFO playground.Animation - img added .\video/sweetAlien2.png |
||||
|
2022-05-04 23:51:55,719 INFO playground.Animation - img added .\video/sweetAlien3.png |
||||
|
2022-05-04 23:51:55,720 INFO playground.Animation - img added .\video/sweetAlien4.png |
||||
|
2022-05-04 23:51:55,722 INFO playground.Animation - img added .\video/sweetAlien5.png |
||||
|
2022-05-04 23:51:55,723 INFO playground.Animation - img added .\video/sweetAlien6.png |
||||
|
2022-05-04 23:51:55,724 INFO playground.Animation - img added .\video/sweetAlien7.png |
||||
|
2022-05-04 23:51:55,727 INFO playground.Animation - img added .\video/heart0.png |
||||
|
2022-05-04 23:51:55,729 INFO playground.Animation - img added .\video/heart1.png |
||||
|
2022-05-04 23:51:55,730 INFO playground.SpaceInvadersLevel - HIGHSCORE2700 |
||||
|
2022-05-04 23:52:07,817 INFO playground.HighscoreManager - Highscore file was opened and saved score: 3100 |
||||
|
2022-05-04 23:52:07,817 INFO playground.SpaceInvadersLevel - no enemies left, level done. |
||||
|
2022-05-04 23:52:07,818 INFO playground.SpaceInvadersLevel - PREPARE |
||||
|
2022-05-04 23:52:07,820 INFO playground.Animation - img added .\video/sweetAlien0.png |
||||
|
2022-05-04 23:52:07,821 INFO playground.Animation - img added .\video/sweetAlien1.png |
||||
|
2022-05-04 23:52:07,823 INFO playground.Animation - img added .\video/sweetAlien2.png |
||||
|
2022-05-04 23:52:07,824 INFO playground.Animation - img added .\video/sweetAlien3.png |
||||
|
2022-05-04 23:52:07,825 INFO playground.Animation - img added .\video/sweetAlien4.png |
||||
|
2022-05-04 23:52:07,826 INFO playground.Animation - img added .\video/sweetAlien5.png |
||||
|
2022-05-04 23:52:07,827 INFO playground.Animation - img added .\video/sweetAlien6.png |
||||
|
2022-05-04 23:52:07,828 INFO playground.Animation - img added .\video/sweetAlien7.png |
||||
|
2022-05-04 23:52:07,831 INFO playground.Animation - img added .\video/heart0.png |
||||
|
2022-05-04 23:52:07,832 INFO playground.Animation - img added .\video/heart1.png |
||||
|
2022-05-04 23:52:07,833 INFO playground.SpaceInvadersLevel - HIGHSCORE3100 |
||||
|
2022-05-04 23:52:21,104 INFO playground.HighscoreManager - Highscore file was opened and saved score: 7500 |
||||
|
2022-05-04 23:52:21,104 INFO playground.SpaceInvadersLevel - no enemies left, level done. |
||||
|
2022-05-04 23:52:21,104 INFO base.GameLoop - reached end of levels |
||||
|
2022-05-04 23:52:21,105 INFO base.GameLoop - Game ends. Bye. |
@ -0,0 +1,231 @@ |
|||||
|
package base; |
||||
|
|
||||
|
import java.io.IOException; |
||||
|
import java.util.ArrayList; |
||||
|
import java.util.List; |
||||
|
import java.util.ListIterator; |
||||
|
import org.apache.logging.log4j.LogManager; |
||||
|
import org.apache.logging.log4j.Logger; |
||||
|
import gameobjects.GameObject; |
||||
|
import playground.Level1; |
||||
|
import playground.Playground; |
||||
|
import ui.GameUI; |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* Main class starting any game, contains main(). Apart from that, this class manages all |
||||
|
* non-logical functionalities which should be hidden from a game designer like: |
||||
|
* <ul> |
||||
|
* <li>Setting up windows, panels, buttons, action callbacks, ... |
||||
|
* <li>Reading keyboard inputs |
||||
|
* <li>Redrawing game window if necessary |
||||
|
* <li>managing the game time and calling the appropriate {@link GameObject} or {@link Playground} |
||||
|
* methods periodically, at every time step of the game. |
||||
|
* </ul> |
||||
|
* There will normally never be a need to modify this file, a designer/game programmer should always |
||||
|
* redefine the {@link GameObject} and {@link Playground} classes and implement new functionality |
||||
|
* there. To make a long story short<br> |
||||
|
*/ |
||||
|
public class GameLoop { |
||||
|
|
||||
|
/** Pixel width of Game GUI ( above 0) */ |
||||
|
public static int SIZEX = 300; |
||||
|
/** Pixel height of Game GUI (above 0) */ |
||||
|
public static int SIZEY = 200; |
||||
|
|
||||
|
/** |
||||
|
* before call to {@link #runGame(String[])} this List should be initialized (in constructor). |
||||
|
*/ |
||||
|
private List<Playground> levels = new ArrayList<Playground>(0); |
||||
|
|
||||
|
private static Logger logger = LogManager.getLogger(GameLoop.class); |
||||
|
|
||||
|
/** constructor which calls {@link #defineLevels()}, which adds all levels of this game. |
||||
|
*/ |
||||
|
public GameLoop() { |
||||
|
this.defineLevels(); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* First resets (clears) the already existing level instances of this game's list of levels ({@link #resetLevels()}), |
||||
|
* then adds one instance of {@link Level1} by calling {@link #addLevel()}. |
||||
|
* Should be called only before playing starts (e.g. in constructor or before {@link #runGame(String[]) } is called. |
||||
|
* |
||||
|
* <br><strong>Note:</strong> Subclasses of {@link GameLoop} should override this method to define own levels for their game. |
||||
|
*/ |
||||
|
void defineLevels() { |
||||
|
this.resetLevels(); |
||||
|
this.addLevel(new Level1()); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Adds the given level instance to the end of the currently already stored list of levels to play. |
||||
|
* Should be called only before playing starts (e.g. in constructor or before {@link #runGame(String[]) } is called. |
||||
|
* |
||||
|
* @param level instance of Playground (a level) to add. |
||||
|
*/ |
||||
|
void addLevel(Playground level) { |
||||
|
this.levels.add(level); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Removes all levels from the list of levels to play! Do not call this method while {@link #runGame(String[]) } is running! |
||||
|
*/ |
||||
|
void resetLevels() { |
||||
|
this.levels.clear(); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* loops over all {@link #levels} and implements the game loop to update continuously the level |
||||
|
* during play time |
||||
|
* |
||||
|
* @param args command line arguments forwarded (currently ignored) |
||||
|
* @throws IOException if hitghscore.txt cannot be written. |
||||
|
*/ |
||||
|
public void runGame(String[] args) throws IOException { |
||||
|
|
||||
|
logger.info("GUI starts"); |
||||
|
GameUI gameUI = new GameUI(SIZEX, SIZEY); // probably change to your new GUI class |
||||
|
|
||||
|
double gameTime = -1; |
||||
|
Playground currentPlayground = null; |
||||
|
|
||||
|
// loop over different levels |
||||
|
ListIterator<Playground> levelIterator = levels.listIterator(); |
||||
|
while (true) { |
||||
|
logger.debug("LevelIndex is " + (levelIterator.nextIndex()) + " (of " + levels.size() + " levels)"); |
||||
|
gameTime = 0; |
||||
|
long start = System.nanoTime(); |
||||
|
|
||||
|
// loop over single level |
||||
|
while (true) { |
||||
|
|
||||
|
int act = GameUI.getNewAction(); |
||||
|
|
||||
|
// Query GameUI for high-level user commands; new game/reset/etc... |
||||
|
if (act == GameUI.ACTION_RESET) { |
||||
|
// ReStart Game in same Level |
||||
|
logger.info("GUI RESET"); |
||||
|
currentPlayground.prepareLevel("level" + (levelIterator.nextIndex()-1)); |
||||
|
GameUI.resetAction(); |
||||
|
} |
||||
|
|
||||
|
if (act == GameUI.ACTION_NEW) { |
||||
|
// new game |
||||
|
logger.info("GUI NEW"); |
||||
|
start = System.nanoTime(); |
||||
|
levelIterator = levels.listIterator(); // reset |
||||
|
currentPlayground = levelIterator.next(); // again level |
||||
|
currentPlayground.prepareLevel("level" + (levelIterator.nextIndex()-1)); |
||||
|
gameUI.setPlayground(currentPlayground); |
||||
|
GameUI.resetAction(); |
||||
|
break; |
||||
|
} |
||||
|
|
||||
|
if (act == GameUI.ACTION_BUTTON) { |
||||
|
// Event of Button pressed --> PAUSE! |
||||
|
logger.info("GUI PAUSE"); |
||||
|
if (currentPlayground != null) { |
||||
|
boolean p = currentPlayground.isPaused(); |
||||
|
p = !p; |
||||
|
currentPlayground.setPaused(p); |
||||
|
} |
||||
|
GameUI.resetAction(); |
||||
|
} |
||||
|
|
||||
|
if (act == GameUI.ACTION_SAVE) { |
||||
|
logger.info("GUI SAVE"); |
||||
|
// UNDONE save current state (not yet working/implemented) |
||||
|
GameUI.resetAction(); |
||||
|
} |
||||
|
|
||||
|
if (act == GameUI.ACTION_LOAD) { |
||||
|
logger.info("GUI LOAD"); |
||||
|
// load game state (currently simply resets) |
||||
|
GameUI.resetAction(); |
||||
|
} |
||||
|
|
||||
|
// if game has been created: execute a single iteration of the game loop |
||||
|
if (currentPlayground != null) { |
||||
|
// calc time that was used for painting the game, in seconds since last loop |
||||
|
long end = System.nanoTime(); |
||||
|
double realTS = ((double) (end - start) / 1000000000.); |
||||
|
|
||||
|
// time calc for one loop of the while |
||||
|
start = System.nanoTime(); |
||||
|
|
||||
|
|
||||
|
|
||||
|
if (currentPlayground.levelFinished() || currentPlayground.gameOver() == true) { |
||||
|
break; // leave level; breaks WHILE |
||||
|
} |
||||
|
|
||||
|
// paint current state of level and start time measurement |
||||
|
gameUI.waitWhilePainting(); |
||||
|
|
||||
|
|
||||
|
gameUI.grabFocus(); // needed to grab input events in next step |
||||
|
|
||||
|
// communicate inputs to level |
||||
|
currentPlayground.processKeyEvents(gameUI.getKeyEvents()); |
||||
|
currentPlayground.processMouseEvents(gameUI.getMouseEvents()); |
||||
|
|
||||
|
if (currentPlayground.isPaused() == false) { |
||||
|
|
||||
|
// update objects and level |
||||
|
currentPlayground.updateObjects(); |
||||
|
currentPlayground.applyGameLogic(); |
||||
|
|
||||
|
|
||||
|
// update game time |
||||
|
gameTime += realTS; |
||||
|
// communicate gameTime and timestep to level |
||||
|
currentPlayground.setTimestep(realTS); |
||||
|
currentPlayground.setGameTime(gameTime); |
||||
|
Playground.setGlobalFlag("gameTime", Double.valueOf(realTS)); |
||||
|
logger.trace("gameTime is now "+gameTime); |
||||
|
|
||||
|
} // if |
||||
|
} // if |
||||
|
|
||||
|
} // inner while loop within level |
||||
|
|
||||
|
// after level is done: leave outer loop if game over |
||||
|
if (currentPlayground.gameOver() == true) { |
||||
|
break; // outer while ends game |
||||
|
} |
||||
|
|
||||
|
// after level is done: reset level and go to next, if there is one |
||||
|
if (currentPlayground.levelFinished() == true) { |
||||
|
currentPlayground.reset(); |
||||
|
|
||||
|
// increase level counter, go on to next one |
||||
|
logger.debug("level finished. now new LevelIndex is " + levelIterator.nextIndex()); |
||||
|
if (levelIterator.nextIndex() >= levels.size()) { |
||||
|
logger.info("reached end of levels"); |
||||
|
break; // outer while ends game; |
||||
|
} |
||||
|
currentPlayground = levelIterator.next(); |
||||
|
currentPlayground.prepareLevel("level" + (levelIterator.nextIndex()-1)); |
||||
|
} |
||||
|
|
||||
|
} // outer loop over levels |
||||
|
logger.info("Game ends. Bye."); |
||||
|
System.exit(0); |
||||
|
} // main() |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* main to start the whole application. |
||||
|
* initializes the {@link #levels} ArrayList of Playground instances (levels) to be played with one level {@link SpaceInvadersLevel} in constructor of {@link #GameLoop}. |
||||
|
* |
||||
|
* @param args Java default command line args, forwarded to {@link #runGame(String[])} |
||||
|
* @throws IOException in case highscore.txt cannot be written. |
||||
|
*/ |
||||
|
public static void main(String[] args) throws IOException { |
||||
|
GameLoop gl = new GameLoop(); |
||||
|
gl.runGame(args); |
||||
|
} |
||||
|
|
||||
|
} |
@ -0,0 +1,30 @@ |
|||||
|
package base; |
||||
|
|
||||
|
import java.io.IOException; |
||||
|
|
||||
|
import playground.*; |
||||
|
|
||||
|
public class MultiLevelGame extends GameLoop { |
||||
|
|
||||
|
@Override |
||||
|
void defineLevels() { |
||||
|
this.resetLevels(); |
||||
|
|
||||
|
//this.addLevel(new Level1()); |
||||
|
// this.addLevel(new LevelHitTwice()); |
||||
|
// this.addLevel(new Level3()); |
||||
|
// this.addLevel(new LevelBoss()); |
||||
|
this.addLevel(new Level5()); |
||||
|
this.addLevel(new Level6()); |
||||
|
this.addLevel(new Level7()); |
||||
|
|
||||
|
} |
||||
|
|
||||
|
public static void main(String[] args) throws IOException { |
||||
|
|
||||
|
MultiLevelGame l5 = new MultiLevelGame(); |
||||
|
l5.runGame(args); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
|
@ -0,0 +1,88 @@ |
|||||
|
package collider; |
||||
|
|
||||
|
import java.awt.Color; |
||||
|
import gameobjects.*; |
||||
|
import org.apache.logging.log4j.Logger; |
||||
|
import org.apache.logging.log4j.LogManager; |
||||
|
|
||||
|
|
||||
|
/** Collider for round objects */ |
||||
|
public class CircleCollider extends Collider { |
||||
|
|
||||
|
double x; |
||||
|
double y; |
||||
|
double vx; |
||||
|
double vy; |
||||
|
|
||||
|
double r; |
||||
|
|
||||
|
private static Logger logger = LogManager.getLogger(Collider.class); |
||||
|
|
||||
|
/** |
||||
|
* Constructor which sets the radius to be respected for collisions. |
||||
|
* |
||||
|
* @param id String unique name for the collider instance |
||||
|
* @param o GameObject it belongs to |
||||
|
* @param radius radius in pixels to use as a size |
||||
|
*/ |
||||
|
public CircleCollider(String id, GameObject o, double radius) { |
||||
|
|
||||
|
super(id, o); |
||||
|
this.r = radius; |
||||
|
} |
||||
|
|
||||
|
/** simple concatenation of all attributes (x,y,r) */ |
||||
|
public String toString() { |
||||
|
return "circ:" + x + " " + y + "/" + r + " "; |
||||
|
} |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* calculates the collission of this with other collider |
||||
|
* |
||||
|
* @param _c2 the other collider |
||||
|
* @return true if a collision was detected |
||||
|
* @throws Exception in case the math operations are invalid (due to illegal values of x y or |
||||
|
* radius) |
||||
|
*/ |
||||
|
public boolean checkCollisionCircCirc(Collider _c2) throws Exception { |
||||
|
CircleCollider c2 = (CircleCollider) _c2; |
||||
|
CircleCollider c1 = this; |
||||
|
logger.trace(c1.x + " " + c1.y + " " + c1.r + " " + c2.x + " " + c2.y+ " " + c2.r); |
||||
|
int kathete1 = (int) (Math.abs(c2.gameobject.getX() - c1.gameobject.getX())); |
||||
|
int kathete2 = (int) (Math.abs(c2.gameobject.getX() - c1.gameobject.getY())); |
||||
|
int hypothenuse = (int) (c1.r + c2.r); |
||||
|
|
||||
|
logger.trace(kathete1 + " " + kathete2 + " " + hypothenuse + " "); |
||||
|
|
||||
|
if (((kathete1 ^ 2) + (kathete2 ^ 2)) <= (hypothenuse ^ 2)) { |
||||
|
logger.trace("Collision"); |
||||
|
return true; |
||||
|
} |
||||
|
return false; |
||||
|
} |
||||
|
|
||||
|
|
||||
|
|
||||
|
@Override |
||||
|
public boolean collidesWith(Collider other) { |
||||
|
|
||||
|
// circ circ |
||||
|
try { |
||||
|
return checkCollisionCircCirc(other); |
||||
|
} catch (Exception e) { |
||||
|
} |
||||
|
|
||||
|
try { |
||||
|
return other.collidesWith(this); |
||||
|
} catch (Exception e) { |
||||
|
} |
||||
|
|
||||
|
throw new RuntimeException("Collider type not implemented!"); |
||||
|
} |
||||
|
|
||||
|
private Color color = Color.WHITE; |
||||
|
|
||||
|
|
||||
|
|
||||
|
} |
@ -0,0 +1,127 @@ |
|||||
|
package collider; |
||||
|
|
||||
|
import java.awt.Graphics2D; |
||||
|
import java.util.LinkedList; |
||||
|
import gameobjects.GameObject; |
||||
|
import playground.Playground; |
||||
|
import controller.ObjectController; |
||||
|
|
||||
|
/** |
||||
|
* abstract base class for all Colliders to detect collisions between GameObjects |
||||
|
* |
||||
|
* |
||||
|
*/ |
||||
|
public abstract class Collider { |
||||
|
|
||||
|
/** unique internal name for Collider */ |
||||
|
public String id = null; |
||||
|
/** GameObject it belongs to */ |
||||
|
protected GameObject gameobject = null; |
||||
|
/** PlayGround instance it belongs to */ |
||||
|
protected Playground playground = null; |
||||
|
/** the ObjectController to the corresponding GameObject (can be null) */ |
||||
|
protected ObjectController controller = null; |
||||
|
|
||||
|
protected double dx = 0.; |
||||
|
double dy = 0.; |
||||
|
|
||||
|
/** |
||||
|
* |
||||
|
* @param id unique name for Collider (internally) |
||||
|
* @param o GameObject instance it belongs to |
||||
|
*/ |
||||
|
public Collider(String id, GameObject o) { |
||||
|
this.gameobject = o; |
||||
|
|
||||
|
this.id = id; |
||||
|
this.controller = o.getObjectController(); |
||||
|
this.playground = o.getPlayground(); |
||||
|
|
||||
|
} |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* setter for offset values to be used relative to GameObject center. default is zero. |
||||
|
* |
||||
|
* @param dx offset in X direction (default 0) |
||||
|
* @param dy offset in Y direction (default 0) |
||||
|
* @return this instance of Collider |
||||
|
*/ |
||||
|
public Collider setOffsets(double dx, double dy) { |
||||
|
this.dx = dx; |
||||
|
this.dy = dy; |
||||
|
return this; |
||||
|
} |
||||
|
|
||||
|
public String toString() { |
||||
|
return "baseColl"; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* returns the corresponding game objects X coordinate (center) plus this colliders offset in X |
||||
|
* (probably zero). |
||||
|
* |
||||
|
* @return X value |
||||
|
*/ |
||||
|
public double getX() { |
||||
|
return this.gameobject.getX() + this.dx; |
||||
|
} |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* returns the corresponding game objects Y coordinate (center) plus this colliders offset in Y |
||||
|
* (probably zero). |
||||
|
* |
||||
|
* @return Y value |
||||
|
*/ |
||||
|
public double getY() { |
||||
|
return this.gameobject.getY() + this.dy; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* returns the internal unique name |
||||
|
* |
||||
|
* @return the String with the name |
||||
|
*/ |
||||
|
public String getId() { |
||||
|
return id; |
||||
|
} |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* setter for corresponding GameObject |
||||
|
* |
||||
|
* @param gameObject to be saved in attribute |
||||
|
*/ |
||||
|
public void setObject(GameObject gameObject) { |
||||
|
this.gameobject = gameObject; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* setter for GameController |
||||
|
* |
||||
|
* @param controller to be saved in attribute |
||||
|
*/ |
||||
|
public void setController(ObjectController controller) { |
||||
|
this.controller = controller; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* setter for Playground instance this collider belongs to |
||||
|
* |
||||
|
* @param playground instance to be stored in attribute |
||||
|
*/ |
||||
|
public void setPlayground(Playground playground) { |
||||
|
this.playground = playground; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* checks the collission with another collider instance. |
||||
|
* |
||||
|
* @param other the instance to compare to |
||||
|
* @return true if the colliders collide (touch or overlap) |
||||
|
*/ |
||||
|
abstract public boolean collidesWith(Collider other); |
||||
|
|
||||
|
|
||||
|
} |
@ -0,0 +1,127 @@ |
|||||
|
package collider; |
||||
|
|
||||
|
import java.awt.Color; |
||||
|
|
||||
|
import gameobjects.*; |
||||
|
import org.apache.logging.log4j.Logger; |
||||
|
import org.apache.logging.log4j.LogManager; |
||||
|
|
||||
|
/** a {@link Collider} for Rectangles, usually used for {@link RectObject} instances. |
||||
|
* @see gameobjects.RectObject#generateColliders() |
||||
|
*/ |
||||
|
public class RectCollider extends Collider { |
||||
|
|
||||
|
//double x; |
||||
|
//double y; |
||||
|
//double vx; |
||||
|
//double vy; |
||||
|
double w, h; |
||||
|
|
||||
|
private Color color = Color.WHITE; |
||||
|
|
||||
|
private static Logger logger = LogManager.getLogger(RectCollider.class); |
||||
|
|
||||
|
/** |
||||
|
* initializes this RectCollider. |
||||
|
* calls superclass constructor of {@link Collider#Collider(String, GameObject)} with params String id and GameObject o. |
||||
|
* |
||||
|
* @param id String unique name for this RectCollider |
||||
|
* @param o GameObject instance this RectCollider belongs to (cannot be null) |
||||
|
* @param w width in pixels for the collider dimensions (> 0) |
||||
|
* @param h height in pixels for the collider dimensions (>0) |
||||
|
*/ |
||||
|
public RectCollider(String id, GameObject o, double w, double h) { |
||||
|
super(id, o); |
||||
|
this.w = w; |
||||
|
this.h = h; |
||||
|
} |
||||
|
|
||||
|
public String toString() { |
||||
|
return " " + w + " " + h + " "; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* checks collision with other Collider, which needs to be a RectCollider, too. |
||||
|
* @param other RectCollider (is casted) to calculate collision with |
||||
|
* @return true if collission is detected |
||||
|
*/ |
||||
|
public boolean checkCollisionRectRect(Collider other) { |
||||
|
RectCollider r1 = this; |
||||
|
RectCollider r2 = (RectCollider) other; |
||||
|
|
||||
|
if ((((r1.getX() + r1.w / 2.) >= (r2.getX() - r2.w / 2.)) && ((r1.getX() + r1.w / 2.) <= (r2 |
||||
|
.getX() + r2.w / 2.))) |
||||
|
|| (((r2.getX() + r2.w / 2.) >= (r1.getX() - r1.w / 2.)) && ((r2.getX() + r2.w / 2.) <= (r1 |
||||
|
.getX() + r1.w / 2.)))) { |
||||
|
if ((((r1.getY() + r1.h / 2.) >= (r2.getY() - r2.h / 2.)) && ((r1.getY() + r1.h / 2.) <= (r2 |
||||
|
.getY() + r2.h / 2.))) |
||||
|
|| (((r2.getY() + r2.h / 2.) >= (r1.getY() - r1.h / 2.)) && ((r2.getY() + r2.h / 2.) <= (r1 |
||||
|
.getY() + r1.h / 2.)))) { |
||||
|
return true; |
||||
|
} |
||||
|
} |
||||
|
return false; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* checks collision with other Collider, which needs to be a CircleCollider |
||||
|
* @param other CircleCollider (is casted) to calculate collision with |
||||
|
* @return true if collission is detected |
||||
|
*/ |
||||
|
public boolean checkCollisionRectCirc(Collider other) { |
||||
|
RectCollider r = this; |
||||
|
CircleCollider c = (CircleCollider) (other); |
||||
|
double circleDistX = Math.abs(c.getX() - (r.getX() )); |
||||
|
double circleDistY = Math.abs(c.getY() - (r.getY() ) ); |
||||
|
|
||||
|
logger.trace("c.x:"+c.x+" "+"c.y:"+c.y+" "+"c.r:"+c.r+" "+"r.x:"+r.getX()+" "+"r.y:"+r.getY()+" "+"r.w:"+r.w+" "+"r.h:"+r.h+" "+"circleDistX:"+circleDistX+" "+"circleDistY:"+circleDistY); |
||||
|
|
||||
|
if (circleDistX > (r.w / 2 + c.r)) |
||||
|
return false; |
||||
|
if (circleDistY > (r.h / 2 + c.r)) |
||||
|
return false; |
||||
|
|
||||
|
if (circleDistX <= (r.w / 2)) { |
||||
|
logger.trace("Collision Rect with circle"); |
||||
|
return true; |
||||
|
} |
||||
|
if (circleDistY <= (r.h / 2)) { |
||||
|
logger.trace("Collision Rect with circle (second)"); |
||||
|
return true; |
||||
|
} |
||||
|
|
||||
|
double cornerDistSqr = Math.pow(circleDistX - r.w / 2, 2) + Math.pow(circleDistY - r.h / 2, 2); // Satz |
||||
|
// des |
||||
|
// Pythagoras |
||||
|
return (cornerDistSqr <= c.r * c.r); // falls true zurueckgegeben: Kollision |
||||
|
} |
||||
|
|
||||
|
|
||||
|
|
||||
|
@Override |
||||
|
public boolean collidesWith(Collider other) { |
||||
|
|
||||
|
// rect circ |
||||
|
try { |
||||
|
return checkCollisionRectCirc(other); |
||||
|
} catch (Exception e) { |
||||
|
// do nothing |
||||
|
} |
||||
|
|
||||
|
// rect rect |
||||
|
try { |
||||
|
return checkCollisionRectRect(other); |
||||
|
} catch (Exception e) { |
||||
|
// do nothing |
||||
|
} |
||||
|
|
||||
|
try { |
||||
|
return other.collidesWith(this); |
||||
|
} catch (Exception e) { |
||||
|
// do nothing |
||||
|
} |
||||
|
|
||||
|
throw new RuntimeException("Collider type not implemented!"); |
||||
|
} |
||||
|
|
||||
|
} |
@ -0,0 +1,84 @@ |
|||||
|
package controller; |
||||
|
|
||||
|
import playground.*; |
||||
|
import gameobjects.*; |
||||
|
import java.util.*; |
||||
|
import java.awt.event.*; |
||||
|
import java.io.File; |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* An EgoController which cannot move through obstacle objects (is collission aware). Only respects |
||||
|
* GameObjects that have the String 'obstacle' in their name. |
||||
|
* |
||||
|
*/ |
||||
|
public class CollisionAwareEgoController extends EgoController { |
||||
|
|
||||
|
double savex, savey, savevx, savevy; |
||||
|
double lastSpaceAt = -1; |
||||
|
private File shot = null; |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* |
||||
|
* @param egoRad radius of ego object to be used. |
||||
|
*/ |
||||
|
public CollisionAwareEgoController(double egoRad) { |
||||
|
super(egoRad); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* |
||||
|
* @param egoRad radius of ego object to be used. |
||||
|
* @param soundOnShot WAV file to be played on shot |
||||
|
*/ |
||||
|
public CollisionAwareEgoController(double egoRad, File soundOnShot) { |
||||
|
super(egoRad); |
||||
|
this.shot = soundOnShot; |
||||
|
} |
||||
|
|
||||
|
public void saveDynamicState() { |
||||
|
this.savex = this.getX(); |
||||
|
this.savey = this.getY(); |
||||
|
this.savevx = this.getVX(); |
||||
|
this.savevy = this.getVY(); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
public void restoreDynamicState() { |
||||
|
this.setX(savex); |
||||
|
this.setY(savey); |
||||
|
this.setVX(savevx); |
||||
|
this.setVY(savevy); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
public boolean stopObject() { |
||||
|
boolean s = super.stopObject(); |
||||
|
|
||||
|
Playground pg = this.getPlayground(); |
||||
|
|
||||
|
LinkedList<GameObject> obstacles = pg.collectObjects("obstacle", false); |
||||
|
|
||||
|
this.saveDynamicState(); |
||||
|
this.applySpeedVector(); |
||||
|
|
||||
|
for (GameObject ob : obstacles) { |
||||
|
if (ob.collisionDetection(this.gameObject)) { |
||||
|
this.restoreDynamicState(); |
||||
|
return true; |
||||
|
} |
||||
|
} |
||||
|
this.restoreDynamicState(); |
||||
|
return s; |
||||
|
} |
||||
|
|
||||
|
public void onSpace(KeyEvent e, GameObject ego) { |
||||
|
double cgt = ego.getGameTime(); |
||||
|
if ((cgt - this.lastSpaceAt) > 0.1) { |
||||
|
super.onSpace(e, ego); |
||||
|
Music.music(this.shot); |
||||
|
} |
||||
|
|
||||
|
} |
||||
|
} |
@ -0,0 +1,216 @@ |
|||||
|
package controller; |
||||
|
|
||||
|
import java.awt.Color; |
||||
|
import java.awt.event.KeyEvent; |
||||
|
import playground.*; |
||||
|
import gameobjects.*; |
||||
|
import java.util.*; |
||||
|
import org.apache.logging.log4j.Logger; |
||||
|
import org.apache.logging.log4j.LogManager; |
||||
|
|
||||
|
/** |
||||
|
* Controller using key events for up, down, left, right and space (shooting) to control the ego |
||||
|
* object behavior. |
||||
|
*/ |
||||
|
public class EgoController extends ObjectController { |
||||
|
// either rad is zero or width/height is zero (guaranteed by constructors) |
||||
|
private double rad = 0; |
||||
|
private double width = 0; |
||||
|
private double height = 0; |
||||
|
|
||||
|
private Integer pressedKey = null; |
||||
|
private Integer lastPressedKey = null; |
||||
|
private static Logger logger = LogManager.getLogger(EgoController.class); |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* constructor that gives the ego controller a radius to stop the ego object when it reaches the level boundaries. |
||||
|
* @param egoRad radius to use as a boundary stop for level borders (usually use the same dimensions as your ego object) |
||||
|
*/ |
||||
|
public EgoController(double egoRad) { |
||||
|
this.rad = egoRad; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* constructor that gives the ego controller a width and height to stop the ego object when it reaches the level boundaries. |
||||
|
* @param width width to use as a boundary stop for level borders (usually use the same dimensions as your ego object) |
||||
|
* @param height height to use as a boundary stop for level borders (usually use the same dimensions as your ego object) |
||||
|
*/ |
||||
|
public EgoController(double width, double height) { |
||||
|
this.width = width; |
||||
|
this.height = height; |
||||
|
} |
||||
|
|
||||
|
|
||||
|
public void onUp(KeyEvent kc, GameObject ego) { |
||||
|
ego.setVX(0.0); |
||||
|
ego.setVY(-SpaceInvadersLevel.EGOSPEED); |
||||
|
} |
||||
|
|
||||
|
public void onDown(KeyEvent kc, GameObject ego) { |
||||
|
ego.setVX(0.0); |
||||
|
ego.setVY(SpaceInvadersLevel.EGOSPEED); |
||||
|
} |
||||
|
|
||||
|
public void onLeft(KeyEvent kc, GameObject ego) { |
||||
|
ego.setVY(0.0); |
||||
|
ego.setVX(-SpaceInvadersLevel.EGOSPEED); |
||||
|
} |
||||
|
|
||||
|
public void onRight(KeyEvent kc, GameObject ego) { |
||||
|
ego.setVY(0.0); |
||||
|
ego.setVX(SpaceInvadersLevel.EGOSPEED); |
||||
|
} |
||||
|
|
||||
|
public void onStop(KeyEvent kc, GameObject ego) { |
||||
|
ego.setVY(0.0); |
||||
|
ego.setVX(0.0); |
||||
|
ego.setComponentProperty("controller", "setDummy", "NEW"); |
||||
|
ego.setComponentProperty("controller", "setDummy2", "XXX"); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
/** checks the position and respects level boundaries and own radius or width/height set on constructor. |
||||
|
* |
||||
|
* @return true if the object reached the boundaries of the level, false otherwise |
||||
|
*/ |
||||
|
public boolean stopObject() { |
||||
|
// check whether ego object is at level boundaries |
||||
|
// can use radius (rad) and width or height in one check as either rad or width/height is zero. |
||||
|
int pgSizeX = this.getPlayground().getSizeX(); |
||||
|
int pgSizeY = this.getPlayground().getSizeY(); |
||||
|
double ts = this.getTimestep(); |
||||
|
if (this.getX() + rad + (width/2d) + this.getVX() * ts >= pgSizeX |
||||
|
|| this.getX() - rad - (width/2d) + this.getVX() * ts < 0) { |
||||
|
return true; |
||||
|
} |
||||
|
if (this.getY() + rad + (height/2d) + this.getVY() * ts >= pgSizeY |
||||
|
|| this.getY() - rad - (height/2d) + this.getVY() * ts < 0) { |
||||
|
return true; |
||||
|
} |
||||
|
return false; |
||||
|
|
||||
|
} |
||||
|
|
||||
|
|
||||
|
/** behavior for shooting on key space |
||||
|
* |
||||
|
* @param e KeyEvent of the space key |
||||
|
* @param ego EgoObject instance (used to determine position of shot object's start) |
||||
|
*/ |
||||
|
public void onSpace(KeyEvent e, GameObject ego) { |
||||
|
pressedKey = lastPressedKey; |
||||
|
lastPressedKey = null; |
||||
|
|
||||
|
// create unique name for object |
||||
|
// read Flag nextShot read (if not existing already it will be set) |
||||
|
// it will be updated by 1 and saved |
||||
|
Integer nextShot = |
||||
|
(Integer) this.getPlayground().getOrCreateLevelFlag("nextShot", Integer.valueOf(0)); |
||||
|
String shotName = "simpleShot" + nextShot++; |
||||
|
this.getPlayground().setLevelFlag("nextShot", nextShot); |
||||
|
|
||||
|
SimpleShotController simpleshot = new SimpleShotController(); |
||||
|
GameObject ss = new RectObject(shotName, this.getPlayground(), ego.getX(), ego.getY(), 0, |
||||
|
-1. * SpaceInvadersLevel.SHOTSPEED, 4, 12, Color.CYAN).addController(simpleshot); |
||||
|
ss.generateColliders(); |
||||
|
this.getPlayground().addObject(ss); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* updates position based on key events (mouse currently ignored) |
||||
|
*/ |
||||
|
public void updateObject() { |
||||
|
|
||||
|
logger.trace("Playground inst is"+this.getPlayground()) ; |
||||
|
Stack<KeyEvent> keyEvents = this.getPlayground().getKeyEvents(); |
||||
|
|
||||
|
GameObject ego = this.gameObject; |
||||
|
|
||||
|
while (!keyEvents.isEmpty()) { |
||||
|
|
||||
|
KeyEvent e = keyEvents.pop(); |
||||
|
boolean pressed = false; |
||||
|
boolean released = true; |
||||
|
int kc = e.getKeyCode(); |
||||
|
|
||||
|
if (e.paramString().indexOf("PRESSED") >= 0) { |
||||
|
pressed = true; |
||||
|
released = false; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Generelle Idee: Wenn eine Taste gedrückt wird wird sie gespeichert. wenn die zuvor |
||||
|
* gespeicherte Taste wieder losgelassen wird stoppt das Ego-Objekt. Falls vor dem Loslassen |
||||
|
* eine andere Taste gedrückt wird, wird diese gespeichert und die alte vergessen. Dh das |
||||
|
* loslassen der alten Taste stoppt das Objekt nicht. Spezialfall: space, das loslassen von |
||||
|
* space stoppt das Objekt nicht! |
||||
|
*/ |
||||
|
|
||||
|
if (pressed == true) { |
||||
|
lastPressedKey = pressedKey; |
||||
|
pressedKey = kc; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Nur eine losgelassene Taste die auch vorher gedrückt wurde stoppt das Objekt. Eine |
||||
|
* losgelassene Taste die nicht vorher gedrückt wurde bzw vergessen wurde stoppt das Objekt |
||||
|
* nicht |
||||
|
*/ |
||||
|
if (released == true) { |
||||
|
if (pressedKey != null) { |
||||
|
if (pressedKey.equals(kc)) { |
||||
|
ego.setVX(0); |
||||
|
ego.setVY(0); |
||||
|
pressedKey = null; |
||||
|
} |
||||
|
} |
||||
|
continue; |
||||
|
} |
||||
|
|
||||
|
if (kc == KeyEvent.VK_LEFT) { |
||||
|
this.onLeft(e, ego); |
||||
|
} |
||||
|
|
||||
|
if (kc == KeyEvent.VK_RIGHT) { |
||||
|
this.onRight(e, ego); |
||||
|
} |
||||
|
|
||||
|
if (kc == KeyEvent.VK_UP) { |
||||
|
this.onUp(e, ego); |
||||
|
} |
||||
|
|
||||
|
if (kc == KeyEvent.VK_DOWN) { |
||||
|
this.onDown(e, ego); |
||||
|
} |
||||
|
|
||||
|
// stop |
||||
|
if (kc == KeyEvent.VK_Z) { |
||||
|
this.onStop(e, ego); |
||||
|
|
||||
|
} |
||||
|
|
||||
|
|
||||
|
// shot |
||||
|
if (kc == KeyEvent.VK_SPACE) { |
||||
|
// space is not registered! Releasing space does not stop the egoobject |
||||
|
this.onSpace(e, ego); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
|
||||
|
boolean stop = this.stopObject(); |
||||
|
|
||||
|
if (stop) { |
||||
|
this.setVX(0); |
||||
|
this.setVY(0); |
||||
|
} |
||||
|
|
||||
|
// updateSpeed and position |
||||
|
applySpeedVector(); |
||||
|
|
||||
|
} |
||||
|
|
||||
|
|
||||
|
} |
@ -0,0 +1,36 @@ |
|||||
|
package controller; |
||||
|
|
||||
|
|
||||
|
import org.apache.logging.log4j.Logger; |
||||
|
import org.apache.logging.log4j.LogManager; |
||||
|
|
||||
|
/** |
||||
|
* This class controls the space invaders. |
||||
|
*/ |
||||
|
public class EnemyController extends ObjectController { |
||||
|
|
||||
|
private static Logger logger = LogManager.getLogger(EnemyController.class); |
||||
|
|
||||
|
@Override |
||||
|
public void updateObject() { |
||||
|
logger.trace("updatre" + gameObject.getId()); |
||||
|
if ((gameObject.getX() > this.getPlayground().getSizeX() * 0.9) && (gameObject.getVX() > 0)) { |
||||
|
logger.trace("toleft!" + gameObject.getX()); |
||||
|
gameObject.setVX(-this.getVX()); |
||||
|
} |
||||
|
if ((gameObject.getX() < this.getPlayground().getSizeX() * 0.1) && (gameObject.getVX() < 0)) { |
||||
|
logger.trace("toright!" + gameObject.getX()); |
||||
|
gameObject.setVX(-this.getVX()); |
||||
|
} |
||||
|
|
||||
|
// if it reaches the bottom, delete it and deduct points |
||||
|
if (gameObject.getY() >= this.getPlayground().getSizeY()) { |
||||
|
this.getPlayground().deleteObject(gameObject.getId()); |
||||
|
// add to points counter |
||||
|
Integer pts = (Integer) this.getPlayground().getGlobalFlag("points"); |
||||
|
this.getPlayground().setGlobalFlag("points", pts - 200); |
||||
|
} |
||||
|
|
||||
|
applySpeedVector(); |
||||
|
} |
||||
|
} |
@ -0,0 +1,24 @@ |
|||||
|
package controller; |
||||
|
|
||||
|
import org.apache.logging.log4j.Logger; |
||||
|
import org.apache.logging.log4j.LogManager; |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* Controls background stars. When they touch the bottom of the display they reappear on top. |
||||
|
*/ |
||||
|
public class FallingStarController extends ObjectController { |
||||
|
int rad = 3; |
||||
|
private static Logger logger = LogManager.getLogger(FallingStarController.class); |
||||
|
|
||||
|
|
||||
|
@Override |
||||
|
public void updateObject() { |
||||
|
logger.trace( |
||||
|
"+" + this.gameObject.getId() + " HO " + this.gameObject + "/" + this.getPlayground()); |
||||
|
if (this.getY() + rad >= this.getPlayground().getSizeY()) { |
||||
|
this.setY(10); |
||||
|
} |
||||
|
applySpeedVector(); |
||||
|
} |
||||
|
} |
@ -0,0 +1,36 @@ |
|||||
|
package controller; |
||||
|
|
||||
|
/** |
||||
|
* Controls and abject that is deleted after a lifetime specified in the constructor, and when it |
||||
|
* leaves the display. |
||||
|
*/ |
||||
|
public class LimitedTimeController extends ObjectController { |
||||
|
int rad = 3; |
||||
|
double g0 = -1; |
||||
|
double duration = 0; |
||||
|
|
||||
|
/** |
||||
|
* Constructor. |
||||
|
* |
||||
|
* @param g0 int initial game time at creation |
||||
|
* @param duration int duration in seconds |
||||
|
*/ |
||||
|
public LimitedTimeController(double g0, double duration) { |
||||
|
this.g0 = g0; |
||||
|
this.duration = duration; |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public void updateObject() { |
||||
|
double gameTime = this.getPlayground().getGameTime(); |
||||
|
applySpeedVector(); |
||||
|
|
||||
|
if (gameObject.getY() >= getPlayground().getSizeY() || gameObject.getY() < 0 |
||||
|
|| gameObject.getX() >= getPlayground().getSizeX() || gameObject.getX() < 0 |
||||
|
|| (gameTime - g0) > duration) { |
||||
|
|
||||
|
this.getPlayground().deleteObject(this.gameObject.getId()); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
} |
@ -0,0 +1,47 @@ |
|||||
|
package controller; |
||||
|
|
||||
|
import controller.ObjectController; |
||||
|
import gameobjects.GameObject; |
||||
|
|
||||
|
import org.apache.logging.log4j.Logger; |
||||
|
import org.apache.logging.log4j.LogManager; |
||||
|
|
||||
|
public class MineController extends ObjectController { |
||||
|
int rad = 3; |
||||
|
|
||||
|
double xSpeed = 0.; |
||||
|
double lineSpeed = 0; |
||||
|
private static Logger logger = LogManager.getLogger(MineController.class); |
||||
|
|
||||
|
|
||||
|
public MineController(double lineSpeed) { |
||||
|
this.lineSpeed = lineSpeed; |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public void updateObject() { |
||||
|
|
||||
|
if (gameObject.getY() >= this.getPlayground().getSizeY() - 10) { |
||||
|
this.gameObject.setVY(0); |
||||
|
if (xSpeed == 0.) { |
||||
|
GameObject ego = getPlayground().getObject("ego"); |
||||
|
double egoXPos = ego.getX(); |
||||
|
if (egoXPos > this.gameObject.getX()) { |
||||
|
xSpeed = 50; |
||||
|
} else { |
||||
|
xSpeed = -50; |
||||
|
} |
||||
|
this.gameObject.setVX(xSpeed); |
||||
|
|
||||
|
} |
||||
|
this.gameObject.setVX(xSpeed); |
||||
|
|
||||
|
} |
||||
|
if (this.gameObject.getX() < 0 || (this.gameObject.getX() > this.getPlayground().getSizeX())) { |
||||
|
logger.debug("deleting" + this.gameObject.getId()); |
||||
|
getPlayground().deleteObject(this.gameObject.getId()); |
||||
|
} |
||||
|
|
||||
|
applySpeedVector(); |
||||
|
} |
||||
|
} |
@ -0,0 +1,110 @@ |
|||||
|
package controller; |
||||
|
|
||||
|
import gameobjects.GameObject; |
||||
|
import playground.Playground; |
||||
|
import org.apache.logging.log4j.Logger; |
||||
|
import org.apache.logging.log4j.LogManager; |
||||
|
|
||||
|
/** |
||||
|
* Class that controls the LOGICAL behavior of an object independently of how it is displayed or |
||||
|
* drawn. The most important method here is {@link #updateObject}: this method is, by various |
||||
|
* indirections, called exactly once per game time step for every object that is on the playground. |
||||
|
* It has, by virtue of the member variables {@link #gameObject} full access to |
||||
|
* <ul> |
||||
|
* <li>the object it is controlling |
||||
|
* <li>the playground this object belongs to |
||||
|
* </ul> |
||||
|
* Typically, updateObject would check whether an object leaves the screen to react appropriately. |
||||
|
* In that case the object can be marked for deletion (by adding it to the flag "deleted" that is |
||||
|
* always defined for any playground), but of course other reactions are possible like rebounding, |
||||
|
* emerging on the other side, ... |
||||
|
*/ |
||||
|
|
||||
|
public abstract class ObjectController { |
||||
|
protected GameObject gameObject = null; |
||||
|
protected String dummy = ""; |
||||
|
|
||||
|
private static Logger logger = LogManager.getLogger(ObjectController.class); |
||||
|
|
||||
|
public void setObject(GameObject gameObject) { |
||||
|
this.gameObject = gameObject; |
||||
|
} |
||||
|
|
||||
|
|
||||
|
public void setDummy(String x) { |
||||
|
logger.debug("DUMMY called!!"); |
||||
|
this.dummy = x; |
||||
|
logger.debug("DUMMY is now:" + dummy); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Is called once every game time step by the game itself. NEVER call this directly, not |
||||
|
* necessary!<br> |
||||
|
* The method can do whatever it likes, including nothing. The attribute {@link #gameObject} |
||||
|
* contains a reference to the controlled object, which allows access to the Playground the object |
||||
|
* belongs to (useful for getting the pixel size in x and y of the playing field.<br> |
||||
|
* <strong>Recommended:</strong> when implementing this method, call at the end |
||||
|
* {@link #applySpeedVector() } method. This is a helper method that sets the new x,y coordinates |
||||
|
* for the {@link #gameObject} correctly. |
||||
|
*/ |
||||
|
public abstract void updateObject(); |
||||
|
|
||||
|
/** |
||||
|
* Convenience method: simply moves the object forward one step from its present position, using |
||||
|
* its present speed. |
||||
|
*/ |
||||
|
public void applySpeedVector() { |
||||
|
double ts = this.getPlayground().getTimestep(); |
||||
|
this.setX(this.getX() + this.getVX() * ts); |
||||
|
gameObject.setY(this.getY() + this.getVY() * ts); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
public double getTimestep() { |
||||
|
return this.gameObject.getPlayground().getTimestep(); |
||||
|
} |
||||
|
|
||||
|
public double getX() { |
||||
|
return this.gameObject.getX(); |
||||
|
} |
||||
|
|
||||
|
public double getY() { |
||||
|
return this.gameObject.getY(); |
||||
|
} |
||||
|
|
||||
|
public double getVX() { |
||||
|
return this.gameObject.getVX(); |
||||
|
} |
||||
|
|
||||
|
public double getVY() { |
||||
|
return this.gameObject.getVY(); |
||||
|
} |
||||
|
|
||||
|
public void setX(double x) { |
||||
|
this.gameObject.setX(x); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
public void setY(double y) { |
||||
|
this.gameObject.setY(y); |
||||
|
} |
||||
|
|
||||
|
public void setVX(double vx) { |
||||
|
this.gameObject.setVX(vx); |
||||
|
} |
||||
|
|
||||
|
public void setVY(double vy) { |
||||
|
this.gameObject.setVY(vy); |
||||
|
} |
||||
|
|
||||
|
public Playground getPlayground() { |
||||
|
return this.gameObject.getPlayground(); |
||||
|
} |
||||
|
|
||||
|
public void setPlayground(Playground playground) { |
||||
|
this.gameObject.setPlayground(playground); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
|
||||
|
} |
@ -0,0 +1,16 @@ |
|||||
|
package controller; |
||||
|
|
||||
|
public class SimpleShotController extends ObjectController { |
||||
|
int rad = 3; |
||||
|
|
||||
|
@Override |
||||
|
public void updateObject() { |
||||
|
if (gameObject.getY() < 0) { |
||||
|
// LinkedList<String> deleteList = (LinkedList<String>) playground.getFlag("delete"); |
||||
|
// deleteList.add(gameObject.getId()); |
||||
|
getPlayground().deleteObject(this.gameObject.getId()); |
||||
|
} else { |
||||
|
applySpeedVector(); |
||||
|
} |
||||
|
} |
||||
|
} |
@ -0,0 +1,32 @@ |
|||||
|
package controller; |
||||
|
|
||||
|
import org.apache.logging.log4j.Logger; |
||||
|
import org.apache.logging.log4j.LogManager; |
||||
|
|
||||
|
public class ZickZackController extends EnemyController { |
||||
|
protected double g0; |
||||
|
protected double dt; |
||||
|
protected double lastMod = -1; |
||||
|
|
||||
|
private static Logger logger = LogManager.getLogger(ZickZackController.class); |
||||
|
|
||||
|
public ZickZackController(double gameTime, double dt) { |
||||
|
super(); |
||||
|
this.dt = dt; |
||||
|
this.g0 = gameTime; |
||||
|
} |
||||
|
|
||||
|
public void updateObject() { |
||||
|
double gameTime = this.getPlayground().getGameTime(); |
||||
|
logger.trace("current Object x: "+gameObject.getX()); |
||||
|
double mod = (gameTime - this.g0) % this.dt; |
||||
|
if (mod < lastMod) { |
||||
|
gameObject.setVX(-1.0 * gameObject.getVX()); |
||||
|
logger.trace("inverting VX"); |
||||
|
} |
||||
|
lastMod = mod; |
||||
|
|
||||
|
super.updateObject(); |
||||
|
|
||||
|
} |
||||
|
} |
@ -0,0 +1,11 @@ |
|||||
|
/** |
||||
|
* The controller package contains Object controllers that govern an objects behavior, without being |
||||
|
* involved in its collision or drawing properties. Object controllers react to user actions/inputs |
||||
|
* and govern for example the movement of {@link gameobjects.GameObject} instances. They can access |
||||
|
* their parent objects' properties and, by indirection, the properties and methods of the |
||||
|
* associated level. <br> |
||||
|
* Controllers should be designed in such a way that they implement behavior that is |
||||
|
* level-independent. All level-dependent behavior should be implemented in |
||||
|
* {@link playground.Playground#applyGameLogic}. |
||||
|
*/ |
||||
|
package controller; |
@ -0,0 +1,42 @@ |
|||||
|
package gameobjects; |
||||
|
|
||||
|
import java.util.LinkedList; |
||||
|
import playground.Playground; |
||||
|
import playground.Animation; |
||||
|
import collider.Collider; |
||||
|
import collider.RectCollider; |
||||
|
import rendering.*; |
||||
|
import org.apache.logging.log4j.Logger; |
||||
|
import org.apache.logging.log4j.LogManager; |
||||
|
|
||||
|
|
||||
|
public class AnimatedGameobject extends GameObject { |
||||
|
|
||||
|
protected AnimationArtist animArtist; |
||||
|
private static Logger logger = LogManager.getLogger(AnimationArtist.class); |
||||
|
|
||||
|
|
||||
|
// auto-generates collider according to box width/height |
||||
|
public GameObject generateColliders() { |
||||
|
logger.debug("Created animated Obj "+ this.animArtist.getW()+" "+this.animArtist.getH()) ; |
||||
|
double w = this.animArtist.getW() ; |
||||
|
double h = this.animArtist.getH() ; |
||||
|
this.addCollider(new RectCollider("RectColl_" + this.id, this, w, |
||||
|
h)) ; |
||||
|
|
||||
|
logger.info("ANIMGO-COLL ID="+this.getId()+" WH= "+w+"/"+h) ; |
||||
|
return this ; |
||||
|
} |
||||
|
|
||||
|
|
||||
|
public AnimatedGameobject(String id, Playground pg, double x, double y, double vx, double vy, |
||||
|
double scale, Animation anim, double t0, String abspielmodus) { |
||||
|
super(id, pg, x, y, vx, vy); // Konstruktor-Aufruf GameObject |
||||
|
|
||||
|
this.artist = new AnimationArtist(this, anim, t0, abspielmodus, scale); |
||||
|
this.animArtist = (AnimationArtist) (this.artist); |
||||
|
|
||||
|
} |
||||
|
|
||||
|
|
||||
|
} |
@ -0,0 +1,34 @@ |
|||||
|
package gameobjects; |
||||
|
|
||||
|
|
||||
|
import java.awt.Color; |
||||
|
import collider.*; |
||||
|
import java.awt.Graphics2D; |
||||
|
import java.awt.image.BufferedImage; |
||||
|
import java.io.File; |
||||
|
import java.io.IOException; |
||||
|
import java.util.LinkedList; |
||||
|
import javax.imageio.ImageIO; |
||||
|
import collider.Collider; |
||||
|
import controller.ObjectController; |
||||
|
import playground.Playground; |
||||
|
import rendering.*; |
||||
|
|
||||
|
public class EgoObject extends GameObject { |
||||
|
|
||||
|
double egoRad = 0; |
||||
|
|
||||
|
public EgoObject(String id, Playground pg, double x, double y, double vx, double vy, |
||||
|
double egoRad) { |
||||
|
super(id, pg, x, y, vx, vy); |
||||
|
this.egoRad = egoRad; |
||||
|
this.artist = new CircleArtist(this, egoRad, Color.WHITE); |
||||
|
} |
||||
|
|
||||
|
public GameObject generateColliders() { |
||||
|
CircleCollider coll = new CircleCollider("coll", this, this.egoRad); |
||||
|
this.addCollider(coll); |
||||
|
return this; |
||||
|
} |
||||
|
|
||||
|
} |
@ -0,0 +1,28 @@ |
|||||
|
package gameobjects; |
||||
|
|
||||
|
import java.awt.Color; |
||||
|
import java.util.LinkedList; |
||||
|
import collider.*; |
||||
|
import playground.Playground; |
||||
|
import rendering.*; |
||||
|
|
||||
|
public class FallingStar extends GameObject { |
||||
|
|
||||
|
private Color color = Color.WHITE; |
||||
|
|
||||
|
protected double rad = -1; |
||||
|
|
||||
|
|
||||
|
public FallingStar(String id, Playground playground, double x, double y, double vx, double vy, |
||||
|
Color color, double rad) { |
||||
|
super(id, playground, x, y, vx, vy); |
||||
|
this.rad = rad; |
||||
|
this.color = color; |
||||
|
LinkedList<Collider> cols = new LinkedList<Collider>(); |
||||
|
CircleCollider cc = new CircleCollider("cc", this, rad); |
||||
|
cols.add(cc); |
||||
|
setColliders(cols); |
||||
|
this.artist = new CircleArtist(this, rad, color); |
||||
|
} |
||||
|
|
||||
|
} |
@ -0,0 +1,377 @@ |
|||||
|
package gameobjects; |
||||
|
|
||||
|
import java.awt.Graphics2D; |
||||
|
import java.awt.image.BufferedImage; |
||||
|
import java.util.LinkedList; |
||||
|
import java.lang.reflect.*; |
||||
|
import rendering.*; |
||||
|
import collider.Collider; |
||||
|
import controller.ObjectController; |
||||
|
import playground.Playground; |
||||
|
import org.apache.logging.log4j.Logger; |
||||
|
import org.apache.logging.log4j.LogManager; |
||||
|
|
||||
|
/** |
||||
|
* The class {@link GameObject} represents a (possibly animated) object appearing in a level of the |
||||
|
* game. It is therefore attached to an instance of the class {@link Playground}. A GameObject has |
||||
|
* at least the following properties: |
||||
|
* <ul> |
||||
|
* <li>2D screen position |
||||
|
* <li>2D speed |
||||
|
* <li>a name that is unique within a certain {@link Playground}<br> |
||||
|
* <li>a reference to the {@link Playground} object it belongs to<br> |
||||
|
* <li>a reference to an instance of {@link controller.ObjectController} that handles the movement |
||||
|
* logic of the object<br> |
||||
|
* <li>a (circular) radius for simple collision checking. This may be handled differently in |
||||
|
* subclasses<br> |
||||
|
* </ul> |
||||
|
* The main task of GameObject, or its subclasses, is to draw the object on the screen, which is |
||||
|
* handles by the {@link #draw(Graphics2D)} method. It is this method that must be redefined if a |
||||
|
* new appearance should be realized. For introducing new behavior, it is sufficient to supply a |
||||
|
* different {@link controller.ObjectController} instance when constructing a GameObject. |
||||
|
*/ |
||||
|
public abstract class GameObject { |
||||
|
|
||||
|
public static final int RADIUS = 0; |
||||
|
public static final int RECTANGLE = 1; |
||||
|
public static final int MASK = 2; |
||||
|
|
||||
|
protected Artist artist = null; |
||||
|
|
||||
|
public String id = null; |
||||
|
protected double x = 0; |
||||
|
protected double vx = 0; |
||||
|
protected double y = 0; |
||||
|
protected double vy = 0; |
||||
|
protected BufferedImage mask = null; // UNDONE implement usage of mask |
||||
|
protected boolean active = true; |
||||
|
// public int collisionMode = GameObject.RADIUS; |
||||
|
protected Playground playground = null; |
||||
|
|
||||
|
private ObjectController controller = null; |
||||
|
public LinkedList<Collider> scol; |
||||
|
|
||||
|
private static Logger logger = LogManager.getLogger(GameObject.class); |
||||
|
|
||||
|
/** |
||||
|
* Constructor to initialize a GameObject, respectively set the current {@link Playground} |
||||
|
* instance this GameObject belongs to. |
||||
|
* |
||||
|
* @param id unique ID for this GameObject (should not be null or empty String) |
||||
|
* @param playground the Playground the GameObject belongs to (should not be null) |
||||
|
* @param x initial screen position in direction horizontal (positive value including zero) |
||||
|
* @param y initial screen position in direction vertical (positive value including zero) |
||||
|
* @param vx initial speed (velocity) in direction horizontal (can be negative, zero, positive) |
||||
|
* @param vy initial speed (velocity) in direction horizontal (can be negative, zero, positive) |
||||
|
*/ |
||||
|
public GameObject(String id, Playground playground, double x, double y, double vx, double vy) { |
||||
|
setX(x); |
||||
|
setY(y); |
||||
|
setVX(vx); |
||||
|
setVY(vy); |
||||
|
this.id = id; |
||||
|
this.controller = null; |
||||
|
this.scol = new LinkedList<Collider>(); |
||||
|
this.setPlayground(playground); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Constructor to initialize a GameObject, respectively set the current Playground instance this |
||||
|
* GameObject belongs to. |
||||
|
* |
||||
|
* @param id unique ID for this GameObject (should not be null or empty String) |
||||
|
* @param playground the Playground the GameObject belongs to (should not be null) |
||||
|
* @param controller controller instance to be used for this GameObject (can be null) |
||||
|
* @param x initial screen position in direction horizontal (positive value including zero) |
||||
|
* @param y initial screen position in direction vertical (positive value including zero) |
||||
|
* @param vx initial speed (velocity) in direction horizontal (can be negative, zero, positive) |
||||
|
* @param vy initial speed (velocity) in direction horizontal (can be negative, zero, positive) |
||||
|
*/ |
||||
|
public GameObject(String id, Playground playground, ObjectController controller, double x, |
||||
|
double y, double vx, double vy) { |
||||
|
this(id, playground, x, y, vx, vy); |
||||
|
this.controller = controller; |
||||
|
if (this.controller != null) { |
||||
|
this.controller.setObject(this); |
||||
|
this.controller.setPlayground(playground); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* sets colliders. |
||||
|
* |
||||
|
* @param l LinkedList of Colliders. |
||||
|
*/ |
||||
|
public void setColliders(LinkedList<Collider> l) { |
||||
|
this.scol = l; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* generates and sets collider(s) for this GameObject. This implementation does nothing. Intended |
||||
|
* to be overridden by subclasses. |
||||
|
* |
||||
|
* @return instance of this GameObject (this). |
||||
|
*/ |
||||
|
public GameObject generateColliders() { |
||||
|
return this; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Sets the controller to use for this GameObject's logical behavior. |
||||
|
* |
||||
|
* @param c instance to be used. |
||||
|
* @return the current instance (this). |
||||
|
*/ |
||||
|
public GameObject addController(ObjectController c) { |
||||
|
this.controller = c; |
||||
|
this.controller.setObject(this); |
||||
|
this.controller.setPlayground(playground); |
||||
|
return this; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Sets the artist to be used for drawing the object onto visible canvas area. |
||||
|
* |
||||
|
* @param a instance to be used for calling {@link rendering.Artist#draw(Graphics2D)}. |
||||
|
* @return the current instance (this). |
||||
|
*/ |
||||
|
public GameObject addArtist(Artist a) { |
||||
|
this.artist = a; |
||||
|
return this; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* saves the collider in the internal list of Colliders to be used for this GameObject. |
||||
|
* |
||||
|
* @param c instance to be added to internal list |
||||
|
*/ |
||||
|
public void addCollider(Collider c) { |
||||
|
if (this.scol == null) { |
||||
|
this.scol = new LinkedList<Collider>(); |
||||
|
} |
||||
|
this.scol.add(c); |
||||
|
} |
||||
|
|
||||
|
public Playground getPlayground() { |
||||
|
return playground; |
||||
|
} |
||||
|
|
||||
|
public void setPlayground(Playground playground) { |
||||
|
this.playground = playground; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* calls via reflection a method of a component if this GameObjects instance and provides the |
||||
|
* given value as String parameter. |
||||
|
* |
||||
|
* @param comp class name of GameObject component. Currently only "controller" is supported, |
||||
|
* otherwise nothing happens. |
||||
|
* @param property method name of the component to call. |
||||
|
* @param value argument to pass to the method as String parameter. |
||||
|
*/ |
||||
|
public void setComponentProperty(String comp, String property, Object value) { |
||||
|
if (comp.equals("controller")) { |
||||
|
Class<? extends Object> clO = this.controller.getClass(); |
||||
|
for (Method m : clO.getMethods()) { |
||||
|
if (m.getName().indexOf(property) != -1) { |
||||
|
logger.debug("Method " + property + " found!!"); |
||||
|
try { |
||||
|
m.invoke(this.getObjectController(), value); |
||||
|
} catch (Exception e) { |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
} |
||||
|
} |
||||
|
|
||||
|
public void setObjectFlag(String flag, Object value) { |
||||
|
this.playground.setLevelFlag(this.id + "/" + flag, value); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
public Object getObjectFlag(String flag) { |
||||
|
return this.playground.getLevelFlag(this.id + "/" + flag); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
public Object getOrCreateObjectFlag(String flag, Object createValue) { |
||||
|
return this.playground.getOrCreateLevelFlag(this.id + "/" + flag, createValue); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
|
||||
|
public boolean isActive() { |
||||
|
return active; |
||||
|
} |
||||
|
|
||||
|
|
||||
|
public GameObject setActive(boolean flag) { |
||||
|
this.active = flag; |
||||
|
return this; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* return the unique object ID. |
||||
|
* |
||||
|
* @return unique object ID |
||||
|
*/ |
||||
|
public String getId() { |
||||
|
return id; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* gets the screen X position. |
||||
|
* |
||||
|
* @return screen x position |
||||
|
*/ |
||||
|
public double getX() { |
||||
|
return x; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* gets the screen Y position. |
||||
|
* |
||||
|
* @return screen Y position |
||||
|
*/ |
||||
|
public double getY() { |
||||
|
return y; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* gets the screen X speed in pixels per frame. |
||||
|
* |
||||
|
* @return screen x speed |
||||
|
*/ |
||||
|
public double getVX() { |
||||
|
return vx; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* gets the screen Y speed in pixels per frame. |
||||
|
* |
||||
|
* @return screen y speed |
||||
|
*/ |
||||
|
public double getVY() { |
||||
|
return vy; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* set screen x position. |
||||
|
* |
||||
|
* @param x new position |
||||
|
*/ |
||||
|
public void setX(double x) { |
||||
|
if (this.active == true) { |
||||
|
this.x = x; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* set screen y position. |
||||
|
* |
||||
|
* @param y new position |
||||
|
*/ |
||||
|
public void setY(double y) { |
||||
|
if (this.active == true) { |
||||
|
this.y = y; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* set screen x speed in pixel per frame |
||||
|
* |
||||
|
* @param vx new x speed |
||||
|
*/ |
||||
|
public void setVX(double vx) { |
||||
|
if (this.active == true) { |
||||
|
this.vx = vx; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* set screen y speed in pixel per frame. |
||||
|
* |
||||
|
* @param vy new y speed. |
||||
|
*/ |
||||
|
public void setVY(double vy) { |
||||
|
if (this.active == true) { |
||||
|
this.vy = vy; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Sets a new object controller (replaces any former one). |
||||
|
* |
||||
|
* @param controller An instance of {@link controller.ObjectController} or one of its subclasses. |
||||
|
*/ |
||||
|
public void setObjectController(ObjectController controller) { |
||||
|
this.controller = controller; |
||||
|
} |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* Access to object controller. |
||||
|
* |
||||
|
* @return the controller for this object. |
||||
|
*/ |
||||
|
public ObjectController getObjectController() { |
||||
|
return this.controller; |
||||
|
} |
||||
|
|
||||
|
|
||||
|
public double getGameTime() { |
||||
|
return this.playground.getGameTime(); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* Collision detection implemented by iteration through the own list of {@link collider.Collider} |
||||
|
* and calling their {@link collider.Collider#collidesWith(Collider)} method to check collision |
||||
|
* with the given parameter instance of other {@link GameObject}. |
||||
|
* |
||||
|
* @param other instance of the other GameObject to check collision with |
||||
|
* @return true if collision is detected, false otherwise |
||||
|
*/ |
||||
|
public boolean collisionDetection(GameObject other) { |
||||
|
if (this.scol == null) { |
||||
|
return false; |
||||
|
} |
||||
|
for (Collider c : this.scol) { |
||||
|
logger.trace(other.id); |
||||
|
for (Collider o : other.scol) { |
||||
|
if (c.collidesWith(o)) { |
||||
|
logger.trace(c.id + " " + o.id); |
||||
|
return true; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
return false; |
||||
|
|
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* triggers this GameObjects own controller (if set) to update the object. |
||||
|
* |
||||
|
* @see GameObject#controller |
||||
|
*/ |
||||
|
public void updateObject() { |
||||
|
if (this.controller != null) { |
||||
|
controller.updateObject(); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Draws the object in its current state. Is called by the game engine, should NOT be called |
||||
|
* otherwise. |
||||
|
* |
||||
|
* @param g object that has all the necessary drawing functionalities |
||||
|
*/ |
||||
|
public void draw(Graphics2D g) { |
||||
|
if (this.artist != null) { |
||||
|
this.artist.draw(g); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
} |
@ -0,0 +1,76 @@ |
|||||
|
package gameobjects; |
||||
|
|
||||
|
import java.awt.Color; |
||||
|
import java.io.File; |
||||
|
import collider.RectCollider; |
||||
|
import playground.Playground; |
||||
|
import playground.SpaceInvadersLevel; |
||||
|
import rendering.RectArtist; |
||||
|
|
||||
|
/** |
||||
|
* A rectangle object. <br> |
||||
|
* If {@link #generateColliders()} is called, it generates a RectCollider with id-prefix |
||||
|
* "shotcollider_" and registers it for this RectObject. |
||||
|
* |
||||
|
*/ |
||||
|
public class RectObject extends GameObject { |
||||
|
|
||||
|
/** width in pixels of the RectObject (> 0) */ |
||||
|
protected double width; |
||||
|
/** height in pixels of the RectObject (> 0) */ |
||||
|
protected double height; |
||||
|
|
||||
|
/** |
||||
|
* Initializes the RectObject with a suitable RectArtist for drawing the RectObject. |
||||
|
* |
||||
|
* @param id String unique name to be used. |
||||
|
* @param pg {@link Playground} instance this RectObject belongs to (the level it belongs to). |
||||
|
* @param x position in horizontal direction in pixels (zero or positive number). |
||||
|
* @param y position in vertical direction in pixels (zero or positive number). |
||||
|
* @param vx speed/velocity in horizontal direction in pixels (negative, zero or positive number). |
||||
|
* @param vy speed/velocity in vertical direction in pixels (negative, zero or positive number). |
||||
|
* @param width in pixels |
||||
|
* @param height in pixels |
||||
|
* @param color solid color for the whole object, used to initialize an instance of |
||||
|
* {@link rendering.RectArtist} used for this RectObject. |
||||
|
*/ |
||||
|
public RectObject(String id, Playground pg, double x, double y, double vx, double vy, |
||||
|
double width, double height, Color color) { |
||||
|
super(id, pg, x, y, vx, vy); |
||||
|
|
||||
|
this.width = width; |
||||
|
this.height = height; |
||||
|
|
||||
|
this.artist = new RectArtist(this, width, height, color); |
||||
|
|
||||
|
} |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* generates a new {@link RectCollider} with id-prefix "shotcollider_" and registers it for 'this' |
||||
|
* [@link RectObject}. The {@link RectCollider} uses the same dimensions ({@link #width} and {@link #height}) as this RectObject. |
||||
|
* |
||||
|
* @return this RectObject itself |
||||
|
*/ |
||||
|
public RectObject generateColliders() { |
||||
|
this.scol.add(new RectCollider("shotcollider_" + id, this, this.width, this.height)); |
||||
|
return this; |
||||
|
} |
||||
|
|
||||
|
/** Getter for the width |
||||
|
* |
||||
|
* @return double width value as set by constructor |
||||
|
*/ |
||||
|
public double getWidth() { |
||||
|
return this.width; |
||||
|
} |
||||
|
|
||||
|
/** Getter for the height |
||||
|
* |
||||
|
* @return double height value as set by constructor |
||||
|
*/ |
||||
|
public double getHeight() { |
||||
|
return this.height; |
||||
|
} |
||||
|
|
||||
|
} |
@ -0,0 +1,70 @@ |
|||||
|
package gameobjects; |
||||
|
|
||||
|
import java.awt.Color; |
||||
|
import java.awt.Font; |
||||
|
import java.awt.Graphics2D; |
||||
|
import java.awt.font.FontRenderContext; |
||||
|
import java.awt.font.TextAttribute; |
||||
|
import java.text.AttributedString; |
||||
|
import java.util.LinkedList; |
||||
|
import collider.*; |
||||
|
import controller.ObjectController; |
||||
|
import playground.Playground; |
||||
|
import rendering.*; |
||||
|
|
||||
|
/** |
||||
|
* Convenience Class subclassing {@link GameObject}, directly instanciating {@link TextArtist} a |
||||
|
* subclass of {@link Artist} that draws a text. The controller is left undefined, the collider as |
||||
|
* well. However, a single call to the overwritten method {@link #generateColliders} will in fact |
||||
|
* generate a {@link RectCollider} of just the right size for the text. |
||||
|
* |
||||
|
*/ |
||||
|
public class TextObject extends GameObject { |
||||
|
|
||||
|
private String text = null; |
||||
|
protected double rx, ry; |
||||
|
|
||||
|
public String getText() { |
||||
|
return this.text; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Constructor. |
||||
|
* |
||||
|
* @param id object name |
||||
|
* @param playground containing {@link Playground} instance |
||||
|
* @param x positionx |
||||
|
* @param y positiony |
||||
|
* @param vx speedx |
||||
|
* @param vy speedy |
||||
|
* @param size font size in Pixel |
||||
|
* @param text String to be displayed |
||||
|
* @param textColor text color, see java.awt.Color |
||||
|
*/ |
||||
|
public TextObject(String id, Playground playground, double x, double y, double vx, double vy, |
||||
|
String text, int size, Color textColor) { |
||||
|
super(id, playground, x, y, vx, vy); |
||||
|
|
||||
|
this.artist = new TextArtist(this, text, size, textColor); |
||||
|
|
||||
|
this.setColliders(new LinkedList<Collider>()); |
||||
|
|
||||
|
} |
||||
|
|
||||
|
|
||||
|
public void setText(String s) { |
||||
|
this.text = s; |
||||
|
((TextArtist) this.artist).setText(s); |
||||
|
} |
||||
|
|
||||
|
public TextObject generateColliders() { |
||||
|
// we need to Cast to TextArtist as we want to access Width and Height of text |
||||
|
TextArtist kruecke = (TextArtist) (this.artist); |
||||
|
|
||||
|
this.scol.clear(); |
||||
|
this.scol.add(new RectCollider("rect", this, kruecke.getTextWidth(), kruecke.getTextHeight())); |
||||
|
return this; |
||||
|
} |
||||
|
|
||||
|
|
||||
|
} |
@ -0,0 +1,30 @@ |
|||||
|
<?xml version="1.0" encoding="UTF-8"?> |
||||
|
|
||||
|
<configuration status="OFF"> |
||||
|
<appenders> |
||||
|
|
||||
|
<Console name="Console" target="SYSTEM_OUT"> |
||||
|
<PatternLayout pattern="%d %-5level %logger{36} - %msg%n" /> |
||||
|
</Console> |
||||
|
|
||||
|
<File name="File" fileName="log\log4j.log"> |
||||
|
<PatternLayout pattern="%d %-5level %logger{36} - %msg%n" /> |
||||
|
</File> |
||||
|
|
||||
|
</appenders> |
||||
|
|
||||
|
<loggers> |
||||
|
|
||||
|
<root level="warn"> |
||||
|
<appender-ref ref="Console" /> |
||||
|
<appender-ref ref="File" /> |
||||
|
</root> |
||||
|
|
||||
|
<Logger name="base.GameLoop" level="info"> |
||||
|
</Logger> |
||||
|
|
||||
|
<Logger name="playground" level="info"> |
||||
|
</Logger> |
||||
|
|
||||
|
</loggers> |
||||
|
</configuration> |
@ -0,0 +1,84 @@ |
|||||
|
package playground; |
||||
|
|
||||
|
|
||||
|
import java.awt.image.BufferedImage; |
||||
|
|
||||
|
import javax.imageio.ImageIO; |
||||
|
import java.io.File; |
||||
|
import java.io.*; |
||||
|
import java.io.FileNotFoundException; |
||||
|
import java.util.LinkedList; |
||||
|
import java.util.Locale; |
||||
|
import java.util.Scanner; |
||||
|
import java.nio.file.Path; |
||||
|
import java.nio.file.Paths; |
||||
|
|
||||
|
import org.apache.logging.log4j.Logger; |
||||
|
import org.apache.logging.log4j.LogManager; |
||||
|
|
||||
|
public class Animation { |
||||
|
|
||||
|
public LinkedList<String> fileList = null; |
||||
|
public LinkedList<Double> showtimeList = null; |
||||
|
public LinkedList<BufferedImage> imageList = null; |
||||
|
|
||||
|
private static Logger logger = LogManager.getLogger(Animation.class); |
||||
|
|
||||
|
public Animation(String datName) { |
||||
|
|
||||
|
Scanner scanner; |
||||
|
this.fileList = new LinkedList<String>(); |
||||
|
this.showtimeList = new LinkedList<Double>(); |
||||
|
this.imageList = new LinkedList<BufferedImage>(); |
||||
|
|
||||
|
try { |
||||
|
scanner = new Scanner(new File(datName), "UTF-8"); |
||||
|
|
||||
|
scanner.useLocale(Locale.GERMANY); |
||||
|
|
||||
|
String zeile; |
||||
|
double zeit; |
||||
|
int it = 0; |
||||
|
|
||||
|
while (scanner.hasNext()) { |
||||
|
if (scanner.hasNextDouble()) { |
||||
|
zeit = scanner.nextDouble(); |
||||
|
showtimeList.add(zeit); |
||||
|
} else { |
||||
|
zeile = scanner.next(); |
||||
|
Path basePath = Paths.get(datName); |
||||
|
String file = basePath.getParent().toString() + "/" + zeile; |
||||
|
fileList.add(file); |
||||
|
try { |
||||
|
this.imageList.add(ImageIO.read(new File(file))); |
||||
|
logger.info("img added " + file); |
||||
|
|
||||
|
} catch (IOException e) { |
||||
|
logger.warn(file + " not found!!"); |
||||
|
} |
||||
|
|
||||
|
it++; |
||||
|
logger.trace(basePath.getParent().toString() + "/" + zeile); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
scanner.close(); |
||||
|
|
||||
|
} catch (FileNotFoundException e) { |
||||
|
e.printStackTrace(); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
public LinkedList<String> getFileList() { |
||||
|
return this.fileList; |
||||
|
} |
||||
|
|
||||
|
public LinkedList<Double> getShowtimeList() { |
||||
|
return this.showtimeList; |
||||
|
} |
||||
|
|
||||
|
public LinkedList<BufferedImage> getImageList() { |
||||
|
return this.imageList; |
||||
|
} |
||||
|
|
||||
|
} |
@ -0,0 +1,55 @@ |
|||||
|
package playground; |
||||
|
|
||||
|
import java.io.*; |
||||
|
import java.util.Scanner; |
||||
|
|
||||
|
import org.apache.logging.log4j.Logger; |
||||
|
import org.apache.logging.log4j.LogManager; |
||||
|
|
||||
|
|
||||
|
// Klasse um Highscore umzusetzen |
||||
|
public class HighscoreManager { |
||||
|
Scanner s; |
||||
|
private static Logger logger = LogManager.getLogger(HighscoreManager.class); |
||||
|
|
||||
|
public HighscoreManager() { |
||||
|
try { |
||||
|
File f = new File("./highscore.txt"); |
||||
|
if (!f.exists()) { |
||||
|
logger.warn("WARNING: Highscore file was not found and reset"); |
||||
|
writeHSToFile(0, -1); |
||||
|
} |
||||
|
s = new Scanner(f); |
||||
|
} catch (FileNotFoundException e) { |
||||
|
e.printStackTrace(); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
public int readHSFromFile() { |
||||
|
if (s.hasNext()) { |
||||
|
int highscore = s.nextInt(); |
||||
|
return highscore; |
||||
|
} |
||||
|
return 0; |
||||
|
} |
||||
|
|
||||
|
public static void writeHSToFile(Integer pts, Integer highscore) { |
||||
|
String highscore2 = String.valueOf(pts); |
||||
|
BufferedWriter bw; |
||||
|
try { |
||||
|
if (pts > highscore) { |
||||
|
FileWriter fw = new FileWriter("./highscore.txt"); |
||||
|
bw = new BufferedWriter(fw); |
||||
|
bw.write(highscore2); |
||||
|
bw.close(); |
||||
|
logger.info("Highscore file was opened and saved score: " + highscore2); |
||||
|
} |
||||
|
} catch (IOException e) { |
||||
|
logger.error("File for Highscore not writeable! Score lost."); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
public void closeFile() { |
||||
|
s.close(); |
||||
|
} |
||||
|
} |
Some files were not shown because too many files changed in this diff
Write
Preview
Loading…
Cancel
Save
Reference in new issue