Hallo Zusammen. Ich habe ein TicTacToe Spiel auf Intellij Idea geschrieben. Ich möchte, dass nach jedem gespielten Zug vom Spieler und Computer ein Sound erscheint. Ich habe vorher noch nie eine Sound Datei in ein Programm hinzugefügt, und im Internet bin ich auf keinen guten Beitrag gestossen, welcher mir weiter helfen kann.
Das ist jetzt z.B. ein Code Ausschnit vom Computer. Er soll nun nach jedem Zug welche er ausgibt einen Sound Abspielen.
public class ComputerPlayer {
private static char[][] gameBoard;
public int computerMove(char[][] gameBoard) {
Random rand = new Random();
try {
TimeUnit.SECONDS.sleep(1);
} catch (InterruptedException e) {
e.printStackTrace();
}
int move = rand.nextInt(9) + 1;
boolean result = Game.validMove(move, gameBoard);
while (!result) {
move = rand.nextInt(9) + 1;
result = Game.validMove(move, gameBoard);
}
System.out.println("Computer Zug " + move);
return move;
}
}
Das ist jetzt z.B. ein Code Ausschnit vom Computer. Er soll nun nach jedem Zug welche er ausgibt einen Sound Abspielen.
public class ComputerPlayer {
private static char[][] gameBoard;
public int computerMove(char[][] gameBoard) {
Random rand = new Random();
try {
TimeUnit.SECONDS.sleep(1);
} catch (InterruptedException e) {
e.printStackTrace();
}
int move = rand.nextInt(9) + 1;
boolean result = Game.validMove(move, gameBoard);
while (!result) {
move = rand.nextInt(9) + 1;
result = Game.validMove(move, gameBoard);
}
System.out.println("Computer Zug " + move);
return move;
}
}