mirror of
https://github.com/michaelrausch/Party-Parrots-At-Sea.git
synced 2026-05-09 06:18:44 +00:00
Merge remote-tracking branch 'origin/develop' into develop
This commit is contained in:
@@ -22,6 +22,7 @@ import javafx.scene.paint.Color;
|
||||
import javafx.scene.shape.Polygon;
|
||||
import javafx.scene.text.Text;
|
||||
import seng302.client.ClientPacketParser;
|
||||
import seng302.client.ClientState;
|
||||
import seng302.fxObjects.BoatGroup;
|
||||
import seng302.models.Colors;
|
||||
import seng302.models.Yacht;
|
||||
@@ -324,10 +325,25 @@ public class CanvasController {
|
||||
if (participantIDs.contains(boat.getSourceId())) {
|
||||
boat.setColour(Colors.getColor());
|
||||
BoatGroup boatGroup = new BoatGroup(boat, boat.getColour());
|
||||
boatGroups.add(boatGroup);
|
||||
if (boat.getSourceId().equals(Integer.parseInt(ClientState.getClientSourceId()))) {
|
||||
boatGroup.setAsPlayer();
|
||||
boatGroups.add(boatGroup);
|
||||
annotations.getChildren().add(boatGroup.getAnnotations());
|
||||
} else {
|
||||
//Move annotations and boat to bottom of group keeping player ontop.
|
||||
if (boatGroups.size() > 0) {
|
||||
boatGroups.add(0, boatGroup);
|
||||
} else {
|
||||
boatGroups.add(boatGroup);
|
||||
}
|
||||
if (annotations.getChildren().size() > 0) {
|
||||
annotations.getChildren().add(0, boatGroup.getAnnotations());
|
||||
} else {
|
||||
annotations.getChildren().add(boatGroup.getAnnotations());
|
||||
}
|
||||
}
|
||||
trails.getChildren().add(boatGroup.getTrail());
|
||||
wakes.getChildren().add(boatGroup.getWake());
|
||||
annotations.getChildren().add(boatGroup.getAnnotations());
|
||||
}
|
||||
}
|
||||
group.getChildren().addAll(trails);
|
||||
|
||||
@@ -156,7 +156,7 @@ public class LobbyController implements Initializable, Observer{
|
||||
|
||||
List<Integer> ids = new ArrayList<>(ClientState.getBoats().keySet());
|
||||
for (int i = 0; i < ids.size(); i++) {
|
||||
competitors.get(i).add(String.format("Player ID: %d", ids.get(i)));
|
||||
competitors.get(i).add(ClientState.getBoats().get(ids.get(i)).getBoatName());
|
||||
listViews.get(i).setItems(competitors.get(i));
|
||||
imageViews.get(i).setVisible(true);
|
||||
}
|
||||
|
||||
@@ -135,7 +135,11 @@ public class ImportantAnnotationController implements Initializable {
|
||||
boatEstTimeToNextMarkSelect.isSelected()));
|
||||
boatElapsedTimeSelect.setOnAction(
|
||||
event -> setAnnotation(Annotation.LEGTIME, boatElapsedTimeSelect.isSelected()));
|
||||
|
||||
// TODO: 26/07/17 cir27 - Create a more robust fix for this when the annotation for the game are decided upon.
|
||||
boatEstTimeToNextMarkSelect.setVisible(false);
|
||||
boatEstTimeToNextMarkSelect.setDisable(true);
|
||||
boatElapsedTimeSelect.setVisible(false);
|
||||
boatElapsedTimeSelect.setDisable(true);
|
||||
closeButton.setOnAction(event -> stage.close());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ public class BoatAnnotations extends Group{
|
||||
private Text velocityObject;
|
||||
private Text estTimeToNextMarkObject;
|
||||
private Text legTimeObject;
|
||||
|
||||
private boolean isPlayer = false;
|
||||
private Yacht boat;
|
||||
|
||||
BoatAnnotations (Yacht boat, Color theme) {
|
||||
@@ -56,12 +56,17 @@ public class BoatAnnotations extends Group{
|
||||
|
||||
velocityObject = getTextObject("0 m/s", theme);
|
||||
velocityObject.relocate(X_OFFSET_TEXT, Y_OFFSET_TEXT_INIT + Y_OFFSET_PER_TEXT * 2);
|
||||
velocityObject.setVisible(false);
|
||||
|
||||
estTimeToNextMarkObject = getTextObject("Next mark: ", theme);
|
||||
estTimeToNextMarkObject.relocate(X_OFFSET_TEXT, Y_OFFSET_TEXT_INIT + Y_OFFSET_PER_TEXT * 3);
|
||||
estTimeToNextMarkObject.setVisible(false);
|
||||
|
||||
legTimeObject = getTextObject("Last mark: -", theme);
|
||||
legTimeObject.relocate(X_OFFSET_TEXT, Y_OFFSET_TEXT_INIT + Y_OFFSET_PER_TEXT * 4);
|
||||
legTimeObject.setVisible(false);
|
||||
|
||||
this.setVisible(true, false, false, false);
|
||||
|
||||
super.getChildren().addAll(background, teamNameObject, velocityObject, estTimeToNextMarkObject, legTimeObject);
|
||||
}
|
||||
@@ -83,6 +88,8 @@ public class BoatAnnotations extends Group{
|
||||
}
|
||||
|
||||
void update () {
|
||||
teamNameObject.setText("Player: " + boat.getShortName());
|
||||
|
||||
velocityObject.setText(String.format(String.format("%.2f m/s", boat.getVelocityMMS())));
|
||||
|
||||
if (boat.getTimeTillNext() != null) {
|
||||
@@ -104,13 +111,19 @@ public class BoatAnnotations extends Group{
|
||||
}
|
||||
}
|
||||
|
||||
void setVisibile (boolean nameVisibility, boolean speedVisibility,
|
||||
void setVisible(boolean nameVisibility, boolean speedVisibility,
|
||||
boolean estTimeVisibility, boolean lastMarkVisibility) {
|
||||
int totalVisible = 0;
|
||||
|
||||
/*
|
||||
This is a temporary fix until the new annotation group is added along with the visualiser
|
||||
overhaul.
|
||||
*/
|
||||
totalVisible = updateVisibility(nameVisibility, teamNameObject, totalVisible);
|
||||
totalVisible = updateVisibility(speedVisibility, velocityObject, totalVisible);
|
||||
totalVisible = updateVisibility(estTimeVisibility, estTimeToNextMarkObject, totalVisible);
|
||||
totalVisible = updateVisibility(lastMarkVisibility, legTimeObject, totalVisible);
|
||||
if (isPlayer)
|
||||
totalVisible = updateVisibility(speedVisibility, velocityObject, totalVisible);
|
||||
// totalVisible = updateVisibility(estTimeVisibility, estTimeToNextMarkObject, totalVisible);
|
||||
// totalVisible = updateVisibility(lastMarkVisibility, legTimeObject, totalVisible);
|
||||
if (totalVisible != 0) {
|
||||
background.setVisible(true);
|
||||
background.setHeight(Math.abs(BACKGROUND_X) + TEXT_BUFFER + BACKGROUND_H_PER_TEXT * totalVisible);
|
||||
@@ -130,4 +143,12 @@ public class BoatAnnotations extends Group{
|
||||
}
|
||||
return totalVisible;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets these annotations to show more detailed info.
|
||||
*/
|
||||
public void setAsPlayer () {
|
||||
isPlayer = true;
|
||||
velocityObject.setVisible(true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import javafx.geometry.Point2D;
|
||||
import javafx.scene.CacheHint;
|
||||
import javafx.scene.Group;
|
||||
import javafx.scene.paint.Color;
|
||||
import javafx.scene.shape.Circle;
|
||||
import javafx.scene.shape.Line;
|
||||
import javafx.scene.shape.Polygon;
|
||||
import javafx.scene.transform.Rotate;
|
||||
@@ -48,8 +49,9 @@ public class BoatGroup extends Group {
|
||||
private Point2D lastPoint;
|
||||
private boolean destinationSet;
|
||||
private BoatAnnotations boatAnnotations;
|
||||
|
||||
private Boolean isSelected = true; //All boats are initialised as selected
|
||||
private Color color;
|
||||
private Boolean isSelected = true; //All boats are initialised as selected\
|
||||
private boolean isPlayer = false;
|
||||
|
||||
/**
|
||||
* Creates a BoatGroup with the default triangular boat polygon.
|
||||
@@ -88,20 +90,21 @@ public class BoatGroup extends Group {
|
||||
* polygon.
|
||||
*/
|
||||
private void initChildren(Color color, double... points) {
|
||||
this.color = color;
|
||||
boatPoly = new Polygon(points);
|
||||
boatPoly.setFill(color);
|
||||
boatPoly.setFill(this.color);
|
||||
boatPoly.setOnMouseEntered(event -> {
|
||||
boatPoly.setFill(Color.FLORALWHITE);
|
||||
boatPoly.setStroke(Color.RED);
|
||||
});
|
||||
boatPoly.setOnMouseExited(event -> {
|
||||
boatPoly.setFill(color);
|
||||
boatPoly.setFill(this.color);
|
||||
boatPoly.setStroke(Color.BLACK);
|
||||
});
|
||||
boatPoly.setOnMouseClicked(event -> setIsSelected(!isSelected));
|
||||
boatPoly.setCache(true);
|
||||
boatPoly.setCacheHint(CacheHint.SPEED);
|
||||
boatAnnotations = new BoatAnnotations(boat, color);
|
||||
boatAnnotations = new BoatAnnotations(boat, this.color);
|
||||
|
||||
leftLayLine = new Line();
|
||||
rightLayline = new Line();
|
||||
@@ -171,29 +174,28 @@ public class BoatGroup extends Group {
|
||||
if (framesToMove <= 0) {
|
||||
isStopped = true;
|
||||
}
|
||||
if (distanceTravelled > 70 && isPlayer) {
|
||||
distanceTravelled = 0d;
|
||||
|
||||
// if (distanceTravelled > 70) {
|
||||
// distanceTravelled = 0d;
|
||||
//
|
||||
// if (lastPoint != null) {
|
||||
// Line l = new Line(
|
||||
// lastPoint.getX(),
|
||||
// lastPoint.getY(),
|
||||
// boatPoly.getLayoutX(),
|
||||
// boatPoly.getLayoutY()
|
||||
// );
|
||||
// l.getStrokeDashArray().setAll(3d, 7d);
|
||||
// l.setStroke(boat.getColour());
|
||||
// l.setCache(true);
|
||||
// l.setCacheHint(CacheHint.SPEED);
|
||||
// lineGroup.getChildren().add(l);
|
||||
// }
|
||||
//
|
||||
// if (destinationSet) {
|
||||
// lastPoint = new Point2D(boatPoly.getLayoutX(), boatPoly.getLayoutY());
|
||||
// }
|
||||
// }
|
||||
wake.updatePosition();
|
||||
if (lastPoint != null) {
|
||||
Line l = new Line(
|
||||
lastPoint.getX(),
|
||||
lastPoint.getY(),
|
||||
boatPoly.getLayoutX(),
|
||||
boatPoly.getLayoutY()
|
||||
);
|
||||
l.getStrokeDashArray().setAll(3d, 7d);
|
||||
l.setStroke(boat.getColour());
|
||||
l.setCache(true);
|
||||
l.setCacheHint(CacheHint.SPEED);
|
||||
lineGroup.getChildren().add(l);
|
||||
}
|
||||
|
||||
if (destinationSet) {
|
||||
lastPoint = new Point2D(boatPoly.getLayoutX(), boatPoly.getLayoutY());
|
||||
}
|
||||
}
|
||||
// wake.updatePosition();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -220,6 +222,7 @@ public class BoatGroup extends Group {
|
||||
destinationSet = true;
|
||||
|
||||
rotateTo(rotation);
|
||||
// wake.rotate(rotation);
|
||||
wake.setRotation(rotation, groundSpeed);
|
||||
boat.setVelocity(groundSpeed);
|
||||
lastTimeValid = timeValid;
|
||||
@@ -276,7 +279,7 @@ public class BoatGroup extends Group {
|
||||
}
|
||||
|
||||
public void setVisibility (boolean teamName, boolean velocity, boolean estTime, boolean legTime, boolean trail, boolean wake) {
|
||||
boatAnnotations.setVisibile(teamName, velocity, estTime, legTime);
|
||||
boatAnnotations.setVisible(teamName, velocity, estTime, legTime);
|
||||
this.wake.setVisible(wake);
|
||||
this.lineGroup.setVisible(trail);
|
||||
}
|
||||
@@ -349,4 +352,18 @@ public class BoatGroup extends Group {
|
||||
return boat.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets this boat to appear highlighted
|
||||
*/
|
||||
public void setAsPlayer() {
|
||||
boatPoly.getPoints().setAll(
|
||||
-BOAT_WIDTH / 1.75, BOAT_HEIGHT / 1.75,
|
||||
0.0, -BOAT_HEIGHT / 1.75,
|
||||
BOAT_WIDTH / 1.75, BOAT_HEIGHT / 1.75
|
||||
);
|
||||
boatPoly.setStroke(Color.BLACK);
|
||||
boatPoly.setStrokeWidth(3);
|
||||
boatAnnotations.setAsPlayer();
|
||||
isPlayer = true;
|
||||
}
|
||||
}
|
||||
@@ -55,29 +55,29 @@ public class Wake extends Group {
|
||||
}
|
||||
|
||||
void setRotation (double rotation, double velocity) {
|
||||
if (Math.abs(rotations[0] - rotation) > 20) {
|
||||
// if (Math.abs(rotations[0] - rotation) > 20) {
|
||||
rotate(rotation);
|
||||
} else {
|
||||
rotations[0] = rotation;
|
||||
((Rotate) arcs[0].getTransforms().get(0)).setAngle(rotation);
|
||||
for (int i = 1; i < numWakes; i++) {
|
||||
double wakeSeparationRad = Math.toRadians(rotations[i - 1] - rotations[i]);
|
||||
double shortestDistance = Math.atan2(
|
||||
Math.sin(wakeSeparationRad),
|
||||
Math.cos(wakeSeparationRad)
|
||||
);
|
||||
double distDeg = Math.toDegrees(shortestDistance);
|
||||
if (rotationalVelocities[i - 1] < 0.01 && rotationalVelocities[i - 1] > -0.01) {
|
||||
rotationalVelocities[i] = distDeg / UNIFICATION_SPEED * 2 * Math.log(Math.abs(distDeg) + 1) / Math.log(MAX_DIFF / numWakes);
|
||||
|
||||
} else {
|
||||
if (distDeg < (MAX_DIFF / numWakes)) {
|
||||
rotationalVelocities[i] = distDeg / UNIFICATION_SPEED * Math.log(Math.abs(distDeg) + 1) / Math.log(MAX_DIFF / numWakes);
|
||||
} else
|
||||
rotationalVelocities[i] = rotationalVelocities[i - 1];
|
||||
}
|
||||
}
|
||||
}
|
||||
// } else {
|
||||
// rotations[0] = rotation;
|
||||
// ((Rotate) arcs[0].getTransforms().get(0)).setAngle(rotation);
|
||||
// for (int i = 1; i < numWakes; i++) {
|
||||
// double wakeSeparationRad = Math.toRadians(rotations[i - 1] - rotations[i]);
|
||||
// double shortestDistance = Math.atan2(
|
||||
// Math.sin(wakeSeparationRad),
|
||||
// Math.cos(wakeSeparationRad)
|
||||
// );
|
||||
// double distDeg = Math.toDegrees(shortestDistance);
|
||||
// if (rotationalVelocities[i - 1] < 0.01 && rotationalVelocities[i - 1] > -0.01) {
|
||||
// rotationalVelocities[i] = distDeg / UNIFICATION_SPEED * 2 * Math.log(Math.abs(distDeg) + 1) / Math.log(MAX_DIFF / numWakes);
|
||||
//
|
||||
// } else {
|
||||
// if (distDeg < (MAX_DIFF / numWakes)) {
|
||||
// rotationalVelocities[i] = distDeg / UNIFICATION_SPEED * Math.log(Math.abs(distDeg) + 1) / Math.log(MAX_DIFF / numWakes);
|
||||
// } else
|
||||
// rotationalVelocities[i] = rotationalVelocities[i - 1];
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
double rad = (14 / numWakes) + velocity;
|
||||
for (Arc arc : arcs) {
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
package seng302.gameServer;
|
||||
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.OutputStream;
|
||||
import java.net.Socket;
|
||||
import java.net.SocketException;
|
||||
@@ -12,6 +15,9 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Observable;
|
||||
import java.util.Observer;
|
||||
import java.util.Random;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.zip.CRC32;
|
||||
import java.util.zip.Checksum;
|
||||
|
||||
@@ -64,17 +70,42 @@ public class ServerToClientThread implements Runnable, Observer {
|
||||
|
||||
public ServerToClientThread(Socket socket) {
|
||||
this.socket = socket;
|
||||
BufferedReader fn;
|
||||
String fName = "";
|
||||
BufferedReader ln;
|
||||
String lName = "";
|
||||
try {
|
||||
is = socket.getInputStream();
|
||||
os = socket.getOutputStream();
|
||||
fn = new BufferedReader(
|
||||
new InputStreamReader(
|
||||
ServerToClientThread.class.getResourceAsStream(
|
||||
"/server_config/CSV_Database_of_First_Names.csv"
|
||||
)
|
||||
)
|
||||
);
|
||||
List<String> all = fn.lines().collect(Collectors.toList());
|
||||
fName = all.get(ThreadLocalRandom.current().nextInt(0, all.size()));
|
||||
ln = new BufferedReader(
|
||||
new InputStreamReader(
|
||||
ServerToClientThread.class.getResourceAsStream(
|
||||
"/server_config/CSV_Database_of_Last_Names.csv"
|
||||
)
|
||||
)
|
||||
);
|
||||
all = ln.lines().collect(Collectors.toList());
|
||||
lName = all.get(ThreadLocalRandom.current().nextInt(0, all.size()));
|
||||
} catch (IOException e) {
|
||||
System.out.println("IO error in server thread upon grabbing streams");
|
||||
e.printStackTrace();
|
||||
}
|
||||
//Attempt threeway handshake with connection
|
||||
sourceId = GameState.getUniquePlayerID();
|
||||
if (threeWayHandshake(sourceId)) {
|
||||
serverLog("Successful handshake. Client allocated id: " + sourceId, 1);
|
||||
Yacht yacht = new Yacht("Yacht", sourceId, sourceId.toString(), "Kapa", "Kappa", "NZ");
|
||||
Yacht yacht = new Yacht(
|
||||
"Yacht", sourceId, sourceId.toString(), fName, fName + " " + lName, "NZ"
|
||||
);
|
||||
// Yacht yacht = new Yacht("Kappa", "Kap", new GeoPoint(57.6708220, 11.8321340), 90.0);
|
||||
GameState.addYacht(sourceId, yacht);
|
||||
GameState.addPlayer(new Player(socket, yacht));
|
||||
@@ -165,7 +196,6 @@ public class ServerToClientThread implements Runnable, Observer {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void sendSetupMessages() {
|
||||
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user