Skip to content

Commit

Permalink
Player board updates when players leave the game mid match
Browse files Browse the repository at this point in the history
  • Loading branch information
NotVeridion committed Apr 30, 2024
1 parent 7f60aec commit a825799
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 7 deletions.
30 changes: 28 additions & 2 deletions src/main/java/com/cse3310/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,36 @@ public void onOpen(WebSocket conn, ClientHandshake handshake) {

@Override
public void onClose(WebSocket conn, int code, String reason, boolean remote) {
GsonBuilder builder = new GsonBuilder();
Gson gson = builder.create();

int gameid = 0;
PlayerList list = new PlayerList();
for (int i = 0; i < ActiveUsers.size(); i++) {
if (ActiveUsers.get(i).conn == conn) {
// Find game the user is in
for (User user : ActiveUsers) {
if (ActiveUsers.get(i).equals(user)) {
gameid = user.GameId;
}
}

// Fill list with player data from the game (EXCEPT THE USER THAT IS ABOUT TO
// LEAVE)
for (User user : ActiveUsers) {
if (gameid == user.GameId && ActiveUsers.get(i).username != user.username) {
list.players.add(user.username);
list.playerScores.add(user.wordCount);
}
}

// Send completed game list to all users in the specific game
for (User user : ActiveUsers) {
if (gameid == user.GameId && ActiveUsers.get(i).username != user.username) {
String jsonString = gson.toJson(list);
user.conn.send(jsonString);
}
}
System.out.println("removing " + ActiveUsers.get(i).username + " from player and lobby list");
String tempName = ActiveUsers.get(i).username;

Expand All @@ -70,8 +97,7 @@ public void onClose(WebSocket conn, int code, String reason, boolean remote) {
break;
}
}
GsonBuilder builder = new GsonBuilder();
Gson gson = builder.create();

String jsonString = gson.toJson(LobbyUsers);
broadcast(jsonString);

Expand Down
Binary file modified target/classes/com/cse3310/App$LetterTimer.class
Binary file not shown.
Binary file modified target/classes/com/cse3310/App.class
Binary file not shown.
Binary file modified target/cse3310-wordsearch.jar
Binary file not shown.
8 changes: 4 additions & 4 deletions target/surefire-reports/TEST-com.cse3310.AppTest.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<testsuite xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://maven.apache.org/surefire/maven-surefire-plugin/xsd/surefire-test-report.xsd" name="com.cse3310.AppTest" time="0.075" tests="1" errors="0" skipped="0" failures="0">
<testsuite xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://maven.apache.org/surefire/maven-surefire-plugin/xsd/surefire-test-report.xsd" name="com.cse3310.AppTest" time="0.073" tests="1" errors="0" skipped="0" failures="0">
<properties>
<property name="awt.toolkit" value="sun.awt.X11.XToolkit"/>
<property name="exec.mainClass" value="com.cse3310.App"/>
Expand All @@ -15,7 +15,7 @@
<property name="os.name" value="Linux"/>
<property name="sun.java.launcher" value="SUN_STANDARD"/>
<property name="sun.boot.library.path" value="/usr/lib/jvm/java-11-openjdk-amd64/lib"/>
<property name="sun.java.command" value="/mnt/c/Users/verid/OneDrive/Documents/School/Classes/CSE 3310 Software Engineering/cse3310_sp24_group_26/target/surefire/surefirebooter2926720106162734571.jar /mnt/c/Users/verid/OneDrive/Documents/School/Classes/CSE 3310 Software Engineering/cse3310_sp24_group_26/target/surefire 2024-04-30T01-02-06_407-jvmRun1 surefire12121635546516175590tmp surefire_07894670919966874431tmp"/>
<property name="sun.java.command" value="/mnt/c/Users/verid/OneDrive/Documents/School/Classes/CSE 3310 Software Engineering/cse3310_sp24_group_26/target/surefire/surefirebooter17198994968071438429.jar /mnt/c/Users/verid/OneDrive/Documents/School/Classes/CSE 3310 Software Engineering/cse3310_sp24_group_26/target/surefire 2024-04-30T01-25-15_624-jvmRun1 surefire11264865311809913031tmp surefire_017562185712209553174tmp"/>
<property name="jdk.debug" value="release"/>
<property name="surefire.test.class.path" value="/mnt/c/Users/verid/OneDrive/Documents/School/Classes/CSE 3310 Software Engineering/cse3310_sp24_group_26/target/test-classes:/mnt/c/Users/verid/OneDrive/Documents/School/Classes/CSE 3310 Software Engineering/cse3310_sp24_group_26/target/classes:/home/veridion/.m2/repository/junit/junit/4.13.1/junit-4.13.1.jar:/home/veridion/.m2/repository/org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3.jar:/home/veridion/.m2/repository/com/google/code/gson/gson/2.9.1/gson-2.9.1.jar:/home/veridion/.m2/repository/net/freeutils/jlhttp/2.6/jlhttp-2.6.jar:/home/veridion/.m2/repository/org/java-websocket/Java-WebSocket/1.5.4/Java-WebSocket-1.5.4.jar:/home/veridion/.m2/repository/org/slf4j/slf4j-api/2.0.0-alpha0/slf4j-api-2.0.0-alpha0.jar:"/>
<property name="sun.cpu.endian" value="little"/>
Expand All @@ -31,7 +31,7 @@
<property name="java.specification.name" value="Java Platform API Specification"/>
<property name="java.vm.specification.vendor" value="Oracle Corporation"/>
<property name="java.awt.graphicsenv" value="sun.awt.X11GraphicsEnvironment"/>
<property name="surefire.real.class.path" value="/mnt/c/Users/verid/OneDrive/Documents/School/Classes/CSE 3310 Software Engineering/cse3310_sp24_group_26/target/surefire/surefirebooter2926720106162734571.jar"/>
<property name="surefire.real.class.path" value="/mnt/c/Users/verid/OneDrive/Documents/School/Classes/CSE 3310 Software Engineering/cse3310_sp24_group_26/target/surefire/surefirebooter17198994968071438429.jar"/>
<property name="sun.management.compiler" value="HotSpot 64-Bit Tiered Compilers"/>
<property name="java.runtime.version" value="11.0.21+9-post-Ubuntu-0ubuntu122.04"/>
<property name="user.name" value="veridion"/>
Expand All @@ -57,5 +57,5 @@
<property name="sun.io.unicode.encoding" value="UnicodeLittle"/>
<property name="java.class.version" value="55.0"/>
</properties>
<testcase name="shouldAnswerWithTrue" classname="com.cse3310.AppTest" time="0.004"/>
<testcase name="shouldAnswerWithTrue" classname="com.cse3310.AppTest" time="0.005"/>
</testsuite>
2 changes: 1 addition & 1 deletion target/surefire-reports/com.cse3310.AppTest.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
-------------------------------------------------------------------------------
Test set: com.cse3310.AppTest
-------------------------------------------------------------------------------
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.075 s - in com.cse3310.AppTest
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.073 s - in com.cse3310.AppTest

0 comments on commit a825799

Please sign in to comment.