Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
JYNguyen committed Apr 25, 2024
2 parents 0ce82eb + 84e484c commit 7c5ed69
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 7 deletions.
16 changes: 15 additions & 1 deletion html/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,24 @@ <h2>Leaderboard</h2>
if(type==="JoinGame")
{
player= JSON.parse(messageData.player);
game = JSON.parse(messageData.game);
//game = JSON.parse(messageData.game);
gameId= gameId+messageData.gameId;
console.log(gameId);
}
else if(type==="UpdateGame")
{
if(messageData.valid==="true")
{
let U= new UserEvent();
const attemptArr= JSON.parse(messageData.attempt)
for(let i=0;i<attemptArr.length();i++)
{
U =attemptArr[i];
document.getElementById(U.cell.toString()).style.backgroundColor="red";

}
}
}

};

Expand Down
2 changes: 2 additions & 0 deletions src/main/java/uta/cse3310/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,7 @@ public String updateHandler(Gson gson, String message, WebSocket conn)
jsonString="";//if update happens, will become jsonString of updated game
JsonObject jsonObject=new JsonObject();//will be sent to various connections
Game G = null;
boolean valid=false;//will determine if word is valid
ArrayList<UserEvent> attempt= new ArrayList<UserEvent>();//series of userevents that make up an attempted word
if(U.action==2)
{
Expand All @@ -429,6 +430,7 @@ public String updateHandler(Gson gson, String message, WebSocket conn)
jsonObject.addProperty("type","UpdateGame");
jsonObject.addProperty("gameData",jsonString);
jsonObject.addProperty("attempt",attempt.toString());
jsonObject.addProperty("valid",String.valueOf(valid));
conn.send(jsonObject.toString());
//search through the game's player lis
for(Player i:G.getPlayersList())
Expand Down
14 changes: 9 additions & 5 deletions src/main/java/uta/cse3310/Game.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public void addPlayers(Player newPlayer) {
}

// Method to update game state
public void updateGame(ArrayList<UserEvent> attempt) {
public boolean updateGame(ArrayList<UserEvent> attempt) {
// if the first action is a click and the last action was a release
if ((attempt.get(0)).action == 0 && (attempt.get(attempt.size() - 1)).action == 2) {
Player player = (attempt.get(0)).player;
Expand All @@ -104,8 +104,9 @@ public void updateGame(ArrayList<UserEvent> attempt) {
word = word + grid[row][column];
System.out.println(word);
}
wordChosen(word, player);
return wordChosen(word, player);
}
else{return false;}
}

// Method for players to exit game
Expand Down Expand Up @@ -141,16 +142,19 @@ public void exitGame(ArrayList<Player> playersList) {
* and after being revealed, the method will check if there are any
* more remaining words
*/
public void wordChosen(String selectedWord, Player player) {
if (gridField.checkWord(selectedWord) == true) {
public boolean wordChosen(String selectedWord, Player player) {
if (gridField.checkWord(selectedWord) == true)
{
gridField.revealWord(selectedWord);// fully highlights word
player.increaseScore(100 * selectedWord.length());// give player points
if (gridField.getRemainingWords() == 0)// exit game if no words remain
{
exitGame(playersList);
}
return true;
}

else{return false;}

}

// Method to update the game timer"Shot Clock"
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/uta/cse3310/gameTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ public void testUpdate()
};


game.updateGame(attempt);
boolean var=game.updateGame(attempt);
assertTrue(wordList.size()==5);

}
Expand Down

0 comments on commit 7c5ed69

Please sign in to comment.