minor comments and refactoring in break_out.model.Level
This commit is contained in:
parent
87048abd6f
commit
f6e8e6fcc5
@ -155,13 +155,13 @@ public class Level extends Thread implements ILevel {
|
||||
// Call here the balls method for reacting on stones of the playground
|
||||
if(getBall().hitsStone(getStones())) {
|
||||
updateStonesAndScore();
|
||||
System.out.println("count: "+stones.size());
|
||||
//System.out.println("count: "+stones.size());
|
||||
}
|
||||
|
||||
// if all stones are broken, go to next level
|
||||
if(allStonesBroken()) {
|
||||
// next level
|
||||
System.out.println("next level");
|
||||
//System.out.println("next level");
|
||||
}
|
||||
|
||||
// update paddles position
|
||||
@ -189,16 +189,18 @@ public class Level extends Thread implements ILevel {
|
||||
*/
|
||||
private void loadLevelData(int levelnr) {
|
||||
JSONReader reader = new JSONReader(String.format("res/Level%s.json", levelnr));
|
||||
int[][] stoneArray = reader.getStones2DArray();
|
||||
int[][] stoneTypes = reader.getStones2DArray();
|
||||
|
||||
// life counter
|
||||
lifeCounter = reader.getLifeCounter();
|
||||
|
||||
// clear stones list, not needed but could cause problems when not done
|
||||
stones.clear();
|
||||
|
||||
// foreach column
|
||||
for(int y = 0; y < stoneArray.length; y++) {
|
||||
for(int y = 0; y < stoneTypes.length; y++) {
|
||||
// foreach element in column x
|
||||
for(int x = 0; x < stoneArray[y].length; x++) {
|
||||
for(int x = 0; x < stoneTypes[y].length; x++) {
|
||||
Position tempPos = new Position(-1, -1);
|
||||
// position calculation, equivalent to grid calculation in "view.Field"
|
||||
|
||||
@ -208,7 +210,7 @@ public class Level extends Thread implements ILevel {
|
||||
|
||||
tempPos.setX(blockWidth * x);
|
||||
tempPos.setY(blockHeight * y);
|
||||
Stone tempStone = new Stone(stoneArray[y][x], tempPos);
|
||||
Stone tempStone = new Stone(stoneTypes[y][x], tempPos);
|
||||
|
||||
// add stone to list
|
||||
if(tempStone.getType() != 0)
|
||||
@ -258,10 +260,16 @@ public class Level extends Thread implements ILevel {
|
||||
* The updater for the levels stones and the player score
|
||||
*/
|
||||
private void updateStonesAndScore() {
|
||||
// hit stone
|
||||
Stone stone = getBall().getHitStone();
|
||||
|
||||
// add value to score
|
||||
score += stone.getValue();
|
||||
|
||||
// set new type
|
||||
stone.setType(stone.getType()-1);
|
||||
|
||||
// stones type is 0? remove it!
|
||||
if(stone.getType() == 0) {
|
||||
stones.remove(stone);
|
||||
}
|
||||
@ -272,8 +280,7 @@ public class Level extends Thread implements ILevel {
|
||||
* @return true when all stones are broken
|
||||
*/
|
||||
private boolean allStonesBroken() {
|
||||
if(stones.isEmpty()) return true;
|
||||
else return false;
|
||||
return stones.isEmpty();
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user