Skip to content

Commit

Permalink
Beta 2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
luigi-borriello00 authored May 26, 2021
2 parents 2d73a23 + 908fd5f commit 32d6ba1
Show file tree
Hide file tree
Showing 32 changed files with 710 additions and 457 deletions.
2 changes: 1 addition & 1 deletion src/main/java/bomberone/BomberOne.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public static void main(final String[] args) {

@Override
public void start(final Stage primaryStage) throws Exception {
primaryStage.setResizable(false);
// primaryStage.setResizable(false);
ResourcesLoader.getInstance().start();
DirectoryLoader.getInstance().start();
RankLoader.getInstance().readUsers();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class ExplosionEvent implements WorldEvent {
private Explosion explosion;

public ExplosionEvent(final Explosion exp) {
SoundsHandler.start(GameSounds.BOMB);
SoundsHandler.getInstance().start(GameSounds.BOMB);
this.explosion = exp;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public void process(final GameMatch match) {
if (!this.entity.isAlive()) {
return;
} else {
SoundsHandler.start(GameSounds.HITTED); // This is the Audio Effect for Bomber's death
SoundsHandler.getInstance().start(GameSounds.HITTED); // This is the Audio Effect for Bomber's death
/*
* If there is a fireObject on the respawn cell, it is removed to avoid
* death-loop bugs
Expand All @@ -67,7 +67,7 @@ public void process(final GameMatch match) {
match.incScore(BOX_INC_SCORE);
}
if (this.entity.getClass().equals(EnemyImpl.class)) {
SoundsHandler.start(GameSounds.ENEMY_HIT); // This is the Sound Effect for Enemy hitted
SoundsHandler.getInstance().start(GameSounds.ENEMY_HIT); // This is the Sound Effect for Enemy hitted
match.incScore(ENEMY_INC_SCORE);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class PickPowerUpEvent implements WorldEvent {
private PowerUp powerUp;

public PickPowerUpEvent(final PowerUp pU) {
SoundsHandler.start(GameSounds.POWER_UP); // This is the Sound Effect for pickUp powerUp
SoundsHandler.getInstance().start(GameSounds.POWER_UP); // This is the Sound Effect for pickUp powerUp
this.powerUp = pU;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,6 @@ public interface SetUpController extends Controller {
* @param choice
*/
void setControls(Controls choice);

void buildUser();
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ public void setControls(final Controls choice) {
}

public void buildUser() {
User user = new UserImpl();
user.setControls(this.controls);
user.setName(this.name);
user.setSkin(this.skin);
User user = new UserImpl.Builder(this.name)
.skin(this.skin)
.controls(this.controls)
.build();
this.match = new GameMatchImpl();
this.match.setDifficulty(this.difficulty);
this.match.setUser(user);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/bomberone/model/bomber/Bomber.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public interface Bomber extends MoveableObject {
void addLifes(int lifes);

/**
* Method for restore the usedAmmo to 0.
* Method for restore an ammo.
*/
void restoreAmmo();

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/bomberone/model/user/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ public interface User extends Serializable {
/**
*
* Set the controls of the User.
*
* @param controls
*/
void setControls(Controls controls);
Expand All @@ -61,5 +62,4 @@ public interface User extends Serializable {
* @return the controls of the User
*/
Controls getControls();

}
28 changes: 28 additions & 0 deletions src/main/java/bomberone/model/user/UserImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,32 @@ public Controls getControls() {
return this.controls;
}

public static class Builder {
private String name;
private Skins skin;
private Controls controls;

public Builder(final String name) {
this.name = name;
}

public final Builder skin(final Skins skin) {
this.skin = skin;
return this;
}

public final Builder controls(final Controls control) {
this.controls = control;
return this;
}

public final User build() {
User user = new UserImpl();
user.setControls(this.controls);
user.setName(this.name);
user.setSkin(this.skin);
return user;
}
}

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package bomberone.model.world.collection;

import java.util.LinkedList;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

Expand All @@ -24,7 +24,7 @@ public class GameObjectCollectionImpl implements GameObjectCollection {
private List<GameObject> gameObjectList;

public GameObjectCollectionImpl() {
this.gameObjectList = new LinkedList<>();
this.gameObjectList = new ArrayList<>();
}

@Override
Expand All @@ -34,7 +34,7 @@ public final List<GameObject> getGameObjectCollection() {

@Override
public final List<Bomb> getBombList() {
List<Bomb> bombList = new LinkedList<>();
List<Bomb> bombList = new ArrayList<>();
gameObjectList.stream().filter(p -> p.getClass().equals(BombImpl.class)).forEach(e -> {
bombList.add((Bomb) e);
});
Expand All @@ -43,7 +43,7 @@ public final List<Bomb> getBombList() {

@Override
public final List<Explosion> getExplosionList() {
List<Explosion> explosionList = new LinkedList<>();
List<Explosion> explosionList = new ArrayList<>();
gameObjectList.stream().filter(p -> p.getClass().equals(ExplosionImpl.class)).forEach(e -> {
explosionList.add((Explosion) e);
});
Expand All @@ -52,7 +52,7 @@ public final List<Explosion> getExplosionList() {

@Override
public final List<Box> getBoxList() {
List<Box> boxList = new LinkedList<>();
List<Box> boxList = new ArrayList<>();
gameObjectList.stream().filter(p -> p.getClass().equals(BoxImpl.class)).forEach(e -> {
boxList.add((Box) e);
});
Expand All @@ -61,7 +61,7 @@ public final List<Box> getBoxList() {

@Override
public final List<HardWall> getHardWallList() {
List<HardWall> hardWallList = new LinkedList<>();
List<HardWall> hardWallList = new ArrayList<>();
gameObjectList.stream().filter(p -> p.getClass().equals(HardWall.class)).forEach(e -> {
hardWallList.add((HardWall) e);
});
Expand All @@ -70,7 +70,7 @@ public final List<HardWall> getHardWallList() {

@Override
public final List<PowerUp> getPowerUpList() {
List<PowerUp> powerUpList = new LinkedList<>();
List<PowerUp> powerUpList = new ArrayList<>();
gameObjectList.stream().filter(p -> p.getClass().equals(PowerUpImpl.class)).forEach(e -> {
powerUpList.add((PowerUp) e);
});
Expand All @@ -79,7 +79,7 @@ public final List<PowerUp> getPowerUpList() {

@Override
public final List<Enemy> getEnemyList() {
List<Enemy> enemyList = new LinkedList<>();
List<Enemy> enemyList = new ArrayList<>();
gameObjectList.stream().filter(p -> p.getClass().equals(EnemyImpl.class)).forEach(e -> {
enemyList.add((Enemy) e);
});
Expand All @@ -88,7 +88,7 @@ public final List<Enemy> getEnemyList() {

@Override
public final List<Fire> getFireList() {
List<Fire> fireList = new LinkedList<>();
List<Fire> fireList = new ArrayList<>();
gameObjectList.stream().filter(p -> p.getClass().equals(FireImpl.class)).forEach(e -> {
fireList.add((Fire) e);
});
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/bomberone/tools/RankLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,9 @@ public void writeUsers(final List<User> hardList, final List<User> stdList) {
/**
* This method take in input two list of User, load from file the different
* ranks and puts them in the lists.
*
* I suppress this Warning because I try many ways to Fix it but i didn't succeed.
*/
@SuppressWarnings("unchecked")
public void readUsers() {
this.rankStandard.clear();
this.rankHard.clear();
Expand Down
63 changes: 43 additions & 20 deletions src/main/java/bomberone/tools/audio/SoundsHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,44 +4,57 @@
import java.util.Arrays;
import java.util.EnumMap;
import java.util.Map;

import javafx.scene.media.Media;
import javafx.scene.media.MediaPlayer;
import javafx.scene.media.MediaPlayer.Status;

public final class SoundsHandler {

private static final Map<GameSounds, Media> CACHE_AUDIO;
private static final Map<GameSounds, Media> CACHE_EFFECTS;
private static MediaPlayer playerAudio;
private static MediaPlayer playerEffects;
private Map<GameSounds, Media> cacheAudio;
private Map<GameSounds, Media> cacheEffects;
private MediaPlayer playerAudio;
private MediaPlayer playerEffects;

static {
CACHE_AUDIO = new EnumMap<>(GameSounds.class);
CACHE_EFFECTS = new EnumMap<>(GameSounds.class);
private SoundsHandler() {
this.cacheAudio = new EnumMap<>(GameSounds.class);
this.cacheEffects = new EnumMap<>(GameSounds.class);
Arrays.stream(GameSounds.values()).forEach(values -> {
if (values.getType().equals(Sounds.EFFECT)) {
try {
final Media audio = new Media(
ClassLoader.getSystemResource(values.getMediaPath()).toURI().toString());
CACHE_EFFECTS.put(values, audio);
this.cacheEffects.put(values, audio);
} catch (URISyntaxException e) {
e.printStackTrace();
}
} else {
try {
final Media audio = new Media(
ClassLoader.getSystemResource(values.getMediaPath()).toURI().toString());
CACHE_AUDIO.put(values, audio);
this.cacheAudio.put(values, audio);
} catch (URISyntaxException e) {
e.printStackTrace();
}
}
});
playerAudio = new MediaPlayer(CACHE_AUDIO.get(GameSounds.HOME));
playerAudio = new MediaPlayer(this.cacheAudio.get(GameSounds.HOME));
}

private SoundsHandler() {
/**
* SINGLETON pattern.
*/
private static class LazyHolder {
private static final SoundsHandler SINGLETON = new SoundsHandler();
}

/**
* Create SINGLETON on the first call.
*
* @return SoundsHandler
*/
public static SoundsHandler getInstance() {
return LazyHolder.SINGLETON;
}

/**
Expand All @@ -51,24 +64,24 @@ private SoundsHandler() {
*
* @param type
*/
public static synchronized void start(final GameSounds type) {
public synchronized void start(final GameSounds type) {
if (type.getType().equals(Sounds.EFFECT)) {
playerEffects = new MediaPlayer(CACHE_EFFECTS.get(type));
playerEffects = new MediaPlayer(this.cacheEffects.get(type));
playerEffects.setVolume(type.getVolume());
playerEffects.play();
playerEffects.setOnEndOfMedia(playerEffects::dispose);
} else {
if (!isPlaying()) {
if (!playerAudio.getMedia().equals(CACHE_AUDIO.get(type))) {
playerAudio = new MediaPlayer(CACHE_AUDIO.get(type));
if (!playerAudio.getMedia().equals(this.cacheAudio.get(type))) {
playerAudio.dispose();
playerAudio = new MediaPlayer(this.cacheAudio.get(type));
}
playerAudio.setVolume(type.getVolume());
playerAudio.play();
playerAudio.setOnEndOfMedia(new Runnable() {
@Override
public void run() {
playerAudio.stop();
playerAudio.play();
SoundsHandler.getInstance().replayAudio();
}
});
}
Expand All @@ -77,16 +90,26 @@ public void run() {

/**
* Method that return true if playerAudio is already playing.
*
* @return boolean
*/
public static boolean isPlaying() {
public boolean isPlaying() {
return playerAudio.getStatus().equals(Status.PLAYING);
}

/**
* Static method that stop the last audio played.
* Method that restart the playerAudio.
*/
public synchronized void replayAudio() {
playerAudio.stop();
playerAudio.play();
}

/**
* Method that stop the last audio played and free all resources associated with
* playerAudio.
*/
public static synchronized void stopAudio() {
public synchronized void stopAudio() {
playerAudio.stop();
playerAudio.dispose();
}
Expand Down
Loading

0 comments on commit 32d6ba1

Please sign in to comment.