Skip to content

Commit

Permalink
Merge pull request #374 from Advanced-Programming-2021/spellsAndSpeci…
Browse files Browse the repository at this point in the history
…lMonsters

music play fixed & show output changed & a bug at shop fixed
  • Loading branch information
amir-haji authored Jul 9, 2021
2 parents 1597239 + 2e2a145 commit 5dd33f7
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 17 deletions.
2 changes: 1 addition & 1 deletion src/main/java/controller/GameController.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public void checkGameEnd() {
MusicPlayer.playWinMusic();
playerWins++;
} else {
MusicPlayer.loseMusic();
MusicPlayer.playLoseMusic();
opponentWins++;
}
playerDuelMenu.showGameWinner(winner.getUsername(), playerWins, opponentWins);
Expand Down
8 changes: 3 additions & 5 deletions src/main/java/view/gui/DuelMenuGui.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ public class DuelMenuGui extends MenuGui {
private static String selectCardMethodName;
private static final Method[] duelMenuMethods;

private static boolean isDuelMenuMute = false;
@FXML
public Pane fieldPane;
@FXML
Expand Down Expand Up @@ -628,6 +627,7 @@ public void activateEffect() {
}

public void surrender() {
MusicPlayer.playLoseMusic();
gameController.surrender();
updateGameBoard();
}
Expand Down Expand Up @@ -748,17 +748,15 @@ public void pause(MouseEvent mouseEvent) {
BorderPane borderPane = new BorderPane();
Button resumeButton = new Button("resume");
Button muteButton = new Button();
if (isDuelMenuMute) muteButton.setText("unmute");
if (MusicPlayer.isDuelMenuMute()) muteButton.setText("unmute");
else muteButton.setText("mute");
Button exitButton = new Button("exit");
resumeButton.setOnAction(e -> pausePopupWindow.close());
muteButton.setOnAction(e -> {
if (isDuelMenuMute) {
isDuelMenuMute = false;
if (MusicPlayer.isDuelMenuMute()) {
MusicPlayer.unMuteDuelMenuMusic();
muteButton.setText("mute");
} else {
isDuelMenuMute = true;
MusicPlayer.muteDuelMenuMusic();
muteButton.setText("unmute");
}
Expand Down
31 changes: 25 additions & 6 deletions src/main/java/view/gui/MusicPlayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public class MusicPlayer {
private static MediaPlayer loginMediaPlayer = new MediaPlayer(loginMenuMusic);
private static MediaPlayer mainMediaPlayer = new MediaPlayer(mainMenuMusic);
private static MediaPlayer duelMenuPlayer = new MediaPlayer(duelMenuMusic);
private static boolean isDuelMenuMute = false;

static {
loginMediaPlayer.setOnEndOfMedia(new Runnable() {
Expand All @@ -39,6 +40,7 @@ public void run() {
public static void playLoginMenuMusic() {
loginMediaPlayer.play();
}

public static void playMainMenuMusic() {
mainMediaPlayer.play();
}
Expand Down Expand Up @@ -69,39 +71,56 @@ public static void playPointDropMusic() {
}

public static void muteDuelMenuMusic() {
isDuelMenuMute = true;
duelMenuPlayer.setMute(true);
}

public static void unMuteDuelMenuMusic() {
isDuelMenuMute = false;
duelMenuPlayer.setMute(false);
}

public static void playSetCardMusic() {
MediaPlayer mediaPlayer = new MediaPlayer(setCardMusic);
mediaPlayer.play();
if (!isDuelMenuMute)
mediaPlayer.play();
}

public static void playWinMusic() {
muteDuelMenuMusic();
duelMenuPlayer.setMute(true);
MediaPlayer mediaPlayer = new MediaPlayer(winMusic);
mediaPlayer.setOnEndOfMedia(new Runnable() {
@Override
public void run() {
unMuteMainMenu();
}
});
mediaPlayer.play();
if (!isDuelMenuMute)
mediaPlayer.play();
else
unMuteMainMenu();
}

public static void loseMusic() {
muteDuelMenuMusic();
public static void playLoseMusic() {
duelMenuPlayer.setMute(true);
MediaPlayer mediaPlayer = new MediaPlayer(loseMusic);
mediaPlayer.setOnEndOfMedia(new Runnable() {
@Override
public void run() {
unMuteMainMenu();
}
});
mediaPlayer.play();
if (!isDuelMenuMute)
mediaPlayer.play();
else
unMuteMainMenu();
}

public static void setIsDuelMenuMute(boolean isDuelMenuMute) {
MusicPlayer.isDuelMenuMute = isDuelMenuMute;
}

public static boolean isDuelMenuMute() {
return isDuelMenuMute;
}
}
1 change: 0 additions & 1 deletion src/main/java/view/gui/ShopCellMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ public void setCardText() {
public void buyCard() throws IOException {
if (shopController.getCardsPrices().get(cardName) <= shopController.getUserMoney()) {
int result = shopController.buyCardErrorHandler(cardName);
numberOfBoughtCardsText.setText("1");
if (result == 2)
ShowOutput.showOutput("Error", "not enough money");
else {
Expand Down
39 changes: 35 additions & 4 deletions src/main/java/view/gui/ShowOutput.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,43 @@
package view.gui;

import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Alert;
import javafx.scene.control.Button;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.HBox;
import javafx.scene.text.Font;
import javafx.scene.text.Text;
import javafx.stage.Modality;
import javafx.stage.Stage;
import org.xml.sax.HandlerBase;

public class ShowOutput {
private static Stage showOutPutPopUpWindow;

public static void showOutput(String title, String header) {
Alert alert = new Alert(Alert.AlertType.INFORMATION);
alert.setTitle(title);
alert.setHeaderText(header);
alert.show();
showOutPutPopUpWindow = new Stage();
showOutPutPopUpWindow.initModality(Modality.APPLICATION_MODAL);

BorderPane borderPane = new BorderPane();
Text text = new Text(header);
text.setFont(new Font("Arial", 14));
text.setStyle("-fx-fill: white");
HBox hBox = new HBox(text);
hBox.setStyle("-fx-background-color: #0303a4");
hBox.setAlignment(Pos.BASELINE_LEFT);
borderPane.setCenter(hBox);

Button okButton = new Button("ok");
okButton.setStyle("-fx-background-color: orange");
okButton.setOnMouseClicked(e -> showOutPutPopUpWindow.close());
HBox bottomHBox = new HBox(okButton);
bottomHBox.setStyle("-fx-background-color: #0303a4");
bottomHBox.setAlignment(Pos.CENTER);
borderPane.setBottom(bottomHBox);

showOutPutPopUpWindow.setScene(new Scene(borderPane, 350, 90));
showOutPutPopUpWindow.setTitle(title);
showOutPutPopUpWindow.showAndWait();
}
}

0 comments on commit 5dd33f7

Please sign in to comment.