mirror of
https://github.com/michaelrausch/Party-Parrots-At-Sea.git
synced 2026-05-09 06:18:44 +00:00
Merge branch 'develop' into story61_player_perspective
# Conflicts: # src/main/java/seng302/App.java # src/main/java/seng302/client/ClientPacketParser.java # src/main/java/seng302/controllers/Controller.java # src/main/java/seng302/controllers/RaceViewController.java # src/main/java/seng302/fxObjects/BoatAnnotations.java # 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/Boat.java # src/main/java/seng302/models/stream/XMLParser.java # src/main/java/seng302/visualiser/ClientToServerThread.java # src/main/java/seng302/visualiser/GameView.java # src/main/java/seng302/visualiser/controllers/FinishScreenViewController.java # src/main/java/seng302/visualiser/controllers/StartScreenController.java # src/main/java/seng302/visualiser/fxObjects/BoatObject.java # src/main/resources/views/LobbyView.fxml # src/main/resources/views/MainView.fxml
This commit is contained in:
@@ -1,8 +1,12 @@
|
||||
package seng302.gameServer;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import seng302.models.Player;
|
||||
import seng302.model.Player;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import seng302.models.Yacht;
|
||||
import seng302.server.messages.BoatActionType;
|
||||
|
||||
/**
|
||||
* A Static class to hold information about the current state of the game (model)
|
||||
@@ -10,23 +14,38 @@ import java.util.ArrayList;
|
||||
*/
|
||||
public class GameState {
|
||||
|
||||
private static Long previousUpdateTime;
|
||||
public static Double windDirection;
|
||||
private static Double windSpeed;
|
||||
|
||||
private static String hostIpAddress;
|
||||
private static ArrayList<Player> players;
|
||||
private static List<Player> players;
|
||||
private static Map<Integer, Yacht> yachts;
|
||||
private static Boolean isRaceStarted;
|
||||
private static GameStages currentStage;
|
||||
|
||||
public GameState(String hostIpAddress) {
|
||||
windDirection = 170d;
|
||||
windSpeed = 10000d;
|
||||
yachts = new HashMap<>();
|
||||
players = new ArrayList<>();
|
||||
|
||||
|
||||
GameState.hostIpAddress = hostIpAddress;
|
||||
players = new ArrayList<>();
|
||||
currentStage = GameStages.LOBBYING;
|
||||
isRaceStarted = false;
|
||||
yachts = new HashMap<>();
|
||||
//set this when game stage changes to prerace
|
||||
previousUpdateTime = System.currentTimeMillis();
|
||||
yachts = new HashMap<>();
|
||||
}
|
||||
|
||||
public static String getHostIpAddress() {
|
||||
return hostIpAddress;
|
||||
}
|
||||
|
||||
public static ArrayList<Player> getPlayers() {
|
||||
public static List<Player> getPlayers() {
|
||||
return players;
|
||||
}
|
||||
|
||||
@@ -38,6 +57,14 @@ public class GameState {
|
||||
players.remove(player);
|
||||
}
|
||||
|
||||
public static void addYacht(Integer sourceId, Yacht yacht) {
|
||||
yachts.put(sourceId, yacht);
|
||||
}
|
||||
|
||||
public static void removeYacht(Integer yachtId) {
|
||||
yachts.remove(yachtId);
|
||||
}
|
||||
|
||||
public static Boolean getIsRaceStarted() {
|
||||
return isRaceStarted;
|
||||
}
|
||||
@@ -50,16 +77,72 @@ public class GameState {
|
||||
GameState.currentStage = currentStage;
|
||||
}
|
||||
|
||||
/**
|
||||
* This iterates through all players and updates each players info to its new state based on its current data
|
||||
*/
|
||||
private void update(){
|
||||
for(Player player : players) {
|
||||
// TODO: 10/07/17 wmu16 - Update all player info
|
||||
public static Double getWindDirection() {
|
||||
return windDirection;
|
||||
}
|
||||
|
||||
public static Double getWindSpeed() {
|
||||
return windSpeed;
|
||||
}
|
||||
|
||||
public static Map<Integer, Yacht> getYachts() {
|
||||
return yachts;
|
||||
}
|
||||
|
||||
public static void updateBoat(Integer sourceId, BoatActionType actionType) {
|
||||
Yacht playerYacht = yachts.get(sourceId);
|
||||
// System.out.println("-----------------------");
|
||||
switch (actionType) {
|
||||
case VMG:
|
||||
// System.out.println("Snapping to VMG");
|
||||
// TODO: 22/07/17 wmu16 - Add in the vmg calculation code here
|
||||
break;
|
||||
case SAILS_IN:
|
||||
playerYacht.toggleSailIn();
|
||||
// System.out.println("Toggling Sails");
|
||||
break;
|
||||
case SAILS_OUT:
|
||||
playerYacht.toggleSailIn();
|
||||
// System.out.println("Toggling Sails");
|
||||
break;
|
||||
case TACK_GYBE:
|
||||
playerYacht.tackGybe(windDirection);
|
||||
// System.out.println("Tack/Gybe");
|
||||
break;
|
||||
case UPWIND:
|
||||
playerYacht.turnUpwind();
|
||||
// System.out.println("Moving upwind");
|
||||
break;
|
||||
case DOWNWIND:
|
||||
playerYacht.turnDownwind();
|
||||
// System.out.println("Moving downwind");
|
||||
break;
|
||||
}
|
||||
|
||||
// System.out.println("-----------------------");
|
||||
// System.out.println("Heading: " + playerYacht.getHeading());
|
||||
// System.out.println("Sails are in: " + playerYacht.getSailIn());
|
||||
// System.out.println("Lat: " + playerYacht.getLocation().getLat());
|
||||
// System.out.println("Lng: " + playerYacht.getLocation().getLng());
|
||||
// System.out.println("-----------------------\n");
|
||||
}
|
||||
|
||||
public static void update() {
|
||||
|
||||
Long timeInterval = System.currentTimeMillis() - previousUpdateTime;
|
||||
previousUpdateTime = System.currentTimeMillis();
|
||||
for (Yacht yacht : yachts.values()) {
|
||||
yacht.update(timeInterval);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Generates a new ID based off the size of current players + 1
|
||||
* @return a playerID to be allocated to a new connetion
|
||||
*/
|
||||
public static Integer getUniquePlayerID() {
|
||||
// TODO: 22/07/17 wmu16 - This may not be robust enough and may have to be improved on.
|
||||
return yachts.size() + 1;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user