Merge branch 'story_64_sails' into 'master'

Story 64 sails



See merge request !29
main
Joseph Gardner 8 years ago
commit 0490237c0c

@ -87,7 +87,6 @@ public class Event {
//Read XML files.
try {
this.raceXML = RaceXMLCreator.alterRaceToWind(raceXMLFile, 90);
//this.raceXML = XMLReader.readXMLFileToString(raceXMLFile, StandardCharsets.UTF_8);
this.boatXML = XMLReader.readXMLFileToString(boatsXMLFile, StandardCharsets.UTF_8);
this.regattaXML = XMLReader.readXMLFileToString(regattaXMLFile, StandardCharsets.UTF_8);

@ -305,7 +305,6 @@ public class MockRace extends Race {
}
/**
* Calculates the distance a boat has travelled and updates its current position according to this value.
*
@ -318,7 +317,7 @@ public class MockRace extends Race {
//Checks if the current boat has finished the race or not.
boolean finish = this.isLastLeg(boat.getCurrentLeg());
if (!finish && totalElapsedMilliseconds >= updatePeriodMilliseconds) {
if (!finish && totalElapsedMilliseconds >= updatePeriodMilliseconds && boat.isSailsOut()) {
checkPosition(boat, totalElapsedMilliseconds);
@ -344,9 +343,12 @@ public class MockRace extends Race {
newOptimalVMG(boat);
}
this.updateEstimatedTime(boat);
} else {
boat.setCurrentSpeed(0);
}
this.updateEstimatedTime(boat);
}
private void newOptimalVMG(MockBoat boat) {
@ -709,4 +711,4 @@ public class MockRace extends Race {
public List<CompoundMark> getCompoundMarks() {
return compoundMarks;
}
}
}

@ -185,4 +185,4 @@ public class RaceLogic implements RunnableWithFramePeriod, Observer {
// else if(e.getBearing().degrees() > 270) System.out.println("Port");
// else System.out.println("Behind");
}
}
}

@ -33,6 +33,8 @@ public class CommandFactory {
case TACK_GYBE: return new TackGybeCommand(race, boat);
case UPWIND: return new WindCommand(race, boat, true);
case DOWNWIND: return new WindCommand(race, boat, false);
case SAILS_OUT: return new SailsCommand(race, boat, true);
case SAILS_IN: return new SailsCommand(race, boat, false);
default: throw new CommandConstructionException("Could not create command for BoatAction: " + action + ". Unknown BoatAction.");
}

@ -0,0 +1,21 @@
package mock.model.commandFactory;
import mock.model.MockBoat;
import mock.model.MockRace;
public class SailsCommand implements Command {
private MockRace race;
private MockBoat boat;
private boolean sailsOut;
public SailsCommand(MockRace race, MockBoat boat, Boolean sailsOut) {
this.race = race;
this.boat = boat;
this.sailsOut = sailsOut;
}
@Override
public void execute() {
this.boat.setSailsOut(this.sailsOut);
}
}

@ -6,12 +6,14 @@ import network.Exceptions.InvalidMessageTypeException;
import network.MessageDecoders.*;
import network.Messages.*;
import network.Messages.Enums.MessageType;
import static network.Utils.ByteConverter.*;
import java.nio.ByteBuffer;
import java.util.Arrays;
import java.util.zip.CRC32;
import static network.Utils.ByteConverter.bytesToInt;
import static network.Utils.ByteConverter.bytesToLong;
/**
* This class can be used to decode/convert a byte array into a messageBody object, descended from AC35Data.
*/

@ -1,13 +1,13 @@
package network;
import network.Messages.Enums.MessageType;
import static network.Utils.ByteConverter.*;
import java.nio.ByteBuffer;
import java.util.zip.CRC32;
import static network.Utils.ByteConverter.*;
/**
* This class can be used to encode/convert a byte array message body, plus header data into a byte array containing the entire message, ready to send.

@ -14,9 +14,7 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import static network.Utils.ByteConverter.bytesToInt;
import static network.Utils.ByteConverter.bytesToLong;
import static network.Utils.ByteConverter.bytesToShort;
import static network.Utils.ByteConverter.*;
/**

@ -7,13 +7,14 @@ import network.Exceptions.InvalidMessageTypeException;
import network.Messages.*;
import network.Messages.Enums.MessageType;
import static network.Utils.ByteConverter.*;
import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;
import static network.Utils.ByteConverter.intToBytes;
import static network.Utils.ByteConverter.longToBytes;
/**

@ -4,7 +4,6 @@ package network.Messages;
import network.Messages.Enums.MessageType;
import network.Messages.Enums.XMLMessageType;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
/**

@ -1,7 +1,6 @@
package shared.dataInput;
import network.Messages.Enums.RaceTypeEnum;
import shared.model.Boat;
import shared.model.CompoundMark;
import shared.model.GPSCoordinate;
import shared.model.Leg;

@ -2,15 +2,11 @@ package shared.dataInput;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;
import shared.dataInput.XMLReader;
import shared.enums.XMLFileType;
import shared.exceptions.InvalidRegattaDataException;
import shared.exceptions.XMLReaderException;
import shared.model.GPSCoordinate;
import javax.xml.parsers.ParserConfigurationException;
import java.io.IOException;
import java.io.InputStream;
/**

@ -3,7 +3,6 @@ package shared.dataInput;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import shared.enums.XMLFileType;
import shared.exceptions.XMLReaderException;

@ -93,6 +93,10 @@ public class Boat extends Collider {
@Nullable
private ZonedDateTime timeAtLastMark;
/**
* The state of the boats sails. True if sails are out.
*/
private boolean sailsOut = true;
/**
* Constructs a boat object with a given sourceID, name, country/team abbreviation, and polars table.
@ -392,6 +396,13 @@ public class Boat extends Collider {
this.timeAtLastMark = timeAtLastMark;
}
public void setSailsOut(boolean sailsOut) {
this.sailsOut = sailsOut;
}
public boolean isSailsOut() {
return sailsOut;
}
public void bounce(double repulsionRadius) {
Azimuth reverseAzimuth = Azimuth.fromDegrees(getBearing().degrees() - 180d);
setPosition(GPSCoordinate.calculateNewPosition(getPosition(), 2 * repulsionRadius, reverseAzimuth));

@ -7,6 +7,7 @@ import shared.exceptions.BoatNotFoundException;
import shared.exceptions.MarkNotFoundException;
import shared.model.GPSCoordinate;
import shared.model.Mark;
import visualiser.model.ThisBoat;
import visualiser.model.VisualiserBoat;
import visualiser.model.VisualiserRaceState;

@ -1,10 +1,8 @@
package visualiser.Controllers;
import javafx.application.Application;
import javafx.fxml.FXML;
import javafx.scene.control.*;
import javafx.scene.control.TextField;
import javafx.scene.layout.AnchorPane;
import javafx.stage.Stage;
import mock.app.Event;
import org.xml.sax.SAXException;
import mock.exceptions.EventConstructionException;
@ -12,14 +10,12 @@ import shared.exceptions.InvalidBoatDataException;
import shared.exceptions.InvalidRaceDataException;
import shared.exceptions.InvalidRegattaDataException;
import shared.exceptions.XMLReaderException;
import visualiser.model.RaceConnection;
import javax.xml.bind.JAXBException;
import javax.xml.parsers.ParserConfigurationException;
import java.io.IOException;
import java.net.Socket;
import java.net.URL;
import java.net.UnknownHostException;
import java.util.ResourceBundle;
import java.util.logging.Level;
import java.util.logging.Logger;

@ -7,7 +7,6 @@ import javafx.scene.control.Button;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.TextField;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.scene.layout.AnchorPane;
import visualiser.model.RaceConnection;

@ -120,8 +120,8 @@ public class RaceController extends Controller {
ControlKey controlKey = keyFactory.getKey(codeString);
if(controlKey != null) {
try {
controllerClient.sendKey(controlKey);
controlKey.onAction(); // Change key state if applicable
controllerClient.sendKey(controlKey);
event.consume();
} catch (InterruptedException e) {
Thread.currentThread().interrupt();

@ -1,14 +1,9 @@
package visualiser.Controllers;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.RadioButton;
import javafx.scene.image.Image;
import javafx.scene.layout.AnchorPane;
import javafx.stage.Stage;
import visualiser.app.App;
import java.io.IOException;

@ -12,7 +12,6 @@ import visualiser.gameController.Keys.ControlKey;
import java.io.DataOutputStream;
import java.io.IOException;
import java.net.Socket;
import java.net.SocketException;
import java.nio.ByteBuffer;
import java.util.concurrent.BlockingQueue;
import java.util.logging.Level;

@ -1,6 +1,7 @@
package visualiser.gameController.Keys;
import network.Messages.Enums.BoatActionEnum;
import visualiser.model.ThisBoat;
/**
* Key to toggle the sails
@ -13,7 +14,7 @@ public class SailsToggleKey extends ControlKey {
*
*/
public SailsToggleKey(String name) {
super(name, BoatActionEnum.SAILS_IN);
super(name, BoatActionEnum.NOT_A_STATUS);
}
/**
@ -21,10 +22,12 @@ public class SailsToggleKey extends ControlKey {
*/
@Override
public void onAction() {
if(protocolCode == BoatActionEnum.SAILS_IN) {
protocolCode = BoatActionEnum.SAILS_OUT;
} else {
if(ThisBoat.getInstance().isSailsOut()) {
protocolCode = BoatActionEnum.SAILS_IN;
ThisBoat.getInstance().setSailsOut(false);
} else {
protocolCode = BoatActionEnum.SAILS_OUT;
ThisBoat.getInstance().setSailsOut(true);
}
}

@ -1,7 +1,5 @@
package visualiser.gameController.Keys;
import javafx.scene.input.KeyCode;
/**
* key to zoom into the game
*/

@ -1,8 +1,5 @@
package visualiser.model;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.Socket;

@ -3,10 +3,6 @@ package visualiser.model;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.Socket;
/**
* Connection for Races
*/

@ -1,6 +1,7 @@
package visualiser.model;
import javafx.scene.image.Image;
import javafx.scene.paint.Color;
import javafx.scene.paint.LinearGradient;
import javafx.scene.paint.Paint;
@ -35,6 +36,10 @@ public class ResizableRaceCanvas extends ResizableCanvas {
*/
private RaceMap map;
private Image sailsRight = new Image("/images/sailsRight.png");
private Image sailsLeft = new Image("/images/sailsLeft.png");
private Image sailsLuff = new Image("/images/sailsLuff.gif", 25, 10, false, false);
/**
* The race we read data from and draw.
*/
@ -336,8 +341,6 @@ public class ResizableRaceCanvas extends ResizableCanvas {
}
/**
* Draws a given boat on the canvas.
* @param boat The boat to draw.
@ -375,7 +378,9 @@ public class ResizableRaceCanvas extends ResizableCanvas {
gc.fillPolygon(x, y, x.length);
gc.restore();
if (boat.getSourceID() == ThisBoat.getInstance().getSourceID()) {
drawSails(boat);
}
}
/**
@ -413,6 +418,70 @@ public class ResizableRaceCanvas extends ResizableCanvas {
}
/**
* Draws sails for a given boat on the canvas. Sail position is
* determined by the boats heading and the current wind direction
* according to the "points of sail".
* @param boat boat to display sails for
*/
private void drawSails(VisualiserBoat boat) {
GraphCoordinate boatPos =
this.map.convertGPS(boat.getPosition());
double xPos = boatPos.getX(); // x pos of sail (on boat)
double yPos = boatPos.getY() - 6; // y pos of sail (on boat)
double boatBearing = boat.getBearing().degrees();
double windDirection = 0; //visualiserRace.getWindDirection().degrees();
double sailRotateAngle = 0; // rotation for correct sail display
Image sailImage = null;
Boolean rightSail = true;
// Getting the correct Points of Sail
if (ThisBoat.getInstance().isSailsOut()){
// correct sail and sailRotateAngle start depending on wind+bearing
if ((windDirection + 180) > 360) {
if ((boatBearing < windDirection) &&
(boatBearing > windDirection - 180)) {
rightSail = false;
} else {
if (boatBearing < 180) {
sailRotateAngle = -180;
}
}
} else {
if (!((boatBearing > windDirection) &&
(boatBearing < windDirection + 180))) {
rightSail = false;
if (boatBearing > 180) {
sailRotateAngle = -180;
}
}
}
if (rightSail) {
sailImage = sailsRight;
xPos -= 1; // right align sail to boat edge on canvas
} else {
sailImage = sailsLeft;
xPos -= 5; // left align sail to boat edge on canvas
}
sailRotateAngle += ((boatBearing + windDirection) * 0.5);
}
// Sails in = luffing sail
else {
xPos -= 6;
yPos += 1;
sailImage = sailsLuff;
sailRotateAngle = boatBearing + 90;
}
gc.save();
// rotate sails based on boats current heading
rotate(sailRotateAngle, boatPos.getX(), boatPos.getY());
gc.drawImage(sailImage, xPos, yPos);
gc.restore();
}
/**
* Draws the wake for a given boat.
@ -756,4 +825,4 @@ public class ResizableRaceCanvas extends ResizableCanvas {
}
}

@ -0,0 +1,31 @@
package visualiser.model;
/**
* The properties of the boat currently being controlled by the player. Singleton.
*/
public class ThisBoat {
private VisualiserBoat boat;
private static ThisBoat instance = new ThisBoat();
private ThisBoat(){}
public static ThisBoat getInstance(){
return instance;
}
public void setSailsOut(boolean sailsOut) {
this.boat.setSailsOut(sailsOut);
}
public boolean isSailsOut() {
return this.boat.isSailsOut();
}
public int getSourceID() {
return this.boat.getSourceID();
}
public void setBoat(VisualiserBoat boat) {
this.boat = boat;
}
}

@ -205,6 +205,7 @@ public class VisualiserRaceState extends RaceState {
if (boat.getSourceID() == getPlayerBoatID()) {
boat.setClientBoat(true);
ThisBoat.getInstance().setBoat(boat);
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 122 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 126 B

@ -1,18 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.image.Image?>
<?import javafx.scene.image.ImageView?>
<?import javafx.scene.layout.ColumnConstraints?>
<?import javafx.scene.layout.GridPane?>
<?import javafx.scene.layout.Pane?>
<?import javafx.scene.layout.RowConstraints?>
<?import javafx.scene.layout.StackPane?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.shape.Circle?>
<?import javafx.scene.text.Font?>
<GridPane fx:id="arrowGridPane" maxHeight="-Infinity" maxWidth="-Infinity" xmlns="http://javafx.com/javafx/8.0.111" xmlns:fx="http://javafx.com/fxml/1" fx:controller="visualiser.Controllers.ArrowController">
<columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" />

@ -1,12 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import java.lang.*?>
<?import javafx.scene.text.*?>
<?import javafx.geometry.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.text.Font?>
<AnchorPane fx:id="hostWrapper" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="600.0" prefWidth="780.0" visible="false" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="visualiser.Controllers.HostController">
<children>
<GridPane AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">

@ -1,9 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import java.lang.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.layout.AnchorPane?>
<AnchorPane fx:id="main" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="visualiser.Controllers.MainController">
<children>
<fx:include fx:id="race" source="race.fxml" />

@ -1,12 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import java.lang.*?>
<?import javafx.scene.text.*?>
<?import javafx.geometry.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.text.Font?>
<AnchorPane fx:id="connectionWrapper" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="600.0" prefWidth="780.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="visualiser.Controllers.ConnectionController">
<children>
<GridPane AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">

@ -1,20 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import java.lang.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.RadioButton?>
<?import javafx.scene.image.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.text.*?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.image.Image?>
<?import javafx.scene.image.ImageView?>
<?import javafx.scene.layout.ColumnConstraints?>
<?import javafx.scene.layout.GridPane?>
<?import javafx.scene.layout.Pane?>
<?import javafx.scene.layout.RowConstraints?>
<?import javafx.scene.text.Font?>
<?import javafx.scene.text.Text?>
<AnchorPane fx:id="titleWrapper" maxHeight="600.0" maxWidth="800.0" minHeight="600.0" minWidth="800.0" prefHeight="600.0" prefWidth="800.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="visualiser.Controllers.TitleController">
<children>
<GridPane layoutY="39.0" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="500.0" prefWidth="800.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">

@ -6,9 +6,7 @@ import org.junit.Before;
import org.junit.Test;
import shared.model.Bearing;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.junit.Assert.*;
/**

@ -4,7 +4,7 @@ import org.junit.Before;
import org.junit.Test;
import shared.model.Bearing;
import static org.junit.Assert.*;
import static org.junit.Assert.assertEquals;
public class VMGTest {

@ -14,9 +14,6 @@ import shared.dataInput.XMLReader;
import shared.exceptions.XMLReaderException;
import javax.xml.transform.TransformerException;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import static org.junit.Assert.fail;

@ -1,6 +1,5 @@
package network.Utils;
import network.Utils.ByteConverter;
import org.junit.Test;
import java.nio.ByteOrder;

@ -3,23 +3,17 @@ package shared.dataInput;
import org.junit.Before;
import org.junit.Test;
import org.xml.sax.SAXException;
import shared.enums.XMLFileType;
import shared.exceptions.InvalidBoatDataException;
import shared.exceptions.XMLReaderException;
import shared.model.Boat;
import shared.model.Mark;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.TransformerException;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.junit.Assert.*;
/**
* Created by cbt24 on 10/05/17.

@ -1,7 +1,5 @@
package shared.model;
import static org.junit.Assert.*;
public class AngleTest {
//TODO
}

@ -1,7 +1,5 @@
package shared.model;
import static org.junit.Assert.*;
public class AzimuthTest {
//TODO
}

@ -1,7 +1,5 @@
package shared.model;
import static org.junit.Assert.*;
public class BearingTest {
//TODO
}

@ -1,7 +1,6 @@
package shared.model;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import static org.junit.Assert.assertEquals;

@ -1,7 +1,5 @@
package shared.model;
import static org.junit.Assert.*;
public class MarkTest {
//TODO
}

@ -1,7 +1,5 @@
package shared.model;
import static org.junit.Assert.*;
public class RaceClockTest {
//TODO
}

@ -7,7 +7,6 @@ import javafx.scene.Scene;
import javafx.scene.layout.GridPane;
import javafx.stage.Stage;
import javafx.stage.WindowEvent;
import visualiser.gameController.InputChecker;
/**
* Start to manually test the game controller

@ -4,7 +4,6 @@ import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
/**

Loading…
Cancel
Save