mirror of
https://github.com/michaelrausch/Party-Parrots-At-Sea.git
synced 2026-05-09 14:28:43 +00:00
Merged with develop. Fixed many bugs in Visualiser.
#bugs
This commit is contained in:
@@ -1,78 +1,75 @@
|
||||
package seng302.client;
|
||||
|
||||
import com.sun.org.apache.xpath.internal.operations.Bool;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import seng302.models.Yacht;
|
||||
import seng302.model.Yacht;
|
||||
|
||||
/**
|
||||
* Used by the client to store static variables to be used in game.
|
||||
*/
|
||||
public class ClientState {
|
||||
|
||||
private static String hostIp = "";
|
||||
private static Boolean isHost = false;
|
||||
private static Boolean raceStarted = false;
|
||||
private static Boolean connectedToHost = false;
|
||||
private static Map<Integer, Yacht> boats = new ConcurrentHashMap<>();
|
||||
private static Boolean dirtyState = true;
|
||||
private static String clientSourceId = "";
|
||||
|
||||
public static String getHostIp() {
|
||||
return hostIp;
|
||||
}
|
||||
|
||||
public static void setHostIp(String hostIp) {
|
||||
ClientState.hostIp = hostIp;
|
||||
}
|
||||
|
||||
public static Boolean isHost() {
|
||||
return isHost;
|
||||
}
|
||||
|
||||
public static void setHost(Boolean isHost) {
|
||||
ClientState.isHost = isHost;
|
||||
}
|
||||
|
||||
public static Boolean isRaceStarted() {
|
||||
return raceStarted;
|
||||
}
|
||||
|
||||
public static void setRaceStarted(Boolean raceStarted) {
|
||||
ClientState.raceStarted = raceStarted;
|
||||
}
|
||||
|
||||
public static Boolean isConnectedToHost() {
|
||||
return connectedToHost;
|
||||
}
|
||||
|
||||
public static void setConnectedToHost(Boolean connectedToHost) {
|
||||
ClientState.connectedToHost = connectedToHost;
|
||||
}
|
||||
|
||||
public static Map<Integer, Yacht> getBoats() {
|
||||
return boats;
|
||||
}
|
||||
|
||||
public static Boolean isDirtyState() {
|
||||
return dirtyState;
|
||||
}
|
||||
|
||||
public static void setDirtyState(Boolean dirtyState) {
|
||||
ClientState.dirtyState = dirtyState;
|
||||
}
|
||||
|
||||
public static String getClientSourceId() {
|
||||
return clientSourceId;
|
||||
}
|
||||
|
||||
public static void setClientSourceId(String clientSourceId) {
|
||||
ClientState.clientSourceId = clientSourceId;
|
||||
}
|
||||
|
||||
public static void setBoats(Map<Integer, Yacht> boats) {
|
||||
ClientState.boats = boats;
|
||||
}
|
||||
// private static String hostIp = "";
|
||||
// private static Boolean isHost = false;
|
||||
// private static Boolean raceStarted = false;
|
||||
// private static Boolean connectedToHost = false;
|
||||
// private static Map<Integer, Yacht> boats = new ConcurrentHashMap<>();
|
||||
// private static Boolean dirtyState = true;
|
||||
// private static String clientSourceId = "";
|
||||
//
|
||||
// public static String getHostIp() {
|
||||
// return hostIp;
|
||||
// }
|
||||
//
|
||||
// public static void setHostIp(String hostIp) {
|
||||
// ClientState.hostIp = hostIp;
|
||||
// }
|
||||
//
|
||||
// public static Boolean isHost() {
|
||||
// return isHost;
|
||||
// }
|
||||
//
|
||||
// public static void setHost(Boolean isHost) {
|
||||
// ClientState.isHost = isHost;
|
||||
// }
|
||||
//
|
||||
// public static Boolean isRaceStarted() {
|
||||
// return raceStarted;
|
||||
// }
|
||||
//
|
||||
// public static void setRaceStarted(Boolean raceStarted) {
|
||||
// ClientState.raceStarted = raceStarted;
|
||||
// }
|
||||
//
|
||||
// public static Boolean isConnectedToHost() {
|
||||
// return connectedToHost;
|
||||
// }
|
||||
//
|
||||
// public static void setConnectedToHost(Boolean connectedToHost) {
|
||||
// ClientState.connectedToHost = connectedToHost;
|
||||
// }
|
||||
//
|
||||
// public static Map<Integer, Yacht> getBoats() {
|
||||
// return boats;
|
||||
// }
|
||||
//
|
||||
// public static Boolean isDirtyState() {
|
||||
// return dirtyState;
|
||||
// }
|
||||
//
|
||||
// public static void setDirtyState(Boolean dirtyState) {
|
||||
// ClientState.dirtyState = dirtyState;
|
||||
// }
|
||||
//
|
||||
// public static String getClientSourceId() {
|
||||
// return clientSourceId;
|
||||
// }
|
||||
//
|
||||
// public static void setClientSourceId(String clientSourceId) {
|
||||
// ClientState.clientSourceId = clientSourceId;
|
||||
// }
|
||||
//
|
||||
// public static void setBoats(Map<Integer, Yacht> boats) {
|
||||
// ClientState.boats = boats;
|
||||
// }
|
||||
}
|
||||
|
||||
@@ -1,43 +1,43 @@
|
||||
package seng302.client;
|
||||
|
||||
import java.util.Observable;
|
||||
|
||||
/**
|
||||
* Used by LobbyController to run a separate thread-loop
|
||||
* updates the controller when change is detected.
|
||||
*/
|
||||
public class ClientStateQueryingRunnable extends Observable implements Runnable {
|
||||
|
||||
private Boolean terminate = false;
|
||||
|
||||
public ClientStateQueryingRunnable() {}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
while(!terminate) {
|
||||
// Sleeping the thread so it will respond to the if statement below
|
||||
// if you know a better fix, pls tell me :) -ryan
|
||||
try {
|
||||
Thread.sleep(0);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
if (ClientState.isRaceStarted() && ClientState.isConnectedToHost()) {
|
||||
setChanged();
|
||||
notifyObservers("game started");
|
||||
terminate();
|
||||
}
|
||||
|
||||
if (ClientState.isDirtyState()) {
|
||||
setChanged();
|
||||
notifyObservers("update players");
|
||||
ClientState.setDirtyState(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void terminate() {
|
||||
terminate = true;
|
||||
}
|
||||
}
|
||||
//package seng302.client;
|
||||
//
|
||||
//import java.util.Observable;
|
||||
//
|
||||
///**
|
||||
// * Used by LobbyController to run a separate thread-loop
|
||||
// * updates the controller when change is detected.
|
||||
// */
|
||||
//public class ClientStateQueryingRunnable extends Observable implements Runnable {
|
||||
//
|
||||
// private Boolean terminate = false;
|
||||
//
|
||||
// public ClientStateQueryingRunnable() {}
|
||||
//
|
||||
// @Override
|
||||
// public void run() {
|
||||
// while(!terminate) {
|
||||
// // Sleeping the thread so it will respond to the if statement below
|
||||
// // if you know a better fix, pls tell me :) -ryan
|
||||
// try {
|
||||
// Thread.sleep(0);
|
||||
// } catch (InterruptedException e) {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
//
|
||||
// if (ClientState.isRaceStarted() && ClientState.isConnectedToHost()) {
|
||||
// setChanged();
|
||||
// notifyObservers("game started");
|
||||
// terminate();
|
||||
// }
|
||||
//
|
||||
// if (ClientState.isDirtyState()) {
|
||||
// setChanged();
|
||||
// notifyObservers("update players");
|
||||
// ClientState.setDirtyState(false);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// public void terminate() {
|
||||
// terminate = true;
|
||||
// }
|
||||
//}
|
||||
|
||||
Reference in New Issue
Block a user