mirror of
https://github.com/michaelrausch/Party-Parrots-At-Sea.git
synced 2026-05-09 06:18:44 +00:00
Added some general UI improvements such as autofilling the color field of the form, and looked at how best to deal with response packets, as it should be part of the spec.
tags: #story[1142]
This commit is contained in:
@@ -186,7 +186,6 @@ public class ServerToClientThread implements Runnable, Observer {
|
||||
long computedCrc = checksum.getValue();
|
||||
long packetCrc = Message.bytesToLong(getBytes(4));
|
||||
if (computedCrc == packetCrc) {
|
||||
//System.out.println("RECEIVED A PACKET");
|
||||
switch (PacketType.assignPacketType(type, payload)) {
|
||||
case BOAT_ACTION:
|
||||
BoatAction actionType = ServerPacketParser
|
||||
@@ -203,7 +202,6 @@ public class ServerToClientThread implements Runnable, Observer {
|
||||
break;
|
||||
|
||||
case RACE_CUSTOMIZATION_REQUEST:
|
||||
System.out.println("CUSTOMIZATION RECEIVED");
|
||||
Long sourceID = Message
|
||||
.bytesToLong(Arrays.copyOfRange(payload, 0, 3));
|
||||
CustomizeRequestType requestType = ServerPacketParser
|
||||
@@ -212,6 +210,7 @@ public class ServerToClientThread implements Runnable, Observer {
|
||||
GameState.customizePlayer(sourceID, requestType,
|
||||
Arrays.copyOfRange(payload, 6, payload.length));
|
||||
GameState.setCustomizationFlag();
|
||||
//// TODO: 17/08/2017 ajm412: Send a response packet here.
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
|
||||
@@ -71,6 +71,7 @@ public class ClientYacht extends Observable {
|
||||
this.heading = 120.0; //In degrees
|
||||
this.currentVelocity = 0d;
|
||||
this.boatStatus = 1;
|
||||
this.colour = Color.rgb(0, 0, 0, 1.0);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -8,12 +8,7 @@ import javafx.scene.paint.Color;
|
||||
public enum Colors {
|
||||
RED, PERU, GOLD, GREEN, BLUE, PURPLE, DEEPPINK, GRAY;
|
||||
|
||||
static Integer index = 0;
|
||||
|
||||
public static Color getColor() {
|
||||
if (index == 8) {
|
||||
index = 0;
|
||||
}
|
||||
return Color.valueOf(values()[index++].toString());
|
||||
public static Color getColor(Integer index) {
|
||||
return Color.valueOf(values()[index].toString());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -68,7 +68,7 @@ public class ServerYacht extends Observable {
|
||||
this.heading = 120.0; //In degrees
|
||||
this.currentVelocity = 0d; //in mms-1
|
||||
this.currentMarkSeqID = 0;
|
||||
this.boatColor = Color.rgb(0, 0, 0);
|
||||
this.boatColor = Colors.getColor(sourceId - 1);
|
||||
|
||||
this.hasEnteredRoundingZone = false;
|
||||
this.hasPassedLine = false;
|
||||
|
||||
@@ -20,13 +20,12 @@ public class CustomizationController {
|
||||
@FXML
|
||||
private Button customizeSubmit;
|
||||
|
||||
private LobbyController lc;
|
||||
private ClientToServerThread socketThread;
|
||||
private Stage windowStage;
|
||||
|
||||
public void initialize() {
|
||||
|
||||
boatColorPicker.setValue(new Color(0.0, 0.0, 0.0, 1.0));
|
||||
|
||||
}
|
||||
|
||||
public void setServerThread(ClientToServerThread ctsThread) {
|
||||
@@ -51,9 +50,14 @@ public class CustomizationController {
|
||||
colorArray[2] = (byte) blue;
|
||||
|
||||
socketThread.sendCustomizationRequest(CustomizeRequestType.COLOR, colorArray);
|
||||
lc.setPlayersColor(color);
|
||||
windowStage.close();
|
||||
}
|
||||
|
||||
public void setLobbyController(LobbyController lc) {
|
||||
this.lc = lc;
|
||||
}
|
||||
|
||||
public void setStage(Stage stage) {
|
||||
this.windowStage = stage;
|
||||
}
|
||||
@@ -62,5 +66,9 @@ public class CustomizationController {
|
||||
this.nameField.setText(name);
|
||||
}
|
||||
|
||||
public void setPlayerColor(Color playerColor) {
|
||||
this.boatColorPicker.setValue(playerColor);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -16,10 +16,12 @@ import javafx.scene.control.Button;
|
||||
import javafx.scene.control.TextArea;
|
||||
import javafx.scene.image.Image;
|
||||
import javafx.scene.image.ImageView;
|
||||
import javafx.scene.paint.Color;
|
||||
import javafx.scene.text.Text;
|
||||
import javafx.stage.Stage;
|
||||
import seng302.gameServer.GameStages;
|
||||
import seng302.gameServer.GameState;
|
||||
import seng302.model.Colors;
|
||||
import seng302.model.RaceState;
|
||||
import seng302.visualiser.ClientToServerThread;
|
||||
|
||||
@@ -86,6 +88,8 @@ public class LobbyController {
|
||||
|
||||
private ClientToServerThread socketThread;
|
||||
|
||||
private Color playersColor;
|
||||
|
||||
private int MAX_NUM_PLAYERS = 8;
|
||||
private Integer playerID;
|
||||
|
||||
@@ -154,9 +158,16 @@ public class LobbyController {
|
||||
CustomizationController cc = fxmlLoader.getController();
|
||||
cc.setServerThread(this.socketThread);
|
||||
cc.setPlayerName(this.players.get(playerID - 1));
|
||||
|
||||
if (this.playersColor == null) {
|
||||
this.playersColor = Colors.getColor(playerID - 1);
|
||||
}
|
||||
|
||||
cc.setPlayerColor(this.playersColor);
|
||||
customizeStage.setTitle("Customize Boat");
|
||||
customizeStage.setScene(new Scene(root, 700, 450));
|
||||
cc.setStage(customizeStage); // pass the stage through so it can be closed later.
|
||||
cc.setLobbyController(this);
|
||||
customizeStage.show();
|
||||
} catch (IOException e) {
|
||||
Logger.logMsg(4, "Failed to load Customization View from resources.");
|
||||
@@ -218,4 +229,9 @@ public class LobbyController {
|
||||
readyButton.setDisable(true);
|
||||
readyButton.setVisible(false);
|
||||
}
|
||||
|
||||
public void setPlayersColor(Color playerColor) {
|
||||
this.playersColor = playerColor;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ public class ColorsTest {
|
||||
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());
|
||||
Assert.assertEquals(expectedColors[i], Colors.getColor(i));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user