Merge branch 'develop' into 1124_switching_to_finish_screen

# Conflicts:
#	src/main/java/seng302/gameServer/GameState.java
#	src/main/java/seng302/gameServer/MainServerThread.java
#	src/main/java/seng302/gameServer/ServerToClientThread.java
#	src/main/java/seng302/model/Yacht.java
#	src/main/java/seng302/visualiser/GameClient.java
#	src/main/java/seng302/visualiser/GameView.java
#	src/main/java/seng302/visualiser/controllers/RaceViewController.java
#	src/test/java/seng302/visualiser/ClientToServerTests/RegularPacketsTest.java
This commit is contained in:
Calum
2017-08-15 23:45:50 +12:00
27 changed files with 1602 additions and 653 deletions
+12
View File
@@ -0,0 +1,12 @@
import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;
import org.junit.runner.RunWith;
/**
* Created by kre39 on 7/08/17.
*/
@RunWith(Cucumber.class)
@CucumberOptions(features = "src/test/java/features")
public class RunCucumberTests {
}
@@ -0,0 +1,5 @@
Feature: SailsToggle
Scenario: User toggles in sail
Given The game is running
When the user has pressed "shift"
Then the sails are "in"
+3 -3
View File
@@ -9,9 +9,9 @@ public class ColorsTest {
@Test
public void testNextColor() {
Color expectedColors[] = {Color.RED, Color.PERU, Color.SEAGREEN, Color.GREEN, Color.BLUE, Color.PURPLE};
for (int i = 0; i<6; i++)
{
Color expectedColors[] = {Color.RED, Color.PERU, Color.GOLD, Color.GREEN, Color.BLUE,
Color.PURPLE, Color.DEEPPINK, Color.GRAY};
for (int i = 0; i < 8; i++) {
Assert.assertEquals(expectedColors[i], Colors.getColor());
}
}
@@ -0,0 +1,92 @@
package seng302.model;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import seng302.gameServer.GameState;
import seng302.utilities.GeoUtility;
/**
* Test update function in Yacht.java to make sure yacht will not be collide each other within 25.0
* meters.
*/
public class UpdateYachtTest {
private Yacht yacht1 = new Yacht("Yacht", 1, "1", "Yacht" + 1, "Yacht" + 1, "Test1");
private Yacht yacht2 = new Yacht("Yacht", 2, "2", "Yacht" + 2, "Yacht" + 2, "Test2");
private GeoPoint geoPoint1 = new GeoPoint(50.0, 50.0);
private GeoPoint geoPoint2 = GeoUtility.getGeoCoordinate(geoPoint1, 90.0, 50.0);
@Before
public void setUpRace() {
new GameState("");
GameState.addYacht(1, yacht1);
GameState.addYacht(2, yacht2);
PolarTable.parsePolarFile(getClass().getResourceAsStream("/config/acc_polars.csv"));
}
@Test
public void testUpdateYachtWithCollision() {
// Yacht 1 heading towards 90 degrees heading
yacht1.setLocation(geoPoint1);
yacht1.updateLocation(geoPoint1.getLat(), geoPoint1.getLng(), 90.0, 5.0);
// Yacht 2 heading towards 270 degrees heading
yacht2.setLocation(geoPoint2);
yacht2.updateLocation(geoPoint2.getLat(), geoPoint2.getLng(), 270.0, 5.0);
// Start yacht 1 and rest yacht 2
if (!yacht1.getSailIn()) {
yacht1.toggleSailIn();
}
for (int i = 0; i < 6; i++) {
yacht1.update((long) 1000);
// Making sure boat is moving
double moved = GeoUtility.getDistance(yacht1.getLocation(), geoPoint1);
Assert.assertTrue(moved > 0);
// Making sure no collision
Double distance = GeoUtility.getDistance(yacht1.getLocation(), geoPoint2);
Assert.assertTrue(distance > Math.min(Yacht.MARK_COLLISION_DISTANCE, Yacht.YACHT_COLLISION_DISTANCE));
}
}
@Test
public void testUpdateYachtWithoutCollision() {
// Yacht 1 heading towards 90 degrees heading
yacht1.setLocation(geoPoint1);
yacht1.updateLocation(geoPoint1.getLat(), geoPoint1.getLng(), 90.0, 5.0);
// Yacht 2 heading towards 90 degrees heading
yacht2.setLocation(geoPoint2);
yacht2.updateLocation(geoPoint2.getLat(), geoPoint2.getLng(), 90.0, 5.0);
// Start yacht 1 and yacht 2
if (!yacht1.getSailIn()) {
yacht1.toggleSailIn();
}
if (!yacht2.getSailIn()) {
yacht2.toggleSailIn();
}
double previousDistance1 = 0;
double previousDistance2 = 0;
for (int i = 0; i < 6; i++) {
yacht1.update((long) 1000);
yacht2.update((long) 1000);
// Making sure boat is moving
double yachtMoved1 = GeoUtility.getDistance(yacht1.getLocation(), geoPoint1);
Assert.assertTrue(yachtMoved1 > previousDistance1);
previousDistance1 = yachtMoved1;
double yachtMoved2 = GeoUtility.getDistance(yacht2.getLocation(), geoPoint2);
Assert.assertTrue(yachtMoved2 > previousDistance2);
previousDistance2 = yachtMoved2;
}
}
}
@@ -0,0 +1,31 @@
package seng302.visualiser.map;
import static junit.framework.TestCase.assertFalse;
import static junit.framework.TestCase.assertTrue;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import seng302.model.Yacht;
import seng302.visualiser.fxObjects.BoatObject;
/**
* Created by kre39 on 6/08/17.
*/
public class BoatSailAnimationToggleTest {
private Yacht yacht;
@Before
public void setup() throws Exception{
yacht = new Yacht("Yacht", 1, "YACHT", "YAC", "Test Yacht", "NZ");
}
@Test
public void sailToggleTest() throws Exception {
assertFalse(yacht.getSailIn());
yacht.toggleClientSail();
assertFalse(yacht.getSailIn());
}
}
+60
View File
@@ -0,0 +1,60 @@
package steps;
import cucumber.api.java.en.Given;
import cucumber.api.java.en.Then;
import cucumber.api.java.en.When;
import java.util.ArrayList;
import org.junit.Assert;
import seng302.gameServer.GameStages;
import seng302.gameServer.GameState;
import seng302.gameServer.MainServerThread;
import seng302.gameServer.server.messages.BoatAction;
import seng302.model.Yacht;
import seng302.visualiser.ClientToServerThread;
import java.util.ArrayList;
/**
* Created by kre39 on 7/08/17.
*/
public class ToggleSailSteps {
MainServerThread mst;
ClientToServerThread client;
boolean sailsIn = false;
long startTime;
private Yacht yacht;
@Given("^The game is running$")
public void the_game_is_running() throws Throwable {
mst = new MainServerThread();
client = new ClientToServerThread("localhost", 4942);
GameState.setCurrentStage(GameStages.RACING);
Thread.sleep(200); // Sleep needed to help the threads all be up to speed with each other
Yacht yacht = (new ArrayList<>(GameState.getYachts().values())).get(0);
Assert.assertFalse(yacht.getSailIn());
}
@When("^the user has pressed \"([^\"]*)\"$")
public void the_user_has_pressed(String arg1) throws Throwable {
startTime = System.currentTimeMillis();
if (arg1 == "shift") {
client.sendBoatAction(BoatAction.SAILS_IN);
}
}
@Then("^the sails are \"([^\"]*)\"$")
public void the_sails_are(String arg1) throws Throwable {
Thread.sleep(200); // Sleep needed to help the threads all be up to speed with each other
Yacht yacht = (new ArrayList<>(GameState.getYachts().values())).get(0);
if (arg1 == "in") {
Assert.assertTrue(yacht.getSailIn());
} else {
Assert.assertFalse(yacht.getSailIn());
}
}
}