Skip to content
Snippets Groups Projects
Commit b9a3bc7b authored by Robert Goldmann's avatar Robert Goldmann
Browse files

Fixed #41

parent 4b5dbec4
Branches
Tags
1 merge request!49merge power-ups into master
...@@ -7,7 +7,7 @@ public class ExtraLifePowerUp extends PowerUp ...@@ -7,7 +7,7 @@ public class ExtraLifePowerUp extends PowerUp
{ {
public ExtraLifePowerUp() public ExtraLifePowerUp()
{ {
super(PowerUpType.EXTRA_LIFE.getId(), PowerUpType.EXTRA_LIFE.getDurationInSeconds()); super(PowerUpType.EXTRA_LIFE.getID(), PowerUpType.EXTRA_LIFE.getDurationInSeconds());
} }
@Override @Override
......
package de.bricked.game.powerups; package de.bricked.game.powerups;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import de.bricked.game.powerups.ball.ExplodeBallPowerUp; import de.bricked.game.powerups.ball.ExplodeBallPowerUp;
import de.bricked.game.powerups.ball.NoCollisionBallPowerUp; import de.bricked.game.powerups.ball.NoCollisionBallPowerUp;
public enum PowerUpType public enum PowerUpType
{ {
NONE(0, -1), NONE(0, -1, null),
EXTRA_LIFE(1, -1), EXTRA_LIFE(1, -1, null),
FASTER_BALL(2, 10), FASTER_BALL(2, 10, Arrays.asList(3)),
SLOWER_BALL(3, 10), SLOWER_BALL(3, 10, Arrays.asList(2, 4, 5)),
EXPLODE_BALL(4, 10), EXPLODE_BALL(4, 10, Arrays.asList(2, 3, 5)),
NO_COLLISION_BALL(5, 10); NO_COLLISION_BALL(5, 10, Arrays.asList(2, 3, 4));
private int id; private int ID;
private int durationInSeconds; private int durationInSeconds;
private List<Integer> deactivatesPowerUpIDs;
public static PowerUpType[] types = PowerUpType.values(); public static PowerUpType[] types = PowerUpType.values();
PowerUpType(int id, int durationInSeconds) PowerUpType(int ID, int durationInSeconds, List<Integer> deactivatesPowerUpdIDs)
{ {
this.id = id; this.ID = ID;
this.durationInSeconds = durationInSeconds; this.durationInSeconds = durationInSeconds;
this.deactivatesPowerUpIDs = deactivatesPowerUpdIDs;
} }
public int getId() public int getID()
{ {
return id; return ID;
} }
public int getDurationInSeconds() public int getDurationInSeconds()
...@@ -33,6 +40,11 @@ public enum PowerUpType ...@@ -33,6 +40,11 @@ public enum PowerUpType
return durationInSeconds; return durationInSeconds;
} }
public ArrayList<Integer> getDeactivatesPowerUpIDs()
{
return new ArrayList<>(deactivatesPowerUpIDs);
}
public static PowerUp getInstance(PowerUpType powerUpType) public static PowerUp getInstance(PowerUpType powerUpType)
{ {
switch (powerUpType) switch (powerUpType)
...@@ -45,4 +57,16 @@ public enum PowerUpType ...@@ -45,4 +57,16 @@ public enum PowerUpType
default: return null; default: return null;
} }
} }
public static PowerUpType valueOf(int ID)
{
for(PowerUpType currentType : PowerUpType.values())
{
if(ID == currentType.getID())
{
return currentType;
}
}
return PowerUpType.NONE;
}
} }
\ No newline at end of file
...@@ -11,7 +11,7 @@ public class ExplodeBallPowerUp extends PowerUp ...@@ -11,7 +11,7 @@ public class ExplodeBallPowerUp extends PowerUp
{ {
public ExplodeBallPowerUp() public ExplodeBallPowerUp()
{ {
super(PowerUpType.EXPLODE_BALL.getId(), PowerUpType.EXPLODE_BALL.getDurationInSeconds()); super(PowerUpType.EXPLODE_BALL.getID(), PowerUpType.EXPLODE_BALL.getDurationInSeconds());
} }
@Override @Override
......
...@@ -11,7 +11,7 @@ public class NoCollisionBallPowerUp extends PowerUp ...@@ -11,7 +11,7 @@ public class NoCollisionBallPowerUp extends PowerUp
{ {
public NoCollisionBallPowerUp() public NoCollisionBallPowerUp()
{ {
super(PowerUpType.NO_COLLISION_BALL.getId(), PowerUpType.NO_COLLISION_BALL.getDurationInSeconds()); super(PowerUpType.NO_COLLISION_BALL.getID(), PowerUpType.NO_COLLISION_BALL.getDurationInSeconds());
} }
@Override @Override
......
...@@ -18,6 +18,7 @@ import de.bricked.game.bricks.BrickType; ...@@ -18,6 +18,7 @@ import de.bricked.game.bricks.BrickType;
import de.bricked.game.paddle.Paddle; import de.bricked.game.paddle.Paddle;
import de.bricked.game.paddle.PaddleSize; import de.bricked.game.paddle.PaddleSize;
import de.bricked.game.powerups.PowerUp; import de.bricked.game.powerups.PowerUp;
import de.bricked.game.powerups.PowerUpType;
import de.bricked.utils.CountdownTimer; import de.bricked.utils.CountdownTimer;
import fontAwesome.FontIcon; import fontAwesome.FontIcon;
import fontAwesome.FontIconType; import fontAwesome.FontIconType;
...@@ -919,6 +920,8 @@ public class LevelController ...@@ -919,6 +920,8 @@ public class LevelController
if(!alreadyActivated) if(!alreadyActivated)
{ {
deactivateAllContraryPowerUps(powerUp);
HBox hbox = new HBox(); HBox hbox = new HBox();
Label labelIcon = new Label(); Label labelIcon = new Label();
labelIcon.setStyle("-fx-background-image: url(\"de/bricked/resources/textures/powerups/" + powerUp.getID() + ".png\");" + "-fx-background-position: center center;" + "-fx-background-repeat: no-repeat;" + "-fx-background-size: contain;"); labelIcon.setStyle("-fx-background-image: url(\"de/bricked/resources/textures/powerups/" + powerUp.getID() + ".png\");" + "-fx-background-position: center center;" + "-fx-background-repeat: no-repeat;" + "-fx-background-size: contain;");
...@@ -949,6 +952,27 @@ public class LevelController ...@@ -949,6 +952,27 @@ public class LevelController
vboxPowerUps.getChildren().clear(); vboxPowerUps.getChildren().clear();
} }
public void deactivateAllContraryPowerUps(PowerUp powerUp)
{
ArrayList<Integer> deactiveIDs = PowerUpType.valueOf(powerUp.getID()).getDeactivatesPowerUpIDs();
if(deactiveIDs != null)
{
for(int currentInt : deactiveIDs)
{
for(CountdownTimer currentTimer : timedPowerUps)
{
PowerUp currentPowerUp = (PowerUp)currentTimer.getHBox().getUserData();
if(currentPowerUp.getID() == currentInt)
{
currentTimer.stop();
deactivatePowerUp(currentTimer, currentTimer.getHBox());
break;
}
}
}
}
}
public void deactivatePowerUp(CountdownTimer timer, HBox hbox) public void deactivatePowerUp(CountdownTimer timer, HBox hbox)
{ {
PowerUp powerUp = (PowerUp)hbox.getUserData(); PowerUp powerUp = (PowerUp)hbox.getUserData();
......
...@@ -12,6 +12,7 @@ public class CountdownTimer ...@@ -12,6 +12,7 @@ public class CountdownTimer
{ {
private int count; private int count;
private HBox hbox; private HBox hbox;
private Timer timer;
public CountdownTimer(int seconds, HBox hbox, LevelController levelController) public CountdownTimer(int seconds, HBox hbox, LevelController levelController)
{ {
...@@ -20,7 +21,7 @@ public class CountdownTimer ...@@ -20,7 +21,7 @@ public class CountdownTimer
CountdownTimer self = this; CountdownTimer self = this;
Timer timer = new Timer(); timer = new Timer();
TimerTask task = new TimerTask() TimerTask task = new TimerTask()
{ {
@Override @Override
...@@ -63,4 +64,10 @@ public class CountdownTimer ...@@ -63,4 +64,10 @@ public class CountdownTimer
{ {
return hbox; return hbox;
} }
public void stop()
{
timer.cancel();
timer.purge();
}
} }
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment