Skip to content

Commit 5dd33f7

Browse files
authored
Merge pull request #374 from Advanced-Programming-2021/spellsAndSpecilMonsters
music play fixed & show output changed & a bug at shop fixed
2 parents 1597239 + 2e2a145 commit 5dd33f7

File tree

5 files changed

+64
-17
lines changed

5 files changed

+64
-17
lines changed

src/main/java/controller/GameController.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public void checkGameEnd() {
5151
MusicPlayer.playWinMusic();
5252
playerWins++;
5353
} else {
54-
MusicPlayer.loseMusic();
54+
MusicPlayer.playLoseMusic();
5555
opponentWins++;
5656
}
5757
playerDuelMenu.showGameWinner(winner.getUsername(), playerWins, opponentWins);

src/main/java/view/gui/DuelMenuGui.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ public class DuelMenuGui extends MenuGui {
5454
private static String selectCardMethodName;
5555
private static final Method[] duelMenuMethods;
5656

57-
private static boolean isDuelMenuMute = false;
5857
@FXML
5958
public Pane fieldPane;
6059
@FXML
@@ -628,6 +627,7 @@ public void activateEffect() {
628627
}
629628

630629
public void surrender() {
630+
MusicPlayer.playLoseMusic();
631631
gameController.surrender();
632632
updateGameBoard();
633633
}
@@ -748,17 +748,15 @@ public void pause(MouseEvent mouseEvent) {
748748
BorderPane borderPane = new BorderPane();
749749
Button resumeButton = new Button("resume");
750750
Button muteButton = new Button();
751-
if (isDuelMenuMute) muteButton.setText("unmute");
751+
if (MusicPlayer.isDuelMenuMute()) muteButton.setText("unmute");
752752
else muteButton.setText("mute");
753753
Button exitButton = new Button("exit");
754754
resumeButton.setOnAction(e -> pausePopupWindow.close());
755755
muteButton.setOnAction(e -> {
756-
if (isDuelMenuMute) {
757-
isDuelMenuMute = false;
756+
if (MusicPlayer.isDuelMenuMute()) {
758757
MusicPlayer.unMuteDuelMenuMusic();
759758
muteButton.setText("mute");
760759
} else {
761-
isDuelMenuMute = true;
762760
MusicPlayer.muteDuelMenuMusic();
763761
muteButton.setText("unmute");
764762
}

src/main/java/view/gui/MusicPlayer.java

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ public class MusicPlayer {
1515
private static MediaPlayer loginMediaPlayer = new MediaPlayer(loginMenuMusic);
1616
private static MediaPlayer mainMediaPlayer = new MediaPlayer(mainMenuMusic);
1717
private static MediaPlayer duelMenuPlayer = new MediaPlayer(duelMenuMusic);
18+
private static boolean isDuelMenuMute = false;
1819

1920
static {
2021
loginMediaPlayer.setOnEndOfMedia(new Runnable() {
@@ -39,6 +40,7 @@ public void run() {
3940
public static void playLoginMenuMusic() {
4041
loginMediaPlayer.play();
4142
}
43+
4244
public static void playMainMenuMusic() {
4345
mainMediaPlayer.play();
4446
}
@@ -69,39 +71,56 @@ public static void playPointDropMusic() {
6971
}
7072

7173
public static void muteDuelMenuMusic() {
74+
isDuelMenuMute = true;
7275
duelMenuPlayer.setMute(true);
7376
}
7477

7578
public static void unMuteDuelMenuMusic() {
79+
isDuelMenuMute = false;
7680
duelMenuPlayer.setMute(false);
7781
}
7882

7983
public static void playSetCardMusic() {
8084
MediaPlayer mediaPlayer = new MediaPlayer(setCardMusic);
81-
mediaPlayer.play();
85+
if (!isDuelMenuMute)
86+
mediaPlayer.play();
8287
}
8388

8489
public static void playWinMusic() {
85-
muteDuelMenuMusic();
90+
duelMenuPlayer.setMute(true);
8691
MediaPlayer mediaPlayer = new MediaPlayer(winMusic);
8792
mediaPlayer.setOnEndOfMedia(new Runnable() {
8893
@Override
8994
public void run() {
9095
unMuteMainMenu();
9196
}
9297
});
93-
mediaPlayer.play();
98+
if (!isDuelMenuMute)
99+
mediaPlayer.play();
100+
else
101+
unMuteMainMenu();
94102
}
95103

96-
public static void loseMusic() {
97-
muteDuelMenuMusic();
104+
public static void playLoseMusic() {
105+
duelMenuPlayer.setMute(true);
98106
MediaPlayer mediaPlayer = new MediaPlayer(loseMusic);
99107
mediaPlayer.setOnEndOfMedia(new Runnable() {
100108
@Override
101109
public void run() {
102110
unMuteMainMenu();
103111
}
104112
});
105-
mediaPlayer.play();
113+
if (!isDuelMenuMute)
114+
mediaPlayer.play();
115+
else
116+
unMuteMainMenu();
117+
}
118+
119+
public static void setIsDuelMenuMute(boolean isDuelMenuMute) {
120+
MusicPlayer.isDuelMenuMute = isDuelMenuMute;
121+
}
122+
123+
public static boolean isDuelMenuMute() {
124+
return isDuelMenuMute;
106125
}
107126
}

src/main/java/view/gui/ShopCellMenu.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,6 @@ public void setCardText() {
9191
public void buyCard() throws IOException {
9292
if (shopController.getCardsPrices().get(cardName) <= shopController.getUserMoney()) {
9393
int result = shopController.buyCardErrorHandler(cardName);
94-
numberOfBoughtCardsText.setText("1");
9594
if (result == 2)
9695
ShowOutput.showOutput("Error", "not enough money");
9796
else {
Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,43 @@
11
package view.gui;
22

3+
import javafx.geometry.Pos;
4+
import javafx.scene.Scene;
35
import javafx.scene.control.Alert;
6+
import javafx.scene.control.Button;
7+
import javafx.scene.layout.BorderPane;
8+
import javafx.scene.layout.HBox;
9+
import javafx.scene.text.Font;
10+
import javafx.scene.text.Text;
11+
import javafx.stage.Modality;
12+
import javafx.stage.Stage;
13+
import org.xml.sax.HandlerBase;
414

515
public class ShowOutput {
16+
private static Stage showOutPutPopUpWindow;
17+
618
public static void showOutput(String title, String header) {
7-
Alert alert = new Alert(Alert.AlertType.INFORMATION);
8-
alert.setTitle(title);
9-
alert.setHeaderText(header);
10-
alert.show();
19+
showOutPutPopUpWindow = new Stage();
20+
showOutPutPopUpWindow.initModality(Modality.APPLICATION_MODAL);
21+
22+
BorderPane borderPane = new BorderPane();
23+
Text text = new Text(header);
24+
text.setFont(new Font("Arial", 14));
25+
text.setStyle("-fx-fill: white");
26+
HBox hBox = new HBox(text);
27+
hBox.setStyle("-fx-background-color: #0303a4");
28+
hBox.setAlignment(Pos.BASELINE_LEFT);
29+
borderPane.setCenter(hBox);
30+
31+
Button okButton = new Button("ok");
32+
okButton.setStyle("-fx-background-color: orange");
33+
okButton.setOnMouseClicked(e -> showOutPutPopUpWindow.close());
34+
HBox bottomHBox = new HBox(okButton);
35+
bottomHBox.setStyle("-fx-background-color: #0303a4");
36+
bottomHBox.setAlignment(Pos.CENTER);
37+
borderPane.setBottom(bottomHBox);
38+
39+
showOutPutPopUpWindow.setScene(new Scene(borderPane, 350, 90));
40+
showOutPutPopUpWindow.setTitle(title);
41+
showOutPutPopUpWindow.showAndWait();
1142
}
1243
}

0 commit comments

Comments
 (0)