- More work on the sound system (magic numbers, CheckStyle).

This commit is contained in:
Agetian
2012-11-11 17:53:36 +00:00
parent 8595507903
commit d410e6bac4

View File

@@ -29,6 +29,7 @@ import javax.sound.sampled.*;
*/ */
public class SoundSystem { public class SoundSystem {
private Clip clip; private Clip clip;
private final int SOUND_SYSTEM_DELAY = 30;
public SoundSystem(String filename) { public SoundSystem(String filename) {
try { try {
@@ -48,7 +49,7 @@ public class SoundSystem {
} }
} }
public void play() { public final void play() {
if (clip != null) { if (clip != null) {
clip.setMicrosecondPosition(0); clip.setMicrosecondPosition(0);
if (!isDone()) { if (!isDone()) {
@@ -56,7 +57,7 @@ public class SoundSystem {
clip.stop(); clip.stop();
} }
try { try {
Thread.sleep(30); Thread.sleep(SOUND_SYSTEM_DELAY);
} catch (InterruptedException ex) { } catch (InterruptedException ex) {
ex.printStackTrace(); ex.printStackTrace();
} }
@@ -64,7 +65,7 @@ public class SoundSystem {
} }
} }
public void loop() { public final void loop() {
if (clip != null) { if (clip != null) {
clip.setMicrosecondPosition(0); clip.setMicrosecondPosition(0);
if (!isDone()) { if (!isDone()) {
@@ -72,7 +73,7 @@ public class SoundSystem {
clip.stop(); clip.stop();
} }
try { try {
Thread.sleep(30); Thread.sleep(SOUND_SYSTEM_DELAY);
} catch (InterruptedException ex) { } catch (InterruptedException ex) {
ex.printStackTrace(); ex.printStackTrace();
} }
@@ -80,18 +81,17 @@ public class SoundSystem {
} }
} }
public void stop() { public final void stop() {
if (clip != null) { if (clip != null) {
clip.stop(); clip.stop();
} }
} }
public boolean isDone() { public final boolean isDone() {
if (clip != null) { if (clip != null) {
return !clip.isRunning(); return !clip.isRunning();
} else { } else {
return false; return false;
} }
} }
} }