|
|
@ -1,11 +1,57 @@ |
|
|
|
package playground; |
|
|
|
|
|
|
|
import java.awt.Color; |
|
|
|
import java.util.HashMap; |
|
|
|
import java.util.LinkedList; |
|
|
|
import gameobjects.TextObject; |
|
|
|
|
|
|
|
import gameobjects.GameObject; |
|
|
|
|
|
|
|
public class BreakoutLevel3 extends BreakoutLevel0 { |
|
|
|
gameobjects.TextObject showPoints = new gameobjects.TextObject("showPoints", this, 50, 10, 0, 0, "0", 20, Color.BLACK); |
|
|
|
gameobjects.TextObject showLives = new gameobjects.TextObject("showLives", this, 600, 10, 0, 0, "3", 20, Color.GREEN); |
|
|
|
|
|
|
|
// your code here |
|
|
|
|
|
|
|
//protected static HashMap<String, Object> flags = new HashMap<String, Object>(); |
|
|
|
//LinkedList<GameObject> addables = new LinkedList<GameObject>(); |
|
|
|
|
|
|
|
@Override |
|
|
|
protected void actionIfBallHitsBrick(GameObject ball, GameObject brick) { |
|
|
|
super.actionIfBallHitsBrick(ball, brick); |
|
|
|
|
|
|
|
this.setLevelFlag("points", (Integer)this.getLevelFlag("points") + 10); |
|
|
|
showPoints.setText(String.valueOf((Integer)this.getLevelFlag("points"))); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void applyGameLogic() { |
|
|
|
super.applyGameLogic(); |
|
|
|
|
|
|
|
if (ball.getY() > ego.getY()) { |
|
|
|
this.setLevelFlag("lives", (Integer)this.getLevelFlag("lives") - 1); |
|
|
|
showLives.setText(String.valueOf((Integer)this.getLevelFlag("lives"))); |
|
|
|
ball.setY(ego.getY() - 20); |
|
|
|
ball.setX(ego.getX()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public boolean gameOver() { |
|
|
|
if( (Integer)this.getLevelFlag("lives") < 0) { |
|
|
|
return true; |
|
|
|
} |
|
|
|
|
|
|
|
return false; |
|
|
|
}; |
|
|
|
|
|
|
|
//prepareLevel |
|
|
|
public void prepareLevel(String level) { |
|
|
|
this.setLevelFlag("points", 0); |
|
|
|
this.setLevelFlag("lives", 3); |
|
|
|
this.addObject(showPoints); |
|
|
|
this.addObject(showLives); |
|
|
|
|
|
|
|
super.prepareLevel(level); |
|
|
|
}; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|