diff --git a/html/index.html b/html/index.html index eb2a94a..9fb4db2 100644 --- a/html/index.html +++ b/html/index.html @@ -114,10 +114,24 @@

Leaderboard

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 attempt= new ArrayList();//series of userevents that make up an attempted word if(U.action==2) { @@ -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()) diff --git a/src/main/java/uta/cse3310/Game.java b/src/main/java/uta/cse3310/Game.java index fb3eecc..8b37f86 100644 --- a/src/main/java/uta/cse3310/Game.java +++ b/src/main/java/uta/cse3310/Game.java @@ -86,7 +86,7 @@ public void addPlayers(Player newPlayer) { } // Method to update game state - public void updateGame(ArrayList attempt) { + public boolean updateGame(ArrayList 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; @@ -104,8 +104,9 @@ public void updateGame(ArrayList 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 @@ -141,16 +142,19 @@ public void exitGame(ArrayList 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" diff --git a/src/test/java/uta/cse3310/gameTest.java b/src/test/java/uta/cse3310/gameTest.java index c4fe749..3ca1d98 100644 --- a/src/test/java/uta/cse3310/gameTest.java +++ b/src/test/java/uta/cse3310/gameTest.java @@ -165,7 +165,7 @@ public void testUpdate() }; - game.updateGame(attempt); + boolean var=game.updateGame(attempt); assertTrue(wordList.size()==5); }