Merge remote-tracking branch 'origin/develop' into develop

This commit is contained in:
Haoming Yin
2017-07-25 23:06:06 +12:00
6 changed files with 64 additions and 52 deletions
@@ -17,8 +17,6 @@ import javafx.scene.image.ImageView;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.Pane;
import javafx.scene.media.Media;
import javafx.scene.media.MediaPlayer;
import javafx.scene.text.Text;
import seng302.client.ClientState;
import seng302.client.ClientStateQueryingRunnable;
@@ -198,29 +196,29 @@ public class LobbyController implements Initializable, Observer{
@FXML
public void readyButtonPressed() {
// setContentPane("/views/RaceView.fxml");
playTheme();
// playTheme();
GameState.setCurrentStage(GameStages.RACING);
mainServerThread.startGame();
}
private static MediaPlayer mediaPlayer;
private void playTheme() {
Random random = new Random(System.currentTimeMillis());
Integer rand = random.nextInt();
if(rand == 10) {
URL file = getClass().getResource("/music/Disturbed - down with the sickness.mp3");
Media hit = new Media(file.toString());
mediaPlayer = new MediaPlayer(hit);
mediaPlayer.play();
} else if(rand == 9) {
URL file = getClass().getResource("/music/Owl City - Fireflies.mp3");
Media hit = new Media(file.toString());
mediaPlayer = new MediaPlayer(hit);
mediaPlayer.play();
}
}
// private static MediaPlayer mediaPlayer;
//
// private void playTheme() {
// Random random = new Random(System.currentTimeMillis());
// Integer rand = random.nextInt();
// if(rand == 10) {
// URL file = getClass().getResource("/music/Disturbed - down with the sickness.mp3");
// Media hit = new Media(file.toString());
// mediaPlayer = new MediaPlayer(hit);
// mediaPlayer.play();
// } else if(rand == 9) {
// URL file = getClass().getResource("/music/Owl City - Fireflies.mp3");
// Media hit = new Media(file.toString());
// mediaPlayer = new MediaPlayer(hit);
// mediaPlayer.play();
// }
// }
private void switchToRaceView() {
if (!switchedPane) {
@@ -83,7 +83,7 @@ public class BoatAnnotations extends Group{
}
void update () {
velocityObject.setText(String.format(String.format("%.2f m/s", boat.getVelocity())));
velocityObject.setText(String.format(String.format("%.2f m/s", boat.getVelocityMMS())));
if (boat.getTimeTillNext() != null) {
DateFormat format = new SimpleDateFormat("mm:ss");
@@ -2,6 +2,7 @@ package seng302.gameServer;
import java.util.*;
import seng302.client.ClientPacketParser;
import seng302.models.Player;
import seng302.models.Yacht;
@@ -80,10 +81,14 @@ public class GameState {
return windDirection;
}
public static Double getWindSpeed() {
public static Double getWindSpeedMMS() {
return windSpeed;
}
public static Double getWindSpeedKnots() {
return windSpeed / 1000 * ClientPacketParser.MS_TO_KNOTS;
}
public static Map<Integer, Yacht> getYachts() {
return yachts;
}
@@ -93,6 +98,7 @@ public class GameState {
// System.out.println("-----------------------");
switch (actionType) {
case VMG:
playerYacht.turnToVMG();
// System.out.println("Snapping to VMG");
// TODO: 22/07/17 wmu16 - Add in the vmg calculation code here
break;
@@ -118,12 +124,13 @@ public class GameState {
break;
}
// System.out.println("-----------------------");
// System.out.println("Heading: " + playerYacht.getHeading());
// System.out.println("Sails are in: " + playerYacht.getSailIn());
// System.out.println("Lat: " + playerYacht.getLocation().getLat());
// System.out.println("Lng: " + playerYacht.getLocation().getLng());
// System.out.println("-----------------------\n");
System.out.println("-----------------------");
System.out.println("Sails are in: " + playerYacht.getSailIn());
System.out.println("Heading: " + playerYacht.getHeading());
System.out.println("Velocity: " + playerYacht.getVelocityMMS() / 1000);
System.out.println("Lat: " + playerYacht.getLocation().getLat());
System.out.println("Lng: " + playerYacht.getLocation().getLng());
System.out.println("-----------------------\n");
}
public static void update() {
@@ -12,10 +12,9 @@ import java.util.ArrayList;
import java.util.List;
import java.util.Observable;
import java.util.Observer;
import java.util.Random;
import java.util.zip.CRC32;
import java.util.zip.Checksum;
import org.apache.commons.io.IOUtils;
import seng302.models.Player;
import seng302.models.Yacht;
import seng302.models.stream.packets.PacketType;
@@ -29,18 +28,11 @@ import seng302.server.messages.BoatStatus;
import seng302.server.messages.BoatSubMessage;
import seng302.server.messages.Message;
import java.io.*;
import java.net.Socket;
import java.util.zip.CRC32;
import java.util.zip.Checksum;
import seng302.server.messages.RaceStatus;
import seng302.server.messages.RaceStatusMessage;
import seng302.server.messages.RaceType;
import seng302.server.messages.XMLMessage;
import seng302.server.messages.XMLMessageSubType;
import seng302.server.messages.XMLMessage;
import seng302.server.messages.XMLMessageSubType;
import seng302.utilities.GeoPoint;
/**
* A class describing a single connection to a Client for the purposes of sending and receiving on
@@ -306,7 +298,7 @@ public class ServerToClientThread implements Runnable, Observer {
yacht.getLocation().getLat(),
yacht.getLocation().getLng(),
yacht.getHeading(),
(long) yacht.getVelocity());
(long) yacht.getVelocityMMS());
sendMessage(boatLocationMessage);
}
@@ -348,7 +340,7 @@ public class ServerToClientThread implements Runnable, Observer {
}
sendMessage(new RaceStatusMessage(1, raceStatus, startTime, GameState.getWindDirection(),
GameState.getWindSpeed().longValue(), GameState.getPlayers().size(),
GameState.getWindSpeedMMS().longValue(), GameState.getPlayers().size(),
RaceType.MATCH_RACE, 1, boatSubMessages));
}
+28 -12
View File
@@ -4,6 +4,7 @@ import static seng302.utilities.GeoUtility.getGeoCoordinate;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import javafx.scene.paint.Color;
import seng302.client.ClientPacketParser;
@@ -110,8 +111,8 @@ public class Yacht {
this.position = "-";
this.sailIn = false;
this.location = new GeoPoint(57.670341, 11.826856);
this.heading = 120.0;
this.velocity = 50000.0;
this.heading = 120.0; //In degrees
this.velocity = 0d; //in mms-1
}
/**
@@ -120,13 +121,14 @@ public class Yacht {
public void update(Long timeInterval) {
if (sailIn) {
Double secondsElapsed = timeInterval / 1000000.0;
Double thisHeading = ((double) Math.floorMod(heading.longValue(), 360L));
Double windSpeedKnots = 0d;
Double boatSpeedInKnots = PolarTable.getBoatSpeed(windSpeedKnots, thisHeading);
velocity = boatSpeedInKnots / ClientPacketParser.MS_TO_KNOTS * 3000;
//System.out.println("velocity = " + velocity);
Double windSpeedKnots = GameState.getWindSpeedKnots();
Double trueWindAngle = Math.abs(GameState.getWindDirection() - heading);
Double boatSpeedInKnots = PolarTable.getBoatSpeed(windSpeedKnots, trueWindAngle);
velocity = boatSpeedInKnots / ClientPacketParser.MS_TO_KNOTS * 1000;
Double metersCovered = velocity * secondsElapsed;
location = getGeoCoordinate(location, heading, metersCovered);
} else {
velocity = 0d;
}
}
@@ -136,13 +138,16 @@ public class Yacht {
}
public void adjustHeading(Double amount) {
Double newVal = heading + amount;
lastHeading = heading;
// TODO: 24/07/17 wmu16 - '%' in java does remainder, we need modulo. All this must be changed here, this is why we have neg values!
heading = (heading + amount) % 360.0;
heading = (double) Math.floorMod(newVal.longValue(), 360L);
}
public void tackGybe(Double windDirection) {
adjustHeading(-2 * ((heading - windDirection) % 360));
Double normalizedHeading = heading - GameState.windDirection;
normalizedHeading = (double) Math.floorMod(normalizedHeading.longValue(), 360);
adjustHeading(-2 * normalizedHeading);
}
public void toggleSailIn() {
@@ -150,7 +155,8 @@ public class Yacht {
}
public void turnUpwind() {
Double normalizedHeading = (heading - GameState.windDirection) % 360;
Double normalizedHeading = heading - GameState.windDirection;
normalizedHeading = (double) Math.floorMod(normalizedHeading.longValue(), 360);
if (normalizedHeading == 0) {
if (lastHeading < 180) {
adjustHeading(-TURN_STEP);
@@ -171,7 +177,8 @@ public class Yacht {
}
public void turnDownwind() {
Double normalizedHeading = (heading - GameState.windDirection) % 360;
Double normalizedHeading = heading - GameState.windDirection;
normalizedHeading = (double) Math.floorMod(normalizedHeading.longValue(), 360);
if (normalizedHeading == 0) {
if (lastHeading < 180) {
adjustHeading(TURN_STEP);
@@ -191,6 +198,11 @@ public class Yacht {
}
}
public void turnToVMG() {
// TODO: 25/07/17 wmu16 - Fix this so it grabs the optimal value from the optimal Polar
}
public String getBoatType() {
return boatType;
@@ -294,10 +306,14 @@ public class Yacht {
this.markRoundTime = markRoundingTime;
}
public double getVelocity() {
public double getVelocityMMS() {
return velocity;
}
public Double getVelocityKnots() {
return velocity / 1000 * ClientPacketParser.MS_TO_KNOTS;
}
public Long getTimeTillNext() {
return timeTillNext;
}
@@ -39,7 +39,6 @@ public class BoatLocationMessage extends Message {
* @param boatSpeed The boats speed
*/
public BoatLocationMessage(int sourceId, int sequenceNum, double latitude, double longitude, double heading, long boatSpeed){
boatSpeed /= 10;
messageVersionNumber = 1;
time = System.currentTimeMillis();
this.sourceId = sourceId;