From d9baeec957dcf39471d4cb5a059ebe06b0740ec3 Mon Sep 17 00:00:00 2001 From: Luca Conte Date: Tue, 3 Dec 2024 13:47:36 +0100 Subject: [PATCH] make all methods static, add player name to start game method params --- src/GameController.java | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/GameController.java b/src/GameController.java index d72c1b6..1c5e392 100644 --- a/src/GameController.java +++ b/src/GameController.java @@ -26,11 +26,11 @@ public class GameController { return semester + 13; } - public HashMap> supportedVersions = new HashMap<>(Map.of( + public static HashMap> supportedVersions = new HashMap<>(Map.of( "1.1.0", OnlinePlayer_1_1_0.class )); - public void startOnlineGame(Class localPlayerClass, InetSocketAddress address, int size) throws IOException { + public static void startOnlineGame(Class localPlayerClass, String localPlayerName, InetSocketAddress address, int size) throws IOException { AsyncSocket clientSocket; boolean localPlayerIsServer = address.getHostName() == null; @@ -106,7 +106,7 @@ public class GameController { * finds the largest common version in two lists of version strings * @return null if no common versions are found */ - public String findMostRecentVersion(List versions1, List versions2) { + public static String findMostRecentVersion(List versions1, List versions2) { if (versions1 == null || versions2 == null) return null; String largestCommonVersion = null; for (String v1 : versions1) { @@ -134,7 +134,7 @@ public class GameController { * 1 if version1 is more recent than version2 * -1 otherwise */ - public int compareVersions(String version1, String version2) { + public static int compareVersions(String version1, String version2) { if (!checkVersionString(version1) || !checkVersionString(version2)) { throw new IllegalArgumentException("Version is not valid version string"); } @@ -159,11 +159,11 @@ public class GameController { /** * checks if a provided string matches the format of a version number */ - public boolean checkVersionString(String versionString) { + public static boolean checkVersionString(String versionString) { return versionString != null && versionString.matches("\\d+\\.\\d+\\.\\d+"); } - public void startLocalGame(Class localPlayerClass, Class enemyClass, int size) { + public static void startLocalGame(Class localPlayerClass, String localPlayerName, Class enemyClass, int size) { LocalPlayer localPlayer; AiPlayer aiPlayer; @@ -181,7 +181,7 @@ public class GameController { startGameWithInstancedPlayers(localPlayer, aiPlayer); } - private void startGameWithInstancedPlayers(LocalPlayer p1, Player p2) { + private static void startGameWithInstancedPlayers(LocalPlayer p1, Player p2) { p1.setEnemy(p2); p2.setEnemy(p1);