10 Commits

  1. 29
      .gitignore
  2. 7
      GameProject/.classpath
  3. 4
      GameProject/src/base/GameLoop.java
  4. 15
      GameProject/src/base/MultiLevelGame.java
  5. 14
      GameProject/src/controller/CollisionAwareEgoController.java
  6. 39
      GameProject/src/controller/EgoController.java
  7. 2
      GameProject/src/log4j2.xml
  8. 2
      GameProject/src/playground/Level2.java
  9. 2
      GameProject/src/playground/Level4.java
  10. 30
      GameProject/src/playground/LevelWithBox.java
  11. 3
      GameProject/src/playground/Playground.java
  12. 81
      GameProject/src/playground/SpaceInvadersLevelTest.java
  13. BIN
      GameProject/video/alexG.jpg

29
.gitignore

@ -1,3 +1,6 @@
<<<<<<< HEAD
*.DS_Store
=======
# General
.DS_Store
.AppleDouble
@ -26,7 +29,7 @@ Network Trash Folder
Temporary Items
.apdisk
.metadata
*.metadata
bin/
tmp/
*.tmp
@ -87,6 +90,7 @@ local.properties
# Typically, this file would be tracked if it contains build/dependency configurations:
#.project
>>>>>>> 28280ec94efca9a2a06808ca8279c3bace4835de
*.metadata/
*.class
/GameProject/doc/
@ -94,26 +98,5 @@ local.properties
/GameProject/log\\log4j.log
/GameProject/highscore.txt
/GameProject/bin/
.metadata/.log
.metadata/.plugins/org.eclipse.e4.workbench/workbench.xmi
.metadata/version.ini
.metadata/.plugins/org.eclipse.core.resources/.projects/.org.eclipse.egit.core.cmp/.markers.snap
.metadata/.plugins/org.eclipse.core.resources/.projects/.org.eclipse.egit.core.cmp/.syncinfo.snap
.metadata/.plugins/org.eclipse.core.resources/.projects/GameProject/.markers.snap
.metadata/.plugins/org.eclipse.core.resources/.projects/GameProject/.syncinfo.snap
.metadata/.plugins/org.eclipse.core.resources/.root/.markers.snap
.metadata/.plugins/org.eclipse.core.resources/.safetable/org.eclipse.core.resources
.metadata/.plugins/org.eclipse.core.resources/4.snap
.metadata/.plugins/org.eclipse.e4.workbench/workbench.xmi
.metadata/.log
.metadata/.plugins/org.eclipse.e4.workbench/workbench.xmi
GameProject/log\log4j.log
.metadata/.plugins/org.eclipse.core.resources/4.snap
.metadata/.plugins/org.eclipse.core.resources/.safetable/org.eclipse.core.resources
.metadata/.plugins/org.eclipse.core.resources/.root/.markers.snap
.metadata/.plugins/org.eclipse.core.resources/.projects/GameProject/.syncinfo.snap
.metadata/.plugins/org.eclipse.core.resources/.projects/GameProject/.syncinfo.snap
.metadata/.plugins/org.eclipse.core.resources/.projects/GameProject/.markers.snap
.metadata/.plugins/org.eclipse.core.resources/.projects/.org.eclipse.egit.core.cmp/.syncinfo.snap
.metadata/.plugins/org.eclipse.core.resources/.projects/.org.eclipse.egit.core.cmp/.markers.snap

7
GameProject/.classpath

@ -1,8 +1,11 @@
<?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="con" path="org.eclipse.jdt.launching.JRE_CONTAINER">
<attributes>
<attribute name="module" value="true"/>
</attributes>
</classpathentry>
<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"/>

4
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.

15
GameProject/src/base/MultiLevelGame.java

@ -2,13 +2,7 @@ package base;
import java.io.IOException;
import playground.Level1;
import playground.Level3;
import playground.Level5;
import playground.Level6;
import playground.Level7;
import playground.LevelBoss;
import playground.LevelHitTwice;
import playground.*;
public class MultiLevelGame extends GameLoop {
@ -27,9 +21,10 @@ public class MultiLevelGame extends GameLoop {
//this.addLevel(new Level3());
//this.addLevel(new LevelBoss());
this.addLevel(new Level5());
this.addLevel(new Level6());
this.addLevel(new Level7());
//this.addLevel(new Level5());
//this.addLevel(new Level6());
//this.addLevel(new Level7());
this.addLevel(new LevelWithBox());
}

14
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) {

39
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) {

2
GameProject/src/log4j2.xml

@ -7,7 +7,7 @@
<PatternLayout pattern="%d %-5level %logger{36} - %msg%n" />
</Console>
<File name="File" fileName="log\log4j.log">
<File name="File" fileName="log/log4j.log">
<PatternLayout pattern="%d %-5level %logger{36} - %msg%n" />
</File>

2
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 {

2
GameProject/src/playground/Level4.java

@ -10,7 +10,7 @@ import org.apache.logging.log4j.Logger;
/**
* extends extends {@link SpaceInvadersLevel}
* extends {@link SpaceInvadersLevel}
* <ul>
* <li>Hit aliens twice to kill them
* <li>they say AUA when not destroyed

30
GameProject/src/playground/LevelWithBox.java

@ -0,0 +1,30 @@
package playground;
import java.awt.Color;
import gameobjects.*;
/** This class adds a new level to the game.
*
* @author team22
*/
public class LevelWithBox extends SpaceInvadersLevel {
/** This method overrides the initial method and adds a red rectangle on the top which does not do anything.
*
* @param id String identifies level
*/
@Override
public void prepareLevel(String id) {
super.prepareLevel(id);
RectObject rectangle = new RectObject("rectangle", this, 350, 100, 0, 0, 700, 250, Color.RED);
addObject(rectangle);
}
/** This method overrides the initial method to change the startup message.
*
* @return String Startup message
*/
@Override
protected String getStartupMessage() {
return "Box-Level!";
}
}

3
GameProject/src/playground/Playground.java

@ -83,6 +83,7 @@ public abstract class Playground {
}
/**
* Puts objects with a certain substring in their name into a LinkedLisrt and returns them.
*
@ -111,6 +112,7 @@ public abstract class Playground {
};
/**
* Removes a graphics object from a level.
*
@ -275,7 +277,6 @@ public abstract class Playground {
return this.mouseEvents;
}
/**
* Method meant to be filled with own code, handles the entore game logic (collision checks, timed
* events, ...).

81
GameProject/src/playground/SpaceInvadersLevelTest.java

@ -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
* <ol>
* <li>calcEnemySpeedX() returns the same value as constant SpaceInvadersLevel.ENEMYSPEEDX
* <li>calcEnemySpeedY() returns the same value as constant SpaceInvadersLevel.ENEMYSPEEDY
* <li>calcNrEnemies() returns the same value as constant SpaceInvadersLevel.NR_ENEMIES
* <li>actionIfEnemyIsHit() adds 200 points to score
* <li>actionIfEgoObjectIsHit() reduces number of lives (egoLives)
* </ol>
* @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
}
}

BIN
GameProject/video/alexG.jpg

Before

Width: 1664  |  Height: 2496  |  Size: 181 KiB

Loading…
Cancel
Save