From 241cb6bdae36121ea6159750ee16df98896c85ce Mon Sep 17 00:00:00 2001 From: Charles Gould Date: Sat, 11 Feb 2017 18:18:44 -0500 Subject: [PATCH] Remove (currently unnecessary) game started event --- .../java/lingo/client/api/Destinations.java | 2 -- .../java/lingo/server/LingoController.java | 2 +- server/src/main/resources/static/client.js | 21 ++++++------------- 3 files changed, 7 insertions(+), 18 deletions(-) diff --git a/client-api/src/main/java/lingo/client/api/Destinations.java b/client-api/src/main/java/lingo/client/api/Destinations.java index e96ff96..a3d5594 100644 --- a/client-api/src/main/java/lingo/client/api/Destinations.java +++ b/client-api/src/main/java/lingo/client/api/Destinations.java @@ -12,8 +12,6 @@ public class Destinations { public static final String GAME_LEFT = topicDestination("gameLeft"); - public static final String GAME_STARTED = topicDestination("gameStarted"); - public static final String OPPONENT_JOINED = topicDestination("opponentJoined"); public static final String OPPONENT_REPORTS = topicDestination("opponentReports"); diff --git a/server/src/main/java/lingo/server/LingoController.java b/server/src/main/java/lingo/server/LingoController.java index a422c24..26eb854 100644 --- a/server/src/main/java/lingo/server/LingoController.java +++ b/server/src/main/java/lingo/server/LingoController.java @@ -154,6 +154,7 @@ public class LingoController { // TODO: require the players to "ready up" game.setAcceptableGuesses(wordRepo.getGuesses()); game.setPossibleWords(wordRepo.getWords()); + final String firstWord = game.newGame(); final String firstLetter = String.valueOf(firstWord.charAt(0)); log.info("First word: {}", firstWord); @@ -163,7 +164,6 @@ public class LingoController { final String[] playerTwoMessage = new String[] { firstLetter, playerOne.getUsername() }; sendToPlayer(playerOne, Destinations.OPPONENT_JOINED, playerOneMessage); sendToPlayer(playerTwo, Destinations.OPPONENT_JOINED, playerTwoMessage); - send(Destinations.GAME_STARTED, new String[] { playerOne.getUsername(), playerTwo.getUsername() }); } } diff --git a/server/src/main/resources/static/client.js b/server/src/main/resources/static/client.js index 9428615..1e25a22 100644 --- a/server/src/main/resources/static/client.js +++ b/server/src/main/resources/static/client.js @@ -343,7 +343,6 @@ function start() { client.subscribe('/topic/gameHosted', onGameHosted); client.subscribe('/topic/gameJoined', onGameJoined); client.subscribe('/topic/gameLeft', onGameLeft); - client.subscribe('/topic/gameStarted', onGameStarted); client.subscribe('/user/topic/opponentJoined', onOpponentJoined); client.subscribe('/user/topic/opponentLeft', onOpponentLeft); client.subscribe('/user/topic/opponentReports', onOpponentReport); @@ -441,7 +440,11 @@ function onGameJoined(message) { var gameId = game.id; var playerOne = game.playerOne.username; var playerTwo = game.playerTwo.username; - console.log(playerTwo + ' joined ' + playerOne + "'s game"); + + var message = playerTwo + ' joined ' + playerOne + "'s game" + console.log(message); + addChatAnnouncement(message); + for (var i = 0; i < vm.games.length; i++) { if (vm.games[i].id === gameId) { vm.games[i].playerTwo = playerTwo; @@ -449,6 +452,7 @@ function onGameJoined(message) { break; } } + if (playerTwo === vm.username) { vm.gameId = gameId; } @@ -480,19 +484,6 @@ function onGameLeft(message) { } } -function onGameStarted(message) { - var report = JSON.parse(message.body); - var playerOne = report[0]; - var playerTwo = report[1]; - if (playerOne === vm.username) { - addChatAnnouncement('You are playing with ' + playerTwo); - } else if (playerTwo === vm.username) { - addChatAnnouncement('You are playing with ' + playerOne); - } else { - addChatAnnouncement(playerOne + ' is playing with ' + playerTwo); - } -} - function onOpponentJoined(message) { var report = JSON.parse(message.body); var firstLetter = report[0];