Skip to content

Commit

Permalink
Merge pull request #50 from utastudents/gameWon
Browse files Browse the repository at this point in the history
Game won
  • Loading branch information
NotVeridion authored Apr 30, 2024
2 parents ce3c9bc + 0de5d6e commit 1caaa82
Show file tree
Hide file tree
Showing 17 changed files with 171 additions and 39 deletions.
58 changes: 25 additions & 33 deletions html/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,7 @@
<div class="collapse navbar-collapse" id="toggleMobileMenu">
<ul class="navbar-nav ms-auto text-end">
<li>
<a class="nav-link" href="#">HOME</a>
</li>
<li>
<a class="nav-link" href="#profile" onclick="showProfile()"> PROFILE</a>
<a class="nav-link" href="#" onclick="location.reload()">HOME</a>
</li>
<li>
<a class="nav-link" href="#contact">SUPPORT</a>
Expand Down Expand Up @@ -150,21 +147,16 @@ <h1>LOBBY</h1>
<div data-aos="fade-up" class="container d-flex justify-content-center flex-column text-center h-auto pb-5 d-none" id="wordBank">
<h1>WORD BANK</h1>
</div>

<div class=" container-fluid custom-body d-none" id="profile">
<div id="home"
class="container-fluid text-center flex-column d-flex justify-content-center align-items-center"
style="height: 100vh;">
<h1 style="font-size: 5vw;">PROFILE</h1>
<h2 id="profile_username"> USERNAME: </h2>
<h3 id="profile_games_won">GAMES WON: </h3>
<h3 id="profile_games_lost">GAMES LOST: </h3>
<a class="btn btn-primary justify-content-center btn-lg active" onclick="hideProfile()"
role="button" aria-pressed="true">HIDE</a>
</div>
<div class=" container-fluid custom-body d-none" id="winScreen">
<div class="container-fluid text-center flex-column d-flex justify-content-center align-items-center"
style="height: 100vh;">
<h1 style="font-size: 5vw;">GAME WON</h1>
<h3 id="win_username"> USERNAME </h3>
<h3 id="win_score"> SCORE </h3>
<a class="btn btn-primary justify-content-center btn-lg active" onclick="hideWin()"
role="button" aria-pressed="true">HOME</a>
</div>

</div>
</div>

<section data-aos="fade-up" id="contact">
<div class="container-fluid custom-footer">
Expand Down Expand Up @@ -245,6 +237,17 @@ <h3 id="profile_games_lost">GAMES LOST: </h3>

let obj = JSON.parse(msg);

if('won' in obj){ // User in the game won
document.getElementById("game").classList.add("d-none");
document.getElementById("wordBank").classList.add("d-none");

const winScreen = document.getElementById("winScreen");
winScreen.classList.remove("d-none");

document.getElementById("win_username").textContent = "WINNER: " + obj.winner;
document.getElementById("win_score").textContent = "SCORE: " + obj.score;
}

if('version' in obj){
console.log("version received: " + obj.version);
const title = document.getElementById("title");
Expand Down Expand Up @@ -505,6 +508,10 @@ <h3 id="profile_games_lost">GAMES LOST: </h3>
}
}

function hideWin(){
location.reload();
}

function startMatchmaking() {
U = new UserEvent;
U.request = 5;
Expand All @@ -519,21 +526,6 @@ <h3 id="profile_games_lost">GAMES LOST: </h3>
U.UserId = this.UserId;
connection.send(JSON.stringify(U));
}

function showProfile() {
// Show profile elements
document.getElementById("profile").classList.remove("d-none");
document.getElementById("profile_username").innerText = "USERNAME: " + UserId.toUpperCase();
document.getElementById("profile_games_won").innerText = "GAMES WON: " + gamesWon;
document.getElementById("profile_games_lost").innerText = "GAMES LOST: " + gamesLost;

}

function hideProfile() {
// Hide profile elements
document.getElementById("profile").classList.add("d-none");
}

</script>

<script>
Expand Down
55 changes: 54 additions & 1 deletion src/main/java/com/cse3310/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,6 @@ public void onMessage(WebSocket conn, String message) {
int id = U.buttonId;
int userIndex = 0;
int gameid = 0;

for (User user : ActiveUsers) {
if (U.UserId.equals(user.username)) {
gameid = user.GameId;
Expand Down Expand Up @@ -261,6 +260,12 @@ public void onMessage(WebSocket conn, String message) {
}
}

User possibleWinner = findWinner(gameid);
if (possibleWinner != null) { // Winner found
gameWon(possibleWinner);
return;
}

UserEvent e = new UserEvent();
e.buttonId = U.buttonId;
e.UserId = U.UserId;
Expand Down Expand Up @@ -349,6 +354,54 @@ public void onMessage(WebSocket conn, String message) {
}
}

public User findWinner(int GameId) {
int totalWordCount = 0;
Game g = ActiveGames.get(GameId);
int most = 0;
User winner = new User();

for (User u : ActiveUsers) {
if (GameId == u.GameId) {
if (u.wordCount > most) {
most = u.wordCount; // Track user with highest score
winner = u;
}

totalWordCount += u.wordCount;
}
}

System.out.println("Total word count: " + totalWordCount);
System.out.println("Word bank size: " + g.wordBank.size());
if (totalWordCount == g.wordBank.size()) {
return winner;
}

return null;
}

public void gameWon(User winner) {
GsonBuilder builder = new GsonBuilder();
Gson gson = builder.create();
ArrayList<User> disconnectUsers = new ArrayList<>();

int wonGameId = winner.GameId;

for (User u : ActiveUsers) {
if (u.GameId == wonGameId) {
Winner e = new Winner(winner);
String jsonString = gson.toJson(e);
u.conn.send(jsonString);

disconnectUsers.add(u);
}
}

for (User u : disconnectUsers) {
ActiveUsers.remove(u);
}
}

public void forceDisconnect(int GameId) {
ArrayList<User> disconnectUsers = new ArrayList<>();
for (User u : ActiveUsers) {
Expand Down
13 changes: 13 additions & 0 deletions src/main/java/com/cse3310/Winner.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.cse3310;

public class Winner {
int won;
String winner;
int score;

public Winner(User u) {
this.won = 1;
this.winner = u.username;
this.score = u.wordCount;
}
}
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 added target/classes/com/cse3310/Winner.class
Binary file not shown.
Binary file modified target/cse3310-wordsearch.jar
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ com/cse3310/Lobby.class
com/cse3310/timerEvent.class
com/cse3310/App$LetterTimer.class
com/cse3310/Game.class
com/cse3310/Winner.class
com/cse3310/Error.class
com/cse3310/ServerEvent.class
com/cse3310/HttpServer$1.class
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/mnt/c/Users/verid/OneDrive/Documents/School/Classes/CSE 3310 Software Engineering/cse3310_sp24_group_26/src/main/java/com/cse3310/ServerEvent.java
/mnt/c/Users/verid/OneDrive/Documents/School/Classes/CSE 3310 Software Engineering/cse3310_sp24_group_26/src/main/java/com/cse3310/Winner.java
/mnt/c/Users/verid/OneDrive/Documents/School/Classes/CSE 3310 Software Engineering/cse3310_sp24_group_26/src/main/java/com/cse3310/User.java
/mnt/c/Users/verid/OneDrive/Documents/School/Classes/CSE 3310 Software Engineering/cse3310_sp24_group_26/src/main/java/com/cse3310/PlayerList.java
/mnt/c/Users/verid/OneDrive/Documents/School/Classes/CSE 3310 Software Engineering/cse3310_sp24_group_26/src/main/java/com/cse3310/Version.java
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
com/cse3310/UserTest.class
com/cse3310/AppTest.class
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
/mnt/c/Users/verid/OneDrive/Documents/School/Classes/CSE 3310 Software Engineering/cse3310_sp24_group_26/src/test/java/com/cse3310/UserTest.java
/mnt/c/Users/verid/OneDrive/Documents/School/Classes/CSE 3310 Software Engineering/cse3310_sp24_group_26/src/test/java/com/cse3310/AppTest.java
12 changes: 8 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.121" 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.503" tests="5" 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/surefirebooter1813527150047078735.jar /mnt/c/Users/verid/OneDrive/Documents/School/Classes/CSE 3310 Software Engineering/cse3310_sp24_group_26/target/surefire 2024-04-30T12-51-39_211-jvmRun1 surefire5735059962496457876tmp surefire_015259733093050081870tmp"/>
<property name="sun.java.command" value="/mnt/c/Users/verid/OneDrive/Documents/School/Classes/CSE 3310 Software Engineering/cse3310_sp24_group_26/target/surefire/surefirebooter1265698555585075939.jar /mnt/c/Users/verid/OneDrive/Documents/School/Classes/CSE 3310 Software Engineering/cse3310_sp24_group_26/target/surefire 2024-04-30T17-05-53_897-jvmRun1 surefire12147627652851137436tmp surefire_011632373026406175695tmp"/>
<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/surefirebooter1813527150047078735.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/surefirebooter1265698555585075939.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,9 @@
<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.005"/>
<testcase name="testGenerateGrid" classname="com.cse3310.AppTest" time="0.293"/>
<testcase name="testApp" classname="com.cse3310.AppTest" time="0"/>
<testcase name="testGame" classname="com.cse3310.AppTest" time="0"/>
<testcase name="testGetCompletedButtons" classname="com.cse3310.AppTest" time="0.09"/>
<testcase name="testEndIdCase" classname="com.cse3310.AppTest" time="0.084"/>
</testsuite>
62 changes: 62 additions & 0 deletions target/surefire-reports/TEST-com.cse3310.UserTest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?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.UserTest" time="0.002" tests="2" errors="0" skipped="0" failures="0">
<properties>
<property name="awt.toolkit" value="sun.awt.X11.XToolkit"/>
<property name="exec.mainClass" value="com.cse3310.App"/>
<property name="java.specification.version" value="11"/>
<property name="sun.cpu.isalist" value=""/>
<property name="sun.jnu.encoding" value="UTF-8"/>
<property name="java.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="java.vm.vendor" value="Ubuntu"/>
<property name="sun.arch.data.model" value="64"/>
<property name="java.vendor.url" value="https://ubuntu.com/"/>
<property name="user.timezone" value=""/>
<property name="java.vm.specification.version" value="11"/>
<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/surefirebooter1265698555585075939.jar /mnt/c/Users/verid/OneDrive/Documents/School/Classes/CSE 3310 Software Engineering/cse3310_sp24_group_26/target/surefire 2024-04-30T17-05-53_897-jvmRun1 surefire12147627652851137436tmp surefire_011632373026406175695tmp"/>
<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"/>
<property name="user.home" value="/home/veridion"/>
<property name="user.language" value="en"/>
<property name="java.specification.vendor" value="Oracle Corporation"/>
<property name="java.version.date" value="2023-10-17"/>
<property name="java.home" value="/usr/lib/jvm/java-11-openjdk-amd64"/>
<property name="file.separator" value="/"/>
<property name="basedir" value="/mnt/c/Users/verid/OneDrive/Documents/School/Classes/CSE 3310 Software Engineering/cse3310_sp24_group_26"/>
<property name="java.vm.compressedOopsMode" value="Zero based"/>
<property name="line.separator" value="&#10;"/>
<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/surefirebooter1265698555585075939.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"/>
<property name="path.separator" value=":"/>
<property name="os.version" value="4.4.0-19041-Microsoft"/>
<property name="java.runtime.name" value="OpenJDK Runtime Environment"/>
<property name="file.encoding" value="UTF-8"/>
<property name="java.vm.name" value="OpenJDK 64-Bit Server VM"/>
<property name="localRepository" value="/home/veridion/.m2/repository"/>
<property name="java.vendor.url.bug" value="https://bugs.launchpad.net/ubuntu/+source/openjdk-lts"/>
<property name="java.io.tmpdir" value="/tmp"/>
<property name="java.version" value="11.0.21"/>
<property name="user.dir" value="/mnt/c/Users/verid/OneDrive/Documents/School/Classes/CSE 3310 Software Engineering/cse3310_sp24_group_26"/>
<property name="os.arch" value="amd64"/>
<property name="java.vm.specification.name" value="Java Virtual Machine Specification"/>
<property name="java.awt.printerjob" value="sun.print.PSPrinterJob"/>
<property name="sun.os.patch.level" value="unknown"/>
<property name="java.library.path" value="/usr/java/packages/lib:/usr/lib/x86_64-linux-gnu/jni:/lib/x86_64-linux-gnu:/usr/lib/x86_64-linux-gnu:/usr/lib/jni:/lib:/usr/lib"/>
<property name="java.vm.info" value="mixed mode, sharing"/>
<property name="java.vendor" value="Ubuntu"/>
<property name="java.vm.version" value="11.0.21+9-post-Ubuntu-0ubuntu122.04"/>
<property name="java.specification.maintenance.version" value="2"/>
<property name="sun.io.unicode.encoding" value="UnicodeLittle"/>
<property name="java.class.version" value="55.0"/>
</properties>
<testcase name="testForDuplicateUsernames" classname="com.cse3310.UserTest" time="0"/>
<testcase name="addFourToScoreAndWins" classname="com.cse3310.UserTest" time="0"/>
</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.121 s - in com.cse3310.AppTest
Tests run: 5, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.503 s - in com.cse3310.AppTest
4 changes: 4 additions & 0 deletions target/surefire-reports/com.cse3310.UserTest.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
-------------------------------------------------------------------------------
Test set: com.cse3310.UserTest
-------------------------------------------------------------------------------
Tests run: 2, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.002 s - in com.cse3310.UserTest
Binary file modified target/test-classes/com/cse3310/AppTest.class
Binary file not shown.
Binary file added target/test-classes/com/cse3310/UserTest.class
Binary file not shown.

0 comments on commit 1caaa82

Please sign in to comment.