fdai7303
3 years ago
32 changed files with 152 additions and 159 deletions
-
4.gitignore
-
7GameProject/.classpath
-
4GameProject/src/base/GameLoop.java
-
33GameProject/src/base/MovingObjectsGame.java
-
9GameProject/src/collider/CircleCollider.java
-
2GameProject/src/collider/Collider.java
-
5GameProject/src/collider/RectCollider.java
-
9GameProject/src/collider/package-info.java
-
14GameProject/src/controller/CollisionAwareEgoController.java
-
46GameProject/src/controller/EgoController.java
-
5GameProject/src/controller/EnemyController.java
-
1GameProject/src/controller/MineController.java
-
2GameProject/src/controller/ObjectController.java
-
2GameProject/src/gameobjects/AnimatedGameobject.java
-
8GameProject/src/gameobjects/EgoObject.java
-
4GameProject/src/gameobjects/FallingStar.java
-
2GameProject/src/gameobjects/RectObject.java
-
6GameProject/src/gameobjects/TextObject.java
-
7GameProject/src/gameobjects/package-info.java
-
2GameProject/src/log4j2.xml
-
2GameProject/src/playground/Animation.java
-
2GameProject/src/playground/Level2.java
-
4GameProject/src/playground/Level4.java
-
5GameProject/src/playground/LevelHitTwice.java
-
21GameProject/src/playground/LevelMovingObjects.java
-
3GameProject/src/playground/SpaceInvadersLevel.java
-
81GameProject/src/playground/SpaceInvadersLevelTest.java
-
9GameProject/src/playground/package-info.java
-
2GameProject/src/rendering/RectArtist.java
-
9GameProject/src/rendering/TextArtist.java
-
1GameProject/src/ui/GameUI.java
-
BINGameProject/video/alexG.jpg
@ -0,0 +1,33 @@ |
|||
package base; |
|||
|
|||
import java.io.IOException; |
|||
import playground.LevelMovingObjects; |
|||
|
|||
/** |
|||
* main class to start a game with only one level {@link playground.LevelMovingObjects}. |
|||
* |
|||
*/ |
|||
public class MovingObjectsGame extends GameLoop { |
|||
|
|||
/** |
|||
* starts this game. |
|||
* |
|||
* @param args command line parameters (forwarded to {@link GameLoop#runGame(String[])}). |
|||
* @throws IOException if highscore.txt file cannot be written or accessed, the exception is |
|||
* thrown (and game ends). |
|||
*/ |
|||
public static void main(String[] args) throws IOException { |
|||
GameLoop myGame = new MovingObjectsGame(); |
|||
myGame.runGame(args); |
|||
} |
|||
|
|||
/** |
|||
* adds only one level to play ({@link playground.LevelMovingObjects}). |
|||
*/ |
|||
@Override |
|||
public void defineLevels() { |
|||
this.resetLevels(); |
|||
this.addLevel(new LevelMovingObjects()); |
|||
} |
|||
|
|||
} |
@ -0,0 +1,9 @@ |
|||
/** |
|||
* The package contains classes implementing a 'bounding box' area around game objects. <br> |
|||
* The abstract base class {@link Collider} provides the abstract method {@link Collider#collidesWith(Collider)}, |
|||
* which needs to be implemented by child classes to detect and decide whether or not an object with such instance really collides with the other. |
|||
* {@link Collider} instances are to be used for game objects ({@link gameobjects}); see constructors.<br> |
|||
* |
|||
* The benefit of seperating Colliders from visual representations is that the area for collisions can be smaller/bigger/other shape to improve game play experience. |
|||
*/ |
|||
package collider; |
@ -0,0 +1,7 @@ |
|||
/** |
|||
* The package gameobjects contains all objects with a visual representation on screen. |
|||
* They can be combined to use controller instances for their behavior (subclasses of {@link controller.ObjectController}). |
|||
* The abstract base class is {@link GameObject}, which forces child-classes to implement the method |
|||
* {@link GameObject#updateObject()}. |
|||
*/ |
|||
package gameobjects; |
@ -0,0 +1,21 @@ |
|||
package playground; |
|||
|
|||
|
|||
|
|||
/** This level adds two distracting objects to the canvas that cannot collide but bounce around all the time. |
|||
*/ |
|||
public class LevelMovingObjects extends SpaceInvadersLevel { |
|||
|
|||
// TODO your code here |
|||
|
|||
|
|||
/** "Moving Objects Level!" is the message. |
|||
* |
|||
* @return String "Moving Objects Level!" |
|||
*/ |
|||
@Override |
|||
protected String getStartupMessage() { |
|||
return "Moving Objects Level!"; |
|||
} |
|||
} |
|||
|
@ -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)myLevel.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)myLevel.getGlobalFlag("points"); // changed? |
|||
assertTrue("numPoints is up +200 after EnemyIsHit", numPointsAfter == numPointsBefore + 200); // points are set +200 , check. |
|||
} |
|||
|
|||
@Test |
|||
void testActionIfEgoObjectIsHitLivesDown() { |
|||
Integer numLivesBefore = (Integer)myLevel.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)myLevel.getGlobalFlag("egoLives"); // changed? |
|||
assertTrue("numLives is reduced by one ifEgoIsHit", numLivesAfter == numLivesBefore - 1); // lives is reduced by one |
|||
|
|||
} |
|||
|
|||
} |
@ -0,0 +1,9 @@ |
|||
/** |
|||
* The package playground contains all level specific logic and control of level logic. |
|||
* The structure and general logic (with global and local flags to be stored/used) |
|||
* is provided in abstract base class {@link Playground}.<br> |
|||
* Child-classes implement specific logic for one level and game type (e.g. {@link SpaceInvadersLevel}).<b> |
|||
* |
|||
* Generally, the base class {@link Playground} supports totally different game types to be implemented. |
|||
*/ |
|||
package playground; |
Before Width: 1664 | Height: 2496 | Size: 181 KiB |
Write
Preview
Loading…
Cancel
Save
Reference in new issue