Skip to content

Commit

Permalink
Updated comp error on methods tested and fixed typos
Browse files Browse the repository at this point in the history
  • Loading branch information
chriscod3 committed Aug 1, 2024
1 parent 79a4b87 commit 413b3bf
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 62 deletions.
13 changes: 8 additions & 5 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<version>1.0-SNAPSHOT</version>

<name>TurnOfDestiny</name>
<description>A webserver based word game.</description>
<description>A word game.</description>
<url>https://example.com</url>

<properties>
Expand All @@ -19,6 +19,7 @@
</properties>

<dependencies>

<dependency>
<groupId>org.java-websocket</groupId>
<artifactId>Java-WebSocket</artifactId>
Expand All @@ -43,36 +44,38 @@
<version>20210307</version>
</dependency>


<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.9.0</version>
<scope>test</scope>
</dependency>


<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.9.0</version>
<scope>test</scope>
</dependency>


<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>4.5.1</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-junit-jupiter</artifactId>
<version>4.5.1</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.7.32</version>
</dependency>
</dependencies>

<build>
Expand Down
102 changes: 51 additions & 51 deletions src/main/java/uta/cse3310/App.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
//App.java starts the HTTP and WebSocket servers.
package uta.cse3310;

import org.java_websocket.server.WebSocketServer;
Expand All @@ -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);
}
}
1 change: 1 addition & 0 deletions src/main/java/uta/cse3310/GameServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
10 changes: 5 additions & 5 deletions src/main/java/uta/cse3310/WordPuzzle.java
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -253,4 +253,4 @@ <h3>Available Lobbies:</h3>

</body>

</html> }
</html>

0 comments on commit 413b3bf

Please sign in to comment.