diff --git a/.gitignore b/.gitignore index 4bcee59..365a5ae 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ -/.metadata/ +*.DS_Store +*.metadata/ *.class /GameProject/doc/ /GameProject/log/ diff --git a/GameProject/.classpath b/GameProject/.classpath index a32988c..9c1fe8d 100644 --- a/GameProject/.classpath +++ b/GameProject/.classpath @@ -1,8 +1,11 @@ - - + + + + + diff --git a/GameProject/src/base/GameLoop.java b/GameProject/src/base/GameLoop.java index eb72c12..f98bd42 100644 --- a/GameProject/src/base/GameLoop.java +++ b/GameProject/src/base/GameLoop.java @@ -217,8 +217,8 @@ public class GameLoop { /** - * 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}. + * main to start the whole application. It calls. {@link #runGame(String[])}. + * (levels are automatically added/loaded by 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. diff --git a/GameProject/src/controller/CollisionAwareEgoController.java b/GameProject/src/controller/CollisionAwareEgoController.java index 12ccf29..e223487 100644 --- a/GameProject/src/controller/CollisionAwareEgoController.java +++ b/GameProject/src/controller/CollisionAwareEgoController.java @@ -37,6 +37,9 @@ public class CollisionAwareEgoController extends EgoController { this.shot = soundOnShot; } + /** + * Copies current values of x,y position and speed vx,vy into attributes. These can be restored by call to {@link #restoreDynamicState()}. + */ public void saveDynamicState() { this.savex = this.getX(); this.savey = this.getY(); @@ -45,6 +48,10 @@ public class CollisionAwareEgoController extends EgoController { } + /** + * Restores formally saved values of x,y position and speed vx,vy from attributes back to the ego object. + * These values should have been stored before by a call to {@link #saveDynamicState()}, otherwise all values will be 0.00. + */ public void restoreDynamicState() { this.setX(savex); this.setY(savey); @@ -53,6 +60,10 @@ public class CollisionAwareEgoController extends EgoController { } + /** + * extends parent class implementation by a check whether or not the ego object collides with any other "obstacle" object. + * If yes, the position stays fixed (by using {@link #saveDynamicState()} and {@link #restoreDynamicState()}. + */ public boolean stopObject() { boolean s = super.stopObject(); @@ -73,6 +84,9 @@ public class CollisionAwareEgoController extends EgoController { return s; } + /** + * calls superclass {@link EgoController#onSpace(KeyEvent, GameObject)} only, if the time elapsed since last pressing of space is above 0.1 ms. + */ public void onSpace(KeyEvent e, GameObject ego) { double cgt = ego.getGameTime(); if ((cgt - this.lastSpaceAt) > 0.1) { diff --git a/GameProject/src/controller/EgoController.java b/GameProject/src/controller/EgoController.java index 85f7a16..45890b5 100644 --- a/GameProject/src/controller/EgoController.java +++ b/GameProject/src/controller/EgoController.java @@ -42,26 +42,51 @@ public class EgoController extends ObjectController { } + /** + * moves ego up by {@link SpaceInvadersLevel#EGOSPEED}. + * @param kc KeyEvent to process (ignored) + * @param ego the ego object + */ public void onUp(KeyEvent kc, GameObject ego) { ego.setVX(0.0); ego.setVY(-SpaceInvadersLevel.EGOSPEED); } + /** + * moves ego down by {@link SpaceInvadersLevel#EGOSPEED}. + * @param kc KeyEvent to process (ignored) + * @param ego the ego object + */ public void onDown(KeyEvent kc, GameObject ego) { ego.setVX(0.0); ego.setVY(SpaceInvadersLevel.EGOSPEED); } + /** + * moves ego left by {@link SpaceInvadersLevel#EGOSPEED}. + * @param kc KeyEvent to process (ignored) + * @param ego the ego object + */ public void onLeft(KeyEvent kc, GameObject ego) { ego.setVY(0.0); ego.setVX(-SpaceInvadersLevel.EGOSPEED); } + /** + * moves ego right by {@link SpaceInvadersLevel#EGOSPEED}. + * @param kc KeyEvent to process (ignored) + * @param ego the ego object + */ public void onRight(KeyEvent kc, GameObject ego) { ego.setVY(0.0); ego.setVX(SpaceInvadersLevel.EGOSPEED); } + /** + * sets speed to 0.0 + * @param kc KeyEvent to process (ignored) + * @param ego the ego object + */ public void onStop(KeyEvent kc, GameObject ego) { ego.setVY(0.0); ego.setVX(0.0); @@ -72,7 +97,7 @@ public class EgoController extends ObjectController { /** 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 + * @return true if the object reached the boundaries of the level, false otherwise. */ public boolean stopObject() { // check whether ego object is at level boundaries @@ -93,7 +118,7 @@ public class EgoController extends ObjectController { } - /** behavior for shooting on key space + /** behavior for shooting on key space. Creates a new shot using {#link SimpleShotController} with a {@link RectObject}. * * @param e KeyEvent of the space key * @param ego EgoObject instance (used to determine position of shot object's start) @@ -119,7 +144,7 @@ public class EgoController extends ObjectController { /** - * updates position based on key events (mouse currently ignored) + * updates position based on key events (mouse currently ignored). */ public void updateObject() { @@ -141,9 +166,9 @@ public class EgoController extends ObjectController { } /** - * Generelle Idee: Wenn eine Taste gedrückt wird wird sie gespeichert. wenn die zuvor + * 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 + * 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! */ @@ -154,8 +179,8 @@ public class EgoController extends ObjectController { } /** - * 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 + * 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) { diff --git a/GameProject/src/log4j2.xml b/GameProject/src/log4j2.xml index 87ecf74..21a7607 100644 --- a/GameProject/src/log4j2.xml +++ b/GameProject/src/log4j2.xml @@ -7,7 +7,7 @@ - + diff --git a/GameProject/src/playground/Level2.java b/GameProject/src/playground/Level2.java index e553575..be0a998 100644 --- a/GameProject/src/playground/Level2.java +++ b/GameProject/src/playground/Level2.java @@ -3,7 +3,7 @@ package playground; /** - * extends extends {@link SpaceInvadersLevel} with a different startup message. + * extends {@link SpaceInvadersLevel} with a different startup message. */ public class Level2 extends SpaceInvadersLevel { diff --git a/GameProject/src/playground/Level4.java b/GameProject/src/playground/Level4.java index cfb39b3..d2bac0b 100644 --- a/GameProject/src/playground/Level4.java +++ b/GameProject/src/playground/Level4.java @@ -10,7 +10,7 @@ import org.apache.logging.log4j.Logger; /** - * extends extends {@link SpaceInvadersLevel} + * extends {@link SpaceInvadersLevel} *
    *
  • Hit aliens twice to kill them *
  • they say AUA when not destroyed diff --git a/GameProject/src/playground/SpaceInvadersLevelTest.java b/GameProject/src/playground/SpaceInvadersLevelTest.java deleted file mode 100644 index 145028e..0000000 --- a/GameProject/src/playground/SpaceInvadersLevelTest.java +++ /dev/null @@ -1,81 +0,0 @@ -package playground; - -import static org.junit.Assert.assertTrue; -import java.awt.Color; -import org.junit.jupiter.api.AfterAll; -import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.Test; -import gameobjects.EgoObject; -import gameobjects.GameObject; -import gameobjects.RectObject; - -/** - * Tests {@link SpaceInvadersLevel} for - *
      - *
    1. calcEnemySpeedX() returns the same value as constant SpaceInvadersLevel.ENEMYSPEEDX - *
    2. calcEnemySpeedY() returns the same value as constant SpaceInvadersLevel.ENEMYSPEEDY - *
    3. calcNrEnemies() returns the same value as constant SpaceInvadersLevel.NR_ENEMIES - *
    4. actionIfEnemyIsHit() adds 200 points to score - *
    5. actionIfEgoObjectIsHit() reduces number of lives (egoLives) - *
    - * @author jkonert - * - */ -class SpaceInvadersLevelTest { - - private static SpaceInvadersLevel myLevel; - - @BeforeAll - static void setUpBeforeClass() throws Exception { - myLevel = new SpaceInvadersLevel(); - SpaceInvadersLevel.setGlobalFlag("egoLives", 5); - SpaceInvadersLevel.setGlobalFlag("points", 500); - SpaceInvadersLevel.setGlobalFlag("highscore", 5000); - } - - @AfterAll - static void tearDownAfterClass() throws Exception { - // nothing - } - - @Test - void testCalcEnemySpeedX() { - assertTrue("EnemySpeedX is as in SpaceInvadersLevel defined", myLevel.calcEnemySpeedX() == SpaceInvadersLevel.ENEMYSPEEDX); - } - - @Test - void testCalcEnemySpeedY() { - assertTrue("EnemySpeedY is as in SpaceInvadersLevel defined", myLevel.calcEnemySpeedY() == SpaceInvadersLevel.ENEMYSPEEDY); - } - - @Test - void testCalcNrEnemies() { - assertTrue("NrOfEnemies is as in SpaceInvadersLevel defined", myLevel.calcNrEnemies() == SpaceInvadersLevel.NR_ENEMIES); - } - - - @Test - void testActionIfEnemyIsHitPointsUp() { - Integer numPointsBefore = (Integer)Playground.getGlobalFlag("points"); - GameObject dummyShot = new RectObject("shot1", myLevel, 0,0,0,0, 12, 12, Color.WHITE); - GameObject dummyEnemy = new RectObject("ego1", myLevel, 0,0,0,0, 12, 12, Color.BLACK); - myLevel.addObject(dummyShot); - myLevel.addObject(dummyEnemy); - myLevel.actionIfEnemyIsHit(dummyEnemy, dummyShot);; // this is the call under test - Integer numPointsAfter = (Integer)Playground.getGlobalFlag("points"); // changed? - assertTrue("numPoints is up +200 after EnemyIsHit", numPointsAfter == numPointsBefore + 200); // points are set +200 , check. - } - - @Test - void testActionIfEgoObjectIsHitLivesDown() { - Integer numLivesBefore = (Integer)Playground.getGlobalFlag("egoLives"); - GameObject dummyShot = new RectObject("shot1", myLevel, 0,0,0,0, 12, 12, Color.RED); - GameObject dummyEgo = new EgoObject("ego1", myLevel, 0,0,0,0, 5); - myLevel.addObject(dummyShot); - myLevel.actionIfEgoObjectIsHit(dummyShot, dummyEgo); // this is the call under test - Integer numLivesAfter = (Integer)Playground.getGlobalFlag("egoLives"); // changed? - assertTrue("numLives is reduced by one ifEgoIsHit", numLivesAfter == numLivesBefore - 1); // lives is reduced by one - - } - -} diff --git a/GameProject/video/alexG.jpg b/GameProject/video/alexG.jpg deleted file mode 100644 index bc03a8c..0000000 Binary files a/GameProject/video/alexG.jpg and /dev/null differ