Browse Source

finished HA09

main
Nico B 2 years ago
parent
commit
83c29d5fc1
  1. 8
      GameProject/src/base/BreakoutGame.java
  2. 48
      GameProject/src/playground/BreakoutLevel3.java

8
GameProject/src/base/BreakoutGame.java

@ -19,12 +19,12 @@ public class BreakoutGame extends GameLoop {
@Override @Override
public void defineLevels() { public void defineLevels() {
this.resetLevels(); // removes Level1 added by superclass constructor this.resetLevels(); // removes Level1 added by superclass constructor
<<<<<<< HEAD
//this.addLevel(new BreakoutLevel1()); // FIXME add this as soon as your level exists //this.addLevel(new BreakoutLevel1()); // FIXME add this as soon as your level exists
this.addLevel(new BreakoutLevel2());
=======
//this.addLevel(new BreakoutLevel2());
this.addLevel(new BreakoutLevel3()); // sorry for the git conflict this may cause! this.addLevel(new BreakoutLevel3()); // sorry for the git conflict this may cause!
>>>>>>> aa2436e4a45e3ac1bb4b8beb537007ae3887598e
} }
/** /**

48
GameProject/src/playground/BreakoutLevel3.java

@ -1,10 +1,56 @@
package playground; package playground;
import java.awt.Color;
import gameobjects.GameObject;
import gameobjects.TextObject;
public class BreakoutLevel3 extends BreakoutLevel0 { public class BreakoutLevel3 extends BreakoutLevel0 {
TextObject pointsText = new TextObject("pointsText", this, 50, 10, 0.,0, "0", 20, Color.BLACK);
TextObject livesText = new TextObject("livesText", this, 600,10,0,0,"3", 20, Color.GREEN);
// your code here
@Override
public void prepareLevel(String id) {
setLevelFlag("points", 0);
TextObject score = pointsText;
this.addObject(score);
setGlobalFlag("lives", 3);
TextObject lives = livesText;
this.addObject(lives);
super.prepareLevel(id);
}
@Override
protected void actionIfBallHitsBrick(GameObject ball, GameObject brick) {
super.actionIfBallHitsBrick(ball, brick);
int value = (int) getLevelFlag("points");
setLevelFlag("points", value + 10);
pointsText.setText("" + getLevelFlag("points"));
}
@Override
public void applyGameLogic (){
super.applyGameLogic();
int value = (int) getGlobalFlag("lives");
if(this.ball.getY() > this.ego.getY()) {
setGlobalFlag("lives", --value);
livesText.setText("" + value);
this.ball.setY(this.ego.getY() - 20);
this.ball.setX(this.ego.getX());
}
}
@Override
public boolean gameOver() {
int value = (int) getGlobalFlag("lives");
if (value <0) {
return true;
}
return false;
}
} }

Loading…
Cancel
Save