mirror of
https://github.com/michaelrausch/Party-Parrots-At-Sea.git
synced 2026-05-09 06:18:44 +00:00
Merge branch 'develop' into 1250_SendingGameObjects
# Conflicts: # src/main/java/seng302/gameServer/GameState.java # src/main/java/seng302/gameServer/MainServerThread.java # src/main/java/seng302/visualiser/GameView.java # src/main/java/seng302/visualiser/controllers/RaceViewController.java
This commit is contained in:
@@ -0,0 +1,163 @@
|
||||
package seng302.utilities;
|
||||
|
||||
import javafx.scene.media.Media;
|
||||
import javafx.scene.media.MediaPlayer;
|
||||
|
||||
/**
|
||||
* Static class for playing sounds throughout the program
|
||||
*
|
||||
* Created by kre39 on 28/08/17.
|
||||
*/
|
||||
public class Sounds {
|
||||
|
||||
private static MediaPlayer musicPlayer;
|
||||
private static MediaPlayer soundEffect;
|
||||
private static MediaPlayer soundPlayer;
|
||||
|
||||
private static boolean musicMuted = false;
|
||||
private static boolean soundEffectsMuted = false;
|
||||
|
||||
|
||||
public static void stopMusic() {
|
||||
if (musicPlayer != null) {
|
||||
musicPlayer.stop();
|
||||
}
|
||||
}
|
||||
|
||||
public static void setMutes() {
|
||||
if (soundPlayer != null) {
|
||||
soundPlayer.setMute(soundEffectsMuted);
|
||||
}
|
||||
if (soundEffect != null) {
|
||||
soundEffect.setMute(soundEffectsMuted);
|
||||
}
|
||||
if (musicPlayer != null) {
|
||||
musicPlayer.setMute(musicMuted);
|
||||
}
|
||||
}
|
||||
|
||||
public static void stopSoundEffects() {
|
||||
if (soundEffect != null) {
|
||||
soundEffect.stop();
|
||||
}
|
||||
}
|
||||
|
||||
public static void toggleMuteMusic() {
|
||||
musicMuted = !musicMuted;
|
||||
if (musicPlayer != null) {
|
||||
musicPlayer.setMute(musicMuted);
|
||||
}
|
||||
}
|
||||
|
||||
public static void toggleMuteEffects() {
|
||||
soundEffectsMuted = !soundEffectsMuted;
|
||||
if (soundPlayer != null) {
|
||||
soundPlayer.setMute(soundEffectsMuted);
|
||||
}
|
||||
if (soundEffect != null) {
|
||||
soundEffect.setMute(soundEffectsMuted);
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isMusicMuted() {
|
||||
return musicMuted;
|
||||
}
|
||||
|
||||
public static boolean isSoundEffectsMuted() {
|
||||
return soundEffectsMuted;
|
||||
}
|
||||
|
||||
public static void playRaceMusic() {
|
||||
// Media menuMusic = new Media(Sounds.class.getClassLoader().getResource("sounds/Chill-house-music-loop-116-bpm.wav").toString());
|
||||
Media raceMusic = new Media(Sounds.class.getClassLoader().getResource("sounds/Music-loop-120-bpm.mp3").toString());
|
||||
musicPlayer = new MediaPlayer(raceMusic);
|
||||
musicPlayer.setCycleCount(MediaPlayer.INDEFINITE);
|
||||
musicPlayer.play();
|
||||
raceMusic = new Media(Sounds.class.getClassLoader().getResource("sounds/Sounds-of-the-ocean.mp3").toString());
|
||||
soundEffect = new MediaPlayer(raceMusic);
|
||||
soundEffect.setCycleCount(MediaPlayer.INDEFINITE);
|
||||
// soundEffect.setVolume(0.3);
|
||||
soundEffect.play();
|
||||
musicPlayer.setMute(musicMuted);
|
||||
soundEffect.setMute(soundEffectsMuted);
|
||||
}
|
||||
|
||||
public static void playMenuMusic() {
|
||||
Media menuMusic = new Media(
|
||||
Sounds.class.getClassLoader().getResource("sounds/Elevator-music.mp3").toString());
|
||||
musicPlayer = new MediaPlayer(menuMusic);
|
||||
musicPlayer.setCycleCount(MediaPlayer.INDEFINITE);
|
||||
musicPlayer.play();
|
||||
}
|
||||
|
||||
|
||||
public static void playFinishMusic() {
|
||||
Media finishMusic = new Media(Sounds.class.getClassLoader().getResource("sounds/Happy-birthday-song.mp3").toString());
|
||||
musicPlayer = new MediaPlayer(finishMusic);
|
||||
musicPlayer.setCycleCount(MediaPlayer.INDEFINITE);
|
||||
musicPlayer.play();
|
||||
musicPlayer.setMute(musicMuted);
|
||||
}
|
||||
|
||||
public static void playButtonClick() {
|
||||
if (!soundEffectsMuted) {
|
||||
Media buttonClick = new Media(
|
||||
Sounds.class.getClassLoader().getResource("sounds/Button-click-sound.mp3")
|
||||
.toString());
|
||||
soundPlayer = new MediaPlayer(buttonClick);
|
||||
soundPlayer.play();
|
||||
soundPlayer.setMute(soundEffectsMuted);
|
||||
}
|
||||
}
|
||||
|
||||
public static void playFinishSound() {
|
||||
if (!soundEffectsMuted) {
|
||||
Media finishSound = new Media(
|
||||
Sounds.class.getClassLoader().getResource("sounds/Sms-notification.mp3")
|
||||
.toString());
|
||||
soundPlayer = new MediaPlayer(finishSound);
|
||||
soundPlayer.play();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static void playMarkRoundingSound() {
|
||||
if (!soundEffectsMuted) {
|
||||
|
||||
Media markRoundingSound = new Media(
|
||||
Sounds.class.getClassLoader().getResource("sounds/sms-tone.mp3").toString());
|
||||
soundPlayer = new MediaPlayer(markRoundingSound);
|
||||
soundPlayer.play();
|
||||
}
|
||||
}
|
||||
|
||||
public static void playCapGunSound() {
|
||||
if (!soundEffectsMuted) {
|
||||
|
||||
Media gunSound = new Media(
|
||||
Sounds.class.getClassLoader().getResource("sounds/Gunshot-sound.mp3").toString());
|
||||
soundPlayer = new MediaPlayer(gunSound);
|
||||
soundPlayer.play();
|
||||
}
|
||||
}
|
||||
|
||||
public static void playCrashSound() {
|
||||
if (!soundEffectsMuted) {
|
||||
Media crashSound = new Media(
|
||||
Sounds.class.getClassLoader().getResource("sounds/Large-metal-door-slam.mp3")
|
||||
.toString());
|
||||
soundPlayer = new MediaPlayer(crashSound);
|
||||
soundPlayer.play();
|
||||
}
|
||||
}
|
||||
|
||||
public static void playHoverSound() {
|
||||
if (!soundEffectsMuted) {
|
||||
Media hoverSound = new Media(Sounds.class.getClassLoader().getResource("sounds/sound-over.wav").toString());
|
||||
soundPlayer = new MediaPlayer(hoverSound);
|
||||
soundPlayer.play();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -2,9 +2,11 @@ package seng302.utilities;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.StringReader;
|
||||
import java.lang.reflect.Array;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import javafx.util.Pair;
|
||||
import javax.xml.parsers.DocumentBuilder;
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
@@ -62,31 +64,10 @@ public class StreamParser {
|
||||
long windDir = bytesToLong(Arrays.copyOfRange(payload, 18, 20));
|
||||
long rawWindSpeed = bytesToLong(Arrays.copyOfRange(payload, 20, 22));
|
||||
|
||||
// DateFormat format = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
|
||||
// currentTime = format.format((new Date(currentTime)))
|
||||
|
||||
RaceStatusData data = new RaceStatusData(
|
||||
windDir, rawWindSpeed, raceStatus, currentTime, expectedStartTime
|
||||
);
|
||||
|
||||
// long timeTillStart =
|
||||
// ((new Date(expectedStartTime)).getTime() - (new Date(currentTime)).getTime()) / 1000;
|
||||
//
|
||||
// if (timeTillStart > 0) {
|
||||
// timeSinceStart = timeTillStart;
|
||||
// } else {
|
||||
// if (raceStatus == 4 || raceStatus == 8) {
|
||||
// raceFinished = true;
|
||||
// raceStarted = false;
|
||||
// } else if (!raceStarted) {
|
||||
// raceStarted = true;
|
||||
// raceFinished = false;
|
||||
// }
|
||||
// timeSinceStart = timeTillStart;
|
||||
// }
|
||||
//
|
||||
|
||||
//
|
||||
int noBoats = payload[22];
|
||||
int raceType = payload[23];
|
||||
long boatID, estTimeAtNextMark, estTimeAtFinish;
|
||||
@@ -106,24 +87,6 @@ public class StreamParser {
|
||||
return data;
|
||||
}
|
||||
|
||||
// private static void setBoatLegPosition(Yacht updatingBoat, Integer leg){
|
||||
// Integer placing = 1;
|
||||
// if (leg != updatingBoat.getLegNumber() && (raceStarted || raceFinished)) {
|
||||
// for (Yacht boat : boats.values()) {
|
||||
// if (boat.getLegNumber() != null && leg <= boat.getLegNumber()){
|
||||
// placing += 1;
|
||||
// }
|
||||
// }
|
||||
// updatingBoat.setPlacing(placing.toString());
|
||||
// updatingBoat.setLegNumber(leg);
|
||||
// boatsPos.putIfAbsent(placing, updatingBoat);
|
||||
// boatsPos.replace(placing, updatingBoat);
|
||||
// } else if(updatingBoat.getLegNumber() == null){
|
||||
// updatingBoat.setPlacing("1");
|
||||
// updatingBoat.setLegNumber(leg);
|
||||
// }
|
||||
// }
|
||||
|
||||
/**
|
||||
* Parses and returns the text from a StreamPacket containing text data for display.
|
||||
*
|
||||
@@ -255,15 +218,15 @@ public class StreamParser {
|
||||
* @return Chatter text message as a string. Returns null if the packet is not of type
|
||||
* CHATTER_TEXT.
|
||||
*/
|
||||
public static String extractChatterText(StreamPacket packet) {
|
||||
public static Pair<Integer, String> extractChatterText(StreamPacket packet) {
|
||||
if (packet.getType() != PacketType.CHATTER_TEXT) {
|
||||
return null;
|
||||
}
|
||||
byte[] payload = packet.getPayload();
|
||||
int messageVersionNo = payload[0];
|
||||
int messageType = payload[1];
|
||||
int length = payload[2];
|
||||
return new String(Arrays.copyOfRange(payload, 3, 3 + length));
|
||||
int length = (int) bytesToLong(new byte[]{payload[2]});
|
||||
return new Pair<>(messageType, new String(Arrays.copyOfRange(payload, 3, 3 + length)));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -392,26 +355,6 @@ public class StreamParser {
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
public static void extractBoatAction(StreamPacket packet) {
|
||||
byte[] payload = packet.getPayload();
|
||||
int messageVersionNo = payload[0];
|
||||
long actionType = bytesToLong(Arrays.copyOfRange(payload, 0, 1));
|
||||
if (actionType == 1) {
|
||||
System.out.println("VMG");
|
||||
} else if (actionType == 2) {
|
||||
System.out.println("SAILS IN");
|
||||
} else if (actionType == 3) {
|
||||
System.out.println("SAILS OUT");
|
||||
} else if (actionType == 4) {
|
||||
System.out.println("TACK/GYBE");
|
||||
} else if (actionType == 5) {
|
||||
System.out.println("UPWIND");
|
||||
} else if (actionType == 6) {
|
||||
System.out.println("DOWNWIND");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* takes an array of up to 7 bytes and returns a positive long constructed from the input bytes
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user