Skip to content
Snippets Groups Projects
Commit 0d322b3c authored by Bariatti Francesco's avatar Bariatti Francesco
Browse files

Modified sound in GUI

parent b4c4185c
No related branches found
No related tags found
No related merge requests found
File moved
...@@ -26,6 +26,7 @@ import java.util.ResourceBundle; ...@@ -26,6 +26,7 @@ import java.util.ResourceBundle;
public class Controller implements Initializable public class Controller implements Initializable
{ {
private static final String introMusicFile = "./resource/pingu_theme.wav";
private GameState gameState; private GameState gameState;
private Process gameProcess; private Process gameProcess;
...@@ -103,6 +104,13 @@ public class Controller implements Initializable ...@@ -103,6 +104,13 @@ public class Controller implements Initializable
UpdateThread upT = new UpdateThread(gameProcess, this.gameState, this.board, this.boardView, humanPlayer, scoreRed, scoreBlue, turnLabel); UpdateThread upT = new UpdateThread(gameProcess, this.gameState, this.board, this.boardView, humanPlayer, scoreRed, scoreBlue, turnLabel);
upT.setDaemon(true); upT.setDaemon(true);
upT.start(); upT.start();
try
{
AudioPlayer.player.start(new AudioStream(new FileInputStream(introMusicFile)));
} catch (IOException e)
{
e.printStackTrace();
}
} }
/** /**
...@@ -114,6 +122,7 @@ public class Controller implements Initializable ...@@ -114,6 +122,7 @@ public class Controller implements Initializable
private int tileNumber; private int tileNumber;
private final String clickSoundFile = "./resource/clic.wav";
public TileClickHandler(int tileNumber) public TileClickHandler(int tileNumber)
{ {
...@@ -130,30 +139,26 @@ public class Controller implements Initializable ...@@ -130,30 +139,26 @@ public class Controller implements Initializable
} }
} }
@Override private void playClickSound()
public void handle(MouseEvent event)
{ {
// open the sound file as a Java input stream try
String intro = "./resource/clic.wav"; {
InputStream in = null; AudioPlayer.player.start(new AudioStream(new FileInputStream(clickSoundFile)));
try { } catch (IOException e)
in = new FileInputStream(intro); {
// create an audiostream from the inputstream
AudioStream audioStream = new AudioStream(in);
// play the audio clip with the audioplayer class
AudioPlayer.player.start(audioStream);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }
}
@Override
public void handle(MouseEvent event)
{
if (!gameState.getCurrent_player().equals(humanPlayer)) if (!gameState.getCurrent_player().equals(humanPlayer))
return; return;
if (selectedTile == tileNumber) //If we clicked again on the selected tile if (selectedTile == tileNumber) //If we clicked again on the selected tile
{ {
playClickSound();
//UnSelect and un-highlight previously selected and highlighted tiles //UnSelect and un-highlight previously selected and highlighted tiles
boardView[selectedTile].setSelected(false); boardView[selectedTile].setSelected(false);
boardView[selectedTile].update(); boardView[selectedTile].update();
...@@ -163,9 +168,11 @@ public class Controller implements Initializable ...@@ -163,9 +168,11 @@ public class Controller implements Initializable
} }
//We clicked on a tile that wasn't previously selected //We clicked on a tile that wasn't previously selected
//Selecting the tile
int penguinNb = gameState.getPenguinOnTile(humanPlayer, tileNumber); int penguinNb = gameState.getPenguinOnTile(humanPlayer, tileNumber);
if (penguinNb != -1) //There is a penguin on this tile: we want to select it if (penguinNb != -1) //There is a penguin on this tile: we want to select it
{ {
playClickSound();
//Unselect previously selected tiles //Unselect previously selected tiles
if (selectedTile != -1) if (selectedTile != -1)
{ {
...@@ -217,6 +224,7 @@ public class Controller implements Initializable ...@@ -217,6 +224,7 @@ public class Controller implements Initializable
} }
else if (boardView[tileNumber].isHighlighted()) //There is no penguin but this is a possible move for the penguin on the selected tile else if (boardView[tileNumber].isHighlighted()) //There is no penguin but this is a possible move for the penguin on the selected tile
{ {
playClickSound();
Move move = boardView[tileNumber].getHighlightMove(); Move move = boardView[tileNumber].getHighlightMove();
int moveNb = gameState.getPlayerMoveNumber(humanPlayer, gameState.getPenguinOnTile(humanPlayer, selectedTile), move.getDirection(), move.getSteps()); int moveNb = gameState.getPlayerMoveNumber(humanPlayer, gameState.getPenguinOnTile(humanPlayer, selectedTile), move.getDirection(), move.getSteps());
//Before playing the move: deselect and de-highlight tiles //Before playing the move: deselect and de-highlight tiles
......
...@@ -32,14 +32,6 @@ public class Main extends Application ...@@ -32,14 +32,6 @@ public class Main extends Application
primaryStage.setScene(scene); primaryStage.setScene(scene);
primaryStage.setTitle("Penguin game"); primaryStage.setTitle("Penguin game");
primaryStage.show(); primaryStage.show();
// open the sound file as a Java input stream
String intro = "./resource/pingu_generique.wav";
InputStream in = new FileInputStream(intro);
// create an audiostream from the inputstream
AudioStream audioStream = new AudioStream(in);
// play the audio clip with the audioplayer class
AudioPlayer.player.start(audioStream);
} }
catch (Exception e) catch (Exception e)
{ {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment