mirror of
https://github.com/michaelrausch/Party-Parrots-At-Sea.git
synced 2026-05-09 06:18:44 +00:00
Began fixing conflicts with LobbyController
#bug
This commit is contained in:
@@ -0,0 +1,161 @@
|
|||||||
|
//package seng302.controllers;
|
||||||
|
//
|
||||||
|
//import java.net.Inet4Address;
|
||||||
|
//import java.net.NetworkInterface;
|
||||||
|
//import java.util.Enumeration;
|
||||||
|
//import javafx.fxml.FXML;
|
||||||
|
//import javafx.fxml.FXMLLoader;
|
||||||
|
//import javafx.scene.control.Alert;
|
||||||
|
//import javafx.scene.control.Alert.AlertType;
|
||||||
|
//import javafx.scene.control.TextField;
|
||||||
|
//import javafx.scene.layout.AnchorPane;
|
||||||
|
//import javafx.scene.layout.GridPane;
|
||||||
|
//import javafx.scene.layout.Pane;
|
||||||
|
//import seng302.client.ClientState;
|
||||||
|
//import seng302.client.ClientToServerThread;
|
||||||
|
//import seng302.gameServer.GameState;
|
||||||
|
//import seng302.gameServer.MainServerThread;
|
||||||
|
//
|
||||||
|
//import java.io.IOException;
|
||||||
|
//import java.net.InetAddress;
|
||||||
|
//import java.net.UnknownHostException;
|
||||||
|
//
|
||||||
|
///**
|
||||||
|
// * A Class describing the actions of the start screen controller
|
||||||
|
// * Created by wmu16 on 10/07/17.
|
||||||
|
// */
|
||||||
|
//public class StartScreenController {
|
||||||
|
//
|
||||||
|
// @FXML
|
||||||
|
// private TextField ipTextField;
|
||||||
|
// @FXML
|
||||||
|
// private TextField portTextField;
|
||||||
|
// @FXML
|
||||||
|
// private GridPane startScreen2;
|
||||||
|
//
|
||||||
|
// private Controller controller;
|
||||||
|
//
|
||||||
|
// /**
|
||||||
|
// * Loads the fxml content into the parent pane
|
||||||
|
// * @param jfxUrl
|
||||||
|
// * @return the controller of the fxml
|
||||||
|
// */
|
||||||
|
// private Object setContentPane(String jfxUrl) {
|
||||||
|
// try {
|
||||||
|
// AnchorPane contentPane = (AnchorPane) startScreen2.getParent();
|
||||||
|
// contentPane.getChildren().removeAll();
|
||||||
|
// contentPane.getChildren().clear();
|
||||||
|
// contentPane.getStylesheets().add(getClass().getResource("/css/master.css").toString());
|
||||||
|
// FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource(jfxUrl));
|
||||||
|
// contentPane.getChildren().addAll((Pane) fxmlLoader.load());
|
||||||
|
//
|
||||||
|
// return fxmlLoader.getController();
|
||||||
|
// } catch (javafx.fxml.LoadException e) {
|
||||||
|
// e.printStackTrace();
|
||||||
|
// } catch (IOException e) {
|
||||||
|
// e.printStackTrace();
|
||||||
|
// }
|
||||||
|
// return null;
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// /**
|
||||||
|
// * ATTEMPTS TO:
|
||||||
|
// * Sets up a new game state with your IP address as designated as the host.
|
||||||
|
// * Starts a thread to listen for incoming connections.
|
||||||
|
// * Starts a client to server thread and connects to own ip.
|
||||||
|
// * Switches to the lobby screen
|
||||||
|
// */
|
||||||
|
// @FXML
|
||||||
|
// public void hostButtonPressed() {
|
||||||
|
// try {
|
||||||
|
// // get the lobby controller so that we can pass the game server thread to it
|
||||||
|
// new GameState(getLocalHostIp());
|
||||||
|
// MainServerThread mainServerThread = new MainServerThread();
|
||||||
|
// ClientState.setHost(true);
|
||||||
|
// // host will connect and handshake to itself after setting up the server
|
||||||
|
// // TODO: 24/07/17 wmu16 - Make port number some static global type constant?
|
||||||
|
// ClientToServerThread clientToServerThread = new ClientToServerThread(ClientState.getHostIp(), 4942);
|
||||||
|
// ClientState.setConnectedToHost(true);
|
||||||
|
// controller.setClientToServerThread(clientToServerThread);
|
||||||
|
// LobbyController lobbyController = (LobbyController) setContentPane("/views/LobbyView.fxml");
|
||||||
|
// lobbyController.setMainServerThread(mainServerThread);
|
||||||
|
// } catch (Exception e) {
|
||||||
|
// Alert alert = new Alert(AlertType.ERROR);
|
||||||
|
// alert.setHeaderText("Cannot host");
|
||||||
|
// alert.setContentText("Oops, failed to host, try to restart.");
|
||||||
|
// alert.showAndWait();
|
||||||
|
// e.printStackTrace();
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// /**
|
||||||
|
// * ATTEMPTS TO:
|
||||||
|
// * Connect to an ip address and port using the ip and port specified on start screen.
|
||||||
|
// * Starts a Client To Server Thread to maintain connection to host.
|
||||||
|
// * Switch view to lobby view.
|
||||||
|
// */
|
||||||
|
// @FXML
|
||||||
|
// public void connectButtonPressed() {
|
||||||
|
// // TODO: 10/07/17 wmu16 - Finish function
|
||||||
|
// try {
|
||||||
|
// String ipAddress = ipTextField.getText().trim().toLowerCase();
|
||||||
|
// Integer port = Integer.valueOf(portTextField.getText().trim());
|
||||||
|
//
|
||||||
|
// ClientToServerThread clientToServerThread = new ClientToServerThread(ipAddress, port);
|
||||||
|
// ClientState.setHost(false);
|
||||||
|
// ClientState.setConnectedToHost(true);
|
||||||
|
//
|
||||||
|
// controller.setClientToServerThread(clientToServerThread);
|
||||||
|
// setContentPane("/views/LobbyView.fxml");
|
||||||
|
// } catch (Exception e) {
|
||||||
|
// Alert alert = new Alert(AlertType.ERROR);
|
||||||
|
// alert.setHeaderText("Cannot reach the host");
|
||||||
|
// alert.setContentText("Please check your host IP address.");
|
||||||
|
// alert.showAndWait();
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// public void setController(Controller controller) {
|
||||||
|
// this.controller = controller;
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// /**
|
||||||
|
// * Gets the local host ip address and sets this ip to ClientState.
|
||||||
|
// * Only runs by the host.
|
||||||
|
// *
|
||||||
|
// * @return the localhost ip address
|
||||||
|
// */
|
||||||
|
// private String getLocalHostIp() {
|
||||||
|
// String ipAddress = null;
|
||||||
|
// try {
|
||||||
|
// Enumeration<NetworkInterface> e = NetworkInterface.getNetworkInterfaces();
|
||||||
|
// while (e.hasMoreElements()) {
|
||||||
|
// NetworkInterface ni = e.nextElement();
|
||||||
|
// if (ni.isLoopback())
|
||||||
|
// continue;
|
||||||
|
// if(ni.isPointToPoint())
|
||||||
|
// continue;
|
||||||
|
// if(ni.isVirtual())
|
||||||
|
// continue;
|
||||||
|
//
|
||||||
|
// Enumeration<InetAddress> addresses = ni.getInetAddresses();
|
||||||
|
// while(addresses.hasMoreElements()) {
|
||||||
|
// InetAddress address = addresses.nextElement();
|
||||||
|
// if(address instanceof Inet4Address) { // skip all ipv6
|
||||||
|
// ipAddress = address.getHostAddress();
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// } catch (Exception e) {
|
||||||
|
// e.printStackTrace();
|
||||||
|
// }
|
||||||
|
// if (ipAddress == null) {
|
||||||
|
// System.out.println("[HOST] Cannot obtain local host ip address.");
|
||||||
|
// }
|
||||||
|
// ClientState.setHostIp(ipAddress);
|
||||||
|
// return ipAddress;
|
||||||
|
// }
|
||||||
|
//}
|
||||||
@@ -108,7 +108,7 @@ public class GameState {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static Double getWindSpeedKnots() {
|
public static Double getWindSpeedKnots() {
|
||||||
return windSpeed / 1000 * ClientPacketParser.MS_TO_KNOTS;
|
return windSpeed / 1000 * 1.943844492; // TODO: 26/07/17 cir27 - remove magic numbers
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Map<Integer, Yacht> getYachts() {
|
public static Map<Integer, Yacht> getYachts() {
|
||||||
|
|||||||
@@ -1,21 +1,17 @@
|
|||||||
package seng302.model;
|
package seng302.model;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
import javafx.beans.property.ReadOnlyDoubleProperty;
|
import javafx.beans.property.ReadOnlyDoubleProperty;
|
||||||
import javafx.beans.property.ReadOnlyDoubleWrapper;
|
import javafx.beans.property.ReadOnlyDoubleWrapper;
|
||||||
import javafx.beans.property.ReadOnlyLongProperty;
|
import javafx.beans.property.ReadOnlyLongProperty;
|
||||||
import javafx.beans.property.ReadOnlyLongWrapper;
|
import javafx.beans.property.ReadOnlyLongWrapper;
|
||||||
|
import javafx.scene.control.ListView;
|
||||||
import javafx.scene.paint.Color;
|
import javafx.scene.paint.Color;
|
||||||
import javafx.scene.paint.Paint;
|
|
||||||
import seng302.model.mark.Mark;
|
import seng302.model.mark.Mark;
|
||||||
import static seng302.utilities.GeoUtility.getGeoCoordinate;
|
import static seng302.utilities.GeoUtility.getGeoCoordinate;
|
||||||
|
|
||||||
import java.text.DateFormat;
|
import java.text.DateFormat;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.ArrayList;
|
|
||||||
|
|
||||||
import javafx.scene.paint.Color;
|
|
||||||
import seng302.client.ClientPacketParser;
|
|
||||||
import seng302.controllers.RaceViewController;
|
|
||||||
import seng302.gameServer.GameState;
|
import seng302.gameServer.GameState;
|
||||||
import seng302.utilities.GeoPoint;
|
import seng302.utilities.GeoPoint;
|
||||||
|
|
||||||
@@ -26,6 +22,12 @@ import seng302.utilities.GeoPoint;
|
|||||||
* also done outside Boat class because some old variables are not used anymore.
|
* also done outside Boat class because some old variables are not used anymore.
|
||||||
*/
|
*/
|
||||||
public class Yacht {
|
public class Yacht {
|
||||||
|
|
||||||
|
@FunctionalInterface
|
||||||
|
public interface YachtLocationListener {
|
||||||
|
void notifyLocation(Yacht yacht, double lat, double lon, double heading, double velocity);
|
||||||
|
}
|
||||||
|
|
||||||
//BOTH AFAIK
|
//BOTH AFAIK
|
||||||
private String boatType;
|
private String boatType;
|
||||||
private Integer sourceId;
|
private Integer sourceId;
|
||||||
@@ -52,10 +54,13 @@ public class Yacht {
|
|||||||
private Double velocity;
|
private Double velocity;
|
||||||
|
|
||||||
//CLIENT SIDE
|
//CLIENT SIDE
|
||||||
|
private List<YachtLocationListener> locationListeners = new ArrayList<>();
|
||||||
private ReadOnlyDoubleWrapper velocityProperty = new ReadOnlyDoubleWrapper();
|
private ReadOnlyDoubleWrapper velocityProperty = new ReadOnlyDoubleWrapper();
|
||||||
private ReadOnlyLongWrapper timeTillNextProperty = new ReadOnlyLongWrapper();
|
private ReadOnlyLongWrapper timeTillNextProperty = new ReadOnlyLongWrapper();
|
||||||
private ReadOnlyLongWrapper timeSinceLastMarkProperty = new ReadOnlyLongWrapper();
|
private ReadOnlyLongWrapper timeSinceLastMarkProperty = new ReadOnlyLongWrapper();
|
||||||
private ReadOnlyDoubleProperty headingProperty = new ReadOnlyDoubleWrapper();
|
// private ReadOnlyDoubleWrapper headingProperty = new ReadOnlyDoubleWrapper();
|
||||||
|
// private ReadOnlyDoubleWrapper latitudeProperty = new ReadOnlyDoubleWrapper();
|
||||||
|
// private ReadOnlyDoubleWrapper longitudeProperty = new ReadOnlyDoubleWrapper();
|
||||||
private Mark lastMarkRounded;
|
private Mark lastMarkRounded;
|
||||||
private Mark nextMark;
|
private Mark nextMark;
|
||||||
private Integer positionInt = 0;
|
private Integer positionInt = 0;
|
||||||
@@ -128,7 +133,7 @@ public class Yacht {
|
|||||||
Double windSpeedKnots = GameState.getWindSpeedKnots();
|
Double windSpeedKnots = GameState.getWindSpeedKnots();
|
||||||
Double trueWindAngle = Math.abs(GameState.getWindDirection() - heading);
|
Double trueWindAngle = Math.abs(GameState.getWindDirection() - heading);
|
||||||
Double boatSpeedInKnots = PolarTable.getBoatSpeed(windSpeedKnots, trueWindAngle);
|
Double boatSpeedInKnots = PolarTable.getBoatSpeed(windSpeedKnots, trueWindAngle);
|
||||||
velocity = boatSpeedInKnots / ClientPacketParser.MS_TO_KNOTS * 1000;
|
velocity = boatSpeedInKnots / 1.943844492 * 1000; // TODO: 26/07/17 cir27 - Remove magic number
|
||||||
Double metersCovered = velocity * secondsElapsed;
|
Double metersCovered = velocity * secondsElapsed;
|
||||||
location = getGeoCoordinate(location, heading, metersCovered);
|
location = getGeoCoordinate(location, heading, metersCovered);
|
||||||
} else {
|
} else {
|
||||||
@@ -269,7 +274,7 @@ public class Yacht {
|
|||||||
this.positionInt = position;
|
this.positionInt = position;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setVelocityProperty(double velocity) {
|
public void updateVelocityProperty(double velocity) {
|
||||||
this.velocityProperty.set(velocity);
|
this.velocityProperty.set(velocity);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -287,9 +292,10 @@ public class Yacht {
|
|||||||
|
|
||||||
public ReadOnlyLongProperty timeTillNextProperty() {
|
public ReadOnlyLongProperty timeTillNextProperty() {
|
||||||
return timeTillNextProperty.getReadOnlyProperty();
|
return timeTillNextProperty.getReadOnlyProperty();
|
||||||
|
}
|
||||||
|
|
||||||
public Double getVelocityKnots() {
|
public Double getVelocityKnots() {
|
||||||
return velocity / 1000 * ClientPacketParser.MS_TO_KNOTS;
|
return velocity / 1000 * 1.943844492; // TODO: 26/07/17 cir27 - remove magic number
|
||||||
}
|
}
|
||||||
|
|
||||||
public Long getTimeTillNext() {
|
public Long getTimeTillNext() {
|
||||||
@@ -361,10 +367,6 @@ public class Yacht {
|
|||||||
return timeSinceLastMarkProperty.getReadOnlyProperty();
|
return timeSinceLastMarkProperty.getReadOnlyProperty();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Long getTimeTillNext() {
|
|
||||||
return timeTillNext;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setTimeTillNext(Long timeTillNext) {
|
public void setTimeTillNext(Long timeTillNext) {
|
||||||
this.timeTillNext = timeTillNext;
|
this.timeTillNext = timeTillNext;
|
||||||
}
|
}
|
||||||
@@ -386,4 +388,43 @@ public class Yacht {
|
|||||||
public void setVelocity(Double velocity) {
|
public void setVelocity(Double velocity) {
|
||||||
this.velocity = velocity;
|
this.velocity = velocity;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// public void updateLatitudeProperty (Double lat) {
|
||||||
|
// latitudeProperty.set(lat);
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// public void updateLongitudeProperty (double lon) {
|
||||||
|
// longitudeProperty.set(lon);
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// public void updateHeadingProperty (double heading) {
|
||||||
|
// headingProperty.set(heading);
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// public ReadOnlyDoubleProperty latitudeProperty () {
|
||||||
|
// return latitudeProperty.getReadOnlyProperty();
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// public ReadOnlyDoubleProperty longitudeProperty () {
|
||||||
|
// return longitudeProperty.getReadOnlyProperty();
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// public ReadOnlyDoubleProperty headingProperty () {
|
||||||
|
// return headingProperty;
|
||||||
|
// }
|
||||||
|
|
||||||
|
public void updateLocation (double lat, double lon, double heading, double velocity) {
|
||||||
|
this.lat = lat;
|
||||||
|
this.lon = lon;
|
||||||
|
this.heading = heading;
|
||||||
|
this.velocity = velocity;
|
||||||
|
updateVelocityProperty(velocity);
|
||||||
|
for (YachtLocationListener yll : locationListeners) {
|
||||||
|
yll.notifyLocation(this, lat, lon, heading, velocity);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addLocationListener (YachtLocationListener listener) {
|
||||||
|
locationListeners.add(listener);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -172,6 +172,7 @@ public class GameClient {
|
|||||||
);
|
);
|
||||||
lobbyList.clear();
|
lobbyList.clear();
|
||||||
allBoatsMap.forEach((id, boat) -> lobbyList.add(id.toString() + boat.getBoatName()));
|
allBoatsMap.forEach((id, boat) -> lobbyList.add(id.toString() + boat.getBoatName()));
|
||||||
|
allBoatsMap.forEach((i, b) -> System.out.println(b.getBoatName()));
|
||||||
startRaceIfAllDataReceived();
|
startRaceIfAllDataReceived();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@@ -206,10 +207,8 @@ public class GameClient {
|
|||||||
if (positionData.getType() == DeviceType.YACHT_TYPE) {
|
if (positionData.getType() == DeviceType.YACHT_TYPE) {
|
||||||
if (allXMLReceived() && allBoatsMap.containsKey(positionData.getDeviceId())) {
|
if (allXMLReceived() && allBoatsMap.containsKey(positionData.getDeviceId())) {
|
||||||
Yacht yacht = allBoatsMap.get(positionData.getDeviceId());
|
Yacht yacht = allBoatsMap.get(positionData.getDeviceId());
|
||||||
yacht.setVelocityProperty(positionData.getGroundSpeed());
|
yacht.updateLocation(positionData.getLat(),
|
||||||
yacht.setLat(positionData.getLat());
|
positionData.getLon(), positionData.getHeading(), positionData.getGroundSpeed());
|
||||||
yacht.setLon(positionData.getLon());
|
|
||||||
yacht.setHeading(positionData.getHeading());
|
|
||||||
}
|
}
|
||||||
} else if (positionData.getType() == DeviceType.MARK_TYPE) {
|
} else if (positionData.getType() == DeviceType.MARK_TYPE) {
|
||||||
Mark mark = courseData.getCompoundMarks().get(positionData.getDeviceId());
|
Mark mark = courseData.getCompoundMarks().get(positionData.getDeviceId());
|
||||||
|
|||||||
@@ -262,8 +262,15 @@ public class GameView extends Pane {
|
|||||||
BoatObject newObject;
|
BoatObject newObject;
|
||||||
for (Yacht yacht : yachts) {
|
for (Yacht yacht : yachts) {
|
||||||
newObject = new BoatObject();
|
newObject = new BoatObject();
|
||||||
// newObject.bindBoat(boat);
|
|
||||||
newObject.setFill(Colors.getColor());
|
newObject.setFill(Colors.getColor());
|
||||||
|
boatObjects.put(yacht, newObject);
|
||||||
|
yacht.addLocationListener((boat, lat, lon, heading, velocity) ->{
|
||||||
|
BoatObject bo = boatObjects.get(boat);
|
||||||
|
Point2D p2d = findScaledXY(lat, lon);
|
||||||
|
bo.setLayoutX(p2d.getX());
|
||||||
|
bo.setLayoutY(p2d.getY());
|
||||||
|
// bo.setTrajectory(heading, velocity * (metersPerPixelX + metersPerPixelY) / 2);
|
||||||
|
});
|
||||||
createAnnotationBox(yacht);
|
createAnnotationBox(yacht);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -88,7 +88,6 @@ public class LobbyController implements Initializable {
|
|||||||
private static ObservableList<String> seventhCompetitor = FXCollections.observableArrayList();
|
private static ObservableList<String> seventhCompetitor = FXCollections.observableArrayList();
|
||||||
private static ObservableList<String> eighthCompetitor = FXCollections.observableArrayList();
|
private static ObservableList<String> eighthCompetitor = FXCollections.observableArrayList();
|
||||||
// private ClientStateQueryingRunnable clientStateQueryingRunnable;
|
// private ClientStateQueryingRunnable clientStateQueryingRunnable;
|
||||||
private ClientStateQueryingRunnable clientStateQueryingRunnable;
|
|
||||||
private static List<ImageView> imageViews;
|
private static List<ImageView> imageViews;
|
||||||
private static List<ListView> listViews;
|
private static List<ListView> listViews;
|
||||||
|
|
||||||
@@ -233,12 +232,12 @@ public class LobbyController implements Initializable {
|
|||||||
// }
|
// }
|
||||||
// });
|
// });
|
||||||
// thread.start();
|
// thread.start();
|
||||||
// }
|
}
|
||||||
|
|
||||||
private void initialiseImageView() {
|
private void initialiseImageView() {
|
||||||
for (int i = 0; i < MAX_NUM_PLAYERS; i++) {
|
// for (int i = 0; i < MAX_NUM_PLAYERS; i++) {
|
||||||
imageViews.get(i).setImage(new Image(getClass().getResourceAsStream("/pics/sail.png")));
|
// imageViews.get(i).setImage(new Image(getClass().getResourceAsStream("/pics/sail.png")));
|
||||||
}
|
// }
|
||||||
// Image image1 = new Image(getClass().getResourceAsStream("/pics/sail.png"));
|
// Image image1 = new Image(getClass().getResourceAsStream("/pics/sail.png"));
|
||||||
// firstImageView.setImage(image1);
|
// firstImageView.setImage(image1);
|
||||||
// Image image2 = new Image(getClass().getResourceAsStream("/pics/sail.png"));
|
// Image image2 = new Image(getClass().getResourceAsStream("/pics/sail.png"));
|
||||||
|
|||||||
Reference in New Issue
Block a user