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;
public class Controller implements Initializable
{
private static final String introMusicFile = "./resource/pingu_theme.wav";
private GameState gameState;
private Process gameProcess;
......@@ -103,6 +104,13 @@ public class Controller implements Initializable
UpdateThread upT = new UpdateThread(gameProcess, this.gameState, this.board, this.boardView, humanPlayer, scoreRed, scoreBlue, turnLabel);
upT.setDaemon(true);
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
private int tileNumber;
private final String clickSoundFile = "./resource/clic.wav";
public TileClickHandler(int tileNumber)
{
......@@ -130,30 +139,26 @@ public class Controller implements Initializable
}
}
@Override
public void handle(MouseEvent event)
private void playClickSound()
{
// open the sound file as a Java input stream
String intro = "./resource/clic.wav";
InputStream in = null;
try {
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) {
try
{
AudioPlayer.player.start(new AudioStream(new FileInputStream(clickSoundFile)));
} catch (IOException e)
{
e.printStackTrace();
}
}
@Override
public void handle(MouseEvent event)
{
if (!gameState.getCurrent_player().equals(humanPlayer))
return;
if (selectedTile == tileNumber) //If we clicked again on the selected tile
{
playClickSound();
//UnSelect and un-highlight previously selected and highlighted tiles
boardView[selectedTile].setSelected(false);
boardView[selectedTile].update();
......@@ -163,9 +168,11 @@ public class Controller implements Initializable
}
//We clicked on a tile that wasn't previously selected
//Selecting the tile
int penguinNb = gameState.getPenguinOnTile(humanPlayer, tileNumber);
if (penguinNb != -1) //There is a penguin on this tile: we want to select it
{
playClickSound();
//Unselect previously selected tiles
if (selectedTile != -1)
{
......@@ -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
{
playClickSound();
Move move = boardView[tileNumber].getHighlightMove();
int moveNb = gameState.getPlayerMoveNumber(humanPlayer, gameState.getPenguinOnTile(humanPlayer, selectedTile), move.getDirection(), move.getSteps());
//Before playing the move: deselect and de-highlight tiles
......
......@@ -32,14 +32,6 @@ public class Main extends Application
primaryStage.setScene(scene);
primaryStage.setTitle("Penguin game");
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)
{
......
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