11 Commits

  1. 11
      .project
  2. 67
      ArrayManipulation.java
  3. 4
      GameProject/src/base/GameLoop.java
  4. 23
      GameProject/src/base/MultiLevelGame.java
  5. 9
      GameProject/src/collider/package-info.java
  6. 2
      GameProject/src/controller/ObjectController.java
  7. 18
      GameProject/src/controller/ReboundController.java
  8. 7
      GameProject/src/gameobjects/package-info.java
  9. 31
      GameProject/src/playground/Level5.java
  10. 32
      GameProject/src/playground/Level6.java
  11. 32
      GameProject/src/playground/Level7.java
  12. 9
      GameProject/src/playground/LevelMovingObjects.java
  13. 44
      GameProject/src/playground/LevelWithBox.java
  14. 1
      GameProject/src/playground/Playground.java
  15. 9
      GameProject/src/playground/package-info.java

11
.project

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>prog2-codebase</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
</buildSpec>
<natures>
</natures>
</projectDescription>

67
ArrayManipulation.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)));
}
}

4
GameProject/src/base/GameLoop.java

@ -8,6 +8,8 @@ import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import gameobjects.GameObject;
import playground.Level1;
import playground.LevelMovingObjects;
import playground.LevelWithBox;
import playground.Playground;
import ui.GameUI;
@ -55,7 +57,7 @@ public class GameLoop {
*/
void defineLevels() {
this.resetLevels();
this.addLevel(new Level1());
this.addLevel(new LevelMovingObjects());
}
/**

23
GameProject/src/base/MultiLevelGame.java

@ -0,0 +1,23 @@
package base;
import java.io.IOException;
import playground.Level5;
import playground.LevelMovingObjects;
import playground.LevelWithBox;
public class MultiLevelGame extends GameLoop {
void defineLevels() {
this.addLevel(new LevelMovingObjects());
}
public static void main(String[] args) throws IOException {
GameLoop gl = new GameLoop();
gl.runGame(args);
}
}

9
GameProject/src/collider/package-info.java

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

2
GameProject/src/controller/ObjectController.java

@ -56,7 +56,7 @@ public abstract class ObjectController {
public void applySpeedVector() {
double ts = this.getPlayground().getTimestep();
this.setX(this.getX() + this.getVX() * ts);
gameObject.setY(this.getY() + this.getVY() * ts);
this.setY(this.getY() + this.getVY() * ts);
}

18
GameProject/src/controller/ReboundController.java

@ -0,0 +1,18 @@
package controller;
public class ReboundController extends ObjectController{
@Override
public void updateObject() {
if(this.gameObject.getX() < 30 && this.gameObject.getX() > 670) {
double vx = this.gameObject.getX();
this.gameObject.setVX(vx * -1);
} else if (this.gameObject.getY() < 30 && this.gameObject.getY() > 670) {
double vy = this.gameObject.getX();
this.gameObject.setVX(vy * -1);
}
}
}

7
GameProject/src/gameobjects/package-info.java

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

31
GameProject/src/playground/Level5.java

@ -0,0 +1,31 @@
package playground;
import gameobjects.GameObject;
public class Level5 extends SpaceInvadersLevel{
protected int calcNrEnemies() {
return 5;
}
protected double calcEnemySpeedX() {
return 160;
}
protected double calcEnemySpeedY() {
return 80;
}
protected String getStartupMessage() {
return "Level5, get ready";
}
void actionIfEnemyIsHit(GameObject e, GameObject shot) {
super.actionIfEnemyIsHit(e, shot);
System.out.println("AUA!!");
}
}

32
GameProject/src/playground/Level6.java

@ -0,0 +1,32 @@
package playground;
import gameobjects.GameObject;
public class Level6 extends SpaceInvadersLevel {
protected int calcNrEnemies() {
return 12;
}
protected double calcEnemySpeedX() {
return 480;
}
protected double calcEnemySpeedY() {
return 80;
}
protected String getStartupMessage() {
return "Level6, get ready";
}
void actionIfEnemyIsHit(GameObject e, GameObject shot) {
super.actionIfEnemyIsHit(e, shot);
System.out.println("AUA!!");
}
}

32
GameProject/src/playground/Level7.java

@ -0,0 +1,32 @@
package playground;
import gameobjects.GameObject;
public class Level7 extends SpaceInvadersLevel {
protected int calcNrEnemies() {
return 21;
}
protected double calcEnemySpeedX() {
return 800;
}
protected double calcEnemySpeedY() {
return 140;
}
protected String getStartupMessage() {
return "Level7, get ready";
}
void actionIfEnemyIsHit(GameObject e, GameObject shot) {
super.actionIfEnemyIsHit(e, shot);
System.out.println("AUA!!");
}
}

9
GameProject/src/playground/LevelMovingObjects.java

@ -1,12 +1,19 @@
package playground;
import java.awt.Color;
import gameobjects.RectObject;
/** 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
public void prepareLevel(String id) {
super.prepareLevel(id);
LevelMovingObjects ml = this;
RectObject object2 = new RectObject(id +"Bluebox",ml,300,300,170,70,30,30,Color.BLUE);
this.addObject(object2);
}
/** "Moving Objects Level!" is the message.

44
GameProject/src/playground/LevelWithBox.java

@ -0,0 +1,44 @@
package playground;
import gameobjects.RectObject;
import java.awt.Color;
/**
* The class creates its own level, which contains 2 methods
* and takes methods from the SpaceInvadersLevel class as well as
* from the RectObject class.The graphical content is changed here.
* RectObject initialized with a suitable RectArtist to draw the RectObject.
*
* This class extends from {@link SpaceInvadersLife}.
*/
public class LevelWithBox extends SpaceInvadersLevel {
/**
*
* PrepareLevel
* First sets up the layer and calls it every time it starts.
* An object with transmitted parameters from RectObject is created.
* addObject Method from the {@link Playground} class adds the graphics object to a level.
* @param id - String unique name to be used.
*/
public void prepareLevel(String id) {
super.prepareLevel(id);
LevelWithBox myLevel = this;
RectObject Object = new RectObject(id,myLevel,350,100,0,0,700,250,Color.RED);
this.addObject(Object);
}
/**
* Returns the text that should be displayed at the beginning of the game.
*
* @return a string that is displayed at the beginning. It should be not longer than 30 characters.
*/
protected String getStartupMessage() {
return "Box-Level!";
}
}

1
GameProject/src/playground/Playground.java

@ -76,7 +76,6 @@ public abstract class Playground {
/**
* Adds a graphics object to a level.
*
* @param o GameObject The object to be added
*/
public void addObjectNow(GameObject o) {
gameObjects.put(o.getId(), o);

9
GameProject/src/playground/package-info.java

@ -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;
Loading…
Cancel
Save