Skip to content

Commit

Permalink
Changed name skeleton to skull
Browse files Browse the repository at this point in the history
  • Loading branch information
juturbo committed Jul 5, 2024
1 parent 886ea34 commit 4c4d15b
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public Consumer<Character> getEffect() {
skull.get(new Random().nextInt(skull.size())).accept(character);

// Set the effect duration and reset logic
character.setSkeletonEffectDuration(EFFECT_DURATION_IN_SECONDS * SECONDS_TO_MILLISECONDS);
character.setSkullEffectDuration(EFFECT_DURATION_IN_SECONDS * SECONDS_TO_MILLISECONDS);
character.setResetEffect(() -> { // Restores all stats modified by the skull
character.setSpeed(previousSpeed);
character.setFlameRange(previousFlameRange);
Expand Down
34 changes: 17 additions & 17 deletions src/main/java/it/unibo/bombardero/character/Character.java
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public enum CharacterType {
private boolean butterfingers; // The character's hand becomes slippery. The character rapidly lays down bombs

// Skull manager
private long skeletonEffectDuration; // Indicates the duration of the skull effect
private long skullEffectDuration; // Indicates the duration of the skull effect
private Optional<Runnable> resetEffect = Optional.empty(); // Restores all stats modified by the skull

/**
Expand All @@ -134,17 +134,17 @@ public Character(final GenPair<Float, Float> coord, final BombFactory bombFactor
public abstract void update(GameManager manager, long elapsedTime);

/**
* Updates the skeleton's effects.
* Updates the skull's effects.
*
* @param manager the game manager
* @param elapsedTime the time elapsed since the last update
* @param type the type of character
*/
public void updateSkeleton(final GameManager manager, final long elapsedTime, final CharacterType type) {
if (this.skeletonEffectDuration > 0) { // Continues until the duration reaches zero
this.skeletonEffectDuration -= elapsedTime;
if (this.skeletonEffectDuration <= 0) { // When the effect ends the character's stats get resetted
setSkeletonEffectDuration(0);
public void updateSkull(final GameManager manager, final long elapsedTime, final CharacterType type) {
if (this.skullEffectDuration > 0) { // Continues until the duration reaches zero
this.skullEffectDuration -= elapsedTime;
if (this.skullEffectDuration <= 0) { // When the effect ends the character's stats get resetted
setSkullEffectDuration(0);
this.resetEffect.ifPresent(Runnable::run); // If there's a effect to reset, it runs the reset effect
this.resetEffect = Optional.empty(); // Clear the reset effect after it has run
}
Expand Down Expand Up @@ -575,26 +575,26 @@ public void setButterfingers(final boolean butterfingers) {
}

/**
* Gets the duration of the skeleton effect.
* Gets the duration of the skull effect.
*
* @return the skeletonEffectDuration
* @return the skullEffectDuration
*/
public long getSkeletonEffectDuration() {
return this.skeletonEffectDuration;
public long getSkullEffectDuration() {
return this.skullEffectDuration;
}

/**
* Sets the skeleton effect's duration.
* Sets the skull effect's duration.
*
* @param duration the duration of the skeleton effect
* @param duration the duration of the skull effect
*/
public void setSkeletonEffectDuration(final long duration) {
this.skeletonEffectDuration = duration;
public void setSkullEffectDuration(final long duration) {
this.skullEffectDuration = duration;
}

// TODO: write better javadoc
/**
* Gets the reset effect.
* Gets the reset effect used to reset the Character's stats after the skull effect ends.
*
* @return the reset effect
*/
Expand All @@ -603,7 +603,7 @@ public Optional<Runnable> getResetEffect() {
}

/**
* Sets the reset effect.
* Sets the reset effect used to reset the Character's stats after the skull effect ends.
*
* @param resetEffect the reset effect
*/
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/it/unibo/bombardero/character/Enemy.java
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ private void computeNextDir(final GameManager manager) {
@Override
public void update(final GameManager manager, final long elapsedTime) {
updateGraph(manager.getGameMap());
updateSkeleton(manager, elapsedTime, CharacterType.ENEMY);
updateSkull(manager, elapsedTime, CharacterType.ENEMY);
if (nextMove.isEmpty()) {
computeNextDir(manager);
} else if (canMoveOn(manager.getGameMap(), nextMove.get())) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/it/unibo/bombardero/character/Player.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public Player(final GenPair<Float, Float> coord, final BombFactory bombFactory)
public void update(final GameManager manager, final long elapsedTime) {
// Skeleton effect:
if (getResetEffect().isPresent()) { // If there's a Task to reset
updateSkeleton(manager, elapsedTime, CharacterType.PLAYER);
updateSkull(manager, elapsedTime, CharacterType.PLAYER);
}
// Player movement:
if (!isStationary()) { // If he's not stationary, computes the new position
Expand Down
12 changes: 6 additions & 6 deletions src/test/java/it/bombardero/TestPowerUp.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ void testCreating100PowerUp() {
powerUP.applyEffect(this.manager.getPlayer());
});
if (this.manager.getPlayer().getResetEffect().isPresent()) {
while (this.manager.getPlayer().getSkeletonEffectDuration() > 0) {
this.manager.getPlayer().updateSkeleton(manager, STANDARD_ELAPSED_TIME, CharacterType.PLAYER);
while (this.manager.getPlayer().getSkullEffectDuration() > 0) {
this.manager.getPlayer().updateSkull(manager, STANDARD_ELAPSED_TIME, CharacterType.PLAYER);
}
}
}
Expand All @@ -72,15 +72,15 @@ void testRandomSkullEffect() {
powerUP.applyEffect(this.manager.getPlayer());

assertEquals(SkullEffect.getEffectDurationInSeconds() * SECONDS_TO_MILLISECONDS,
this.manager.getPlayer().getSkeletonEffectDuration());
this.manager.getPlayer().getSkullEffectDuration());
assertTrue(this.manager.getPlayer().getResetEffect().isPresent());

while (this.manager.getPlayer().getSkeletonEffectDuration() > 0) {
this.manager.getPlayer().updateSkeleton(manager, STANDARD_ELAPSED_TIME, CharacterType.PLAYER);
while (this.manager.getPlayer().getSkullEffectDuration() > 0) {
this.manager.getPlayer().updateSkull(manager, STANDARD_ELAPSED_TIME, CharacterType.PLAYER);
}

// Asserts the skull duration is 0
assertEquals(0L, this.manager.getPlayer().getSkeletonEffectDuration());
assertEquals(0L, this.manager.getPlayer().getSkullEffectDuration());
// Asserts there is no Reset effect to run
assertEquals(Optional.empty(), this.manager.getPlayer().getResetEffect());
// Asserts the initial stats are resetted
Expand Down

0 comments on commit 4c4d15b

Please sign in to comment.