kill the zombies

This commit is contained in:
Luca Conte 2024-12-10 14:42:15 +01:00
parent 5cf8befdc1
commit 60e6ed1277
1 changed files with 21 additions and 3 deletions

View File

@ -1,8 +1,10 @@
import javazoom.jl.decoder.JavaLayerException;
import javazoom.jl.player.Player;
import java.awt.List;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
@ -10,6 +12,8 @@ public class SoundHandler {
private static boolean soundOn = true;
private static ArrayList<Thread> runningThreads = new ArrayList<Thread>();
// Wenn fehler beim erstellen von .jar mit sound hier gucken
private static HashMap<String, String> sounds = new HashMap<String, String>(Map.of(
"hit", "./Sound/water-drip.mp3"
@ -17,7 +21,7 @@ public class SoundHandler {
public static void playSound(String soundName) {
if (soundOn) {
new Thread(new Runnable() {
Thread thread = new Thread(new Runnable() {
@Override
public void run() {
try {
@ -27,9 +31,23 @@ public class SoundHandler {
e.printStackTrace();
}
}
}).start();
// TODO: kill zombies
});
thread.start();
runningThreads.add(thread);
}
for (Thread oldThread : runningThreads) {
if (!oldThread.isAlive()) {
try {
oldThread.join();
runningThreads.remove(oldThread);
System.out.println("cleared thread");
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}