diff --git a/pom.xml b/pom.xml index 7fc12f9..13af6e0 100644 --- a/pom.xml +++ b/pom.xml @@ -9,7 +9,7 @@ 1.0-SNAPSHOT TurnOfDestiny - A webserver based word game. + A word game. https://example.com @@ -19,6 +19,7 @@ + org.java-websocket Java-WebSocket @@ -43,7 +44,6 @@ 20210307 - org.junit.jupiter junit-jupiter-api @@ -51,7 +51,6 @@ test - org.junit.jupiter junit-jupiter-engine @@ -59,20 +58,24 @@ test - org.mockito mockito-core 4.5.1 test - org.mockito mockito-junit-jupiter 4.5.1 test + + + org.slf4j + slf4j-simple + 1.7.32 + diff --git a/src/main/java/uta/cse3310/App.java b/src/main/java/uta/cse3310/App.java index 42b1755..b836bd3 100644 --- a/src/main/java/uta/cse3310/App.java +++ b/src/main/java/uta/cse3310/App.java @@ -1,4 +1,3 @@ -//App.java starts the HTTP and WebSocket servers. package uta.cse3310; import org.java_websocket.server.WebSocketServer; @@ -7,54 +6,55 @@ import java.net.InetSocketAddress; public class App { - public static void main(String[] args) { - String httpPortStr = System.getenv("HTTP_PORT"); - int httpPort = (httpPortStr != null) ? Integer.parseInt(httpPortStr) : 9002; - -String wsPortStr = System.getenv("WEBSOCKET_PORT"); - int websocketPort = (wsPortStr != null) ? Integer.parseInt(wsPortStr) : 9102; - -String htmlDir = "src/main/resources"; - -HttpServer httpServer = new HttpServer(httpPort, htmlDir); -httpServer.start(); - -GameServer gameServer = new GameServer(httpPort, websocketPort); - -WebSocketServer webSocketServer = new WebSocketServer(new InetSocketAddress(websocketPort)) { -@Override - public void onOpen(WebSocket conn, ClientHandshake handshake) { - System.out.println("New connection from " + conn.getRemoteSocketAddress().getAddress().getHostAddress()); - gameServer.getWebsocket().onOpen(conn, handshake); + public static void main(String[] args) { + String httpPortStr = System.getenv("HTTP_PORT"); + int httpPort = (httpPortStr != null) ? Integer.parseInt(httpPortStr) : 9002; + + String wsPortStr = System.getenv("WEBSOCKET_PORT"); + int websocketPort = (wsPortStr != null) ? Integer.parseInt(wsPortStr) : 9102; + + String htmlDir = "src/main/resources"; + + HttpServer httpServer = new HttpServer(httpPort, htmlDir); + httpServer.start(); + + GameServer gameServer = new GameServer(httpPort, websocketPort); + + WebSocketServer webSocketServer = new WebSocketServer(new InetSocketAddress(websocketPort)) { + @Override + public void onOpen(WebSocket conn, ClientHandshake handshake) { + System.out.println("New connection from " + conn.getRemoteSocketAddress().getAddress().getHostAddress()); + gameServer.getWebsocket().onOpen(conn, handshake); + } + + @Override + public void onClose(WebSocket conn, int code, String reason, boolean remote) { + System.out.println("Closed connection to " + conn.getRemoteSocketAddress().getAddress().getHostAddress()); + gameServer.getWebsocket().onClose(conn, code, reason, remote); + } + + @Override + public void onMessage(WebSocket conn, String message) { + gameServer.getWebsocket().onMessage(conn, message); + } + + @Override + public void onError(WebSocket conn, Exception ex) { + System.err.println("Error occurred on connection " + conn); + ex.printStackTrace(); + gameServer.getWebsocket().onError(conn, ex); + } + + @Override + public void onStart() { + System.out.println("WebSocket server started on port: " + websocketPort); + } + }; + + webSocketServer.start(); + gameServer.start(); + + System.out.println("HTTP server started on port " + httpPort); + System.out.println("WebSocket server started on port " + websocketPort); + } } - -@Override -public void onClose(WebSocket conn, int code, String reason, boolean remote) { - System.out.println("Closed connection to " + conn.getRemoteSocketAddress().getAddress().getHostAddress()); -gameServer.getWebsocket().onClose(conn, code, reason, remote); -} -@Override -public void onMessage(WebSocket conn, String message) { - gameServer.getWebsocket().onMessage(conn, message); -} - -@Override -public void onError(WebSocket conn, Exception ex) { - System.err.println("Error occurred on connection " + conn); - ex.printStackTrace(); - gameServer.getWebsocket().onError(conn, ex); - } - -@Override -public void onStart() { -System.out.println("WebSocket server started on port: " + websocketPort); - } - }; - - webSocketServer.start(); - gameServer.start(); - - System.out.println("HTTP server started on port " + httpPort); -System.out.println("WebSocket server started on port " + websocketPort); - } -} \ No newline at end of file diff --git a/src/main/java/uta/cse3310/GameServer.java b/src/main/java/uta/cse3310/GameServer.java index bb300b8..fe41cd0 100644 --- a/src/main/java/uta/cse3310/GameServer.java +++ b/src/main/java/uta/cse3310/GameServer.java @@ -19,6 +19,7 @@ public GameServer(int httpPort, int wsPort) { this.httpPort = httpPort; this.wsPort = wsPort; this.lobbies = new HashMap<>(); + this.scoreboard = new Scoreboard(); // Initialize scoreboard this.websocket = new Websocket(wsPort, this); } diff --git a/src/main/java/uta/cse3310/WordPuzzle.java b/src/main/java/uta/cse3310/WordPuzzle.java index 3284c04..1ec50fc 100644 --- a/src/main/java/uta/cse3310/WordPuzzle.java +++ b/src/main/java/uta/cse3310/WordPuzzle.java @@ -14,11 +14,11 @@ public class WordPuzzle { private String displayedPuzzle; private String currentPuzzle; - public WordPuzzle() { - words = new ArrayList<>(); -displayedPuzzle = ""; - currentPuzzle = ""; -loadWords(getWordSource()); + public WordPuzzle() { + words = new ArrayList<>(); + displayedPuzzle = ""; + currentPuzzle = ""; + loadWords(getWordSource()); } private String getWordSource() { diff --git a/src/main/resources/index.html b/src/main/resources/index.html index 5f416a3..e415393 100644 --- a/src/main/resources/index.html +++ b/src/main/resources/index.html @@ -253,4 +253,4 @@

Available Lobbies:

- } \ No newline at end of file +