Compare commits

..

No commits in common. "f20896566c402957550ecfba099014b385edfbfa" and "175bb20345bc358583b58006f5fb4c9064989e1d" have entirely different histories.

1 changed files with 7 additions and 16 deletions

View File

@ -10,15 +10,6 @@ import java.util.Map;
public class GameController { public class GameController {
private static MainFrame mainFrame;
public static MainFrame getMainFrame() {
return GameController.mainFrame;
}
public static void setMainFrame(MainFrame mainFrame) {
GameController.mainFrame = mainFrame;
}
// Connection timeout for client sockets in milliseconds // Connection timeout for client sockets in milliseconds
public static final int CONNECTION_TIMEOUT = 10 * 1000; public static final int CONNECTION_TIMEOUT = 10 * 1000;
@ -26,11 +17,11 @@ public class GameController {
return semester + 13; return semester + 13;
} }
public static HashMap<String, Class<? extends OnlinePlayer>> supportedVersions = new HashMap<>(Map.of( public HashMap<String, Class<? extends OnlinePlayer>> supportedVersions = new HashMap<>(Map.of(
"1.1.0", OnlinePlayer_1_1_0.class "1.1.0", OnlinePlayer_1_1_0.class
)); ));
public static void startOnlineGame(Class<? extends LocalPlayer> localPlayerClass, String localPlayerName, InetSocketAddress address, int size) throws IOException { public void startOnlineGame(Class<? extends LocalPlayer> localPlayerClass, InetSocketAddress address, int size) throws IOException {
AsyncSocket clientSocket; AsyncSocket clientSocket;
boolean localPlayerIsServer = address.getHostName() == null; boolean localPlayerIsServer = address.getHostName() == null;
@ -106,7 +97,7 @@ public class GameController {
* finds the largest common version in two lists of version strings * finds the largest common version in two lists of version strings
* @return null if no common versions are found * @return null if no common versions are found
*/ */
public static String findMostRecentVersion(List<String> versions1, List<String> versions2) { public String findMostRecentVersion(List<String> versions1, List<String> versions2) {
if (versions1 == null || versions2 == null) return null; if (versions1 == null || versions2 == null) return null;
String largestCommonVersion = null; String largestCommonVersion = null;
for (String v1 : versions1) { for (String v1 : versions1) {
@ -134,7 +125,7 @@ public class GameController {
* 1 if version1 is more recent than version2 * 1 if version1 is more recent than version2
* -1 otherwise * -1 otherwise
*/ */
public static int compareVersions(String version1, String version2) { public int compareVersions(String version1, String version2) {
if (!checkVersionString(version1) || !checkVersionString(version2)) { if (!checkVersionString(version1) || !checkVersionString(version2)) {
throw new IllegalArgumentException("Version is not valid version string"); throw new IllegalArgumentException("Version is not valid version string");
} }
@ -159,11 +150,11 @@ public class GameController {
/** /**
* checks if a provided string matches the format of a version number * checks if a provided string matches the format of a version number
*/ */
public static boolean checkVersionString(String versionString) { public boolean checkVersionString(String versionString) {
return versionString != null && versionString.matches("\\d+\\.\\d+\\.\\d+"); return versionString != null && versionString.matches("\\d+\\.\\d+\\.\\d+");
} }
public static void startLocalGame(Class<? extends LocalPlayer> localPlayerClass, String localPlayerName, Class<? extends AiPlayer> enemyClass, int size) { public void startLocalGame(Class<? extends LocalPlayer> localPlayerClass, Class<? extends AiPlayer> enemyClass, int size) {
LocalPlayer localPlayer; LocalPlayer localPlayer;
AiPlayer aiPlayer; AiPlayer aiPlayer;
@ -181,7 +172,7 @@ public class GameController {
startGameWithInstancedPlayers(localPlayer, aiPlayer); startGameWithInstancedPlayers(localPlayer, aiPlayer);
} }
private static void startGameWithInstancedPlayers(LocalPlayer p1, Player p2) { private void startGameWithInstancedPlayers(LocalPlayer p1, Player p2) {
p1.setEnemy(p2); p1.setEnemy(p2);
p2.setEnemy(p1); p2.setEnemy(p1);